Skip to content
Snippets Groups Projects
Commit 8552a7d3 authored by Simon Barner's avatar Simon Barner
Browse files

- Ensure that in each session, the hint how to create new connections is...

- Ensure that in each session, the hint how to create new connections is displayed until the user has managed to create three of them.
- (Side note): The current implementation cannot distinguish connections created interactively by the user, and connections created by a model-transformations. However, we can assume that a user who is able to issue a model-transformation also knows how to create a channel in the GUI.
refs 2229
parent d801e7e6
No related branches found
No related tags found
No related merge requests found
......@@ -42,7 +42,11 @@ import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.eclipse.gef.EditDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;
......@@ -86,6 +90,7 @@ import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.ui.dnd.gef.ElementCompositionDropTargetListener;
......@@ -135,13 +140,52 @@ public class DiagramEditorBase<T extends EObject> extends GEFEditorBase<T> imple
/** A container for editor actions. */
private final ActionRegistry actionRegistry = new ActionRegistry();
/**
* Number of {@link IConnection}s to be created until the respective hint how to
* create connections using the GUI is hidden.
*/
private static int numberOfConnectionsToBeCreatedUntilCreationHintIsHidden = 3;
/**
* Adapter to watch for added {@link IConnection}s (used to update
* {@link #numberOfConnectionsToBeCreatedUntilCreationHintIsHidden}).
*/
private static final Adapter addConnectionAdapter = new EContentAdapter() {
@Override
public void notifyChanged(Notification notification) {
super.notifyChanged(notification);
int eventType = notification.getEventType();
if(eventType == Notification.REMOVING_ADAPTER) {
return;
}
// Only count the notification by the IHierarchicElement owning the new IConnection
Object newValue = notification.getNewValue();
if(eventType == Notification.ADD && newValue instanceof IConnection &&
notification.getNotifier() == ((EObject)newValue).eContainer()) {
if(numberOfConnectionsToBeCreatedUntilCreationHintIsHidden > 0) {
numberOfConnectionsToBeCreatedUntilCreationHintIsHidden--;
} else if(numberOfConnectionsToBeCreatedUntilCreationHintIsHidden <= 0) {
// Hints will no longer be displayed: remove adapter
EObject rootObj = (EObject)notification.getNotifier();
while(rootObj.eContainer() != null) {
rootObj = rootObj.eContainer();
}
rootObj.eAdapters().remove(addConnectionAdapter);
for(TreeIterator<EObject> iter = rootObj.eAllContents(); iter.hasNext();) {
EObject obj = iter.next();
obj.eAdapters().remove(addConnectionAdapter);
}
}
}
}
};
/** Selection listener used to update selection actions. */
private final ISelectionListener selectionListener = new ISelectionListener() {
/** A counter for the selection. */
private int selectionCount = 0;
/** The number of times the hints about creating connections should be displayed. */
private final int HINTS_COUNT = 2;
/** {@inheritDoc} */
@Override
......@@ -149,16 +193,18 @@ public class DiagramEditorBase<T extends EObject> extends GEFEditorBase<T> imple
EditPart ep = SelectionUtils.checkAndPickFirstSafe(selection, EditPart.class);
if(ep != null) {
Control control = ep.getViewer().getControl();
if(ep.getModel() instanceof IConnector && selectionCount < HINTS_COUNT) {
control.setToolTipText("Link two connectors by pressing ALT and dragging from source to target.");
selectionCount++;
} else if(ep.getModel() instanceof IHierarchicElement &&
selectionCount < HINTS_COUNT) {
control.setToolTipText("Create a connection by pressing ALT and dragging.");
selectionCount++;
} else {
control.setToolTipText("");
Object model = ep.getModel();
String hint = "";
if(numberOfConnectionsToBeCreatedUntilCreationHintIsHidden > 0) {
if(model instanceof IConnector) {
hint =
"Link two connectors by pressing ALT and dragging from source to target.";
} else if(model instanceof IHierarchicElement) {
hint = "Create a connection by pressing ALT and dragging.";
}
}
control.setToolTipText(hint);
}
updateActions(selectionActions);
}
......@@ -172,6 +218,18 @@ public class DiagramEditorBase<T extends EObject> extends GEFEditorBase<T> imple
getSite().getWorkbenchWindow().getSelectionService()
.addSelectionListener(selectionListener);
// Install adapter to top-most object to watch for addition of IConnections.
if(numberOfConnectionsToBeCreatedUntilCreationHintIsHidden > 0) {
EObject model = getEditedObject();
EObject obj = model;
while(obj != null) {
obj = obj.eContainer();
}
if(!model.eAdapters().contains(addConnectionAdapter)) {
model.eAdapters().add(addConnectionAdapter);
}
}
}
/** {@inheritDoc} */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment