瀏覽代碼

Moved listener code pertaining to the workbench from help policy to the main statechart editor class. Added context sensitive help to those EditParts featuring expression properties. Updated help context ids.

essermar@googlemail.com 14 年之前
父節點
當前提交
10df8accd6

+ 2 - 1
plugins/org.yakindu.sct.ui.editor/META-INF/MANIFEST.MF

@@ -38,7 +38,8 @@ Require-Bundle: org.eclipse.core.runtime,
  de.itemis.xtext.utils.gmf;bundle-version="[1.0.0,2.0.0)",
  de.itemis.xtext.utils.jface;bundle-version="[1.0.0,2.0.0)",
  de.itemis.gmf.runtime.commons;bundle-version="1.0.0",
- org.eclipse.gmf.runtime.notation.providers;bundle-version="1.3.0"
+ org.eclipse.gmf.runtime.notation.providers;bundle-version="1.3.0",
+ org.eclipse.help;bundle-version="3.5.100"
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Export-Package: org.yakindu.sct.ui.editor,

+ 135 - 6
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editor/StatechartDiagramEditor.java

@@ -16,33 +16,47 @@ import org.eclipse.emf.transaction.ResourceSetListenerImpl;
 import org.eclipse.gmf.runtime.common.ui.services.marker.MarkerNavigationService;
 import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
 import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
+import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPartReference;
+import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.ide.IGotoMarker;
 import org.yakindu.sct.ui.editor.DiagramActivator;
+import org.yakindu.sct.ui.editor.utils.IYakinduSctHelpContextIds;
 import org.yakindu.sct.ui.editor.validation.ValidationAction;
 
 /**
  * 
  * @author andreas muelder
- * 
+ * @author martin esser
  */
 public class StatechartDiagramEditor extends DiagramDocumentEditor implements
 		IGotoMarker {
 
 	public static final String ID = "org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor";
 
+	// Duplicate of the internal constant used to register the help view as a UI
+	// extension.
+	// @see org.eclipse.help.ui.internalDefaulHelptUI#HELP_VIEW_ID
+	private final static String HELP_VIEW_ID = "org.eclipse.help.ui.HelpView";
+
+	// Declared static to prevent problems in case of an access attempt on
+	// startup
+	private static boolean dynamicHelpViewShowing = false;
+
+	private IPartListener2 dynamicHelpViewListener;
+
 	public StatechartDiagramEditor() {
 		super(true);
 	}
 
-	@Override
-	public String getContributorId() {
-		return ID;
-	}
-
 	@Override
 	public void init(IEditorSite site, IEditorInput input)
 			throws PartInitException {
@@ -63,6 +77,19 @@ public class StatechartDiagramEditor extends DiagramDocumentEditor implements
 
 					}
 				});
