Skip to content
Snippets Groups Projects
Commit d8708134 authored by Vincent Aravantinos's avatar Vincent Aravantinos
Browse files

n-th attempt to display in a relevant manner the hint on connecting diagram elements

refs 2334
parent c8a6061e
No related branches found
No related tags found
No related merge requests found
......@@ -38,6 +38,7 @@ import java.util.List;
import java.util.Set;
import org.conqat.ide.commons.ui.selection.SelectionUtils;
import org.eclipse.core.runtime.Platform;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
......@@ -116,7 +117,7 @@ import org.fortiss.tooling.kernel.ui.service.IEditPartFactoryService;
* @author hoelzl
* @author $Author: aravantinos $
* @version $Rev: 13954 $
* @ConQAT.Rating YELLOW Hash: 12D04B9F7350EF3487A8E98778EE8424
* @ConQAT.Rating YELLOW Hash: A015DFFF58B1950E95D81CE8D7E39435
*/
abstract class CommonDiagramEditorBase<T extends EObject> extends GEFEditorBase<T> implements
IPostSelectionProvider, ContextMenuContextProvider {
......@@ -143,10 +144,15 @@ abstract class CommonDiagramEditorBase<T extends EObject> extends GEFEditorBase<
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.
* Number of times the hint was displayed until we assume the user knows how to draw a
* connection.
*/
private static int numberOfConnectionsToBeCreatedUntilCreationHintIsHidden = 3;
private static int numberOfHintDisplays = 1;
/** Returns numberOfHintDisplays *and decrements it*. */
private static boolean shouldDisplayHint() {
return numberOfHintDisplays-- >= 0;
}
/** Constructor. */
public CommonDiagramEditorBase(GraphicalViewer viewer, EditPartFactory factory) {
......@@ -155,8 +161,8 @@ abstract class CommonDiagramEditorBase<T extends EObject> extends GEFEditorBase<
}
/**
* Adapter to watch for added {@link IConnection}s (used to update
* {@link #numberOfConnectionsToBeCreatedUntilCreationHintIsHidden}).
* Adapter to watch for added {@link IConnection}s (used to update {@link #numberOfHintDisplays}
* ).
*/
private static final Adapter addConnectionAdapter = new EContentAdapter() {
@Override
......@@ -173,10 +179,7 @@ abstract class CommonDiagramEditorBase<T extends EObject> extends GEFEditorBase<
Object newValue = notification.getNewValue();
if(eventType == Notification.ADD && newValue instanceof IConnection &&
notification.getNotifier() == ((EObject)newValue).eContainer()) {
if(numberOfConnectionsToBeCreatedUntilCreationHintIsHidden > 0) {
numberOfConnectionsToBeCreatedUntilCreationHintIsHidden--;
} else if(numberOfConnectionsToBeCreatedUntilCreationHintIsHidden <= 0) {
if(!shouldDisplayHint()) {
// Hints will no longer be displayed: remove adapter
EObject rootObj = (EObject)notification.getNotifier();
while(rootObj.eContainer() != null) {
......@@ -204,13 +207,16 @@ abstract class CommonDiagramEditorBase<T extends EObject> extends GEFEditorBase<
Object model = ep.getModel();
String hint = "";
if(numberOfConnectionsToBeCreatedUntilCreationHintIsHidden > 0) {
if(shouldDisplayHint()) {
String key = Platform.getOS().equals(Platform.OS_LINUX) ? "Ctrl" : "Alt";
String commonStr = " by pressing " + key + " and dragging";
if(model instanceof IConnector) {
hint =
"Link two connectors by pressing ALT and dragging from source to target.";
hint = "Link two connectors" + commonStr + "from source to target";
} else if(model instanceof IHierarchicElement) {
hint = "Create a connection by pressing ALT and dragging.";
hint = "Create a connection" + commonStr;
}
hint +=
" (select anything on the diagram to prevent further display of this message).";
}
control.setToolTipText(hint);
}
......@@ -227,7 +233,7 @@ abstract class CommonDiagramEditorBase<T extends EObject> extends GEFEditorBase<
.addSelectionListener(selectionListener);
// Install adapter to top-most object to watch for addition of IConnections.
if(numberOfConnectionsToBeCreatedUntilCreationHintIsHidden > 0) {
if(shouldDisplayHint()) {
EObject model = getEditedObject();
EObject obj = model;
while(obj != null) {
......
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