Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormgolubev2012-05-02 13:19:39 +0000
committermgolubev2012-05-02 13:19:39 +0000
commitf86f3d78b1ba0e99e7592e76af42f659040cdf6a (patch)
treed4502af1f0aba8a815470c424ed215aa7811f5b8
parent8b2896b97a4f2d37e58fcd32e328c16cc4315920 (diff)
downloadorg.eclipse.gmf-tooling-f86f3d78b1ba0e99e7592e76af42f659040cdf6a.tar.gz
org.eclipse.gmf-tooling-f86f3d78b1ba0e99e7592e76af42f659040cdf6a.tar.xz
org.eclipse.gmf-tooling-f86f3d78b1ba0e99e7592e76af42f659040cdf6a.zip
Fixed: Main diagram uses FileEditorInput, tweak OpenSubDiagramCommand to
switch to existing main diagram instead of creating a new one
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SubDiagramActionBase.java30
1 files changed, 25 insertions, 5 deletions
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
index b1c54bac7..b75ddb99a 100644
--- 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
@@ -6,6 +6,7 @@ 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;
@@ -14,8 +15,10 @@ 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;
@@ -27,6 +30,7 @@ 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 {
@@ -90,12 +94,24 @@ public abstract class SubDiagramActionBase extends DiagramAction {
}
Diagram diagram = spec.getDiagram();
+ SubDiagramSupport support = (SubDiagramSupport) spec.eContainer();
saveResourceSet(spec);
- URI uri = EcoreUtil.getURI(diagram);
- String editorName = uri.lastSegment() + '#' + OpenSubDiagramAction.safeGetSubDiagramName(spec);
- IEditorInput editorInput = new URIEditorInput(uri, editorName);
+ 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);
@@ -130,15 +146,19 @@ public abstract class SubDiagramActionBase extends DiagramAction {
}
}
-
+
+ /**
+ * 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<String, Object> saveOptions = new HashMap<String, Object>();
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<T> {

Back to the top