Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormgolubev2012-05-02 12:52:46 +0000
committermgolubev2012-05-02 12:52:46 +0000
commit8b2896b97a4f2d37e58fcd32e328c16cc4315920 (patch)
treedd2fb158b9e6c13950dec84b26b6b0b3f75c16f9
parent9682700f637dddaa03d95d3b44f862a4f66213e6 (diff)
downloadorg.eclipse.gmf-tooling-8b2896b97a4f2d37e58fcd32e328c16cc4315920.tar.gz
org.eclipse.gmf-tooling-8b2896b97a4f2d37e58fcd32e328c16cc4315920.tar.xz
org.eclipse.gmf-tooling-8b2896b97a4f2d37e58fcd32e328c16cc4315920.zip
Fixed: subdiagam should have correct layers enablement,
+ "New..." as a menu item label
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/CreateSubDiagramAction.java5
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/SubDiagramActionBase.java46
2 files changed, 48 insertions, 3 deletions
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
index 355985f18..e9b82d9d9 100644
--- 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
@@ -6,7 +6,6 @@ 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;
@@ -65,7 +64,7 @@ public class CreateSubDiagramAction extends SubDiagramActionBase {
}
protected String calculateText() {
- return safeGetSubDiagramName(mySpec);
+ return "New...";
}
protected boolean calculateChecked() {
@@ -101,7 +100,7 @@ public class CreateSubDiagramAction extends SubDiagramActionBase {
}
Diagram clone = EcoreUtil.copy(myTemplate.getDiagram());
- SubDiagramSpec result = LayersFactory.eINSTANCE.createSubDiagramSpec();
+ SubDiagramSpec result = EcoreUtil.copy(myTemplate);
result.setDiagram(clone);
result.setName(dialog.getValue());
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 5ccd56ca6..b1c54bac7 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
@@ -1,13 +1,22 @@
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.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.gef.Request;
import org.eclipse.gmf.examples.layers.SubDiagramSpec;
+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;
@@ -17,6 +26,7 @@ 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;
public abstract class SubDiagramActionBase extends DiagramAction {
@@ -81,6 +91,8 @@ public abstract class SubDiagramActionBase extends DiagramAction {
Diagram diagram = spec.getDiagram();
+ saveResourceSet(spec);
+
URI uri = EcoreUtil.getURI(diagram);
String editorName = uri.lastSegment() + '#' + OpenSubDiagramAction.safeGetSubDiagramName(spec);
IEditorInput editorInput = new URIEditorInput(uri, editorName);
@@ -93,6 +105,40 @@ public abstract class SubDiagramActionBase extends DiagramAction {
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);
+ }
+
+ }
+
+ 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