+
+		// Create the help view listener and register it with the workbench
+		Display.getCurrent().asyncExec(new Runnable() {
+			public void run() {
+				createDynamicHelpViewListener();
+				PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+						.getPartService()
+						.addPartListener(dynamicHelpViewListener);
+				// Listener may have missed view opening
+				dynamicHelpViewShowing = askWorkbenchIfDynamicHelpViewShowing();
+			}
+		});
+
 	}
 
 	public void gotoMarker(IMarker marker) {
@@ -73,4 +100,106 @@ public class StatechartDiagramEditor extends DiagramDocumentEditor implements
 	protected PreferencesHint getPreferencesHint() {
 		return DiagramActivator.DIAGRAM_PREFERENCES_HINT;
 	}
+
+	@Override
+	protected void createGraphicalViewer(Composite parent) {
+		super.createGraphicalViewer(parent);
+		// Tag the viewer with the desired help context id
+		PlatformUI
+				.getWorkbench()
+				.getHelpSystem()
+				.setHelp(getGraphicalViewer().getControl(),
+						IYakinduSctHelpContextIds.SC_EDITOR_GRAPHICAL_VIEWER); // /CHANGE
+																				// ID!!!
+	}
+
+	@Override
+	public void dispose() {
+		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService()
+				.removePartListener(dynamicHelpViewListener);
+		super.dispose();
+	}
+
+	private void createDynamicHelpViewListener() {
+		dynamicHelpViewListener = new IPartListener2() {
+
+			public void partOpened(IWorkbenchPartReference partRef) {
+				partVisible(partRef);
+			}
+
+			// Will be notified reliably when Dynamic Help View is opened in ANY
+			// perspective
+			public void partVisible(IWorkbenchPartReference partRef) {
+				if (HELP_VIEW_ID.equals(partRef.getId())) {
+					dynamicHelpViewShowing = true;
+				}
+
+			}
+
+			public void partClosed(IWorkbenchPartReference partRef) {
+				partHidden(partRef);
+			}
+
+			// Will be notified reliably when Dynamic Help View is closed in ANY
+			// perspective
+			public void partHidden(IWorkbenchPartReference partRef) {
+				if (HELP_VIEW_ID.equals(partRef.getId())) {
+					dynamicHelpViewShowing = false;
+					PlatformUI
+							.getWorkbench()
+							.getHelpSystem()
+							.setHelp(
+									getGraphicalViewer().getControl(),
+									IYakinduSctHelpContextIds.SC_EDITOR_GRAPHICAL_VIEWER);
+				}
+			}
+
+			public void partActivated(IWorkbenchPartReference partRef) {
+				// do nothing
+			}
+
+			public void partBroughtToTop(IWorkbenchPartReference partRef) {
+				// do nothing
+			}
+
+			public void partDeactivated(IWorkbenchPartReference partRef) {
+				// do nothing
+			}
+
+			public void partInputChanged(IWorkbenchPartReference partRef) {
+				// do nothing
+			}
+
+		};
+	}
+
+	public static boolean askWorkbenchIfDynamicHelpViewShowing() {
+		boolean open = false;
+		IWorkbenchWindow activeWindow = PlatformUI.getWorkbench()
+				.getActiveWorkbenchWindow();
+		if (activeWindow != null) {
+			IWorkbenchPage activePage = activeWindow.getActivePage();
+			if (activePage != null) {
+				IViewPart view = activePage.findView(HELP_VIEW_ID);
+				if (view != null) {
+					open = true;
+				}
+			}
+		}
+		return open;
+	}
+
+	@Override
+	public String getContributorId() {
+		return ID;
+	}
+
+	public static void setDynamicHelpViewShowing(boolean dynamicHelpViewShowing) {
+		StatechartDiagramEditor.dynamicHelpViewShowing = dynamicHelpViewShowing;
+	}
+
+	public static boolean isDynamicHelpViewShowing() {
+		return StatechartDiagramEditor.dynamicHelpViewShowing;
+	}
+
 }

+ 6 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/EntryEditPart.java

@@ -33,6 +33,8 @@ import org.yakindu.sct.ui.editor.editor.figures.DeepHistoryFigure;
 import org.yakindu.sct.ui.editor.editor.figures.InitialStateFigure;
 import org.yakindu.sct.ui.editor.editor.figures.ShallowHistoryFigure;
 import org.yakindu.sct.ui.editor.editor.figures.utils.MapModeUtils;
+import org.yakindu.sct.ui.editor.policies.ContextSensitiveHelpPolicy;
+import org.yakindu.sct.ui.editor.utils.IYakinduSctHelpContextIds;
 
 import de.itemis.gmf.runtime.commons.editpolicies.OneWayConnectionHandlesEditPolicy;
 import de.itemis.gmf.runtime.commons.figures.EllipseAnchorDefaultSizeNodeFigure;
@@ -56,6 +58,10 @@ public class EntryEditPart extends AbstractBorderedShapeEditPart {
 				new OneWayConnectionHandlesEditPolicy(HandleDirection.OUTGOING));
 		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
 				new NonResizableEditPolicyEx());
+		installEditPolicy(
+				EditPolicy.SELECTION_FEEDBACK_ROLE,
+				new ContextSensitiveHelpPolicy(
+						IYakinduSctHelpContextIds.SC_PROPERTIES_ENTRY_ENTRYKIND));
 	}
 
 	@Override

+ 8 - 4
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/StateTextCompartmentExpressionEditPart.java

@@ -2,6 +2,8 @@ package org.yakindu.sct.ui.editor.editparts;
 
 import org.eclipse.gef.EditPolicy;
 import org.eclipse.gmf.runtime.notation.View;
+import org.yakindu.sct.ui.editor.policies.ContextSensitiveHelpPolicy;
+import org.yakindu.sct.ui.editor.utils.IYakinduSctHelpContextIds;
 
 import de.itemis.xtext.utils.gmf.directedit.IXtextAwareEditPart;
 
@@ -16,12 +18,14 @@ public class StateTextCompartmentExpressionEditPart extends
 	public StateTextCompartmentExpressionEditPart(View view) {
 		super(view);
 	}
-	
+
 	@Override
 	protected void createDefaultEditPolicies() {
 		super.createDefaultEditPolicies();
-		removeEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);		
+		removeEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
+		installEditPolicy(
+				EditPolicy.SELECTION_FEEDBACK_ROLE,
+				new ContextSensitiveHelpPolicy(
+						IYakinduSctHelpContextIds.SC_PROPERTIES_STATE_EXPRESSION));
 	}
-
-
 }

+ 7 - 2
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/StatechartTextExpressionEditPart.java

@@ -3,6 +3,8 @@ package org.yakindu.sct.ui.editor.editparts;
 import org.eclipse.gef.EditPolicy;
 import org.eclipse.gef.editpolicies.RootComponentEditPolicy;
 import org.eclipse.gmf.runtime.notation.View;
+import org.yakindu.sct.ui.editor.policies.ContextSensitiveHelpPolicy;
+import org.yakindu.sct.ui.editor.utils.IYakinduSctHelpContextIds;
 
 /**
  * 
@@ -22,8 +24,11 @@ public class StatechartTextExpressionEditPart extends
 		// Disables deletion of the text compartment view via keyboard
 		installEditPolicy(EditPolicy.COMPONENT_ROLE,
 				new RootComponentEditPolicy());
-		removeEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);	
+		removeEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
+		installEditPolicy(
+				EditPolicy.SELECTION_FEEDBACK_ROLE,
+				new ContextSensitiveHelpPolicy(
+						IYakinduSctHelpContextIds.SC_PROPERTIES_STATECHART_EXPRESSION));
 	}
 
-
 }

+ 15 - 4
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/TransitionExpressionEditPart.java

@@ -10,21 +10,32 @@
  */
 package org.yakindu.sct.ui.editor.editparts;
 
+import org.eclipse.gef.EditPolicy;
 import org.eclipse.gmf.runtime.notation.View;
+import org.yakindu.sct.ui.editor.policies.ContextSensitiveHelpPolicy;
+import org.yakindu.sct.ui.editor.utils.IYakinduSctHelpContextIds;
 
 import de.itemis.xtext.utils.gmf.directedit.IXtextAwareEditPart;
 
 /**
  * 
  * @author muelder
- *
+ * 
  */
