From 60398929970657f97a12a823a7bcbec8ef729e09 Mon Sep 17 00:00:00 2001
From: mgolubev
Date: Tue, 15 May 2012 14:40:35 +0200
Subject: Subsetting / layering diagram support for GMFT separated from Taipan
sample to be reusable.
---
.../.classpath | 7 +
.../.project | 28 +++
.../.settings/org.eclipse.jdt.core.prefs | 7 +
.../META-INF/MANIFEST.MF | 37 ++++
.../build.properties | 4 +
.../layers/subdiagrams/DefaultSaveOptions.java | 29 +++
.../layers/subdiagrams/SubDiagramManager.java | 10 +
.../layers/subdiagrams/SubDiagramManagerImpl.java | 85 +++++++++
.../subdiagrams/popup/AssignToLayerAction.java | 107 +++++++++++
.../popup/AssignToLayerItemProvider.java | 93 +++++++++
.../popup/AssignToLayerItemProviderPolicy.java | 35 ++++
.../subdiagrams/popup/CreateNewLayerAction.java | 109 +++++++++++
.../subdiagrams/popup/CreateSubDiagramAction.java | 115 +++++++++++
.../subdiagrams/popup/DomainOnlyEditRequest.java | 21 +++
.../subdiagrams/popup/OpenSubDiagramAction.java | 47 +++++
.../subdiagrams/popup/SubDiagramActionBase.java | 195 +++++++++++++++++++
.../subdiagrams/popup/SubDiagramsItemProvider.java | 85 +++++++++
.../popup/SwitchLayerVisibilityAction.java | 210 +++++++++++++++++++++
.../popup/SwitchLayerVisibilityItemProvider.java | 76 ++++++++
.../subdiagrams/popup/UniqueNameValidator.java | 65 +++++++
.../.classpath | 1 -
.../META-INF/MANIFEST.MF | 2 +-
.../build.properties | 3 +-
.../examples/subdiagrams/SubDiagramManager.java | 10 -
.../subdiagrams/SubDiagramManagerImpl.java | 85 ---------
.../subdiagrams/popup/AssignToLayerAction.java | 107 -----------
.../popup/AssignToLayerItemProvider.java | 93 ---------
.../popup/AssignToLayerItemProviderPolicy.java | 35 ----
.../subdiagrams/popup/CreateNewLayerAction.java | 109 -----------
.../subdiagrams/popup/CreateSubDiagramAction.java | 115 -----------
.../subdiagrams/popup/DomainOnlyEditRequest.java | 21 ---
.../subdiagrams/popup/OpenSubDiagramAction.java | 47 -----
.../subdiagrams/popup/SubDiagramActionBase.java | 195 -------------------
.../subdiagrams/popup/SubDiagramsItemProvider.java | 85 ---------
.../popup/SwitchLayerVisibilityAction.java | 210 ---------------------
.../popup/SwitchLayerVisibilityItemProvider.java | 76 --------
.../subdiagrams/popup/UniqueNameValidator.java | 65 -------
.../plugin.xml | 8 +-
.../gmf/editor/part/TaiPanDiagramEditorUtil.java | 2 +-
39 files changed, 1372 insertions(+), 1262 deletions(-)
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/.classpath
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/.project
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/.settings/org.eclipse.jdt.core.prefs
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/META-INF/MANIFEST.MF
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/build.properties
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/DefaultSaveOptions.java
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/SubDiagramManager.java
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/SubDiagramManagerImpl.java
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/AssignToLayerAction.java
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/AssignToLayerItemProvider.java
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/AssignToLayerItemProviderPolicy.java
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/CreateNewLayerAction.java
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/CreateSubDiagramAction.java
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/DomainOnlyEditRequest.java
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/OpenSubDiagramAction.java
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SubDiagramActionBase.java
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SubDiagramsItemProvider.java
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SwitchLayerVisibilityAction.java
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SwitchLayerVisibilityItemProvider.java
create mode 100644 examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/UniqueNameValidator.java
delete mode 100644 examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/SubDiagramManager.java
delete mode 100644 examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/SubDiagramManagerImpl.java
delete mode 100644 examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerAction.java
delete mode 100644 examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerItemProvider.java
delete mode 100644 examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerItemProviderPolicy.java
delete mode 100644 examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/CreateNewLayerAction.java
delete mode 100644 examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/CreateSubDiagramAction.java
delete mode 100644 examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/DomainOnlyEditRequest.java
delete mode 100644 examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/OpenSubDiagramAction.java
delete mode 100644 examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SubDiagramActionBase.java
delete mode 100644 examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SubDiagramsItemProvider.java
delete mode 100644 examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SwitchLayerVisibilityAction.java
delete mode 100644 examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SwitchLayerVisibilityItemProvider.java
delete mode 100644 examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/UniqueNameValidator.java
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/.classpath b/examples/org.eclipse.gmf.examples.layers.subdiagrams/.classpath
new file mode 100644
index 000000000..8a8f1668c
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/.project b/examples/org.eclipse.gmf.examples.layers.subdiagrams/.project
new file mode 100644
index 000000000..47a634d9e
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/.project
@@ -0,0 +1,28 @@
+
+
+ org.eclipse.gmf.examples.layers.subdiagrams
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.pde.ManifestBuilder
+
+
+
+
+ org.eclipse.pde.SchemaBuilder
+
+
+
+
+
+ org.eclipse.pde.PluginNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/.settings/org.eclipse.jdt.core.prefs b/examples/org.eclipse.gmf.examples.layers.subdiagrams/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..f287d53cf
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/META-INF/MANIFEST.MF b/examples/org.eclipse.gmf.examples.layers.subdiagrams/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..3c0daff5c
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/META-INF/MANIFEST.MF
@@ -0,0 +1,37 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Sample : Subsetting / Layerig support for arbitrary GMFT diagram
+Bundle-SymbolicName: org.eclipse.gmf.examples.layers.subdiagrams
+Bundle-Version: 1.0.0.qualifier
+Bundle-Vendor: Eclipse.org
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.core.resources,
+ org.eclipse.core.expressions,
+ org.eclipse.jface,
+ org.eclipse.ui.ide,
+ org.eclipse.ui.views,
+ org.eclipse.draw2d;visibility:=reexport,
+ org.eclipse.gef;visibility:=reexport,
+ org.eclipse.emf.ecore,
+ org.eclipse.emf.ecore.xmi,
+ org.eclipse.emf.edit.ui,
+ org.eclipse.gmf.runtime.emf.core,
+ org.eclipse.gmf.runtime.emf.commands.core,
+ org.eclipse.gmf.runtime.emf.ui.properties,
+ org.eclipse.gmf.runtime.diagram.ui,
+ org.eclipse.gmf.runtime.diagram.ui.properties,
+ org.eclipse.gmf.runtime.diagram.ui.providers,
+ org.eclipse.gmf.runtime.diagram.ui.providers.ide,
+ org.eclipse.gmf.runtime.diagram.ui.render,
+ org.eclipse.gmf.runtime.diagram.ui.resources.editor,
+ org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide,
+ org.eclipse.gmf.runtime.draw2d.ui;visibility:=reexport,
+ org.eclipse.gmf.runtime.notation;visibility:=reexport,
+ org.eclipse.gmf.examples.taipan.ui,
+ org.eclipse.gmf.tooling.runtime,
+ org.eclipse.gmf.examples.layers;bundle-version="1.0.0";visibility:=reexport
+Export-Package: org.eclipse.gmf.examples.layers.subdiagrams,
+ org.eclipse.gmf.examples.layers.subdiagrams.popup
+
+
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/build.properties b/examples/org.eclipse.gmf.examples.layers.subdiagrams/build.properties
new file mode 100644
index 000000000..41eb6ade2
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/DefaultSaveOptions.java b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/DefaultSaveOptions.java
new file mode 100644
index 000000000..8099bf148
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/DefaultSaveOptions.java
@@ -0,0 +1,29 @@
+package org.eclipse.gmf.examples.layers.subdiagrams;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+
+/**
+ * @deprecated find a way to plug the real per-diagram save options (XXXDiagramEditorUtil.getSaveOptions) here.
+ */
+@Deprecated
+public class DefaultSaveOptions {
+
+ /**
+ * XXX: We don't have a way to plug the actual diagram save options (XXXDiagramEditorUtil.getSaveOptions) here.
+ * For now we will use the default ones, but it may lead to a problem if actual diagram has this method generated NOT.
+ *
+ * @deprecated find a way to plug the real per-diagram save options (XXXDiagramEditorUtil.getSaveOptions) here.
+ */
+ @Deprecated
+ public static Map, ?> getSaveOptions() {
+ HashMap saveOptions = new HashMap();
+ saveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
+ saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
+ return saveOptions;
+ }
+
+}
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/SubDiagramManager.java b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/SubDiagramManager.java
new file mode 100644
index 000000000..53eea5cc5
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/SubDiagramManager.java
@@ -0,0 +1,10 @@
+package org.eclipse.gmf.examples.layers.subdiagrams;
+
+import org.eclipse.gmf.examples.layers.SubDiagramSupport;
+
+
+public interface SubDiagramManager {
+
+ public SubDiagramSupport getSubDiagramSupport();
+
+}
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/SubDiagramManagerImpl.java b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/SubDiagramManagerImpl.java
new file mode 100644
index 000000000..fb16f70a6
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/SubDiagramManagerImpl.java
@@ -0,0 +1,85 @@
+package org.eclipse.gmf.examples.layers.subdiagrams;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gmf.examples.layers.LayersFactory;
+import org.eclipse.gmf.examples.layers.SubDiagramSpec;
+import org.eclipse.gmf.examples.layers.SubDiagramSupport;
+import org.eclipse.gmf.runtime.notation.Diagram;
+
+public class SubDiagramManagerImpl implements SubDiagramManager {
+
+ private static class ManagerHolderAdapter extends AdapterImpl {
+
+ private final SubDiagramManagerImpl myManager;
+
+ public ManagerHolderAdapter(SubDiagramManagerImpl manager) {
+ myManager = manager;
+ }
+
+ public SubDiagramManagerImpl getManager() {
+ return myManager;
+ }
+ }
+
+ public static SubDiagramManager findOrCreateSubsetManager(Diagram diagram) {
+ for (Adapter next : diagram.eAdapters()) {
+ if (next instanceof ManagerHolderAdapter) {
+ return ((ManagerHolderAdapter) next).getManager();
+ }
+ }
+ SubDiagramManagerImpl result = new SubDiagramManagerImpl(diagram.eResource());
+ diagram.eAdapters().add(new ManagerHolderAdapter(result));
+ return result;
+ }
+
+ public static void setupSubsetsSupport(Diagram diagram, Resource diagramResource) {
+ SubDiagramSupport support = LayersFactory.eINSTANCE.createSubDiagramSupport();
+ diagramResource.getContents().add(support);
+
+ SubDiagramSpec mainDiagramSpec = LayersFactory.eINSTANCE.createSubDiagramSpec();
+ mainDiagramSpec.setName("Main");
+ mainDiagramSpec.setShowing(true);
+ mainDiagramSpec.setDiagram(diagram);
+ support.setMainDiagram(mainDiagramSpec);
+
+ //fake layers
+ // Layer layerA = LayersFactory.eINSTANCE.createLayer();
+ // layerA.setName("Layer A");
+ //
+ // Layer layerB = LayersFactory.eINSTANCE.createLayer();
+ // layerB.setName("Layer B");
+ //
+ // support.getLayers().add(layerA);
+ // support.getLayers().add(layerB);
+ //
+
+ support.ensureAllSubDiagramsHaveEnablementForAllLayers();
+ }
+
+ private final Resource myDiagramResource;
+
+ private final SubDiagramSupport mySubDiagramSupport;
+
+ public SubDiagramManagerImpl(Resource diagramResource) {
+ myDiagramResource = diagramResource;
+ mySubDiagramSupport = findSubDiagramSupport(myDiagramResource);
+ }
+
+ private static SubDiagramSupport findSubDiagramSupport(Resource resource) {
+ for (EObject next : resource.getContents()) {
+ if (next instanceof SubDiagramSupport) {
+ return (SubDiagramSupport) next;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public SubDiagramSupport getSubDiagramSupport() {
+ return mySubDiagramSupport;
+ }
+
+}
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/AssignToLayerAction.java b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/AssignToLayerAction.java
new file mode 100644
index 000000000..9c73bc9cf
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/AssignToLayerAction.java
@@ -0,0 +1,107 @@
+package org.eclipse.gmf.examples.layers.subdiagrams.popup;
+
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.examples.layers.Layer;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.ui.IWorkbenchPage;
+
+public class AssignToLayerAction extends DiagramAction {
+
+ protected static final String EMPTY_LAYER_NAME = "";
+
+ private final Layer myLayerToAssign;
+
+ private final List mySemanticElements;
+
+ public AssignToLayerAction(IWorkbenchPage workbenchPage, List semanticElements, Layer layer) {
+ super(workbenchPage);
+ mySemanticElements = semanticElements;
+ myLayerToAssign = layer;
+ }
+
+ @Override
+ protected Request createTargetRequest() {
+ return null;
+ }
+
+ @Override
+ protected boolean isSelectionListener() {
+ return true;
+ }
+
+ @Override
+ protected Command getCommand() {
+ DiagramEditPart diagramEditPart = getDiagramEditPart();
+ if (diagramEditPart == null) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ IEditCommandRequest request = new DomainOnlyEditRequest(diagramEditPart);
+ boolean addNotRemove = !isAssignedToLayer(mySemanticElements, myLayerToAssign);
+ return new ICommandProxy(new AssignToLayer("Changing Layer Assignments", myLayerToAssign, mySemanticElements, addNotRemove, request));
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return getDiagramEditPart() != null;
+ }
+
+ @Override
+ public void refresh() {
+ super.refresh();
+ setText(calculateText());
+ setChecked(calculateChecked());
+ }
+
+ protected String calculateText() {
+ String name = myLayerToAssign.getName();
+ return name != null ? name : EMPTY_LAYER_NAME;
+ }
+
+ protected boolean calculateChecked() {
+ return isAssignedToLayer(mySemanticElements, myLayerToAssign);
+ }
+
+ private boolean isAssignedToLayer(List semanticElements, Layer layer) {
+ return layer.getParticipants().containsAll(semanticElements);
+ }
+
+ public static class AssignToLayer extends EditElementCommand {
+
+ private final Layer myLayer;
+
+ private final List myAssignees;
+
+ private final boolean myAddNotRemove;
+
+ protected AssignToLayer(String label, Layer layer, List assignees, boolean addNotRemove, IEditCommandRequest request) {
+ super(label, layer, request);
+ myAssignees = assignees;
+ myLayer = layer;
+ myAddNotRemove = addNotRemove;
+ }
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ if (myAddNotRemove) {
+ myLayer.getParticipants().addAll(myAssignees);
+ } else {
+ myLayer.getParticipants().removeAll(myAssignees);
+ }
+ return CommandResult.newOKCommandResult(myLayer);
+ }
+
+ }
+}
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/AssignToLayerItemProvider.java b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/AssignToLayerItemProvider.java
new file mode 100644
index 000000000..7651bd7d8
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/AssignToLayerItemProvider.java
@@ -0,0 +1,93 @@
+package org.eclipse.gmf.examples.layers.subdiagrams.popup;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.examples.layers.Layer;
+import org.eclipse.gmf.examples.layers.SubDiagramSpec;
+import org.eclipse.gmf.examples.layers.SubDiagramSupport;
+import org.eclipse.gmf.examples.layers.subdiagrams.SubDiagramManager;
+import org.eclipse.gmf.examples.layers.subdiagrams.SubDiagramManagerImpl;
+import org.eclipse.gmf.runtime.common.core.service.IProvider;
+import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.AbstractContributionItemProvider;
+import org.eclipse.gmf.runtime.common.ui.util.IWorkbenchPartDescriptor;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.ui.IWorkbenchPage;
+
+public class AssignToLayerItemProvider extends AbstractContributionItemProvider implements IProvider {
+
+ public static final String MENU_ASSIGN_TO_LAYER = "menu_assign_to_layer"; //$NON-NLS-1$
+
+ @Override
+ protected IMenuManager createMenuManager(String menuId, IWorkbenchPartDescriptor partDescriptor) {
+ if (!MENU_ASSIGN_TO_LAYER.equals(menuId)) {
+ return super.createMenuManager(menuId, partDescriptor);
+ }
+ MenuManager menuManager = new MenuManager("Assign To Layer");
+ MenuBuilder builder = new MenuBuilder(partDescriptor);
+ // XXX: build initial content -- otherwise menu is never shown
+ builder.buildMenu(menuManager);
+
+ menuManager.addMenuListener(builder);
+ return menuManager;
+ }
+
+ private class MenuBuilder implements IMenuListener {
+
+ private final IWorkbenchPartDescriptor myWorkbenchPart;
+
+ public MenuBuilder(IWorkbenchPartDescriptor workbenchPart) {
+ myWorkbenchPart = workbenchPart;
+ }
+
+ public void menuAboutToShow(IMenuManager manager) {
+ buildMenu(manager);
+ }
+
+ public void buildMenu(IMenuManager manager) {
+ manager.removeAll();
+ IGraphicalEditPart firstSelected = (IGraphicalEditPart) getSelectedObject(myWorkbenchPart);
+ Diagram activeDiagram = firstSelected.getNotationView().getDiagram();
+
+ SubDiagramManager subsetManager = SubDiagramManagerImpl.findOrCreateSubsetManager(activeDiagram);
+ SubDiagramSupport support = subsetManager.getSubDiagramSupport();
+
+ SubDiagramSpec activeSpec = support.findDiagramSpec(activeDiagram);
+
+ List allSelectedEObjects = Collections.unmodifiableList(resolveSelectedSemanticElements());
+ for (Layer next : support.getLayers()) {
+ AssignToLayerAction action = new AssignToLayerAction(getWorkbenchPage(), allSelectedEObjects, next);
+ action.init();
+ manager.add(action);
+ }
+
+ manager.add(new Separator());
+ CreateNewLayerAction createNewAction = new CreateNewLayerAction(getWorkbenchPage(), allSelectedEObjects, support, activeSpec);
+ createNewAction.init();
+ manager.add(createNewAction);
+ }
+
+ private List resolveSelectedSemanticElements() {
+ LinkedHashSet result = new LinkedHashSet();
+ for (Object next : getStructuredSelection(myWorkbenchPart).toArray()) {
+ if (next instanceof IGraphicalEditPart) {
+ result.add(((IGraphicalEditPart) next).resolveSemanticElement());
+ }
+ }
+ return new ArrayList(result);
+ }
+
+ private IWorkbenchPage getWorkbenchPage() {
+ return myWorkbenchPart.getPartPage();
+ }
+ }
+
+}
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/AssignToLayerItemProviderPolicy.java b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/AssignToLayerItemProviderPolicy.java
new file mode 100644
index 000000000..f0397c695
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/AssignToLayerItemProviderPolicy.java
@@ -0,0 +1,35 @@
+package org.eclipse.gmf.examples.layers.subdiagrams.popup;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.IPopupMenuContributionPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+
+public class AssignToLayerItemProviderPolicy implements IPopupMenuContributionPolicy {
+
+ @Override
+ public boolean appliesTo(ISelection selection, IConfigurationElement configuration) {
+ if (false == selection instanceof IStructuredSelection) {
+ return false;
+ }
+ List> allSelected = ((IStructuredSelection) selection).toList();
+ if (allSelected.isEmpty()) {
+ return false;
+ }
+ for (Object next : allSelected) {
+ if (!checkSelectedElement(next)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private boolean checkSelectedElement(Object selected) {
+ return selected instanceof IGraphicalEditPart && !(selected instanceof DiagramEditPart);
+ }
+
+}
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/CreateNewLayerAction.java b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/CreateNewLayerAction.java
new file mode 100644
index 000000000..9e020c9ad
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/CreateNewLayerAction.java
@@ -0,0 +1,109 @@
+package org.eclipse.gmf.examples.layers.subdiagrams.popup;
+
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.examples.layers.Layer;
+import org.eclipse.gmf.examples.layers.LayersFactory;
+import org.eclipse.gmf.examples.layers.LayersPackage;
+import org.eclipse.gmf.examples.layers.SubDiagramSpec;
+import org.eclipse.gmf.examples.layers.SubDiagramSupport;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+
+public class CreateNewLayerAction extends DiagramAction {
+
+ private final List mySemanticElements;
+
+ private final SubDiagramSupport mySupport;
+
+ private final SubDiagramSpec myDiagram;
+
+ public CreateNewLayerAction(IWorkbenchPage workbenchPage, List semanticElements, SubDiagramSupport support, SubDiagramSpec diagram) {
+ super(workbenchPage);
+ mySemanticElements = semanticElements;
+ mySupport = support;
+ myDiagram = diagram;
+ setText("Add To New Layer...");
+ setChecked(false);
+ }
+
+ @Override
+ protected Request createTargetRequest() {
+ return null;
+ }
+
+ @Override
+ protected boolean isSelectionListener() {
+ return true;
+ }
+
+ @Override
+ protected Command getCommand() {
+ DiagramEditPart diagramEditPart = getDiagramEditPart();
+ if (diagramEditPart == null) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ IEditCommandRequest request = new DomainOnlyEditRequest(diagramEditPart);
+ return new ICommandProxy(new CreateNewLayer("Creating New Layer", mySupport, mySemanticElements, myDiagram, request, getWorkbenchPart().getSite().getShell()));
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return getDiagramEditPart() != null && !mySemanticElements.isEmpty();
+ }
+
+ public static class CreateNewLayer extends EditElementCommand {
+
+ private final SubDiagramSupport mySupport;
+
+ private final List myAssignees;
+
+ private final Shell myShell;
+
+ private final SubDiagramSpec myDiagram;
+
+ protected CreateNewLayer(String label, SubDiagramSupport support, List assignees, SubDiagramSpec diagram, IEditCommandRequest request, Shell shell) {
+ super(label, support, request);
+ myAssignees = assignees;
+ mySupport = support;
+ myDiagram = diagram;
+ myShell = shell;
+ }
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ UniqueNameValidator validator = new UniqueNameValidator(mySupport.getLayers(), LayersPackage.eINSTANCE.getLayer_Name());
+ InputDialog dialog = new InputDialog(myShell, //
+ "Enter The Name", "New Layer's Name:", validator.guessNewName("Layer "), validator);
+
+ if (dialog.open() != Window.OK) {
+ return CommandResult.newCancelledCommandResult();
+ }
+
+ Layer layer = LayersFactory.eINSTANCE.createLayer();
+ layer.setName(dialog.getValue());
+ mySupport.getLayers().add(layer);
+ mySupport.ensureAllSubDiagramsHaveEnablementForAllLayers();
+ layer.getParticipants().addAll(myAssignees);
+
+ myDiagram.findLayerEnablement(layer).setVisible(true);
+
+ return CommandResult.newOKCommandResult(layer);
+ }
+ }
+}
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/CreateSubDiagramAction.java b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/CreateSubDiagramAction.java
new file mode 100644
index 000000000..9004c22ee
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/CreateSubDiagramAction.java
@@ -0,0 +1,115 @@
+package org.eclipse.gmf.examples.layers.subdiagrams.popup;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.examples.layers.LayersPackage;
+import org.eclipse.gmf.examples.layers.SubDiagramSpec;
+import org.eclipse.gmf.examples.layers.SubDiagramSupport;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+
+public class CreateSubDiagramAction extends SubDiagramActionBase {
+
+ private final SubDiagramSpec mySpec;
+
+ private final SubDiagramSupport mySupport;
+
+ public CreateSubDiagramAction(IWorkbenchPage workbenchPage, SubDiagramSpec spec, SubDiagramSupport support) {
+ super(workbenchPage);
+ mySpec = spec;
+ mySupport = support;
+ }
+
+ @Override
+ protected Command getCommand() {
+ DiagramEditPart diagramEditPart = getDiagramEditPart();
+ if (diagramEditPart == null) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ if (mySpec == null) {
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ String label = "Creating New Sub Diagram";
+ Ref gateBetweenCommands = new Ref();
+ CompositeTransactionalCommand composite = new CompositeTransactionalCommand(getDiagramEditPart().getEditingDomain(), label);
+ composite.add(new CreateNewSubDiagram(label, mySupport, mySpec, gateBetweenCommands, new DomainOnlyEditRequest(diagramEditPart), getShell()));
+ composite.add(createOpenCommand("Opening New Diagram", gateBetweenCommands));
+
+ return new ICommandProxy(composite);
+ }
+
+ private Shell getShell() {
+ return getWorkbenchPart().getSite().getShell();
+ }
+
+ @Override
+ public void refresh() {
+ super.refresh();
+ setText(calculateText());
+ setChecked(calculateChecked());
+ }
+
+ protected String calculateText() {
+ return "New...";
+ }
+
+ protected boolean calculateChecked() {
+ return false;
+ }
+
+ private static class CreateNewSubDiagram extends EditElementCommand {
+
+ private final SubDiagramSupport mySupport;
+
+ private final SubDiagramSpec myTemplate;
+
+ private final Ref myResultRef;
+
+ private final Shell myShell;
+
+ protected CreateNewSubDiagram(String label, SubDiagramSupport support, SubDiagramSpec template, Ref result, IEditCommandRequest request, Shell shell) {
+ super(label, support, request);
+ mySupport = support;
+ myTemplate = template;
+ myResultRef = result;
+ myShell = shell;
+ }
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ UniqueNameValidator validator = new UniqueNameValidator(mySupport.getAllDiagrams(), LayersPackage.eINSTANCE.getSubDiagramSpec_Name());
+ InputDialog dialog = new InputDialog(myShell, //
+ "Enter The Name", "New Sub Diagram' Name:", validator.guessNewName("Sub Diagram "), validator);
+
+ if (dialog.open() != Window.OK) {
+ return CommandResult.newCancelledCommandResult();
+ }
+
+ Diagram clone = EcoreUtil.copy(myTemplate.getDiagram());
+ SubDiagramSpec result = EcoreUtil.copy(myTemplate);
+ result.setDiagram(clone);
+ result.setName(dialog.getValue());
+
+ mySupport.getSubDiagrams().add(result);
+ mySupport.eResource().getContents().add(clone);
+
+ myResultRef.set(result);
+
+ return CommandResult.newOKCommandResult(result);
+ }
+ }
+}
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/DomainOnlyEditRequest.java b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/DomainOnlyEditRequest.java
new file mode 100644
index 000000000..818d5b8df
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/DomainOnlyEditRequest.java
@@ -0,0 +1,21 @@
+package org.eclipse.gmf.examples.layers.subdiagrams.popup;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest;
+
+class DomainOnlyEditRequest extends AbstractEditCommandRequest {
+
+ public DomainOnlyEditRequest(TransactionalEditingDomain editingDomain) {
+ super(editingDomain);
+ }
+
+ public DomainOnlyEditRequest(IGraphicalEditPart editPart) {
+ this(editPart.getEditingDomain());
+ }
+
+ @Override
+ public Object getEditHelperContext() {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/OpenSubDiagramAction.java b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/OpenSubDiagramAction.java
new file mode 100644
index 000000000..6f174ac11
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/OpenSubDiagramAction.java
@@ -0,0 +1,47 @@
+package org.eclipse.gmf.examples.layers.subdiagrams.popup;
+
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.examples.layers.SubDiagramSpec;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.ui.IWorkbenchPage;
+
+public class OpenSubDiagramAction extends SubDiagramActionBase {
+
+ private final SubDiagramSpec mySpec;
+
+ public OpenSubDiagramAction(IWorkbenchPage workbenchPage, SubDiagramSpec spec) {
+ super(workbenchPage);
+ mySpec = spec;
+ }
+
+ @Override
+ protected Command getCommand() {
+ DiagramEditPart diagramEditPart = getDiagramEditPart();
+ if (diagramEditPart == null) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ if (mySpec == null) {
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ return new ICommandProxy(createOpenCommand("Opening Diagram", mySpec));
+ }
+
+ @Override
+ public void refresh() {
+ super.refresh();
+ setText(calculateText());
+ setChecked(calculateChecked());
+ }
+
+ protected String calculateText() {
+ return safeGetSubDiagramName(mySpec);
+ }
+
+ protected boolean calculateChecked() {
+ return false;
+ }
+
+}
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SubDiagramActionBase.java b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SubDiagramActionBase.java
new file mode 100644
index 000000000..46e231c10
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SubDiagramActionBase.java
@@ -0,0 +1,195 @@
+package org.eclipse.gmf.examples.layers.subdiagrams.popup;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.ui.URIEditorInput;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.gef.Request;
+import org.eclipse.gmf.examples.layers.SubDiagramSpec;
+import org.eclipse.gmf.examples.layers.SubDiagramSupport;
+import org.eclipse.gmf.examples.layers.subdiagrams.DefaultSaveOptions;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction;
+import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.eclipse.ui.part.FileEditorInput;
+
+public abstract class SubDiagramActionBase extends DiagramAction {
+
+ protected static final String EMPTY_DIAGRAM_NAME = "";
+
+ public SubDiagramActionBase(IWorkbenchPage workbenchPage) {
+ super(workbenchPage);
+ }
+
+ @Override
+ protected Request createTargetRequest() {
+ return null;
+ }
+
+ @Override
+ protected boolean isSelectionListener() {
+ return true;
+ }
+
+ protected String findDiagramEditorId() {
+ return getDiagramWorkbenchPart().getSite().getId();
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return getDiagramEditPart() != null;
+ }
+
+ protected static String safeGetSubDiagramName(SubDiagramSpec spec) {
+ String name = spec.getName();
+ return name != null ? name : EMPTY_DIAGRAM_NAME;
+
+ }
+
+ protected OpenSubDiagramCommand createOpenCommand(String label, SubDiagramSpec spec) {
+ return createOpenCommand(label, Ref.create(spec));
+ }
+
+ protected OpenSubDiagramCommand createOpenCommand(String label, Ref spec) {
+ IEditCommandRequest request = new DomainOnlyEditRequest(getDiagramEditPart());
+ return new OpenSubDiagramCommand(label, spec, findDiagramEditorId(), request);
+ }
+
+ protected static class OpenSubDiagramCommand extends EditElementCommand {
+
+ private final Ref mySpecRef;
+
+ private final String myEditorId;
+
+ public OpenSubDiagramCommand(String label, Ref spec, String editorId, IEditCommandRequest request) {
+ super(label, spec.get(), request);
+ mySpecRef = spec;
+ myEditorId = editorId;
+ }
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ SubDiagramSpec spec = mySpecRef.get();
+ if (spec == null) {
+ throw new ExecutionException("Can't find diagram specification");
+ }
+
+ Diagram diagram = spec.getDiagram();
+ SubDiagramSupport support = (SubDiagramSupport) spec.eContainer();
+
+ saveResourceSet(spec);
+
+ IEditorInput editorInput = null;
+ if (spec == support.getMainDiagram()) {
+ //to switch to the main diagram if already open
+ IFile file = WorkspaceSynchronizer.getFile(diagram.eResource());
+ if (file != null) {
+ editorInput = new FileEditorInput(file);
+ }
+ }
+ if (editorInput == null) {
+ URI uri = EcoreUtil.getURI(diagram);
+ String editorName = uri.lastSegment() + '#' + OpenSubDiagramAction.safeGetSubDiagramName(spec);
+ editorInput = new URIEditorInput(uri, editorName);
+ }
+
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ try {
+ page.openEditor(editorInput, myEditorId);
+ } catch (PartInitException e) {
+ throw new ExecutionException("Can't Open Sub Diagram", e);
+ }
+
+ return CommandResult.newOKCommandResult();
+ }
+
+ protected void saveResourceSet(final SubDiagramSpec diagramSpec) throws ExecutionException {
+ try {
+ new WorkspaceModifyOperation() {
+
+ @Override
+ protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
+ try {
+ for (Resource nextResource : diagramSpec.eResource().getResourceSet().getResources()) {
+ if (nextResource.isLoaded() && !getEditingDomain().isReadOnly(nextResource)) {
+ nextResource.save(DefaultSaveOptions.getSaveOptions());
+ }
+ }
+ } catch (IOException ex) {
+ throw new InvocationTargetException(ex, "Save operation failed");
+ }
+ }
+ }.run(null);
+ } catch (InvocationTargetException e) {
+ throw new ExecutionException("Can't save diagram file", e);
+ } catch (InterruptedException e) {
+ throw new ExecutionException("Can't save diagram file", e);
+ }
+
+ }
+
+ /**
+ * XXX: this is copied from default diagram save options.
+ * It may be a problem if the particular diagram has a custom changed ones
+ */
+ protected static Map, ?> getSaveOptions() {
+
+ HashMap saveOptions = new HashMap();
+ saveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
+ saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
+ return saveOptions;
+ }
+
+ }
+
+ protected static class Ref {
+
+ private T myValue;
+
+ public Ref() {
+ }
+
+ public Ref(T value) {
+ myValue = value;
+ }
+
+ public boolean isNull() {
+ return myValue == null;
+ }
+
+ public T get() {
+ return myValue;
+ }
+
+ public void set(T value) {
+ myValue = value;
+ }
+
+ public static Ref create(T value) {
+ return new Ref(value);
+ }
+
+ public String toString() {
+ return String.valueOf(myValue);
+ }
+ }
+}
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SubDiagramsItemProvider.java b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SubDiagramsItemProvider.java
new file mode 100644
index 000000000..052131c60
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SubDiagramsItemProvider.java
@@ -0,0 +1,85 @@
+package org.eclipse.gmf.examples.layers.subdiagrams.popup;
+
+import org.eclipse.gmf.examples.layers.SubDiagramSpec;
+import org.eclipse.gmf.examples.layers.SubDiagramSupport;
+import org.eclipse.gmf.examples.layers.subdiagrams.SubDiagramManager;
+import org.eclipse.gmf.examples.layers.subdiagrams.SubDiagramManagerImpl;
+import org.eclipse.gmf.runtime.common.core.service.IProvider;
+import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.AbstractContributionItemProvider;
+import org.eclipse.gmf.runtime.common.ui.util.IWorkbenchPartDescriptor;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.ui.IWorkbenchPage;
+
+public class SubDiagramsItemProvider extends AbstractContributionItemProvider implements IProvider {
+
+ public static final String MENU_MANAGE_SUB_DIAGRAMS = "menu_manage_subdiagrams"; //$NON-NLS-1$
+
+ @Override
+ protected IMenuManager createMenuManager(String menuId, IWorkbenchPartDescriptor partDescriptor) {
+ if (!MENU_MANAGE_SUB_DIAGRAMS.equals(menuId)) {
+ return super.createMenuManager(menuId, partDescriptor);
+ }
+ MenuManager menuManager = new MenuManager("Open Sub Diagram");
+ MenuBuilder builder = new MenuBuilder(partDescriptor);
+ // XXX: build initial content -- otherwise menu is never shown
+ builder.buildMenu(menuManager);
+
+ menuManager.addMenuListener(builder);
+ return menuManager;
+ }
+
+ private class MenuBuilder implements IMenuListener {
+
+ private final IWorkbenchPartDescriptor myWorkbenchPart;
+
+ public MenuBuilder(IWorkbenchPartDescriptor workbenchPart) {
+ myWorkbenchPart = workbenchPart;
+ }
+
+ public void menuAboutToShow(IMenuManager manager) {
+ buildMenu(manager);
+ }
+
+ public void buildMenu(IMenuManager manager) {
+ manager.removeAll();
+ DiagramEditPart selected = (DiagramEditPart) getSelectedObject(myWorkbenchPart);
+ Diagram diagram = selected.getDiagramView();
+
+ SubDiagramManager subsetManager = SubDiagramManagerImpl.findOrCreateSubsetManager(diagram);
+ SubDiagramSupport support = subsetManager.getSubDiagramSupport();
+ if (support == null) {
+ return;
+ }
+
+ SubDiagramSpec thisSpec = support.findDiagramSpec(diagram);
+ if (thisSpec == null) {
+ return;
+ }
+
+ for (SubDiagramSpec nextSpec : support.getAllDiagrams()) {
+ if (nextSpec == thisSpec) {
+ continue;
+ }
+ OpenSubDiagramAction action = new OpenSubDiagramAction(getWorkbenchPage(), nextSpec);
+ action.init();
+ manager.add(action);
+ }
+
+ manager.add(new Separator());
+
+ CreateSubDiagramAction createNew = new CreateSubDiagramAction(getWorkbenchPage(), thisSpec, support);
+ createNew.init();
+ manager.add(createNew);
+ }
+
+ private IWorkbenchPage getWorkbenchPage() {
+ return myWorkbenchPart.getPartPage();
+ }
+ }
+
+}
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SwitchLayerVisibilityAction.java b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SwitchLayerVisibilityAction.java
new file mode 100644
index 000000000..c56d74249
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SwitchLayerVisibilityAction.java
@@ -0,0 +1,210 @@
+package org.eclipse.gmf.examples.layers.subdiagrams.popup;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.examples.layers.Layer;
+import org.eclipse.gmf.examples.layers.LayerEnablement;
+import org.eclipse.gmf.examples.layers.LayersFactory;
+import org.eclipse.gmf.examples.layers.SubDiagramSpec;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.ui.IWorkbenchPage;
+
+public class SwitchLayerVisibilityAction extends DiagramAction {
+
+ protected static final String EMPTY_LAYER_NAME = "";
+
+ private final Layer myLayer;
+
+ private final SubDiagramSpec mySpec;
+
+ public SwitchLayerVisibilityAction(IWorkbenchPage workbenchPage, Layer layer, SubDiagramSpec spec) {
+ super(workbenchPage);
+ myLayer = layer;
+ mySpec = spec;
+ }
+
+ @Override
+ protected Request createTargetRequest() {
+ return null;
+ }
+
+ @Override
+ protected boolean isSelectionListener() {
+ return true;
+ }
+
+ @Override
+ protected Command getCommand() {
+ DiagramEditPart diagramEditPart = getDiagramEditPart();
+ if (diagramEditPart == null) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ if (mySpec == null) {
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ IEditCommandRequest request = new DomainOnlyEditRequest(diagramEditPart);
+ return new ICommandProxy(new SwitchLayerVisibility("Switching Layer Visibility", myLayer, mySpec, request));
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return getDiagramEditPart() != null;
+ }
+
+ @Override
+ public void refresh() {
+ super.refresh();
+ setText(calculateText());
+ setChecked(calculateChecked());
+ }
+
+ protected String calculateText() {
+ String name = myLayer.getName();
+ return name != null ? name : EMPTY_LAYER_NAME;
+ }
+
+ protected boolean calculateChecked() {
+ LayerEnablement layerEnablement = mySpec.findLayerEnablement(myLayer);
+ //may be null, but only if disabled
+ return layerEnablement != null && layerEnablement.isVisible();
+ }
+
+ protected static class SwitchLayerVisibility extends EditElementCommand {
+
+ private final Layer myLayer;
+
+ private final SubDiagramSpec myDiagramSpec;
+
+ protected SwitchLayerVisibility(String label, Layer layer, SubDiagramSpec spec, IEditCommandRequest request) {
+ super(label, layer, request);
+ myLayer = layer;
+ myDiagramSpec = spec;
+ }
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ final NodesBag mappedNodes = mapDiagramNodes();
+ LayerEnablement enablement = myDiagramSpec.findLayerEnablement(myLayer);
+ if (enablement != null && enablement.isVisible()) {
+ enablement.setVisible(false);
+
+ final Map> mappedLayers = mapLayers();
+ for (EObject nextParticipant : enablement.getLayer().getParticipants()) {
+ List allLayers = mappedLayers.get(nextParticipant);
+ if (!hasVisibleLayerOtherThan(allLayers, enablement.getLayer())) {
+ mappedNodes.setAllNodesVisibleFor(nextParticipant, false);
+ }
+ }
+ } else {
+ if (enablement == null) {
+ enablement = LayersFactory.eINSTANCE.createLayerEnablement();
+ enablement.setLayer(myLayer);
+ myDiagramSpec.getDiagramLayers().add(enablement);
+ }
+ enablement.setVisible(true);
+ //if element is in at least one visible layer, it is visible for sure
+ for (EObject nextParticiant : myLayer.getParticipants()) {
+ mappedNodes.setAllNodesVisibleFor(nextParticiant, true);
+ }
+ }
+ return CommandResult.newOKCommandResult(enablement);
+ }
+
+ private static boolean hasVisibleLayerOtherThan(List allLayers, Layer layer) {
+ if (allLayers == null) {
+ return false;
+ }
+ for (LayerEnablement next : allLayers) {
+ if (next.getLayer() == layer) {
+ continue;
+ }
+ if (next.isVisible()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private NodesBag mapDiagramNodes() {
+ NodesBag result = new NodesBag();
+ LinkedList queue = new LinkedList();
+ queue.add(myDiagramSpec.getDiagram());
+
+ while (!queue.isEmpty()) {
+ View next = queue.removeFirst();
+ if (next.isSetElement() && next instanceof Node) {
+ EObject element = next.getElement();
+ if (element != null) {
+ result.putOne(element, (Node) next);
+ }
+ }
+ @SuppressWarnings("unchecked")
+ List children = next.getChildren();
+ queue.addAll(children);
+ }
+
+ return result;
+ }
+
+ private BagByEObject mapLayers() {
+ BagByEObject result = new BagByEObject();
+ for (LayerEnablement next : myDiagramSpec.getDiagramLayers()) {
+ for (EObject participant : next.getLayer().getParticipants()) {
+ result.putOne(participant, next);
+ }
+ }
+ return result;
+ }
+
+ }
+
+ @SuppressWarnings("serial")
+ private static class BagByEObject extends HashMap> {
+
+ public void putOne(EObject key, V value) {
+ if (key == null) {
+ return;
+ }
+ List values = get(key);
+ if (values == null) {
+ values = new ArrayList();
+ put(key, values);
+ }
+ values.add(value);
+ }
+ }
+
+ @SuppressWarnings("serial")
+ private static class NodesBag extends BagByEObject {
+
+ public void setAllNodesVisibleFor(EObject object, boolean visible) {
+ List nodes = this.get(object);
+ if (nodes != null) {
+ for (Node nextNode : nodes) {
+ nextNode.setVisible(visible);
+ }
+ }
+ }
+
+ }
+
+}
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SwitchLayerVisibilityItemProvider.java b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SwitchLayerVisibilityItemProvider.java
new file mode 100644
index 000000000..206de8774
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/SwitchLayerVisibilityItemProvider.java
@@ -0,0 +1,76 @@
+package org.eclipse.gmf.examples.layers.subdiagrams.popup;
+
+import org.eclipse.gmf.examples.layers.Layer;
+import org.eclipse.gmf.examples.layers.SubDiagramSpec;
+import org.eclipse.gmf.examples.layers.SubDiagramSupport;
+import org.eclipse.gmf.examples.layers.subdiagrams.SubDiagramManager;
+import org.eclipse.gmf.examples.layers.subdiagrams.SubDiagramManagerImpl;
+import org.eclipse.gmf.runtime.common.core.service.IProvider;
+import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.AbstractContributionItemProvider;
+import org.eclipse.gmf.runtime.common.ui.util.IWorkbenchPartDescriptor;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.ui.IWorkbenchPage;
+
+public class SwitchLayerVisibilityItemProvider extends AbstractContributionItemProvider implements IProvider {
+
+ public static final String MENU_SET_LAYER_VISIBILITY = "menu_switch_layer_visibility"; //$NON-NLS-1$
+
+ @Override
+ protected IMenuManager createMenuManager(String menuId, IWorkbenchPartDescriptor partDescriptor) {
+ if (!MENU_SET_LAYER_VISIBILITY.equals(menuId)) {
+ return super.createMenuManager(menuId, partDescriptor);
+ }
+ MenuManager menuManager = new MenuManager("Show Layers");
+ MenuBuilder builder = new MenuBuilder(partDescriptor);
+ // XXX: build initial content -- otherwise menu is never shown
+ builder.buildMenu(menuManager);
+
+ menuManager.addMenuListener(builder);
+ return menuManager;
+ }
+
+ private class MenuBuilder implements IMenuListener {
+
+ private final IWorkbenchPartDescriptor myWorkbenchPart;
+
+ public MenuBuilder(IWorkbenchPartDescriptor workbenchPart) {
+ myWorkbenchPart = workbenchPart;
+ }
+
+ public void menuAboutToShow(IMenuManager manager) {
+ buildMenu(manager);
+ }
+
+ public void buildMenu(IMenuManager manager) {
+ manager.removeAll();
+ DiagramEditPart selected = (DiagramEditPart) getSelectedObject(myWorkbenchPart);
+ Diagram diagram = selected.getDiagramView();
+
+ SubDiagramManager subsetManager = SubDiagramManagerImpl.findOrCreateSubsetManager(diagram);
+ SubDiagramSupport support = subsetManager.getSubDiagramSupport();
+ if (support == null) {
+ return;
+ }
+
+ SubDiagramSpec diagramSpec = support.findDiagramSpec(diagram);
+ if (diagramSpec == null) {
+ return;
+ }
+
+ for (Layer next : support.getLayers()) {
+ SwitchLayerVisibilityAction action = new SwitchLayerVisibilityAction(getWorkbenchPage(), next, diagramSpec);
+ action.init();
+ manager.add(action);
+ }
+ }
+
+ private IWorkbenchPage getWorkbenchPage() {
+ return myWorkbenchPart.getPartPage();
+ }
+ }
+
+}
diff --git a/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/UniqueNameValidator.java b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/UniqueNameValidator.java
new file mode 100644
index 000000000..5fdaafd22
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.layers.subdiagrams/src/org/eclipse/gmf/examples/layers/subdiagrams/popup/UniqueNameValidator.java
@@ -0,0 +1,65 @@
+package org.eclipse.gmf.examples.layers.subdiagrams.popup;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.jface.dialogs.IInputValidator;
+
+class UniqueNameValidator implements IInputValidator {
+
+ private final Set myAllNames = new HashSet();
+
+ private boolean myAllowEmptyName;
+
+ public UniqueNameValidator(List extends EObject> objects, EStructuralFeature nameFeature) {
+ for (EObject next : objects) {
+ Object nextValue = next.eGet(nameFeature);
+ if (nextValue != null) {
+ myAllNames.add(String.valueOf(nextValue));
+ }
+ }
+ }
+
+ public void setAllowEmptyName(boolean allowEmptyName) {
+ myAllowEmptyName = allowEmptyName;
+ }
+
+ @Override
+ public String isValid(String newText) {
+ if (newText == null) {
+ return myAllowEmptyName ? null : "Empty Name Is Not Allowed";
+ }
+ newText = newText.trim();
+ if (newText.length() == 0 && !myAllowEmptyName) {
+ return "Empty Name Is Not Allowed";
+ }
+ if (myAllNames.contains(newText)) {
+ return "This Name Already Exists";
+ }
+ return null;
+ }
+
+ public String guessNewName(String prefix) {
+ for (int i = 0; i < 26; i++) {
+ String nextCandidate = prefix + (char) ('A' + i);
+ if (isValid(nextCandidate) == null) {
+ return nextCandidate;
+ }
+ }
+
+ //wow
+ int i = 0;
+ while (++i < 1000) {
+ String nextCandidate = prefix + i;
+ if (isValid(nextCandidate) == null) {
+ return nextCandidate;
+ }
+ }
+
+ return "";
+ }
+
+}
\ No newline at end of file
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/.classpath b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/.classpath
index c50b57478..021596729 100644
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/.classpath
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/.classpath
@@ -1,7 +1,6 @@
-
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/META-INF/MANIFEST.MF b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/META-INF/MANIFEST.MF
index 18d94a28f..0d52baaca 100644
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/META-INF/MANIFEST.MF
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/META-INF/MANIFEST.MF
@@ -41,7 +41,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.gmf.examples.taipan.ui,
org.eclipse.emf.validation.ocl;visibility:=reexport,
org.eclipse.gmf.tooling.runtime,
- org.eclipse.gmf.examples.layers;bundle-version="1.0.0"
+ org.eclipse.gmf.examples.layers.subdiagrams;bundle-version="1.0.0"
Eclipse-LazyStart: true
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/build.properties b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/build.properties
index aa8661e5b..45032b6db 100644
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/build.properties
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/build.properties
@@ -7,6 +7,5 @@ bin.includes = .,\
messages.properties,\
.options
jars.compile.order = .
-source.. = src/,\
- custom-src/
+source.. = src/
output.. = bin/
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/SubDiagramManager.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/SubDiagramManager.java
deleted file mode 100644
index 873392efe..000000000
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/SubDiagramManager.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.eclipse.gmf.examples.subdiagrams;
-
-import org.eclipse.gmf.examples.layers.SubDiagramSupport;
-
-
-public interface SubDiagramManager {
-
- public SubDiagramSupport getSubDiagramSupport();
-
-}
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/SubDiagramManagerImpl.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/SubDiagramManagerImpl.java
deleted file mode 100644
index e20a06dc1..000000000
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/SubDiagramManagerImpl.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package org.eclipse.gmf.examples.subdiagrams;
-
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.impl.AdapterImpl;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.gmf.examples.layers.LayersFactory;
-import org.eclipse.gmf.examples.layers.SubDiagramSpec;
-import org.eclipse.gmf.examples.layers.SubDiagramSupport;
-import org.eclipse.gmf.runtime.notation.Diagram;
-
-public class SubDiagramManagerImpl implements SubDiagramManager {
-
- private static class ManagerHolderAdapter extends AdapterImpl {
-
- private final SubDiagramManagerImpl myManager;
-
- public ManagerHolderAdapter(SubDiagramManagerImpl manager) {
- myManager = manager;
- }
-
- public SubDiagramManagerImpl getManager() {
- return myManager;
- }
- }
-
- public static SubDiagramManager findOrCreateSubsetManager(Diagram diagram) {
- for (Adapter next : diagram.eAdapters()) {
- if (next instanceof ManagerHolderAdapter) {
- return ((ManagerHolderAdapter) next).getManager();
- }
- }
- SubDiagramManagerImpl result = new SubDiagramManagerImpl(diagram.eResource());
- diagram.eAdapters().add(new ManagerHolderAdapter(result));
- return result;
- }
-
- public static void setupSubsetsSupport(Diagram diagram, Resource diagramResource) {
- SubDiagramSupport support = LayersFactory.eINSTANCE.createSubDiagramSupport();
- diagramResource.getContents().add(support);
-
- SubDiagramSpec mainDiagramSpec = LayersFactory.eINSTANCE.createSubDiagramSpec();
- mainDiagramSpec.setName("Main");
- mainDiagramSpec.setShowing(true);
- mainDiagramSpec.setDiagram(diagram);
- support.setMainDiagram(mainDiagramSpec);
-
- //fake layers
- // Layer layerA = LayersFactory.eINSTANCE.createLayer();
- // layerA.setName("Layer A");
- //
- // Layer layerB = LayersFactory.eINSTANCE.createLayer();
- // layerB.setName("Layer B");
- //
- // support.getLayers().add(layerA);
- // support.getLayers().add(layerB);
- //
-
- support.ensureAllSubDiagramsHaveEnablementForAllLayers();
- }
-
- private final Resource myDiagramResource;
-
- private final SubDiagramSupport mySubDiagramSupport;
-
- public SubDiagramManagerImpl(Resource diagramResource) {
- myDiagramResource = diagramResource;
- mySubDiagramSupport = findSubDiagramSupport(myDiagramResource);
- }
-
- private static SubDiagramSupport findSubDiagramSupport(Resource resource) {
- for (EObject next : resource.getContents()) {
- if (next instanceof SubDiagramSupport) {
- return (SubDiagramSupport) next;
- }
- }
- return null;
- }
-
- @Override
- public SubDiagramSupport getSubDiagramSupport() {
- return mySubDiagramSupport;
- }
-
-}
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerAction.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerAction.java
deleted file mode 100644
index 6557a7aa8..000000000
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerAction.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package org.eclipse.gmf.examples.subdiagrams.popup;
-
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.examples.layers.Layer;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
-import org.eclipse.ui.IWorkbenchPage;
-
-public class AssignToLayerAction extends DiagramAction {
-
- protected static final String EMPTY_LAYER_NAME = "";
-
- private final Layer myLayerToAssign;
-
- private final List mySemanticElements;
-
- public AssignToLayerAction(IWorkbenchPage workbenchPage, List semanticElements, Layer layer) {
- super(workbenchPage);
- mySemanticElements = semanticElements;
- myLayerToAssign = layer;
- }
-
- @Override
- protected Request createTargetRequest() {
- return null;
- }
-
- @Override
- protected boolean isSelectionListener() {
- return true;
- }
-
- @Override
- protected Command getCommand() {
- DiagramEditPart diagramEditPart = getDiagramEditPart();
- if (diagramEditPart == null) {
- return UnexecutableCommand.INSTANCE;
- }
- IEditCommandRequest request = new DomainOnlyEditRequest(diagramEditPart);
- boolean addNotRemove = !isAssignedToLayer(mySemanticElements, myLayerToAssign);
- return new ICommandProxy(new AssignToLayer("Changing Layer Assignments", myLayerToAssign, mySemanticElements, addNotRemove, request));
- }
-
- @Override
- public boolean isEnabled() {
- return getDiagramEditPart() != null;
- }
-
- @Override
- public void refresh() {
- super.refresh();
- setText(calculateText());
- setChecked(calculateChecked());
- }
-
- protected String calculateText() {
- String name = myLayerToAssign.getName();
- return name != null ? name : EMPTY_LAYER_NAME;
- }
-
- protected boolean calculateChecked() {
- return isAssignedToLayer(mySemanticElements, myLayerToAssign);
- }
-
- private boolean isAssignedToLayer(List semanticElements, Layer layer) {
- return layer.getParticipants().containsAll(semanticElements);
- }
-
- public static class AssignToLayer extends EditElementCommand {
-
- private final Layer myLayer;
-
- private final List myAssignees;
-
- private final boolean myAddNotRemove;
-
- protected AssignToLayer(String label, Layer layer, List assignees, boolean addNotRemove, IEditCommandRequest request) {
- super(label, layer, request);
- myAssignees = assignees;
- myLayer = layer;
- myAddNotRemove = addNotRemove;
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- if (myAddNotRemove) {
- myLayer.getParticipants().addAll(myAssignees);
- } else {
- myLayer.getParticipants().removeAll(myAssignees);
- }
- return CommandResult.newOKCommandResult(myLayer);
- }
-
- }
-}
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerItemProvider.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerItemProvider.java
deleted file mode 100644
index c984245c6..000000000
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerItemProvider.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package org.eclipse.gmf.examples.subdiagrams.popup;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.examples.layers.Layer;
-import org.eclipse.gmf.examples.layers.SubDiagramSpec;
-import org.eclipse.gmf.examples.layers.SubDiagramSupport;
-import org.eclipse.gmf.examples.subdiagrams.SubDiagramManager;
-import org.eclipse.gmf.examples.subdiagrams.SubDiagramManagerImpl;
-import org.eclipse.gmf.runtime.common.core.service.IProvider;
-import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.AbstractContributionItemProvider;
-import org.eclipse.gmf.runtime.common.ui.util.IWorkbenchPartDescriptor;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.jface.action.IMenuListener;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.ui.IWorkbenchPage;
-
-public class AssignToLayerItemProvider extends AbstractContributionItemProvider implements IProvider {
-
- public static final String MENU_ASSIGN_TO_LAYER = "menu_assign_to_layer"; //$NON-NLS-1$
-
- @Override
- protected IMenuManager createMenuManager(String menuId, IWorkbenchPartDescriptor partDescriptor) {
- if (!MENU_ASSIGN_TO_LAYER.equals(menuId)) {
- return super.createMenuManager(menuId, partDescriptor);
- }
- MenuManager menuManager = new MenuManager("Assign To Layer");
- MenuBuilder builder = new MenuBuilder(partDescriptor);
- // XXX: build initial content -- otherwise menu is never shown
- builder.buildMenu(menuManager);
-
- menuManager.addMenuListener(builder);
- return menuManager;
- }
-
- private class MenuBuilder implements IMenuListener {
-
- private final IWorkbenchPartDescriptor myWorkbenchPart;
-
- public MenuBuilder(IWorkbenchPartDescriptor workbenchPart) {
- myWorkbenchPart = workbenchPart;
- }
-
- public void menuAboutToShow(IMenuManager manager) {
- buildMenu(manager);
- }
-
- public void buildMenu(IMenuManager manager) {
- manager.removeAll();
- IGraphicalEditPart firstSelected = (IGraphicalEditPart) getSelectedObject(myWorkbenchPart);
- Diagram activeDiagram = firstSelected.getNotationView().getDiagram();
-
- SubDiagramManager subsetManager = SubDiagramManagerImpl.findOrCreateSubsetManager(activeDiagram);
- SubDiagramSupport support = subsetManager.getSubDiagramSupport();
-
- SubDiagramSpec activeSpec = support.findDiagramSpec(activeDiagram);
-
- List allSelectedEObjects = Collections.unmodifiableList(resolveSelectedSemanticElements());
- for (Layer next : support.getLayers()) {
- AssignToLayerAction action = new AssignToLayerAction(getWorkbenchPage(), allSelectedEObjects, next);
- action.init();
- manager.add(action);
- }
-
- manager.add(new Separator());
- CreateNewLayerAction createNewAction = new CreateNewLayerAction(getWorkbenchPage(), allSelectedEObjects, support, activeSpec);
- createNewAction.init();
- manager.add(createNewAction);
- }
-
- private List resolveSelectedSemanticElements() {
- LinkedHashSet result = new LinkedHashSet();
- for (Object next : getStructuredSelection(myWorkbenchPart).toArray()) {
- if (next instanceof IGraphicalEditPart) {
- result.add(((IGraphicalEditPart) next).resolveSemanticElement());
- }
- }
- return new ArrayList(result);
- }
-
- private IWorkbenchPage getWorkbenchPage() {
- return myWorkbenchPart.getPartPage();
- }
- }
-
-}
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerItemProviderPolicy.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerItemProviderPolicy.java
deleted file mode 100644
index 4875b9b6d..000000000
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerItemProviderPolicy.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.eclipse.gmf.examples.subdiagrams.popup;
-
-import java.util.List;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.IPopupMenuContributionPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-
-public class AssignToLayerItemProviderPolicy implements IPopupMenuContributionPolicy {
-
- @Override
- public boolean appliesTo(ISelection selection, IConfigurationElement configuration) {
- if (false == selection instanceof IStructuredSelection) {
- return false;
- }
- List> allSelected = ((IStructuredSelection) selection).toList();
- if (allSelected.isEmpty()) {
- return false;
- }
- for (Object next : allSelected) {
- if (!checkSelectedElement(next)) {
- return false;
- }
- }
- return true;
- }
-
- private boolean checkSelectedElement(Object selected) {
- return selected instanceof IGraphicalEditPart && !(selected instanceof DiagramEditPart);
- }
-
-}
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/CreateNewLayerAction.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/CreateNewLayerAction.java
deleted file mode 100644
index c08a04484..000000000
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/CreateNewLayerAction.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.eclipse.gmf.examples.subdiagrams.popup;
-
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.examples.layers.Layer;
-import org.eclipse.gmf.examples.layers.LayersFactory;
-import org.eclipse.gmf.examples.layers.LayersPackage;
-import org.eclipse.gmf.examples.layers.SubDiagramSpec;
-import org.eclipse.gmf.examples.layers.SubDiagramSupport;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbenchPage;
-
-public class CreateNewLayerAction extends DiagramAction {
-
- private final List mySemanticElements;
-
- private final SubDiagramSupport mySupport;
-
- private final SubDiagramSpec myDiagram;
-
- public CreateNewLayerAction(IWorkbenchPage workbenchPage, List semanticElements, SubDiagramSupport support, SubDiagramSpec diagram) {
- super(workbenchPage);
- mySemanticElements = semanticElements;
- mySupport = support;
- myDiagram = diagram;
- setText("Add To New Layer...");
- setChecked(false);
- }
-
- @Override
- protected Request createTargetRequest() {
- return null;
- }
-
- @Override
- protected boolean isSelectionListener() {
- return true;
- }
-
- @Override
- protected Command getCommand() {
- DiagramEditPart diagramEditPart = getDiagramEditPart();
- if (diagramEditPart == null) {
- return UnexecutableCommand.INSTANCE;
- }
- IEditCommandRequest request = new DomainOnlyEditRequest(diagramEditPart);
- return new ICommandProxy(new CreateNewLayer("Creating New Layer", mySupport, mySemanticElements, myDiagram, request, getWorkbenchPart().getSite().getShell()));
- }
-
- @Override
- public boolean isEnabled() {
- return getDiagramEditPart() != null && !mySemanticElements.isEmpty();
- }
-
- public static class CreateNewLayer extends EditElementCommand {
-
- private final SubDiagramSupport mySupport;
-
- private final List myAssignees;
-
- private final Shell myShell;
-
- private final SubDiagramSpec myDiagram;
-
- protected CreateNewLayer(String label, SubDiagramSupport support, List assignees, SubDiagramSpec diagram, IEditCommandRequest request, Shell shell) {
- super(label, support, request);
- myAssignees = assignees;
- mySupport = support;
- myDiagram = diagram;
- myShell = shell;
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- UniqueNameValidator validator = new UniqueNameValidator(mySupport.getLayers(), LayersPackage.eINSTANCE.getLayer_Name());
- InputDialog dialog = new InputDialog(myShell, //
- "Enter The Name", "New Layer's Name:", validator.guessNewName("Layer "), validator);
-
- if (dialog.open() != Window.OK) {
- return CommandResult.newCancelledCommandResult();
- }
-
- Layer layer = LayersFactory.eINSTANCE.createLayer();
- layer.setName(dialog.getValue());
- mySupport.getLayers().add(layer);
- mySupport.ensureAllSubDiagramsHaveEnablementForAllLayers();
- layer.getParticipants().addAll(myAssignees);
-
- myDiagram.findLayerEnablement(layer).setVisible(true);
-
- return CommandResult.newOKCommandResult(layer);
- }
- }
-}
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/CreateSubDiagramAction.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/CreateSubDiagramAction.java
deleted file mode 100644
index e9b82d9d9..000000000
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/CreateSubDiagramAction.java
+++ /dev/null
@@ -1,115 +0,0 @@
-package org.eclipse.gmf.examples.subdiagrams.popup;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.examples.layers.LayersPackage;
-import org.eclipse.gmf.examples.layers.SubDiagramSpec;
-import org.eclipse.gmf.examples.layers.SubDiagramSupport;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbenchPage;
-
-public class CreateSubDiagramAction extends SubDiagramActionBase {
-
- private final SubDiagramSpec mySpec;
-
- private final SubDiagramSupport mySupport;
-
- public CreateSubDiagramAction(IWorkbenchPage workbenchPage, SubDiagramSpec spec, SubDiagramSupport support) {
- super(workbenchPage);
- mySpec = spec;
- mySupport = support;
- }
-
- @Override
- protected Command getCommand() {
- DiagramEditPart diagramEditPart = getDiagramEditPart();
- if (diagramEditPart == null) {
- return UnexecutableCommand.INSTANCE;
- }
- if (mySpec == null) {
- return UnexecutableCommand.INSTANCE;
- }
-
- String label = "Creating New Sub Diagram";
- Ref gateBetweenCommands = new Ref();
- CompositeTransactionalCommand composite = new CompositeTransactionalCommand(getDiagramEditPart().getEditingDomain(), label);
- composite.add(new CreateNewSubDiagram(label, mySupport, mySpec, gateBetweenCommands, new DomainOnlyEditRequest(diagramEditPart), getShell()));
- composite.add(createOpenCommand("Opening New Diagram", gateBetweenCommands));
-
- return new ICommandProxy(composite);
- }
-
- private Shell getShell() {
- return getWorkbenchPart().getSite().getShell();
- }
-
- @Override
- public void refresh() {
- super.refresh();
- setText(calculateText());
- setChecked(calculateChecked());
- }
-
- protected String calculateText() {
- return "New...";
- }
-
- protected boolean calculateChecked() {
- return false;
- }
-
- private static class CreateNewSubDiagram extends EditElementCommand {
-
- private final SubDiagramSupport mySupport;
-
- private final SubDiagramSpec myTemplate;
-
- private final Ref myResultRef;
-
- private final Shell myShell;
-
- protected CreateNewSubDiagram(String label, SubDiagramSupport support, SubDiagramSpec template, Ref result, IEditCommandRequest request, Shell shell) {
- super(label, support, request);
- mySupport = support;
- myTemplate = template;
- myResultRef = result;
- myShell = shell;
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- UniqueNameValidator validator = new UniqueNameValidator(mySupport.getAllDiagrams(), LayersPackage.eINSTANCE.getSubDiagramSpec_Name());
- InputDialog dialog = new InputDialog(myShell, //
- "Enter The Name", "New Sub Diagram' Name:", validator.guessNewName("Sub Diagram "), validator);
-
- if (dialog.open() != Window.OK) {
- return CommandResult.newCancelledCommandResult();
- }
-
- Diagram clone = EcoreUtil.copy(myTemplate.getDiagram());
- SubDiagramSpec result = EcoreUtil.copy(myTemplate);
- result.setDiagram(clone);
- result.setName(dialog.getValue());
-
- mySupport.getSubDiagrams().add(result);
- mySupport.eResource().getContents().add(clone);
-
- myResultRef.set(result);
-
- return CommandResult.newOKCommandResult(result);
- }
- }
-}
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/DomainOnlyEditRequest.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/DomainOnlyEditRequest.java
deleted file mode 100644
index 22ec737ee..000000000
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/DomainOnlyEditRequest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.eclipse.gmf.examples.subdiagrams.popup;
-
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest;
-
-class DomainOnlyEditRequest extends AbstractEditCommandRequest {
-
- public DomainOnlyEditRequest(TransactionalEditingDomain editingDomain) {
- super(editingDomain);
- }
-
- public DomainOnlyEditRequest(IGraphicalEditPart editPart) {
- this(editPart.getEditingDomain());
- }
-
- @Override
- public Object getEditHelperContext() {
- return null;
- }
-}
\ No newline at end of file
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/OpenSubDiagramAction.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/OpenSubDiagramAction.java
deleted file mode 100644
index d69a90498..000000000
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/OpenSubDiagramAction.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package org.eclipse.gmf.examples.subdiagrams.popup;
-
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.examples.layers.SubDiagramSpec;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.ui.IWorkbenchPage;
-
-public class OpenSubDiagramAction extends SubDiagramActionBase {
-
- private final SubDiagramSpec mySpec;
-
- public OpenSubDiagramAction(IWorkbenchPage workbenchPage, SubDiagramSpec spec) {
- super(workbenchPage);
- mySpec = spec;
- }
-
- @Override
- protected Command getCommand() {
- DiagramEditPart diagramEditPart = getDiagramEditPart();
- if (diagramEditPart == null) {
- return UnexecutableCommand.INSTANCE;
- }
- if (mySpec == null) {
- return UnexecutableCommand.INSTANCE;
- }
-
- return new ICommandProxy(createOpenCommand("Opening Diagram", mySpec));
- }
-
- @Override
- public void refresh() {
- super.refresh();
- setText(calculateText());
- setChecked(calculateChecked());
- }
-
- protected String calculateText() {
- return safeGetSubDiagramName(mySpec);
- }
-
- protected boolean calculateChecked() {
- return false;
- }
-
-}
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SubDiagramActionBase.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SubDiagramActionBase.java
deleted file mode 100644
index b75ddb99a..000000000
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SubDiagramActionBase.java
+++ /dev/null
@@ -1,195 +0,0 @@
-package org.eclipse.gmf.examples.subdiagrams.popup;
-
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.common.ui.URIEditorInput;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.ecore.xmi.XMLResource;
-import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
-import org.eclipse.gef.Request;
-import org.eclipse.gmf.examples.layers.SubDiagramSpec;
-import org.eclipse.gmf.examples.layers.SubDiagramSupport;
-import org.eclipse.gmf.examples.taipan.gmf.editor.part.TaiPanDiagramEditorUtil;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction;
-import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.actions.WorkspaceModifyOperation;
-import org.eclipse.ui.part.FileEditorInput;
-
-public abstract class SubDiagramActionBase extends DiagramAction {
-
- protected static final String EMPTY_DIAGRAM_NAME = "";
-
- public SubDiagramActionBase(IWorkbenchPage workbenchPage) {
- super(workbenchPage);
- }
-
- @Override
- protected Request createTargetRequest() {
- return null;
- }
-
- @Override
- protected boolean isSelectionListener() {
- return true;
- }
-
- protected String findDiagramEditorId() {
- return getDiagramWorkbenchPart().getSite().getId();
- }
-
- @Override
- public boolean isEnabled() {
- return getDiagramEditPart() != null;
- }
-
- protected static String safeGetSubDiagramName(SubDiagramSpec spec) {
- String name = spec.getName();
- return name != null ? name : EMPTY_DIAGRAM_NAME;
-
- }
-
- protected OpenSubDiagramCommand createOpenCommand(String label, SubDiagramSpec spec) {
- return createOpenCommand(label, Ref.create(spec));
- }
-
- protected OpenSubDiagramCommand createOpenCommand(String label, Ref spec) {
- IEditCommandRequest request = new DomainOnlyEditRequest(getDiagramEditPart());
- return new OpenSubDiagramCommand(label, spec, findDiagramEditorId(), request);
- }
-
- protected static class OpenSubDiagramCommand extends EditElementCommand {
-
- private final Ref mySpecRef;
-
- private final String myEditorId;
-
- public OpenSubDiagramCommand(String label, Ref spec, String editorId, IEditCommandRequest request) {
- super(label, spec.get(), request);
- mySpecRef = spec;
- myEditorId = editorId;
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- SubDiagramSpec spec = mySpecRef.get();
- if (spec == null) {
- throw new ExecutionException("Can't find diagram specification");
- }
-
- Diagram diagram = spec.getDiagram();
- SubDiagramSupport support = (SubDiagramSupport) spec.eContainer();
-
- saveResourceSet(spec);
-
- IEditorInput editorInput = null;
- if (spec == support.getMainDiagram()) {
- //to switch to the main diagram if already open
- IFile file = WorkspaceSynchronizer.getFile(diagram.eResource());
- if (file != null) {
- editorInput = new FileEditorInput(file);
- }
- }
- if (editorInput == null) {
- URI uri = EcoreUtil.getURI(diagram);
- String editorName = uri.lastSegment() + '#' + OpenSubDiagramAction.safeGetSubDiagramName(spec);
- editorInput = new URIEditorInput(uri, editorName);
- }
-
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- try {
- page.openEditor(editorInput, myEditorId);
- } catch (PartInitException e) {
- throw new ExecutionException("Can't Open Sub Diagram", e);
- }
-
- return CommandResult.newOKCommandResult();
- }
-
- protected void saveResourceSet(final SubDiagramSpec diagramSpec) throws ExecutionException {
- try {
- new WorkspaceModifyOperation() {
-
- @Override
- protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
- try {
- for (Resource nextResource : diagramSpec.eResource().getResourceSet().getResources()) {
- if (nextResource.isLoaded() && !getEditingDomain().isReadOnly(nextResource)) {
- nextResource.save(TaiPanDiagramEditorUtil.getSaveOptions());
- }
- }
- } catch (IOException ex) {
- throw new InvocationTargetException(ex, "Save operation failed");
- }
- }
- }.run(null);
- } catch (InvocationTargetException e) {
- throw new ExecutionException("Can't save diagram file", e);
- } catch (InterruptedException e) {
- throw new ExecutionException("Can't save diagram file", e);
- }
-
- }
-
- /**
- * XXX: this is copied from default diagram save options.
- * It may be a problem if the particular diagram has a custom changed ones
- */
- protected static Map, ?> getSaveOptions() {
-
- HashMap saveOptions = new HashMap();
- saveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
- saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
- return saveOptions;
- }
-
- }
-
- protected static class Ref {
-
- private T myValue;
-
- public Ref() {
- }
-
- public Ref(T value) {
- myValue = value;
- }
-
- public boolean isNull() {
- return myValue == null;
- }
-
- public T get() {
- return myValue;
- }
-
- public void set(T value) {
- myValue = value;
- }
-
- public static Ref create(T value) {
- return new Ref(value);
- }
-
- public String toString() {
- return String.valueOf(myValue);
- }
- }
-}
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SubDiagramsItemProvider.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SubDiagramsItemProvider.java
deleted file mode 100644
index ba9376019..000000000
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SubDiagramsItemProvider.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package org.eclipse.gmf.examples.subdiagrams.popup;
-
-import org.eclipse.gmf.examples.layers.SubDiagramSpec;
-import org.eclipse.gmf.examples.layers.SubDiagramSupport;
-import org.eclipse.gmf.examples.subdiagrams.SubDiagramManager;
-import org.eclipse.gmf.examples.subdiagrams.SubDiagramManagerImpl;
-import org.eclipse.gmf.runtime.common.core.service.IProvider;
-import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.AbstractContributionItemProvider;
-import org.eclipse.gmf.runtime.common.ui.util.IWorkbenchPartDescriptor;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.jface.action.IMenuListener;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.ui.IWorkbenchPage;
-
-public class SubDiagramsItemProvider extends AbstractContributionItemProvider implements IProvider {
-
- public static final String MENU_MANAGE_SUB_DIAGRAMS = "menu_manage_subdiagrams"; //$NON-NLS-1$
-
- @Override
- protected IMenuManager createMenuManager(String menuId, IWorkbenchPartDescriptor partDescriptor) {
- if (!MENU_MANAGE_SUB_DIAGRAMS.equals(menuId)) {
- return super.createMenuManager(menuId, partDescriptor);
- }
- MenuManager menuManager = new MenuManager("Open Sub Diagram");
- MenuBuilder builder = new MenuBuilder(partDescriptor);
- // XXX: build initial content -- otherwise menu is never shown
- builder.buildMenu(menuManager);
-
- menuManager.addMenuListener(builder);
- return menuManager;
- }
-
- private class MenuBuilder implements IMenuListener {
-
- private final IWorkbenchPartDescriptor myWorkbenchPart;
-
- public MenuBuilder(IWorkbenchPartDescriptor workbenchPart) {
- myWorkbenchPart = workbenchPart;
- }
-
- public void menuAboutToShow(IMenuManager manager) {
- buildMenu(manager);
- }
-
- public void buildMenu(IMenuManager manager) {
- manager.removeAll();
- DiagramEditPart selected = (DiagramEditPart) getSelectedObject(myWorkbenchPart);
- Diagram diagram = selected.getDiagramView();
-
- SubDiagramManager subsetManager = SubDiagramManagerImpl.findOrCreateSubsetManager(diagram);
- SubDiagramSupport support = subsetManager.getSubDiagramSupport();
- if (support == null) {
- return;
- }
-
- SubDiagramSpec thisSpec = support.findDiagramSpec(diagram);
- if (thisSpec == null) {
- return;
- }
-
- for (SubDiagramSpec nextSpec : support.getAllDiagrams()) {
- if (nextSpec == thisSpec) {
- continue;
- }
- OpenSubDiagramAction action = new OpenSubDiagramAction(getWorkbenchPage(), nextSpec);
- action.init();
- manager.add(action);
- }
-
- manager.add(new Separator());
-
- CreateSubDiagramAction createNew = new CreateSubDiagramAction(getWorkbenchPage(), thisSpec, support);
- createNew.init();
- manager.add(createNew);
- }
-
- private IWorkbenchPage getWorkbenchPage() {
- return myWorkbenchPart.getPartPage();
- }
- }
-
-}
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SwitchLayerVisibilityAction.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SwitchLayerVisibilityAction.java
deleted file mode 100644
index 462c73a52..000000000
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SwitchLayerVisibilityAction.java
+++ /dev/null
@@ -1,210 +0,0 @@
-package org.eclipse.gmf.examples.subdiagrams.popup;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.examples.layers.Layer;
-import org.eclipse.gmf.examples.layers.LayerEnablement;
-import org.eclipse.gmf.examples.layers.LayersFactory;
-import org.eclipse.gmf.examples.layers.SubDiagramSpec;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.ui.IWorkbenchPage;
-
-public class SwitchLayerVisibilityAction extends DiagramAction {
-
- protected static final String EMPTY_LAYER_NAME = "";
-
- private final Layer myLayer;
-
- private final SubDiagramSpec mySpec;
-
- public SwitchLayerVisibilityAction(IWorkbenchPage workbenchPage, Layer layer, SubDiagramSpec spec) {
- super(workbenchPage);
- myLayer = layer;
- mySpec = spec;
- }
-
- @Override
- protected Request createTargetRequest() {
- return null;
- }
-
- @Override
- protected boolean isSelectionListener() {
- return true;
- }
-
- @Override
- protected Command getCommand() {
- DiagramEditPart diagramEditPart = getDiagramEditPart();
- if (diagramEditPart == null) {
- return UnexecutableCommand.INSTANCE;
- }
- if (mySpec == null) {
- return UnexecutableCommand.INSTANCE;
- }
-
- IEditCommandRequest request = new DomainOnlyEditRequest(diagramEditPart);
- return new ICommandProxy(new SwitchLayerVisibility("Switching Layer Visibility", myLayer, mySpec, request));
- }
-
- @Override
- public boolean isEnabled() {
- return getDiagramEditPart() != null;
- }
-
- @Override
- public void refresh() {
- super.refresh();
- setText(calculateText());
- setChecked(calculateChecked());
- }
-
- protected String calculateText() {
- String name = myLayer.getName();
- return name != null ? name : EMPTY_LAYER_NAME;
- }
-
- protected boolean calculateChecked() {
- LayerEnablement layerEnablement = mySpec.findLayerEnablement(myLayer);
- //may be null, but only if disabled
- return layerEnablement != null && layerEnablement.isVisible();
- }
-
- protected static class SwitchLayerVisibility extends EditElementCommand {
-
- private final Layer myLayer;
-
- private final SubDiagramSpec myDiagramSpec;
-
- protected SwitchLayerVisibility(String label, Layer layer, SubDiagramSpec spec, IEditCommandRequest request) {
- super(label, layer, request);
- myLayer = layer;
- myDiagramSpec = spec;
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- final NodesBag mappedNodes = mapDiagramNodes();
- LayerEnablement enablement = myDiagramSpec.findLayerEnablement(myLayer);
- if (enablement != null && enablement.isVisible()) {
- enablement.setVisible(false);
-
- final Map> mappedLayers = mapLayers();
- for (EObject nextParticipant : enablement.getLayer().getParticipants()) {
- List allLayers = mappedLayers.get(nextParticipant);
- if (!hasVisibleLayerOtherThan(allLayers, enablement.getLayer())) {
- mappedNodes.setAllNodesVisibleFor(nextParticipant, false);
- }
- }
- } else {
- if (enablement == null) {
- enablement = LayersFactory.eINSTANCE.createLayerEnablement();
- enablement.setLayer(myLayer);
- myDiagramSpec.getDiagramLayers().add(enablement);
- }
- enablement.setVisible(true);
- //if element is in at least one visible layer, it is visible for sure
- for (EObject nextParticiant : myLayer.getParticipants()) {
- mappedNodes.setAllNodesVisibleFor(nextParticiant, true);
- }
- }
- return CommandResult.newOKCommandResult(enablement);
- }
-
- private static boolean hasVisibleLayerOtherThan(List allLayers, Layer layer) {
- if (allLayers == null) {
- return false;
- }
- for (LayerEnablement next : allLayers) {
- if (next.getLayer() == layer) {
- continue;
- }
- if (next.isVisible()) {
- return true;
- }
- }
- return false;
- }
-
- private NodesBag mapDiagramNodes() {
- NodesBag result = new NodesBag();
- LinkedList queue = new LinkedList();
- queue.add(myDiagramSpec.getDiagram());
-
- while (!queue.isEmpty()) {
- View next = queue.removeFirst();
- if (next.isSetElement() && next instanceof Node) {
- EObject element = next.getElement();
- if (element != null) {
- result.putOne(element, (Node) next);
- }
- }
- @SuppressWarnings("unchecked")
- List children = next.getChildren();
- queue.addAll(children);
- }
-
- return result;
- }
-
- private BagByEObject mapLayers() {
- BagByEObject result = new BagByEObject();
- for (LayerEnablement next : myDiagramSpec.getDiagramLayers()) {
- for (EObject participant : next.getLayer().getParticipants()) {
- result.putOne(participant, next);
- }
- }
- return result;
- }
-
- }
-
- @SuppressWarnings("serial")
- private static class BagByEObject extends HashMap> {
-
- public void putOne(EObject key, V value) {
- if (key == null) {
- return;
- }
- List values = get(key);
- if (values == null) {
- values = new ArrayList();
- put(key, values);
- }
- values.add(value);
- }
- }
-
- @SuppressWarnings("serial")
- private static class NodesBag extends BagByEObject {
-
- public void setAllNodesVisibleFor(EObject object, boolean visible) {
- List nodes = this.get(object);
- if (nodes != null) {
- for (Node nextNode : nodes) {
- nextNode.setVisible(visible);
- }
- }
- }
-
- }
-
-}
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SwitchLayerVisibilityItemProvider.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SwitchLayerVisibilityItemProvider.java
deleted file mode 100644
index 3c58ba041..000000000
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SwitchLayerVisibilityItemProvider.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package org.eclipse.gmf.examples.subdiagrams.popup;
-
-import org.eclipse.gmf.examples.layers.Layer;
-import org.eclipse.gmf.examples.layers.SubDiagramSpec;
-import org.eclipse.gmf.examples.layers.SubDiagramSupport;
-import org.eclipse.gmf.examples.subdiagrams.SubDiagramManager;
-import org.eclipse.gmf.examples.subdiagrams.SubDiagramManagerImpl;
-import org.eclipse.gmf.runtime.common.core.service.IProvider;
-import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.AbstractContributionItemProvider;
-import org.eclipse.gmf.runtime.common.ui.util.IWorkbenchPartDescriptor;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.jface.action.IMenuListener;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.ui.IWorkbenchPage;
-
-public class SwitchLayerVisibilityItemProvider extends AbstractContributionItemProvider implements IProvider {
-
- public static final String MENU_SET_LAYER_VISIBILITY = "menu_switch_layer_visibility"; //$NON-NLS-1$
-
- @Override
- protected IMenuManager createMenuManager(String menuId, IWorkbenchPartDescriptor partDescriptor) {
- if (!MENU_SET_LAYER_VISIBILITY.equals(menuId)) {
- return super.createMenuManager(menuId, partDescriptor);
- }
- MenuManager menuManager = new MenuManager("Show Layers");
- MenuBuilder builder = new MenuBuilder(partDescriptor);
- // XXX: build initial content -- otherwise menu is never shown
- builder.buildMenu(menuManager);
-
- menuManager.addMenuListener(builder);
- return menuManager;
- }
-
- private class MenuBuilder implements IMenuListener {
-
- private final IWorkbenchPartDescriptor myWorkbenchPart;
-
- public MenuBuilder(IWorkbenchPartDescriptor workbenchPart) {
- myWorkbenchPart = workbenchPart;
- }
-
- public void menuAboutToShow(IMenuManager manager) {
- buildMenu(manager);
- }
-
- public void buildMenu(IMenuManager manager) {
- manager.removeAll();
- DiagramEditPart selected = (DiagramEditPart) getSelectedObject(myWorkbenchPart);
- Diagram diagram = selected.getDiagramView();
-
- SubDiagramManager subsetManager = SubDiagramManagerImpl.findOrCreateSubsetManager(diagram);
- SubDiagramSupport support = subsetManager.getSubDiagramSupport();
- if (support == null) {
- return;
- }
-
- SubDiagramSpec diagramSpec = support.findDiagramSpec(diagram);
- if (diagramSpec == null) {
- return;
- }
-
- for (Layer next : support.getLayers()) {
- SwitchLayerVisibilityAction action = new SwitchLayerVisibilityAction(getWorkbenchPage(), next, diagramSpec);
- action.init();
- manager.add(action);
- }
- }
-
- private IWorkbenchPage getWorkbenchPage() {
- return myWorkbenchPart.getPartPage();
- }
- }
-
-}
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/UniqueNameValidator.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/UniqueNameValidator.java
deleted file mode 100644
index 03e853c0b..000000000
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/UniqueNameValidator.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package org.eclipse.gmf.examples.subdiagrams.popup;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.jface.dialogs.IInputValidator;
-
-class UniqueNameValidator implements IInputValidator {
-
- private final Set myAllNames = new HashSet();
-
- private boolean myAllowEmptyName;
-
- public UniqueNameValidator(List extends EObject> objects, EStructuralFeature nameFeature) {
- for (EObject next : objects) {
- Object nextValue = next.eGet(nameFeature);
- if (nextValue != null) {
- myAllNames.add(String.valueOf(nextValue));
- }
- }
- }
-
- public void setAllowEmptyName(boolean allowEmptyName) {
- myAllowEmptyName = allowEmptyName;
- }
-
- @Override
- public String isValid(String newText) {
- if (newText == null) {
- return myAllowEmptyName ? null : "Empty Name Is Not Allowed";
- }
- newText = newText.trim();
- if (newText.length() == 0 && !myAllowEmptyName) {
- return "Empty Name Is Not Allowed";
- }
- if (myAllNames.contains(newText)) {
- return "This Name Already Exists";
- }
- return null;
- }
-
- public String guessNewName(String prefix) {
- for (int i = 0; i < 26; i++) {
- String nextCandidate = prefix + (char) ('A' + i);
- if (isValid(nextCandidate) == null) {
- return nextCandidate;
- }
- }
-
- //wow
- int i = 0;
- while (++i < 1000) {
- String nextCandidate = prefix + i;
- if (isValid(nextCandidate) == null) {
- return nextCandidate;
- }
- }
-
- return "";
- }
-
-}
\ No newline at end of file
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/plugin.xml b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/plugin.xml
index f8d080ed8..8cd7acf88 100644
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/plugin.xml
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/plugin.xml
@@ -636,7 +636,7 @@ Contributors: