Просмотр исходного кода

Added context menu action "Create Subdiagram" - filtering context menu

Andreas Mülder 13 лет назад
Родитель
Сommit
07c5e36a56

+ 9 - 3
plugins/org.yakindu.sct.refactoring/src/org/yakindu/sct/refactoring/refactor/impl/ExtractSubdiagramRefactoring.java

@@ -14,6 +14,7 @@ import org.eclipse.emf.common.util.EList;
 import org.eclipse.emf.common.util.TreeIterator;
 import org.eclipse.emf.common.util.TreeIterator;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.util.EcoreUtil;
 import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
 import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
 import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
 import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
 import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
 import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
 import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
@@ -30,20 +31,25 @@ import org.yakindu.sct.model.sgraph.State;
 import org.yakindu.sct.model.sgraph.Transition;
 import org.yakindu.sct.model.sgraph.Transition;
 import org.yakindu.sct.model.stext.stext.EntryPointSpec;
 import org.yakindu.sct.model.stext.stext.EntryPointSpec;
 import org.yakindu.sct.model.stext.stext.StextFactory;
 import org.yakindu.sct.model.stext.stext.StextFactory;
+import org.yakindu.sct.refactoring.refactor.AbstractRefactoring;
+import org.yakindu.sct.ui.editor.DiagramActivator;
 import org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor;
 import org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor;
 import org.yakindu.sct.ui.editor.providers.SemanticHints;
 import org.yakindu.sct.ui.editor.providers.SemanticHints;
+import static org.yakindu.sct.ui.editor.partitioning.DiagramPartitioningUtil.*;
 
 
 /**
 /**
  * 
  * 
  * @author andreas muelder - Initial contribution and API
  * @author andreas muelder - Initial contribution and API
  * 
  * 
  */
  */
-public class ExtractSubdiagramRefactoring extends SubdiagramRefactoring {
+public class ExtractSubdiagramRefactoring extends AbstractRefactoring<View> {
+
+	protected PreferencesHint preferencesHint = DiagramActivator.DIAGRAM_PREFERENCES_HINT;
 
 
 	@Override
 	@Override
 	public boolean isExecutable() {
 	public boolean isExecutable() {
 		State state = (State) getContextObject().getElement();
 		State state = (State) getContextObject().getElement();
-		BooleanValueStyle inlineStyle = getInlineStyle();
+		BooleanValueStyle inlineStyle = getInlineStyle(getContextObject());
 		return super.isExecutable() && state.isComposite() && (inlineStyle == null || inlineStyle.isBooleanValue());
 		return super.isExecutable() && state.isComposite() && (inlineStyle == null || inlineStyle.isBooleanValue());
 	}
 	}
 
 
@@ -136,7 +142,7 @@ public class ExtractSubdiagramRefactoring extends SubdiagramRefactoring {
 	 */
 	 */
 	@SuppressWarnings("unchecked")
 	@SuppressWarnings("unchecked")
 	protected void setNotationStyle() {
 	protected void setNotationStyle() {
-		BooleanValueStyle inlineStyle = getInlineStyle();
+		BooleanValueStyle inlineStyle = getInlineStyle(getContextObject());
 		if (inlineStyle == null) {
 		if (inlineStyle == null) {
 			inlineStyle = createInlineStyle();
 			inlineStyle = createInlineStyle();
 			getContextObject().getStyles().add(inlineStyle);
 			getContextObject().getStyles().add(inlineStyle);

+ 6 - 3
plugins/org.yakindu.sct.refactoring/src/org/yakindu/sct/refactoring/refactor/impl/InlineSubdiagramRefactoring.java

@@ -16,25 +16,28 @@ import org.eclipse.gmf.runtime.notation.Diagram;
 import org.eclipse.gmf.runtime.notation.Edge;
 import org.eclipse.gmf.runtime.notation.Edge;
 import org.eclipse.gmf.runtime.notation.View;
 import org.eclipse.gmf.runtime.notation.View;
 import org.yakindu.sct.model.sgraph.State;
 import org.yakindu.sct.model.sgraph.State;
+import org.yakindu.sct.refactoring.refactor.AbstractRefactoring;
 import org.yakindu.sct.ui.editor.partitioning.DiagramPartitioningUtil;
 import org.yakindu.sct.ui.editor.partitioning.DiagramPartitioningUtil;
 import org.yakindu.sct.ui.editor.providers.SemanticHints;
 import org.yakindu.sct.ui.editor.providers.SemanticHints;
+import static org.yakindu.sct.ui.editor.partitioning.DiagramPartitioningUtil.*;
 
 
 /**
 /**
  * 
  * 
  * @author andreas muelder - Initial contribution and API
  * @author andreas muelder - Initial contribution and API
  * 
  * 
  */
  */
-public class InlineSubdiagramRefactoring extends SubdiagramRefactoring {
+public class InlineSubdiagramRefactoring extends AbstractRefactoring<View> {
 
 
 	@Override
 	@Override
 	public boolean isExecutable() {
 	public boolean isExecutable() {
-		return super.isExecutable() && getInlineStyle() != null && !getInlineStyle().isBooleanValue();
+		BooleanValueStyle inlineStyle = getInlineStyle(getContextObject());
+		return super.isExecutable() && inlineStyle != null && !inlineStyle.isBooleanValue();
 	}
 	}
 
 
 	@SuppressWarnings("unchecked")
 	@SuppressWarnings("unchecked")
 	@Override
 	@Override
 	protected void internalExecute() {
 	protected void internalExecute() {
-		BooleanValueStyle inlineStyle = getInlineStyle();
+		BooleanValueStyle inlineStyle = getInlineStyle(getContextObject());
 		if (inlineStyle == null) {
 		if (inlineStyle == null) {
 			inlineStyle = createInlineStyle();
 			inlineStyle = createInlineStyle();
 			getContextObject().getStyles().add(inlineStyle);
 			getContextObject().getStyles().add(inlineStyle);

+ 0 - 43
plugins/org.yakindu.sct.refactoring/src/org/yakindu/sct/refactoring/refactor/impl/SubdiagramRefactoring.java

@@ -1,43 +0,0 @@
-/**
- * Copyright (c) 2013 committers of YAKINDU and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * Contributors:
- * 	committers of YAKINDU - initial API and implementation
- * 
- */
-package org.yakindu.sct.refactoring.refactor.impl;
-
-import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
-import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
-import org.eclipse.gmf.runtime.notation.NotationFactory;
-import org.eclipse.gmf.runtime.notation.View;
-import org.yakindu.sct.refactoring.refactor.AbstractRefactoring;
-import org.yakindu.sct.ui.editor.DiagramActivator;
-import org.yakindu.sct.ui.editor.utils.GMFNotationUtil;
-import static org.yakindu.sct.ui.editor.partitioning.DiagramPartitioningUtil.*;
-
-/**
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public abstract class SubdiagramRefactoring extends AbstractRefactoring<View> {
-
-	protected PreferencesHint preferencesHint = DiagramActivator.DIAGRAM_PREFERENCES_HINT;
-
-	protected BooleanValueStyle getInlineStyle() {
-		BooleanValueStyle result = GMFNotationUtil.getBooleanValueStyle(getContextObject(), INLINE_STYLE);
-		return result;
-	}
-
-	protected BooleanValueStyle createInlineStyle() {
-		BooleanValueStyle result = NotationFactory.eINSTANCE.createBooleanValueStyle();
-		result.setName(INLINE_STYLE);
-		result.setBooleanValue(true);
-		return result;
-	}
-
-}

+ 25 - 0
plugins/org.yakindu.sct.ui.editor/plugin.xml

@@ -816,6 +816,11 @@
        id="org.yakindu.sct.ui.editor.commands.ToggleShowDocumentation"
        id="org.yakindu.sct.ui.editor.commands.ToggleShowDocumentation"
        name="Toggle Documentation">
        name="Toggle Documentation">
  	</command>
  	</command>
+ 	<command
+       defaultHandler="org.yakindu.sct.ui.editor.commands.CreateSubdiagramCommand"
+       id="org.yakindu.sct.ui.editor.commands.CreateSubdiagram"
+       name="Create Subdiagram">
+ 	</command>
 </extension>
 </extension>
 
 
 <extension
 <extension
@@ -908,6 +913,26 @@
              </with>
              </with>
           </visibleWhen>
           </visibleWhen>
        </command>
        </command>
+        <command
+             commandId="org.yakindu.sct.ui.editor.commands.CreateSubdiagram"
+             label="Create Subdiagram"
+             style="push">
+          <visibleWhen
+                checkEnabled="false">
+             <with
+                   variable="selection">
+                <iterate
+                      ifEmpty="false"
+                      operator="and">
+                   <or>
+                      <instanceof
+                            value="org.yakindu.sct.ui.editor.editparts.StateEditPart">
+                      </instanceof>
+                   </or>
+                </iterate>
+             </with>
+          </visibleWhen>
+       </command>
     </menuContribution>
     </menuContribution>
  </extension>
  </extension>
  
  

+ 122 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/commands/CreateSubdiagramCommand.java

@@ -0,0 +1,122 @@
+/**
+ * Copyright (c) 2013 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.ui.editor.commands;
+
+import java.util.Collections;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.IOperationHistory;
+import org.eclipse.core.commands.operations.OperationHistoryFactory;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.yakindu.sct.model.sgraph.State;
+import org.yakindu.sct.ui.editor.DiagramActivator;
+import org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor;
+import org.yakindu.sct.ui.editor.editparts.StateEditPart;
+import org.yakindu.sct.ui.editor.partitioning.DiagramPartitioningUtil;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class CreateSubdiagramCommand extends AbstractHandler {
+
+	public Object execute(ExecutionEvent event) throws ExecutionException {
+		Node state = unwrap(HandlerUtil.getCurrentSelection(event));
+		if (state == null)
+			return null;
+		CreateSubDiagramCommand cmd = new CreateSubDiagramCommand(state);
+		executeCommand(cmd);
+		return null;
+	}
+
+	protected void executeCommand(AbstractTransactionalCommand operation) {
+		IOperationHistory history = OperationHistoryFactory.getOperationHistory();
+		try {
+			history.execute(operation, new NullProgressMonitor(), null);
+		} catch (ExecutionException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public Node unwrap(ISelection selection) {
+		IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+		Object firstElement = structuredSelection.getFirstElement();
+		if (firstElement == null)
+			return null;
+		return (Node) ((StateEditPart) firstElement).getNotationView();
+	}
+
+	@Override
+	public boolean isEnabled() {
+		IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+		if (activeWorkbenchWindow == null)
+			return false;
+		ISelection selection = activeWorkbenchWindow.getActivePage().getSelection();
+		if (selection == null)
+			return false;
+		Node unwrap = unwrap(selection);
+		State state = (State) unwrap.getElement();
+		if (state.isComposite())
+			return false;
+		BooleanValueStyle inlineStyle = DiagramPartitioningUtil.getInlineStyle(unwrap);
+		if (inlineStyle != null && !inlineStyle.isBooleanValue())
+			return false;
+		return super.isEnabled();
+	}
+
+	protected static class CreateSubDiagramCommand extends AbstractTransactionalCommand {
+
+		private Node node;
+
+		public CreateSubDiagramCommand(Node node) {
+			super(TransactionUtil.getEditingDomain(node), "Create Subdiagram", Collections
+					.singletonList(WorkspaceSynchronizer.getFile(node.eResource())));
+			this.node = node;
+		}
+
+		@SuppressWarnings("unchecked")
+		@Override
+		protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
+				throws ExecutionException {
+			BooleanValueStyle inlineStyle = DiagramPartitioningUtil.getInlineStyle(node);
+			if (inlineStyle != null) {
+				inlineStyle.setBooleanValue(false);
+			} else {
+				inlineStyle = DiagramPartitioningUtil.createInlineStyle();
+				inlineStyle.setBooleanValue(false);
+				node.getStyles().add(inlineStyle);
+			}
+			Diagram subdiagram = ViewService.createDiagram(node.getElement(), StatechartDiagramEditor.ID,
+					DiagramActivator.DIAGRAM_PREFERENCES_HINT);
+			node.eResource().getContents().add(subdiagram);
+			return CommandResult.newOKCommandResult();
+		}
+
+	}
+}

+ 26 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/partitioning/DiagramPartitioningEditor.java

@@ -20,10 +20,15 @@ import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.edit.domain.IEditingDomainProvider;
 import org.eclipse.emf.edit.domain.IEditingDomainProvider;
 import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
 import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
 import org.eclipse.emf.transaction.TransactionalEditingDomain;
 import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.ContextMenuProvider;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds;
 import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput;
 import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput;
+import org.eclipse.gmf.runtime.diagram.ui.providers.DiagramContextMenuProvider;
 import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocumentProvider;
 import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocumentProvider;
 import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
 import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
 import org.eclipse.gmf.runtime.notation.Diagram;
 import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.action.IContributionItem;
 import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.jface.viewers.BaseLabelProvider;
 import org.eclipse.jface.viewers.BaseLabelProvider;
@@ -38,6 +43,7 @@ import org.eclipse.jface.viewers.ViewerLabel;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorInput;
+import org.eclipse.xtext.util.Arrays;
 import org.yakindu.base.base.NamedElement;
 import org.yakindu.base.base.NamedElement;
 import org.yakindu.sct.model.sgraph.Statechart;
 import org.yakindu.sct.model.sgraph.Statechart;
 import org.yakindu.sct.model.sgraph.provider.SGraphItemProviderAdapterFactory;
 import org.yakindu.sct.model.sgraph.provider.SGraphItemProviderAdapterFactory;
@@ -107,6 +113,26 @@ public abstract class DiagramPartitioningEditor extends DiagramDocumentEditor im
 
 
 	}
 	}
 
 
+	@Override
+	protected void configureGraphicalViewer() {
+		super.configureGraphicalViewer();
+		GraphicalViewer graphicalViewer = getGraphicalViewer();
+		ContextMenuProvider provider = new DiagramContextMenuProvider(this, graphicalViewer) {
+			protected boolean allowItem(IContributionItem itemToAdd) {
+				String[] exclude = new String[] { "addNoteLinkAction", "properties",
+						"org.eclipse.mylyn.context.ui.commands.attachment.retrieveContext",
+						"org.eclipse.mylyn.resources.ui.ui.interest.remove.element", "formatMenu", "filtersMenu","addGroup","navigateGroup" };
+				if (Arrays.contains(exclude, itemToAdd.getId())) {
+					itemToAdd.setVisible(false);
+				}
+				System.out.println(itemToAdd.getId());
+				return super.allowItem(itemToAdd);
+			}
+		};
+		graphicalViewer.setContextMenu(provider);
+		getSite().registerContextMenu(ActionIds.DIAGRAM_EDITOR_CONTEXT_MENU, provider, viewer);
+	}
+
 	private void createBreadcrumbViewer(Composite parent) {
 	private void createBreadcrumbViewer(Composite parent) {
 		viewer = new DiagramPartitioningBreadcrumbViewer(parent, SWT.READ_ONLY);
 		viewer = new DiagramPartitioningBreadcrumbViewer(parent, SWT.READ_ONLY);
 		viewer.addSelectionChangedListener(this);
 		viewer.addSelectionChangedListener(this);

+ 22 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/partitioning/DiagramPartitioningUtil.java

@@ -25,7 +25,9 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain;
 import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
 import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
 import org.eclipse.gmf.runtime.diagram.core.DiagramEditingDomainFactory;
 import org.eclipse.gmf.runtime.diagram.core.DiagramEditingDomainFactory;
 import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput;
 import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput;
+import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
 import org.eclipse.gmf.runtime.notation.Diagram;
 import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.NotationFactory;
 import org.eclipse.gmf.runtime.notation.NotationPackage;
 import org.eclipse.gmf.runtime.notation.NotationPackage;
 import org.eclipse.gmf.runtime.notation.Style;
 import org.eclipse.gmf.runtime.notation.Style;
 import org.eclipse.gmf.runtime.notation.View;
 import org.eclipse.gmf.runtime.notation.View;
@@ -42,6 +44,7 @@ import org.yakindu.sct.model.sgraph.CompositeElement;
 import org.yakindu.sct.model.sgraph.State;
 import org.yakindu.sct.model.sgraph.State;
 import org.yakindu.sct.model.sgraph.Statechart;
 import org.yakindu.sct.model.sgraph.Statechart;
 import org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor;
 import org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor;
+import org.yakindu.sct.ui.editor.utils.GMFNotationUtil;
 
 
 /**
 /**
  * 
  * 
@@ -58,6 +61,25 @@ public class DiagramPartitioningUtil {
 	private DiagramPartitioningUtil() {
 	private DiagramPartitioningUtil() {
 	}
 	}
 
 
+	/**
+	 * returns the style for diagram inlining
+	 * 
+	 */
+	public static BooleanValueStyle getInlineStyle(View view) {
+		BooleanValueStyle result = GMFNotationUtil.getBooleanValueStyle(view, INLINE_STYLE);
+		return result;
+	}
+
+	/**
+	 * creates a new style for diagam inlining
+	 */
+	public static BooleanValueStyle createInlineStyle() {
+		BooleanValueStyle result = NotationFactory.eINSTANCE.createBooleanValueStyle();
+		result.setName(INLINE_STYLE);
+		result.setBooleanValue(true);
+		return result;
+	}
+
 	/**
 	/**
 	 * Returns the Shared Editing Domain that is used for all Editors acting on
 	 * Returns the Shared Editing Domain that is used for all Editors acting on
 	 * the same {@link IResource}
 	 * the same {@link IResource}