-public class TransitionExpressionEditPart extends PlugableExternalXtextLabelEditPart implements
-		IXtextAwareEditPart {
-
+public class TransitionExpressionEditPart extends
+		PlugableExternalXtextLabelEditPart implements IXtextAwareEditPart {
 
 	public TransitionExpressionEditPart(View view) {
 		super(view);
 	}
 
+	@Override
+	protected void createDefaultEditPolicies() {
+		super.createDefaultEditPolicies();
+		installEditPolicy(
+				EditPolicy.SELECTION_FEEDBACK_ROLE,
+				new ContextSensitiveHelpPolicy(
+						IYakinduSctHelpContextIds.SC_PROPERTIES_TRANSITION_EXPRESSION));
+	}
+
 }

+ 6 - 99
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/policies/ContextSensitiveHelpPolicy.java

@@ -1,13 +1,8 @@
 package org.yakindu.sct.ui.editor.policies;
 
 import org.eclipse.gef.editpolicies.SelectionEditPolicy;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IPartListener2;
-import org.eclipse.ui.IViewPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPartReference;
-import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PlatformUI;
+import org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor;
 import org.yakindu.sct.ui.editor.utils.IYakinduSctHelpContextIds;
 
 /**
@@ -17,88 +12,16 @@ import org.yakindu.sct.ui.editor.utils.IYakinduSctHelpContextIds;
  */
 public class ContextSensitiveHelpPolicy extends SelectionEditPolicy {
 
-	protected IPartListener2 helpViewListener = new IPartListener2() {
-
-		public void partOpened(IWorkbenchPartReference partRef) {
-			partVisible(partRef);
-		}
-
-		public void partVisible(IWorkbenchPartReference partRef) {
-			if (HELP_VIEW_ID.equals(partRef.getId())) {
-				dynamicHelpViewShowing = true;
-			}
-
-		}
-
-		public void partClosed(IWorkbenchPartReference partRef) {
-			partHidden(partRef);
-		}
-
-		public void partHidden(IWorkbenchPartReference partRef) {
-			if (HELP_VIEW_ID.equals(partRef.getId())) {
-				dynamicHelpViewShowing = false;
-				PlatformUI
-						.getWorkbench()
-						.getHelpSystem()
-						.setHelp(
-								getHost().getViewer().getControl(),
-								IYakinduSctHelpContextIds.SC_EDITOR_EDITPART_VIEWER);
-			}
-		}
-
-		public void partActivated(IWorkbenchPartReference partRef) {
-			// do nothing
-		}
-
-		public void partBroughtToTop(IWorkbenchPartReference partRef) {
-			// do nothing
-		}
-
-		public void partDeactivated(IWorkbenchPartReference partRef) {
-			// do nothing
-		}
-
-		public void partInputChanged(IWorkbenchPartReference partRef) {
-			// do nothing
-		}
-
-	};
-
-	// Copied from extension point
-	private final static String HELP_VIEW_ID = "org.eclipse.help.ui.HelpView";
-
 	private String helpContextId;
-	private static boolean dynamicHelpViewShowing = false;
 
+	
 	public ContextSensitiveHelpPolicy(String helpContextId) {
 		this.helpContextId = helpContextId;
 	}
 
-	@Override
-	public void activate() {
-		super.activate();
-		// Workbench might be in the process of starting up
-		Runnable runnable = new Runnable() {
-			public void run() {
-				PlatformUI.getWorkbench().getActiveWorkbenchWindow()
-						.getPartService().addPartListener(helpViewListener);
-				// Listener may have missed view opening
-				dynamicHelpViewShowing = isDynamicHelpViewShowing();
-			}
-		};
-		Display.getCurrent().asyncExec(runnable);
-	}
-
-	@Override
-	public void deactivate() {
-		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService()
-				.removePartListener(helpViewListener);
-		super.deactivate();
-	}
-
 	@Override
 	protected void showSelection() {
-		if (dynamicHelpViewShowing) {
+		if (StatechartDiagramEditor.isDynamicHelpViewShowing()) {
 			displayViewerHelpContext(helpContextId);
 			// Simple, but unreliable alternative
 			// PlatformUI.getWorkbench().getHelpSystem().displayHelp(helpContextId);
@@ -107,27 +30,11 @@ public class ContextSensitiveHelpPolicy extends SelectionEditPolicy {
 
 	@Override
 	protected void hideSelection() {
-		if (dynamicHelpViewShowing) {
-			displayViewerHelpContext(IYakinduSctHelpContextIds.SC_EDITOR_EDITPART_VIEWER);
+		if (StatechartDiagramEditor.isDynamicHelpViewShowing()) {
+			displayViewerHelpContext(IYakinduSctHelpContextIds.SC_EDITOR_GRAPHICAL_VIEWER);
 			// Simple, but unreliable alternative
-			// PlatformUI.getWorkbench().getHelpSystem().displayHelp(IYakinduSctHelpContextIds.SC_EDITOR_EDITPART_VIEWER);
-		}
-	}
-
-	private static boolean isDynamicHelpViewShowing() {
-		boolean open = false;
-		IWorkbenchWindow activeWindow = PlatformUI.getWorkbench()
-				.getActiveWorkbenchWindow();
-		if (activeWindow != null) {
-			IWorkbenchPage activePage = activeWindow.getActivePage();
-			if (activePage != null) {
-				IViewPart view = activePage.findView(HELP_VIEW_ID);
-				if (view != null) {
-					open = true;
-				}
-			}
+			// PlatformUI.getWorkbench().getHelpSystem().displayHelp(IYakinduSctHelpContextIds.SC_EDITOR_GRAPHICAL_VIEWER);
 		}
-		return open;
 	}
 
 	private void displayViewerHelpContext(String helpContextId) {

+ 1 - 1
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/utils/IYakinduSctHelpContextIds.java

@@ -13,7 +13,7 @@ public interface IYakinduSctHelpContextIds {
 	public static final String PREFIX = DiagramActivator.PLUGIN_ID + '.';
 
 	// Diagram viewer
-	public static final String SC_EDITOR_EDITPART_VIEWER = PREFIX + "sc_editor_editpart_viewer"; //$NON-NLS-1$
+	public static final String SC_EDITOR_GRAPHICAL_VIEWER = PREFIX + "sc_editor_graphical_viewer"; //$NON-NLS-1$
 	
 	// Property sheets and EditParts
 	public static final String SC_PROPERTIES_ENTRY_ENTRYKIND = PREFIX + "sc_properties_entry_entrykind"; //$NON-NLS-1$