Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormgolubev2012-05-02 12:25:15 +0000
committermgolubev2012-05-02 12:25:15 +0000
commit9682700f637dddaa03d95d3b44f862a4f66213e6 (patch)
treea5de575baa2bdfebbfb3bebd99d72a9c9bc0ae1b
parente2dd989bc6ecb487d4d7744c25c36f92a2173fe0 (diff)
downloadorg.eclipse.gmf-tooling-9682700f637dddaa03d95d3b44f862a4f66213e6.tar.gz
org.eclipse.gmf-tooling-9682700f637dddaa03d95d3b44f862a4f66213e6.tar.xz
org.eclipse.gmf-tooling-9682700f637dddaa03d95d3b44f862a4f66213e6.zip
popup menu for managing opening of the subdiagramssub
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/CreateNewLayerAction.java66
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/CreateSubDiagramAction.java116
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/OpenSubDiagramAction.java47
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SubDiagramActionBase.java129
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SubDiagramsItemProvider.java85
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/UniqueNameValidator.java65
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/plugin.xml22
7 files changed, 470 insertions, 60 deletions
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
index f5168a8f1..c08a04484 100644
--- 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
@@ -1,8 +1,6 @@
package org.eclipse.gmf.examples.subdiagrams.popup;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
@@ -13,6 +11,7 @@ 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;
@@ -21,7 +20,6 @@ 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.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
@@ -61,7 +59,7 @@ public class CreateNewLayerAction extends DiagramAction {
return UnexecutableCommand.INSTANCE;
}
IEditCommandRequest request = new DomainOnlyEditRequest(diagramEditPart);
- return new ICommandProxy(new CreateNewLayerLayer("Creating New Layer", mySupport, mySemanticElements, myDiagram, request, getWorkbenchPart().getSite().getShell()));
+ return new ICommandProxy(new CreateNewLayer("Creating New Layer", mySupport, mySemanticElements, myDiagram, request, getWorkbenchPart().getSite().getShell()));
}
@Override
@@ -69,7 +67,7 @@ public class CreateNewLayerAction extends DiagramAction {
return getDiagramEditPart() != null && !mySemanticElements.isEmpty();
}
- public static class CreateNewLayerLayer extends EditElementCommand {
+ public static class CreateNewLayer extends EditElementCommand {
private final SubDiagramSupport mySupport;
@@ -79,7 +77,7 @@ public class CreateNewLayerAction extends DiagramAction {
private final SubDiagramSpec myDiagram;
- protected CreateNewLayerLayer(String label, SubDiagramSupport support, List<EObject> assignees, SubDiagramSpec diagram, IEditCommandRequest request, Shell shell) {
+ protected CreateNewLayer(String label, SubDiagramSupport support, List<EObject> assignees, SubDiagramSpec diagram, IEditCommandRequest request, Shell shell) {
super(label, support, request);
myAssignees = assignees;
mySupport = support;
@@ -89,9 +87,9 @@ public class CreateNewLayerAction extends DiagramAction {
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- UniqueNameValidator validator = new UniqueNameValidator(mySupport);
+ UniqueNameValidator validator = new UniqueNameValidator(mySupport.getLayers(), LayersPackage.eINSTANCE.getLayer_Name());
InputDialog dialog = new InputDialog(myShell, //
- "Enter The Name", "New Layer's Name:", validator.guessNewLayerName(), validator);
+ "Enter The Name", "New Layer's Name:", validator.guessNewName("Layer "), validator);
if (dialog.open() != Window.OK) {
return CommandResult.newCancelledCommandResult();
@@ -107,57 +105,5 @@ public class CreateNewLayerAction extends DiagramAction {
return CommandResult.newOKCommandResult(layer);
}
-
- private static class UniqueNameValidator implements IInputValidator {
-
- private final Set<String> myAllNames = new HashSet<String>();
-
- public UniqueNameValidator(SubDiagramSupport support) {
- for (Layer next : support.getLayers()) {
- String nextName = next.getName();
- if (nextName != null) {
- myAllNames.add(nextName);
- }
- }
- }
-
- @Override
- public String isValid(String newText) {
- if (newText == null) {
- return "Empty Name Is Not Allowed";
- }
- newText = newText.trim();
- if (newText.length() == 0) {
- return "Empty Name Is Not Allowed";
- }
- if (myAllNames.contains(newText)) {
- return "This Name Already Exists";
- }
- return null;
- }
-
- public String guessNewLayerName() {
-
- String prefix = "Layer ";
- 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 "<can't guess -- too many names already>";
- }
-
- }
}
}
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
new file mode 100644
index 000000000..355985f18
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/CreateSubDiagramAction.java
@@ -0,0 +1,116 @@
+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.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.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<SubDiagramSpec> gateBetweenCommands = new Ref<SubDiagramSpec>();
+ 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 safeGetSubDiagramName(mySpec);
+ }
+
+ protected boolean calculateChecked() {
+ return false;
+ }
+
+ private static class CreateNewSubDiagram extends EditElementCommand {
+
+ private final SubDiagramSupport mySupport;
+
+ private final SubDiagramSpec myTemplate;
+
+ private final Ref<SubDiagramSpec> myResultRef;
+
+ private final Shell myShell;
+
+ protected CreateNewSubDiagram(String label, SubDiagramSupport support, SubDiagramSpec template, Ref<SubDiagramSpec> 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 = LayersFactory.eINSTANCE.createSubDiagramSpec();
+ 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/OpenSubDiagramAction.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/OpenSubDiagramAction.java
new file mode 100644
index 000000000..d69a90498
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/OpenSubDiagramAction.java
@@ -0,0 +1,47 @@
+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
new file mode 100644
index 000000000..5ccd56ca6
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SubDiagramActionBase.java
@@ -0,0 +1,129 @@
+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.common.ui.URIEditorInput;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gef.Request;
+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.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;
+
+public abstract class SubDiagramActionBase extends DiagramAction {
+
+ protected static final String EMPTY_DIAGRAM_NAME = "<empty-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<SubDiagramSpec> spec) {
+ IEditCommandRequest request = new DomainOnlyEditRequest(getDiagramEditPart());
+ return new OpenSubDiagramCommand(label, spec, findDiagramEditorId(), request);
+ }
+
+ protected static class OpenSubDiagramCommand extends EditElementCommand {
+
+ private final Ref<SubDiagramSpec> mySpecRef;
+
+ private final String myEditorId;
+
+ public OpenSubDiagramCommand(String label, Ref<SubDiagramSpec> 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();
+
+ URI uri = EcoreUtil.getURI(diagram);
+ String editorName = uri.lastSegment() + '#' + OpenSubDiagramAction.safeGetSubDiagramName(spec);
+ IEditorInput 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 static class Ref<T> {
+
+ 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 <T> Ref<T> create(T value) {
+ return new Ref<T>(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
new file mode 100644
index 000000000..ba9376019
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SubDiagramsItemProvider.java
@@ -0,0 +1,85 @@
+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/UniqueNameValidator.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/UniqueNameValidator.java
new file mode 100644
index 000000000..03e853c0b
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/UniqueNameValidator.java
@@ -0,0 +1,65 @@
+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<String> myAllNames = new HashSet<String>();
+
+ 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 "<can't guess -- too many names already>";
+ }
+
+} \ 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 de95b95fb..f8d080ed8 100644
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/plugin.xml
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/plugin.xml
@@ -674,6 +674,28 @@ Contributors:
</popupStructuredContributionCriteria>
</popupContribution>
</contributionItemProvider>
+
+ <contributionItemProvider
+ checkPluginLoaded="true"
+ class="org.eclipse.gmf.examples.subdiagrams.popup.SubDiagramsItemProvider">
+ <Priority name="Medium"/>
+ <popupContribution
+ class="org.eclipse.gmf.examples.taipan.gmf.editor.part.DiagramEditorContextMenuProvider">
+ <popupMenuGroup
+ id="SubDiagramsGroup"
+ path="/propertiesGroup">
+ </popupMenuGroup>
+ <popupMenu
+ path="/