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/org.eclipse.emf.cdo.dawn.examples.acore.graphiti
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/org.eclipse.emf.cdo.dawn.examples.acore.graphiti')
-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
5 files changed, 164 insertions, 30 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);
+ }
+ }
+ }
+}

Back to the top