Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Fluegge2011-10-25 09:44:18 +0000
committerMartin Fluegge2011-10-25 09:44:18 +0000
commit69117c8416fda55d147060e7a38ee53f6d5745e8 (patch)
tree18b55a5dd5b7f341eab7121425420549f42b77b7 /plugins
parent53b22bda9348fac657b37f4b232b0f0db218482c (diff)
downloadcdo-69117c8416fda55d147060e7a38ee53f6d5745e8.tar.gz
cdo-69117c8416fda55d147060e7a38ee53f6d5745e8.tar.xz
cdo-69117c8416fda55d147060e7a38ee53f6d5745e8.zip
[359656] [Dawn] Provide collaborative extension for Graphiti editors
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/META-INF/MANIFEST.MF48
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/diagram/AcoreDiagramTypeProvider.java12
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/features/AcoreBasicAddElementFeature.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/features/AcoreBasicCreateElementFeature.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/util/DawnGraphitiAcoreResourceUtil.java122
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.graphiti/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.graphiti/icons/dawn_graphiti_editor.gifbin0 -> 884 bytes
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.graphiti/plugin.xml4
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/notifications/DawnGraphitiHandler.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnBasicGraphitiWizard.java222
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnGenericGraphitiWizard.java140
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/helper/DawnEditorHelper.java138
12 files changed, 475 insertions, 228 deletions
diff --git a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/META-INF/MANIFEST.MF
index 860aff8d81..e96b388ad4 100644
--- a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/META-INF/MANIFEST.MF
@@ -1,24 +1,24 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: %pluginName
-Bundle-SymbolicName: org.eclipse.emf.cdo.dawn.examples.acore.graphiti;singleton:=true
-Bundle-Version: 1.0.0.qualifier
-Bundle-Activator: org.eclipse.emf.cdo.dawn.examples.acore.graphiti.Activator
-Require-Bundle: org.eclipse.ui;bundle-version="[3.6.0,4.0.0)",
- org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)",
- org.eclipse.graphiti;bundle-version="[0.9.0,1.0.0)",
- org.eclipse.graphiti.ui;bundle-version="[0.9.0,1.0.0)",
- org.eclipse.core.resources;bundle-version="[3.6.0,4.0.0)",
- org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)",
- org.eclipse.ui.views.properties.tabbed;bundle-version="[3.5.0,4.0.0)",
- org.eclipse.emf.cdo.dawn.examples.acore;bundle-version="[1.0.100,2.0.0)",
- org.eclipse.emf.cdo.dawn.examples.acore.edit;bundle-version="[1.0.100,2.0.0)",
- org.eclipse.emf.cdo.dawn;bundle-version="[2.0.0,3.0.0)",
- org.eclipse.emf.transaction;bundle-version="[1.4.0,2.0.0)"
-Bundle-ActivationPolicy: lazy
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Export-Package: org.eclipse.emf.cdo.dawn.examples.acore.graphiti;version="1.0.0",
- org.eclipse.emf.cdo.dawn.examples.acore.graphiti.diagram;version="1.0.0",
- org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features;version="1.0.0",
- org.eclipse.emf.cdo.dawn.examples.acore.graphiti.util;version="1.0.0"
-Bundle-Vendor: %providerName
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.emf.cdo.dawn.examples.acore.graphiti;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.eclipse.emf.cdo.dawn.examples.acore.graphiti.Activator
+Require-Bundle: org.eclipse.ui;bundle-version="[3.6.0,4.0.0)",
+ org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)",
+ org.eclipse.graphiti;bundle-version="[0.9.0,1.0.0)",
+ org.eclipse.graphiti.ui;bundle-version="[0.9.0,1.0.0)",
+ org.eclipse.core.resources;bundle-version="[3.6.0,4.0.0)",
+ org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)",
+ org.eclipse.ui.views.properties.tabbed;bundle-version="[3.5.0,4.0.0)",
+ org.eclipse.emf.cdo.dawn.examples.acore;bundle-version="[1.0.100,2.0.0)",
+ org.eclipse.emf.cdo.dawn.examples.acore.edit;bundle-version="[1.0.100,2.0.0)",
+ org.eclipse.emf.cdo.dawn;bundle-version="[2.0.0,3.0.0)",
+ org.eclipse.emf.transaction;bundle-version="[1.4.0,2.0.0)"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Export-Package: org.eclipse.emf.cdo.dawn.examples.acore.graphiti;version="1.0.0",
+ org.eclipse.emf.cdo.dawn.examples.acore.graphiti.diagram;version="1.0.0",
+ org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features;version="1.0.0",
+ org.eclipse.emf.cdo.dawn.examples.acore.graphiti.util;version="1.0.0"
+Bundle-Vendor: %providerName
diff --git a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/diagram/AcoreDiagramTypeProvider.java b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/diagram/AcoreDiagramTypeProvider.java
index 8c1427be1a..7ddc6a63bf 100644
--- a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/diagram/AcoreDiagramTypeProvider.java
+++ b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/diagram/AcoreDiagramTypeProvider.java
@@ -11,7 +11,11 @@
*/
package org.eclipse.emf.cdo.dawn.examples.acore.graphiti.diagram;
+import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.util.DawnGraphitiAcoreResourceUtil;
+
import org.eclipse.graphiti.dt.AbstractDiagramTypeProvider;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.platform.IDiagramEditor;
import org.eclipse.graphiti.tb.IToolBehaviorProvider;
/**
@@ -42,4 +46,12 @@ public class AcoreDiagramTypeProvider extends AbstractDiagramTypeProvider
}
return toolBehaviorProviders;
}
+
+ @Override
+ public void init(Diagram diagram, IDiagramEditor diagramEditor)
+ {
+ super.init(diagram, diagramEditor);
+ DawnGraphitiAcoreResourceUtil.wireDomainModel(diagram, diagram.eResource().getResourceSet(), getDiagramEditor()
+ .getEditingDomain());
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/features/AcoreBasicAddElementFeature.java b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/features/AcoreBasicAddElementFeature.java
index b355c8a837..057e620ffd 100644
--- a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/features/AcoreBasicAddElementFeature.java
+++ b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/features/AcoreBasicAddElementFeature.java
@@ -12,6 +12,7 @@
package org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features;
import org.eclipse.emf.cdo.dawn.examples.acore.ABasicClass;
+import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.util.DawnGraphitiAcoreResourceUtil;
import org.eclipse.graphiti.features.IDirectEditingInfo;
import org.eclipse.graphiti.features.IFeatureProvider;
@@ -160,7 +161,8 @@ public abstract class AcoreBasicAddElementFeature extends AbstractAddShapeFeatur
// in a real scenario the business model would have its own resource
if (addedClass.eResource() == null)
{
- getDiagram().eResource().getContents().add(addedClass);
+ // getDiagram().eResource().getContents().add(addedClass);
+ DawnGraphitiAcoreResourceUtil.addToModelResource(addedClass, getDiagram().eResource().getResourceSet());
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/features/AcoreBasicCreateElementFeature.java b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/features/AcoreBasicCreateElementFeature.java
index 5a9a290930..67585c91fa 100644
--- a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/features/AcoreBasicCreateElementFeature.java
+++ b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/features/AcoreBasicCreateElementFeature.java
@@ -11,6 +11,8 @@
*/
package org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features;
+import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.util.DawnGraphitiAcoreResourceUtil;
+
import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.features.IFeatureProvider;
@@ -37,11 +39,7 @@ public abstract class AcoreBasicCreateElementFeature extends AbstractCreateFeatu
{
EObject newObject = createElement();
- // Add model element to resource.
- // We add the model element to the resource of the diagram for
- // simplicity's sake. Normally, a customer would use its own
- // model persistence layer for storing the business model separately.
- getDiagram().eResource().getContents().add(newObject);
+ DawnGraphitiAcoreResourceUtil.addToModelResource(newObject, getDiagram().eResource().getResourceSet());
// do the add
addGraphicalRepresentation(context, newObject);
diff --git a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/util/DawnGraphitiAcoreResourceUtil.java b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/util/DawnGraphitiAcoreResourceUtil.java
new file mode 100644
index 0000000000..735d4a7e5d
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.graphiti/src/org/eclipse/emf/cdo/dawn/examples/acore/graphiti/util/DawnGraphitiAcoreResourceUtil.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Fluegge - initial API and implementation
+ */
+package org.eclipse.emf.cdo.dawn.examples.acore.graphiti.util;
+
+import org.eclipse.emf.cdo.dawn.examples.acore.AClass;
+import org.eclipse.emf.cdo.dawn.examples.acore.ACoreRoot;
+import org.eclipse.emf.cdo.dawn.examples.acore.AInterface;
+import org.eclipse.emf.cdo.dawn.examples.acore.AcoreFactory;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.PictogramLink;
+import org.eclipse.graphiti.mm.pictograms.PictogramsFactory;
+
+import java.io.IOException;
+
+/**
+ * @author Martin Fluegge
+ */
+public class DawnGraphitiAcoreResourceUtil
+{
+ /**
+ * In our example the root of the semantic model is an AcoreRoot. This method ensures that AcoreRoot is wiredn to the
+ * Diagram element if needed.
+ */
+ public static void wireDomainModel(final Diagram diagram, final ResourceSet resourceSet, EditingDomain domain)
+ {
+ domain.getCommandStack().execute(new RecordingCommand((TransactionalEditingDomain)domain)
+ {
+ @Override
+ protected void doExecute()
+ {
+ PictogramLink link = diagram.getLink();
+ if (link == null)
+ {
+ link = PictogramsFactory.eINSTANCE.createPictogramLink();
+ diagram.setLink(link);
+ }
+
+ EList<EObject> businessObjects = link.getBusinessObjects();
+
+ if (businessObjects.size() == 0)
+ {
+ // create AcoreRoot
+ ACoreRoot acoreRoot = AcoreFactory.eINSTANCE.createACoreRoot();
+ Resource modelResource = resourceSet.getResources().get(0);
+ if (modelResource.equals(diagram.eResource()))
+ {
+ modelResource = resourceSet.getResources().get(1);
+ }
+ modelResource.getContents().add(acoreRoot);
+
+ link.getBusinessObjects().add(acoreRoot);
+
+ try
+ {
+ diagram.eResource().save(null);
+ modelResource.save(null);
+ }
+ catch (IOException ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ }
+ }
+ });
+ }
+
+ public static void addToModelResource(EObject element, ResourceSet resourceSet)
+ {
+ Resource resource = resourceSet.getResources().get(0);
+
+ if (resource.getContents().size() > 0 && resource.getContents().get(0) instanceof Diagram)
+ {
+ // wrong resource
+ resource = resourceSet.getResources().get(1);
+ }
+
+ if (resource.getContents().size() > 0)
+ {
+ ACoreRoot acoreRoot = (ACoreRoot)resource.getContents().get(0);
+
+ addElement(element, acoreRoot);
+ }
+ // else
+ // {
+ // ACoreRoot acoreRoot = AcoreFactory.eINSTANCE.createACoreRoot();
+ // resource.getContents().add(acoreRoot);
+ // addElement(element, acoreRoot);
+ // }
+ }
+
+ private static void addElement(EObject element, ACoreRoot acoreRoot)
+ {
+ if (acoreRoot instanceof ACoreRoot)
+ {
+ if (element instanceof AClass)
+ {
+ acoreRoot.getClasses().add((AClass)element);
+ }
+ else if (element instanceof AInterface)
+ {
+ acoreRoot.getInterfaces().add((AInterface)element);
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.graphiti/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.dawn.graphiti/META-INF/MANIFEST.MF
index bb6f13fbb8..0a382250c6 100644
--- a/plugins/org.eclipse.emf.cdo.dawn.graphiti/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.dawn.graphiti/META-INF/MANIFEST.MF
@@ -12,9 +12,9 @@ Require-Bundle: org.eclipse.ui;bundle-version="[3.6.0,4.0.0)",
org.eclipse.graphiti.ui;bundle-version="[0.9.0,1.0.0)",
org.eclipse.emf.cdo.dawn.ui;bundle-version="[2.0.0,3.0.0)",
org.eclipse.emf.cdo.dawn.util;bundle-version="[2.0.0,3.0.0)",
- org.eclipse.emf.transaction;bundle-version="[1.4.0,2.0.0)",
+ org.eclipse.emf.transaction;bundle-version="[1.4.0,2.0.0)";visibility:=reexport,
org.eclipse.ui.views.properties.tabbed;bundle-version="[3.5.200,4.0.0)",
- org.eclipse.gef;bundle-version="[3.7.1,4.0.0)",
+ org.eclipse.gef;bundle-version="[3.7.1,4.0.0)";visibility:=reexport,
org.eclipse.emf.workspace;bundle-version="[1.4.0,2.0.0)",
org.eclipse.emf.cdo.ui;bundle-version="[4.0.100,5.0.0)",
org.eclipse.emf.cdo.dawn.gmf;bundle-version="[2.0.0,3.0.0)"
diff --git a/plugins/org.eclipse.emf.cdo.dawn.graphiti/icons/dawn_graphiti_editor.gif b/plugins/org.eclipse.emf.cdo.dawn.graphiti/icons/dawn_graphiti_editor.gif
new file mode 100644
index 0000000000..70c6afe178
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.graphiti/icons/dawn_graphiti_editor.gif
Binary files differ
diff --git a/plugins/org.eclipse.emf.cdo.dawn.graphiti/plugin.xml b/plugins/org.eclipse.emf.cdo.dawn.graphiti/plugin.xml
index 1e6f937cee..8bf6d82e45 100644
--- a/plugins/org.eclipse.emf.cdo.dawn.graphiti/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.dawn.graphiti/plugin.xml
@@ -16,6 +16,7 @@
<wizard
category="org.eclipse.emf.cdo.dawn.ui.category.dawn"
class="org.eclipse.emf.cdo.dawn.graphiti.wizards.DawnGenericGraphitiWizard"
+ icon="icons/dawn_graphiti_editor.gif"
id="org.eclipse.emf.cdo.dawn.graphiti.wizard1"
name="Dawn Generic Graphiti Diagram">
</wizard>
@@ -25,7 +26,8 @@
<editor
class="org.eclipse.emf.cdo.dawn.graphiti.editors.DawnGraphitiDiagramEditor"
default="false"
- extensions="acore_graphiti"
+ extensions="graphiti"
+ icon="icons/dawn_graphiti_editor.gif"
id="org.eclipse.emf.cdo.dawn.graphiti.editor"
name="Dawn Graphiti Editor">
</editor>
diff --git a/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/notifications/DawnGraphitiHandler.java b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/notifications/DawnGraphitiHandler.java
index 2c64b85e45..a16d5de457 100644
--- a/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/notifications/DawnGraphitiHandler.java
+++ b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/notifications/DawnGraphitiHandler.java
@@ -52,6 +52,7 @@ public class DawnGraphitiHandler extends BasicDawnTransactionHandler
editor.getDawnEditorSupport().refresh();
// CDOViewInvalidationEvent e = event;
+
//
// adjustDeletedEdges(e);
//
diff --git a/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnBasicGraphitiWizard.java b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnBasicGraphitiWizard.java
new file mode 100644
index 0000000000..81ba76b128
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnBasicGraphitiWizard.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Fluegge - initial API and implementation
+ */
+package org.eclipse.emf.cdo.dawn.graphiti.wizards;
+
+import org.eclipse.emf.cdo.dawn.graphiti.DawnGraphitiUIPlugin;
+import org.eclipse.emf.cdo.dawn.graphiti.editors.DawnGraphitiDiagramEditor;
+import org.eclipse.emf.cdo.dawn.graphiti.editors.DawnGraphitiDiagramEditorFactory;
+import org.eclipse.emf.cdo.dawn.graphiti.editors.DawnGraphitiEditorInput;
+import org.eclipse.emf.cdo.dawn.preferences.PreferenceConstants;
+import org.eclipse.emf.cdo.dawn.ui.composites.CDOResourceNodeChooserComposite.ResourceChooserValidator;
+import org.eclipse.emf.cdo.dawn.ui.wizards.DawnCreateNewDiagramResourceWizardPage;
+import org.eclipse.emf.cdo.dawn.ui.wizards.DawnCreateNewResourceWizardPage;
+import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.emf.common.command.CommandStack;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.ui.editor.DiagramEditorInput;
+import org.eclipse.graphiti.ui.services.GraphitiUi;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+import java.io.IOException;
+
+/**
+ * @author Martin Fluegge
+ */
+public class DawnBasicGraphitiWizard extends Wizard implements INewWizard
+{
+ protected CDOView view;
+
+ protected DawnCreateNewDiagramResourceWizardPage dawnDiagramModelFilePage;
+
+ protected DawnCreateNewResourceWizardPage dawnDomainModelFilePage;
+
+ protected String diagramExtension = "model_graphiti";
+
+ protected String modelExtension = "model";
+
+ public DawnBasicGraphitiWizard()
+ {
+ super();
+ CDOConnectionUtil.instance.init(PreferenceConstants.getRepositoryName(), PreferenceConstants.getProtocol(),
+ PreferenceConstants.getServerName());
+ CDOSession session = CDOConnectionUtil.instance.openSession();
+ view = CDOConnectionUtil.instance.openView(session);
+ }
+
+ public DawnBasicGraphitiWizard(String modelExtension, String diagramExtension)
+ {
+ this();
+ this.diagramExtension = diagramExtension;
+ this.modelExtension = modelExtension;
+ }
+
+ public void init(IWorkbench workbench, IStructuredSelection selection)
+ {
+ }
+
+ @Override
+ public void addPages()
+ {
+ dawnDiagramModelFilePage = new DawnCreateNewDiagramResourceWizardPage(diagramExtension, false, view);
+ dawnDiagramModelFilePage.setTitle("");
+ dawnDiagramModelFilePage.setDescription("");
+ dawnDiagramModelFilePage.setCreateAutomaticResourceName(true);
+ addPage(dawnDiagramModelFilePage);
+
+ dawnDomainModelFilePage = new DawnCreateNewResourceWizardPage(modelExtension, true, view)
+ {
+ @Override
+ public void setVisible(boolean visible)
+ {
+ if (visible)
+ {
+ URI uri = dawnDiagramModelFilePage.getURI();
+ String fileName = uri.lastSegment();
+ fileName = fileName.substring(0, fileName.length() - ("." + diagramExtension).length()); //$NON-NLS-1$
+ fileName += ".acore";
+ dawnDomainModelFilePage.setResourceNamePrefix(fileName);
+ dawnDomainModelFilePage.setResourcePath(dawnDiagramModelFilePage.getResourcePath());
+ }
+ super.setVisible(visible);
+ }
+ };
+ dawnDomainModelFilePage.setTitle("");
+ dawnDomainModelFilePage.setDescription("");
+
+ // allows to connect to an existing resource
+ dawnDomainModelFilePage.setResourceValidationType(ResourceChooserValidator.VALIDATION_WARN);
+ addPage(dawnDomainModelFilePage);
+ }
+
+ @Override
+ public boolean performFinish()
+ {
+ String diagramTypeId = geTypeId();
+
+ URI diagramResourceURI = dawnDiagramModelFilePage.getURI();
+ URI domainModelResourceURI = dawnDomainModelFilePage.getURI();
+
+ Diagram diagram = Graphiti.getPeCreateService()
+ .createDiagram(diagramTypeId, diagramResourceURI.lastSegment(), true);
+
+ String editorID = DawnGraphitiDiagramEditor.ID;
+
+ TransactionalEditingDomain editingDomain = createEditingDomain(diagramResourceURI, diagram);
+
+ createModelResource(domainModelResourceURI, editingDomain.getResourceSet());
+
+ Resource diagramResource = createDiagramResource(diagramResourceURI, diagram, editingDomain);
+
+ String providerId = GraphitiUi.getExtensionManager().getDiagramTypeProviderId(diagram.getDiagramTypeId());
+ DiagramEditorInput editorInput = new DawnGraphitiEditorInput(EcoreUtil.getURI(diagram), editingDomain, providerId,
+ true, diagramResource);
+
+ try
+ {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput, editorID);
+ }
+ catch (PartInitException e)
+ {
+ String error = "Error opening diagram";
+ IStatus status = new Status(IStatus.ERROR, DawnGraphitiUIPlugin.ID, error, e);
+ ErrorDialog.openError(getShell(), "Error", null, status);
+ return false;
+ }
+
+ return true;
+ }
+
+ protected String geTypeId()
+ {
+ return modelExtension;
+ }
+
+ private Resource createModelResource(URI uri, ResourceSet resourceSet)
+ {
+ Resource resource = null;
+
+ // try
+ // {
+ // resource = resourceSet.getResource(uri, true);
+ // }
+ // catch (Exception ex)
+ // {
+ // // ignore
+ // }
+ //
+ // if (resource == null)
+ // {
+ resource = resourceSet.createResource(uri);
+ // }
+
+ return resource;
+ }
+
+ private TransactionalEditingDomain createEditingDomain(URI diagramResourceURI, final Diagram diagram)
+ {
+ final TransactionalEditingDomain editingDomain = DawnGraphitiDiagramEditorFactory
+ .createResourceSetAndEditingDomain();
+
+ return editingDomain;
+ }
+
+ private Resource createDiagramResource(URI diagramResourceURI, final Diagram diagram,
+ final TransactionalEditingDomain editingDomain)
+ {
+ final ResourceSet resourceSet = editingDomain.getResourceSet();
+ final Resource resource = createModelResource(diagramResourceURI, resourceSet);
+
+ final CommandStack commandStack = editingDomain.getCommandStack();
+ commandStack.execute(new RecordingCommand(editingDomain)
+ {
+ @Override
+ protected void doExecute()
+ {
+ resource.getContents().add(diagram);
+ }
+ });
+
+ try
+ {
+ resource.save(null);
+ }
+ catch (IOException ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ return resource;
+ }
+
+ @Override
+ public void dispose()
+ {
+ view.close();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnGenericGraphitiWizard.java b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnGenericGraphitiWizard.java
index 2fed0614d4..3aa0afc63e 100644
--- a/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnGenericGraphitiWizard.java
+++ b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnGenericGraphitiWizard.java
@@ -10,66 +10,22 @@
*/
package org.eclipse.emf.cdo.dawn.graphiti.wizards;
-import org.eclipse.emf.cdo.dawn.graphiti.DawnGraphitiUIPlugin;
-import org.eclipse.emf.cdo.dawn.graphiti.editors.DawnGraphitiDiagramEditor;
-import org.eclipse.emf.cdo.dawn.graphiti.editors.DawnGraphitiDiagramEditorFactory;
-import org.eclipse.emf.cdo.dawn.graphiti.editors.DawnGraphitiEditorInput;
-import org.eclipse.emf.cdo.dawn.preferences.PreferenceConstants;
import org.eclipse.emf.cdo.dawn.ui.composites.CDOResourceNodeChooserComposite.ResourceChooserValidator;
import org.eclipse.emf.cdo.dawn.ui.wizards.DawnCreateNewDiagramResourceWizardPage;
import org.eclipse.emf.cdo.dawn.ui.wizards.DawnCreateNewResourceWizardPage;
-import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil;
-import org.eclipse.emf.cdo.session.CDOSession;
-import org.eclipse.emf.cdo.view.CDOView;
-import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.graphiti.mm.pictograms.Diagram;
-import org.eclipse.graphiti.services.Graphiti;
-import org.eclipse.graphiti.ui.editor.DiagramEditorInput;
-import org.eclipse.graphiti.ui.services.GraphitiUi;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-
-import java.io.IOException;
/**
* @author Martin Fluegge
*/
-public class DawnGenericGraphitiWizard extends Wizard implements INewWizard
+public class DawnGenericGraphitiWizard extends DawnBasicGraphitiWizard
{
- private CDOView view;
-
private DawnGraphitiyDiagramTypeSelectionWizardPage dawnSelectModelPage;
- private DawnCreateNewDiagramResourceWizardPage dawnDiagramModelFilePage;
-
- private DawnCreateNewResourceWizardPage dawnDomainModelFilePage;
-
public DawnGenericGraphitiWizard()
{
- super();
- CDOConnectionUtil.instance.init(PreferenceConstants.getRepositoryName(), PreferenceConstants.getProtocol(),
- PreferenceConstants.getServerName());
- CDOSession session = CDOConnectionUtil.instance.openSession();
- view = CDOConnectionUtil.instance.openView(session);
- }
-
- public void init(IWorkbench workbench, IStructuredSelection selection)
- {
+ super("", "graphiti");
}
@Override
@@ -78,19 +34,17 @@ public class DawnGenericGraphitiWizard extends Wizard implements INewWizard
dawnSelectModelPage = new DawnGraphitiyDiagramTypeSelectionWizardPage("title");
addPage(dawnSelectModelPage);
- dawnDiagramModelFilePage = new DawnCreateNewDiagramResourceWizardPage("acore_graphiti", false, view)
+ dawnDiagramModelFilePage = new DawnCreateNewDiagramResourceWizardPage(diagramExtension, false, view)
{
@Override
public void setVisible(boolean visible)
{
if (visible)
{
- String extension = dawnSelectModelPage.getText();
-
URI uri = dawnDiagramModelFilePage.getURI();
String fileName = uri.lastSegment();
- fileName = fileName.substring(0, fileName.length() - ("." + extension + "_graphiti").length()); //$NON-NLS-1$
- fileName += "." + extension + "_graphiti";
+ fileName = fileName.substring(0, fileName.length() - ("." + diagramExtension).length()); //$NON-NLS-1$
+ fileName += "." + diagramExtension;
dawnDomainModelFilePage.setResourceNamePrefix(fileName);
dawnDomainModelFilePage.setResourcePath(dawnDiagramModelFilePage.getResourcePath());
}
@@ -103,7 +57,7 @@ public class DawnGenericGraphitiWizard extends Wizard implements INewWizard
dawnDiagramModelFilePage.setCreateAutomaticResourceName(true);
addPage(dawnDiagramModelFilePage);
- dawnDomainModelFilePage = new DawnCreateNewResourceWizardPage("acore", true, view)
+ dawnDomainModelFilePage = new DawnCreateNewResourceWizardPage("", true, view)
{
@Override
public void setVisible(boolean visible)
@@ -113,7 +67,7 @@ public class DawnGenericGraphitiWizard extends Wizard implements INewWizard
String extension = dawnSelectModelPage.getText();
URI uri = dawnDiagramModelFilePage.getURI();
String fileName = uri.lastSegment();
- fileName = fileName.substring(0, fileName.length() - ("." + extension + "_graphiti").length()); //$NON-NLS-1$
+ fileName = fileName.substring(0, fileName.length() - ("." + diagramExtension).length()); //$NON-NLS-1$
fileName += "." + extension;
dawnDomainModelFilePage.setResourceNamePrefix(fileName);
dawnDomainModelFilePage.setResourcePath(dawnDiagramModelFilePage.getResourcePath());
@@ -130,84 +84,8 @@ public class DawnGenericGraphitiWizard extends Wizard implements INewWizard
}
@Override
- public boolean performFinish()
- {
- String diagramTypeId = dawnSelectModelPage.getText();
-
- URI diagramResourceURI = dawnDiagramModelFilePage.getURI();
- @SuppressWarnings("unused")
- URI domainModelResourceURI = dawnDomainModelFilePage.getURI();
-
- Diagram diagram = Graphiti.getPeCreateService()
- .createDiagram(diagramTypeId, diagramResourceURI.lastSegment(), true);
-
- String editorID = DawnGraphitiDiagramEditor.ID;
- // String diagramTypeProviderId = GraphitiUi.getExtensionManager().getDiagramTypeProviderId(diagramTypeId);
-
- TransactionalEditingDomain domain = createEditingDomain(diagramResourceURI, diagram);
-
- Resource resource = createResource(diagramResourceURI, diagram, domain);
-
- String providerId = GraphitiUi.getExtensionManager().getDiagramTypeProviderId(diagram.getDiagramTypeId());
- DiagramEditorInput editorInput = new DawnGraphitiEditorInput(EcoreUtil.getURI(diagram), domain, providerId, true,
- resource);
-
- try
- {
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput, editorID);
- }
- catch (PartInitException e)
- {
- String error = "Error opening diagram";
- IStatus status = new Status(IStatus.ERROR, DawnGraphitiUIPlugin.ID, error, e);
- ErrorDialog.openError(getShell(), "Error", null, status);
- return false;
- }
-
- return true;
- }
-
- private TransactionalEditingDomain createEditingDomain(URI diagramResourceURI, final Diagram diagram)
- {
- // Create a resource set and EditingDomain
- final TransactionalEditingDomain editingDomain = DawnGraphitiDiagramEditorFactory
- .createResourceSetAndEditingDomain();
-
- // save(editingDomain, Collections.<Resource, Map<?, ?>> emptyMap());
- return editingDomain;
- }
-
- private Resource createResource(URI diagramResourceURI, final Diagram diagram,
- final TransactionalEditingDomain editingDomain)
- {
- final ResourceSet resourceSet = editingDomain.getResourceSet();
- // Create a resource for this file.
- final Resource resource = resourceSet.createResource(diagramResourceURI);
- final CommandStack commandStack = editingDomain.getCommandStack();
- commandStack.execute(new RecordingCommand(editingDomain)
- {
- @Override
- protected void doExecute()
- {
- // resource.setTrackingModification(true);
- resource.getContents().add(diagram);
- }
- });
-
- try
- {
- resource.save(null);
- }
- catch (IOException ex)
- {
- throw new RuntimeException(ex);
- }
- return resource;
- }
-
- @Override
- public void dispose()
+ protected String geTypeId()
{
- view.close();
+ return dawnSelectModelPage.getText();
}
}
diff --git a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/helper/DawnEditorHelper.java b/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/helper/DawnEditorHelper.java
index 3c668db182..83369936a0 100644
--- a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/helper/DawnEditorHelper.java
+++ b/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/helper/DawnEditorHelper.java
@@ -1,64 +1,74 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.helper;
-
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * TODO move this one to the dawn.util bundle
- *
- * @author Martin Fluegge
- */
-public class DawnEditorHelper
-{
- public static Shell getActiveShell()
- {
- Shell shell = Display.getCurrent().getActiveShell();
- return shell;
- }
-
- public static IEditorPart getActiveEditor()
- {
- IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- IEditorPart editor = null;
- if (window != null)
- {
- IWorkbenchPage page = window.getActivePage();
- if (page != null)
- {
- editor = page.getActiveEditor();
- }
- }
- return editor;
- }
-
- /**
- * This method tries to retrieve a Display. First it tries to get the current display. If this fails it will return
- * the default display.
- *
- * @return the current display, if not null. If the current Display is null then the default Display.
- * @since 2.0
- */
- public static Display getDisplay()
- {
- Display display = Display.getCurrent();
- if (display == null)
- {
- display = Display.getDefault();
- }
- return display;
- }
-}
+/*
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Fluegge - initial API and implementation
+ */
+package org.eclipse.emf.cdo.dawn.helper;
+
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * TODO move this one to the dawn.util bundle
+ *
+ * @author Martin Fluegge
+ */
+public class DawnEditorHelper
+{
+ /**
+ * Delivers the active shell from the current display.
+ *
+ * @return the active shell on the current display
+ */
+ public static Shell getActiveShell()
+ {
+ Shell shell = Display.getCurrent().getActiveShell();
+ return shell;
+ }
+
+ /**
+ * This method returns the active editor from the active workbench page
+ *
+ * @return the active editor from the active workbench page or null if there is none
+ */
+ public static IEditorPart getActiveEditor()
+ {
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ IEditorPart editor = null;
+ if (window != null)
+ {
+ IWorkbenchPage page = window.getActivePage();
+ if (page != null)
+ {
+ editor = page.getActiveEditor();
+ }
+ }
+ return editor;
+ }
+
+ /**
+ * This method tries to retrieve a Display. First it tries to get the current display. If this fails it will return
+ * the default display.
+ *
+ * @return the current display, if not null. If the current Display is null then the default Display.
+ * @since 2.0
+ */
+ public static Display getDisplay()
+ {
+ Display display = Display.getCurrent();
+ if (display == null)
+ {
+ display = Display.getDefault();
+ }
+ return display;
+ }
+}

Back to the top