Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2013-10-24 08:27:56 +0000
committerVincent Lorenzo2013-10-24 08:45:55 +0000
commit3c54f277d3f1ec84ef181dcabe89f0c5fba8933d (patch)
treea4682d98f73edc862c0a5c6805df31a339787336 /extraplugins
parenta1179807d265b8c27e6d675cd515147ea1e023a7 (diff)
downloadorg.eclipse.papyrus-3c54f277d3f1ec84ef181dcabe89f0c5fba8933d.tar.gz
org.eclipse.papyrus-3c54f277d3f1ec84ef181dcabe89f0c5fba8933d.tar.xz
org.eclipse.papyrus-3c54f277d3f1ec84ef181dcabe89f0c5fba8933d.zip
411233: [Releng] Add RobotML to Releng
https://bugs.eclipse.org/bugs/show_bug.cgi?id=411233
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/.classpath7
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/.project28
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/.settings/org.eclipse.jdt.core.prefs11
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/META-INF/MANIFEST.MF22
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/about.html28
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/build.properties9
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/icons/allocation.gifbin0 -> 143 bytes
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/icons/depPlan.gifbin0 -> 104 bytes
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/plugin.properties3
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/plugin.xml135
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Activator.java61
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/AllocUtils.java284
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/CommandSupport.java102
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Copy.java826
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepCreation.java476
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepPlanSync.java135
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepPlanUtils.java319
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepUtils.java309
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DialogUtils.java100
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Log.java86
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/RunnableWithResult.java26
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/StUtils.java441
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/TransformationException.java22
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Utils.java537
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/AllocationDialog.java304
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/AttributeLabelProvider.java32
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/ConfigureInstanceDialog.java509
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/Description.java75
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/InstanceLabelProvider.java35
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/AllocateHandler.java89
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/CmdHandler.java140
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/ConfigureInstanceHandler.java129
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/CreateDepPlanHandler.java148
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/CreatePlatformHandler.java97
-rw-r--r--extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/listener/CopyListener.java35
35 files changed, 5560 insertions, 0 deletions
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/.classpath b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/.classpath
new file mode 100644
index 00000000000..02159672985
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/.project b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/.project
new file mode 100644
index 00000000000..a2fbfac05ab
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.robotml.deployment</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/.settings/org.eclipse.jdt.core.prefs b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..54e493c07c9
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/META-INF/MANIFEST.MF b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..6439a4bf489
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/META-INF/MANIFEST.MF
@@ -0,0 +1,22 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name
+Bundle-SymbolicName: org.eclipse.papyrus.robotml.deployment;singleton:=true
+Bundle-Version: 0.10.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.robotml.deployment.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.emf;bundle-version="2.6.0",
+ org.eclipse.emf.ecore,
+ org.eclipse.gmf.runtime.common.core,
+ org.eclipse.uml2.uml,
+ org.eclipse.papyrus.robotml;bundle-version="0.10.0",
+ org.eclipse.gef,
+ org.eclipse.gmf.runtime.notation.edit,
+ org.eclipse.emf.transaction,
+ org.eclipse.gmf.runtime.emf.commands.core,
+ org.eclipse.papyrus.infra.core;bundle-version="0.10.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
+Bundle-Vendor: %Bundle-Vendor
+Bundle-Localization: plugin
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/about.html b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/about.html
new file mode 100644
index 00000000000..82d49bf5f81
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2007</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/build.properties b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/build.properties
new file mode 100644
index 00000000000..70645fd2be5
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/build.properties
@@ -0,0 +1,9 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ plugin.properties,\
+ icons/,\
+ about.html
+src.includes = about.html
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/icons/allocation.gif b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/icons/allocation.gif
new file mode 100644
index 00000000000..ced634f9c9c
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/icons/allocation.gif
Binary files differ
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/icons/depPlan.gif b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/icons/depPlan.gif
new file mode 100644
index 00000000000..712a2485f8d
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/icons/depPlan.gif
Binary files differ
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/plugin.properties b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/plugin.properties
new file mode 100644
index 00000000000..b2a07cb8b38
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/plugin.properties
@@ -0,0 +1,3 @@
+#Properties file for org.eclipse.papyrus.robotml.deployment
+Bundle-Vendor = Eclipse Modeling Project
+Bundle-Name = org.eclipse.papyrus.robotml.deployment (Incubation) \ No newline at end of file
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/plugin.xml b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/plugin.xml
new file mode 100644
index 00000000000..635017df27d
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/plugin.xml
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.robotml.deployment.handlers.CreateDepPlanHandler"
+ description="Create deployment plan"
+ id="org.eclipse.papyrus.robotml.deployment.menuActions.CreateDepPlanCmd"
+ name="dummy">
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.robotml.deployment.handlers.CreatePlatformHandler"
+ description="Create platform definition"
+ id="org.eclipse.papyrus.robotml.deployment.menuActions.CreatePlatformCmd"
+ name="dummy">
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.robotml.deployment.handlers.ConfigureInstanceHandler"
+ description="Configure instance"
+ id="org.eclipse.papyrus.robotml.deployment.menuActions.ConfigureInstanceCmd"
+ name="dummy">
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.robotml.deployment.handlers.AllocateHandler"
+ description="Allocate to node"
+ id="org.eclipse.papyrus.robotml.deployment.menuActions.AllocateCmd"
+ name="dummy">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.views.modelexplorer.modelexplorer.popup">
+ <command
+ commandId="org.eclipse.papyrus.robotml.deployment.menuActions.CreateDepPlanCmd"
+ icon="icons/depPlan.gif"
+ id="org.eclipse.papyrus.robotml.deployment.menuActions.CreateDepPlanMenu"
+ label="Create deployment plan"
+ mnemonic="d"
+ mode="FORCE_TEXT"
+ style="push">
+ <visibleWhen>
+ <reference
+ definitionId="org.eclipse.papyrus.robotml.diagram.common.IsPapyrusActiveWithRobotml">
+ </reference>
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.robotml.deployment.menuActions.CreatePlatformCmd"
+ icon="icons/depPlan.gif"
+ id="org.eclipse.papyrus.robotml.deployment.menuActions.CreatePlatformMenu"
+ label="Create platform definition"
+ mnemonic="d"
+ mode="FORCE_TEXT"
+ style="push">
+ <visibleWhen>
+ <reference
+ definitionId="org.eclipse.papyrus.robotml.diagram.common.IsPapyrusActiveWithRobotml">
+ </reference>
+ </visibleWhen>
+ </command>
+
+ <command
+ commandId="org.eclipse.papyrus.robotml.deployment.menuActions.AllocateCmd"
+ icon="icons/allocation.gif"
+ id="org.eclipse.papyrus.robotml.deployment.menuActions.AllocateMenu"
+ label="Allocate to node"
+ mnemonic="A"
+ mode="FORCE_TEXT"
+ style="push">
+ <visibleWhen>
+ <reference
+ definitionId="org.eclipse.papyrus.robotml.diagram.common.IsPapyrusActiveWithRobotml">
+ </reference>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu">
+ <command
+ commandId="org.eclipse.papyrus.robotml.deployment.menuActions.CreateDepPlanCmd"
+ icon="icons/depPlan.gif"
+ id="org.eclipse.papyrus.robotml.deployment.menuActions.CreateDepPlanMenu"
+ label="Create deployment plan"
+ mnemonic="d"
+ mode="FORCE_TEXT"
+ style="push">
+ <visibleWhen>
+ <reference
+ definitionId="org.eclipse.papyrus.robotml.diagram.common.IsPapyrusActiveWithRobotml">
+ </reference>
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.robotml.deployment.menuActions.CreatePlatformCmd"
+ icon="icons/depPlan.gif"
+ id="org.eclipse.papyrus.robotml.deployment.menuActions.CreatePlatformMenu"
+ label="Create platform definition"
+ mnemonic="d"
+ mode="FORCE_TEXT"
+ style="push">
+ <visibleWhen>
+ <reference
+ definitionId="org.eclipse.papyrus.robotml.diagram.common.IsPapyrusActiveWithRobotml">
+ </reference>
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.robotml.deployment.menuActions.AllocateCmd"
+ icon="icons/allocation.gif"
+ id="org.eclipse.papyrus.robotml.deployment.menuActions.AllocateMenu"
+ label="Allocate to node"
+ mnemonic="A"
+ mode="FORCE_TEXT"
+ style="push">
+ <visibleWhen>
+ <reference
+ definitionId="org.eclipse.papyrus.robotml.diagram.common.IsPapyrusActiveWithRobotml">
+ </reference>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+
+
+ </extension>
+
+</plugin>
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Activator.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Activator.java
new file mode 100644
index 00000000000..0c3f0a47ce1
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Activator.java
@@ -0,0 +1,61 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.robotml.deployment"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/AllocUtils.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/AllocUtils.java
new file mode 100644
index 00000000000..1f753db9c27
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/AllocUtils.java
@@ -0,0 +1,284 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.UniqueEList;
+import org.eclipse.papyrus.RobotML.Allocate;
+import org.eclipse.uml2.uml.Abstraction;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.DirectedRelationship;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Node;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.UMLPackage;
+
+
+
+public class AllocUtils {
+
+ /**
+ * Retrieve a list of nodes to which the instance is allocated to *or*
+ * to which one of the contained instances is allocated to (recursively)
+ *
+ * @param instance
+ * @return a list of nodes
+ */
+ public static EList<InstanceSpecification> getAllNodes(InstanceSpecification instance) {
+ EList<InstanceSpecification> nodeList = getNodes(instance);
+ for(InstanceSpecification containedInstance : DepUtils.getContainedInstances(instance)) {
+ nodeList.addAll(getAllNodes(containedInstance));
+ }
+ return nodeList;
+ }
+
+ /**
+ * Retrieve a list of nodes to which the instance is allocated to *or*
+ * to which one of the containing instances is explicitly allocated
+ *
+ * @param instance
+ * @return a list of nodes
+ */
+ public static EList<InstanceSpecification> getAllNodesOrThreadsParent(InstanceSpecification instance) {
+ EList<InstanceSpecification> nodeList = getNodesOrThreads(instance);
+ Package cdp = instance.getNearestPackage();
+ // TODO: not very efficient: loop each time over all instance specifications
+ for(NamedElement parentNE : cdp.getMembers()) {
+ if(parentNE instanceof InstanceSpecification) {
+ // possible parent instance specification
+ InstanceSpecification parentIS = (InstanceSpecification)parentNE;
+ if(DepUtils.getContainedInstances(parentIS).contains(instance)) {
+ nodeList.addAll(getAllNodesOrThreadsParent(parentIS));
+ }
+ }
+ }
+ return nodeList;
+ }
+
+ public static InstanceSpecification getNode(InstanceSpecification instance) {
+ EList<InstanceSpecification> nodeList = getNodes(instance);
+ if(nodeList.size() != 0) {
+ return nodeList.get(0);
+ }
+ return null;
+ }
+
+ public static InstanceSpecification getNodeOrThread(InstanceSpecification instanceOrThread) {
+ EList<InstanceSpecification> nodeList = getNodesOrThreads(instanceOrThread);
+ if(nodeList.size() != 0) {
+ return nodeList.get(0);
+ }
+ return null;
+ }
+
+ /**
+ * This method returns a list of nodes when given an instance.
+ * It is based on MARTE Allocation (a stereotyped abstraction) which is a generic
+ * mechanism to deploy UML elements to nodes.
+ *
+ * @param instanceOrThread
+ * The instance that should be deployed
+ * @return
+ */
+ public static EList<InstanceSpecification> getNodesOrThreads(NamedElement instanceOrThread) {
+ EList<InstanceSpecification> nodeList = new UniqueEList<InstanceSpecification>();
+
+ for(DirectedRelationship relationship : instanceOrThread.getSourceDirectedRelationships(UMLPackage.eINSTANCE.getAbstraction())) {
+ Abstraction abstraction = (Abstraction)relationship;
+ if(StUtils.isApplied(abstraction, Allocate.class)) {
+ for(Element target : abstraction.getTargets()) {
+ if(target instanceof InstanceSpecification) {
+ nodeList.add((InstanceSpecification)target);
+ }
+ }
+ }
+ }
+ return nodeList;
+ }
+
+ /**
+ * This method returns a list of nodes when given an instance.
+ * It is based on MARTE Allocation (a stereotyped abstraction) which is a generic
+ * mechanism to deploy UML elements to nodes.
+ *
+ * @param instanceOrThread
+ * The instance that should be deployed
+ * @return
+ */
+ public static EList<InstanceSpecification> getNodes(NamedElement instanceOrThread) {
+ EList<InstanceSpecification> nodeList = new UniqueEList<InstanceSpecification>();
+ EList<InstanceSpecification> nodeOrThreads = getNodesOrThreads(instanceOrThread);
+ for(InstanceSpecification nodeOrThread : nodeOrThreads)
+ {
+ Classifier nodeOrThreadC = DepUtils.getClassifier(nodeOrThread);
+// if(StUtils.isApplied(nodeOrThreadC, SwSchedulableResource.class)) {
+// // tread case that instance is allocated to a thread
+// // follow allocation of Thread
+// nodeList.add(getNode(nodeOrThread));
+// }
+// else {
+ nodeList.add(nodeOrThread);
+// }
+ }
+ return nodeList;
+ }
+
+ /**
+ * This method updates (and optionally removes) the allocations of an instance
+ *
+ * @param instance
+ * The instance that should be deployed
+ * @param oldNode
+ * the old node allocation
+ * @param newNode
+ * the new node allocation, may be null to indicate removal
+ * @return
+ */
+ public static EList<Node> updateAllocation(InstanceSpecification instance, InstanceSpecification oldNode, InstanceSpecification newNode) {
+ EList<Node> nodeList = new UniqueEList<Node>();
+
+ Iterator<DirectedRelationship> relShipIt =
+ instance.getSourceDirectedRelationships(UMLPackage.eINSTANCE.getAbstraction()).iterator();
+
+ while(relShipIt.hasNext()) {
+ Abstraction abstraction = (Abstraction)relShipIt.next();
+ if(StUtils.isApplied(abstraction, Allocate.class)) {
+ EList<NamedElement> suppliers = abstraction.getSuppliers(); // use suppliers instead of targets (derived)
+ for(int index = 0; index < suppliers.size(); index++) {
+ if(suppliers.get(index) == oldNode) {
+ if(newNode == null) {
+ // remove relationship completely, since we assume a single target
+ // (cannot call remove on relShipIt, since list is derived)
+ abstraction.destroy();
+ } else {
+ suppliers.set(index, newNode);
+ }
+ break;
+ }
+ }
+ }
+ }
+ return nodeList;
+ }
+
+// /**
+// * Retrieve a list of nodes to which the instance is allocated to *or*
+// * to which one of the contained instances is allocated to (recursively)
+// *
+// * @param instance
+// * @param A
+// * port of the composite. Contained instances are examined only if
+// * they have a connection with this port.
+// * @return a list of nodes
+// */
+// public static EList<InstanceSpecification> getAllNodesForPort(InstanceSpecification instance, Port port) {
+// EList<InstanceSpecification> nodeList = getNodes(instance);
+// Classifier composite = DepUtils.getClassifier(instance);
+// if(composite instanceof Class) {
+// Class compositeCL = (Class)composite;
+// for(Slot slot : instance.getSlots()) {
+// Property containedProperty = (Property)slot.getDefiningFeature();
+//
+// for(Connector connection : compositeCL.getOwnedConnectors()) {
+// // is one connector end targeted at the containedProperty ?
+// ConnectorEnd end = ConnectorUtils.connEndForPart(connection, containedProperty);
+// if(end == null)
+// continue;
+//
+// // does the connector at the same connect the composite's port?
+// if(ConnectorUtils.connectsPort(connection, port)) {
+// Port containedPort = (Port)end.getRole();
+// nodeList.addAll(getAllNodesForPort(DepUtils.getInstance(slot), containedPort));
+// }
+// }
+// }
+// }
+// return nodeList;
+// }
+
+ public static boolean allocate(InstanceSpecification instance, InstanceSpecification node) {
+ Package cdp = (Package)instance.getOwner();
+ Abstraction allocation = (Abstraction)
+ cdp.createPackagedElement("allocate to " + node.getName(), UMLPackage.eINSTANCE.getAbstraction());
+ if(StUtils.apply(allocation, Allocate.class) == null) {
+ // stereotype application failed
+ return false;
+ }
+ allocation.getClients().add(instance);
+ allocation.getSuppliers().add(node);
+ return true;
+ }
+
+// /**
+// * Assign node name to leafs
+// *
+// * @param instance
+// * @param A
+// * port of the composite. Contained instances are examined only if the
+// * have a connection with this port. If null, no sub-instances are examined
+// * @param nodes
+// * A list of nodes to which leafs are allocated
+// */
+// public static void propagateNodesViaPort(InstanceSpecification instance, Port port, EList<InstanceSpecification> nodes) {
+// if(instance == null) {
+// return;
+// }
+// EList<Slot> slots = instance.getSlots();
+// Class composite = DepUtils.getImplementation(instance);
+// /*
+// * ComponentImpl componentImpl =
+// * StUtils.getApplication(composite, ComponentImpl.class);
+// * if(!((componentImpl != null) && componentImpl.isIsAssembly())) {
+// * // do not set nodes on an assembly
+// * // how-to assure to set only leafs?
+// * for(InstanceSpecification node : nodes) {
+// * AllocUtils.allocate(instance, node);
+// * }
+// * }
+// */
+// if((composite != null) && (port != null)) {
+// Class compositeCL = (Class)composite;
+// for(Slot slot : slots) {
+// Property containedProperty = (Property)slot.getDefiningFeature();
+//
+//// FCM.Part fcmPart = StUtils.getApplication(containedProperty, FCM.Part.class);
+//// if(fcmPart != null) {
+//// EList<Port> colocateWithPort = fcmPart.getColocateWithPort();
+//// // is the port within the list?
+//// if(Utils.getNamedElementFromList(colocateWithPort, port.getName()) != null) {
+//// // compare qualified name, since containedPort (stereotype attribute)
+//// // points to a source model element
+//// propagateNodesViaPort(DepUtils.getInstance(slot), port, nodes);
+//// continue;
+//// }
+//// }
+// for(Connector connection : compositeCL.getOwnedConnectors()) {
+// if(ConnectorUtils.connectsPort(connection, port)) {
+// Log.log(Log.INFO_MSG, Log.TRAFO_CONNECTOR, "connector: " + connection.getName());
+// Log.log(Log.INFO_MSG, Log.TRAFO_CONNECTOR, "end1: " + connection.getEnds().get(0).getPartWithPort());
+// Log.log(Log.INFO_MSG, Log.TRAFO_CONNECTOR, "end2: " + connection.getEnds().get(1).getPartWithPort());
+// ConnectorEnd end = ConnectorUtils.connEndForPart(connection, containedProperty);
+// // other connector end targeted at containedProperty?
+// if(end != null) {
+// Port containedPort = (Port)end.getRole();
+// propagateNodesViaPort(DepUtils.getInstance(slot), containedPort, nodes);
+// }
+// }
+// }
+// }
+// }
+// }
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/CommandSupport.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/CommandSupport.java
new file mode 100644
index 00000000000..44052bac45b
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/CommandSupport.java
@@ -0,0 +1,102 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.robotml.deployment;
+
+import java.util.Collections;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.IOperationHistory;
+import org.eclipse.core.commands.operations.OperationHistoryFactory;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
+
+/**
+ * Utility function. Allow execution of commands on a transactional command stack
+ *
+ * @author ansgar
+ *
+ */
+@SuppressWarnings("deprecation")
+public class CommandSupport {
+
+ /**
+ * Execute the passed Runnable within a command
+ *
+ * @param label
+ * @param command
+ */
+ public static void exec(String label, final Runnable command) {
+ ServiceUtilsForActionHandlers serviceUtils = ServiceUtilsForActionHandlers.getInstance();
+ try {
+ exec(serviceUtils.getTransactionalEditingDomain(), label, command);
+ } catch (ServiceException e) {
+ Log.log(Log.ERROR_MSG, Log.UTILS, "Can not get editing domain");
+ }
+ }
+
+ /**
+ * Execute the passed Runnable with result within a command
+ *
+ * @param label
+ * @param command
+ */
+ public static void exec(String label, final RunnableWithResult command) {
+ ServiceUtilsForActionHandlers serviceUtils = ServiceUtilsForActionHandlers.getInstance();
+ IOperationHistory history = OperationHistoryFactory.getOperationHistory();
+ try {
+ history.execute(new AbstractTransactionalCommand(serviceUtils.getTransactionalEditingDomain(),
+ label, Collections.EMPTY_LIST) {
+
+ public CommandResult doExecuteWithResult(IProgressMonitor dummy, IAdaptable info) {
+ return command.run();
+ }
+ }, null, null);
+ } catch (ExecutionException e) {
+ Log.log(Log.ERROR_MSG, Log.UTILS, "error during command execution");
+ } catch (ServiceException e) {
+ Log.log(Log.ERROR_MSG, Log.UTILS, "Can not get editing domain");
+ }
+ }
+
+ /**
+ * Execute the passed Runnable within a command
+ *
+ * @param label
+ * @param command
+ */
+ public static void exec(TransactionalEditingDomain domain, String label, final Runnable command) {
+ if(domain == null) {
+ command.run();
+ }
+ else {
+ IOperationHistory history = OperationHistoryFactory.getOperationHistory();
+ try {
+ history.execute(new AbstractTransactionalCommand(domain, label, Collections.EMPTY_LIST) {
+
+ public CommandResult doExecuteWithResult(IProgressMonitor dummy, IAdaptable info) {
+ command.run();
+ return CommandResult.newOKCommandResult();
+ }
+ }, null, null);
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Copy.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Copy.java
new file mode 100644
index 00000000000..4a0e65c20cf
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Copy.java
@@ -0,0 +1,826 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil.Copier;
+import org.eclipse.emf.ecore.util.InternalEList;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.papyrus.robotml.deployment.listener.CopyListener;
+import org.eclipse.uml2.uml.Behavior;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Feature;
+import org.eclipse.uml2.uml.LiteralBoolean;
+import org.eclipse.uml2.uml.LiteralInteger;
+import org.eclipse.uml2.uml.LiteralNull;
+import org.eclipse.uml2.uml.LiteralString;
+import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
+import org.eclipse.uml2.uml.MultiplicityElement;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Namespace;
+import org.eclipse.uml2.uml.OpaqueExpression;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.PackageableElement;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Slot;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.ValueSpecification;
+
+/**
+ * information about source and target packages within a model transformation
+ *
+ * @author ansgar
+ *
+ */
+public class Copy extends Copier {
+
+ public Copy(Package source_, Package target_, boolean copyExtResources_) {
+ source = source_;
+ target = target_;
+ // useOriginalReferences = false;
+ copyExtReferences = copyExtResources_;
+ preCopyListeners = new BasicEList<CopyListener>();
+ postCopyListeners = new BasicEList<CopyListener>();
+ templateMapInfo = new HashMap<EObject, Map<EObject, EObject>>();
+ standardMap = new HashMap<EObject, EObject>();
+ shallowMap = new HashMap<EObject, Boolean>();
+ boundPackages = new Stack<Namespace>();
+ if(copyExtReferences) {
+ // original source package becomes a sub-package in the target model
+ Package newSourceRoot = target.createNestedPackage(source.getName());
+ put(source, newSourceRoot);
+ }
+ else {
+ put(source, target);
+ }
+ };
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -1664013545661635289L;
+
+ /**
+ * Source model within a transformation
+ */
+
+ public Package source;
+
+ /**
+ * Target model within a transformation
+ */
+ public Package target;
+
+ /**
+ * if true, copy packages or elements that are imported into the target
+ * model
+ */
+ public boolean copyExtReferences;
+
+ /**
+ * Bound package template
+ */
+ private Namespace boundPackage;
+
+ /**
+ * Map to identify target objects when given source objects
+ */
+ private Map<EObject, EObject> standardMap;
+
+ /**
+ * Map to identify target objects when given source objects
+ */
+ private Map<EObject, EObject> templateMap;
+
+ /**
+ * Set of maps for template instantiations
+ */
+ private Map<EObject, Map<EObject, EObject>> templateMapInfo;
+
+ /**
+ * Map using a target EObject as key
+ */
+ private Map<EObject, Boolean> shallowMap;
+
+ /**
+ * Elements within package templates must be treated differently, we have to ensure that:
+ * (1) several instantiations with same binding of the same package template do not lead to double copies
+ * (yet, it may be possible that a 2nd instantiation adds contents, e.g. the trace package template could be
+ * instantiated containing only OTF trace (and superclasses), a second instantiation might add a different trace
+ * implementation)
+ * (2) several instantiations with different binding do not prevent classes from being copied that have already
+ * been copied earlier.
+ * The solution is to use a different map for the elements with package template. This map is instantiated once
+ * for each binding (managed by the TemplateInstantiation class)
+ */
+ public Map<EObject, EObject> getMap(EObject sourceEObj) {
+ boolean withinTemplate = withinTemplate(sourceEObj);
+ return withinTemplate ?
+ templateMap :
+ standardMap;
+ }
+
+ @Override
+ public EObject get(Object sourceEObj) {
+ if(sourceEObj instanceof EObject) {
+ Map<EObject, EObject> map = getMap((EObject)sourceEObj);
+ return map.get(sourceEObj);
+ }
+ return null;
+ }
+
+ @Override
+ public EObject put(EObject sourceEObj, EObject targetEObj) {
+ if(sourceEObj instanceof EObject) {
+ Map<EObject, EObject> map = getMap((EObject)sourceEObj);
+ return map.put(sourceEObj, targetEObj);
+ }
+ return null;
+ }
+
+ @Override
+ public boolean containsKey(Object sourceEObj) {
+ if(sourceEObj instanceof EObject) {
+ Map<EObject, EObject> map = getMap((EObject)sourceEObj);
+ return map.containsKey(sourceEObj);
+ }
+ return false;
+ }
+
+ @Override
+ public EObject remove(Object sourceEObj) {
+ if(sourceEObj instanceof EObject) {
+ Map<EObject, EObject> map = getMap((EObject)sourceEObj);
+ return map.remove(sourceEObj);
+ }
+ return null;
+ }
+
+ public void setShallow(EObject targetEObj, boolean isShallow) {
+ shallowMap.put(targetEObj, isShallow);
+ }
+
+ /**
+ * return true, if a shallow copy of the passed EObject exists
+ *
+ * @param sourceEObj
+ * @return
+ */
+ public boolean isShallow(EObject targetEObj) {
+ Boolean shallow = shallowMap.get(targetEObj);
+ if(shallow != null) {
+ return shallow;
+ }
+ return false;
+ }
+
+ // public Namespace getPackageTemplate() {
+ // return null;
+ // }
+
+ /**
+ * Set the reference of a bound package template. It must be a member of the target model.
+ * Setting the package template is required to assure that elements that are part of a different
+ * resource get copied (depending on the copyExtReferences flag, this is not the case)
+ *
+ * @param packageTemplate
+ * Reference to package (with a template signature) in source model that should be instantiated
+ * @param boundPackage
+ * Reference to (an initially empty) package in which the packate template will be instantiated
+ * during the copy process
+ */
+ public void setPackageTemplate(Namespace packageTemplate, Namespace boundPackage) {
+ this.boundPackage = boundPackage;
+ if(packageTemplate == null) {
+ return;
+ }
+ templateMap =
+ templateMapInfo.get(boundPackage);
+ if(templateMap == null) {
+ templateMap = new HashMap<EObject, EObject>();
+ templateMapInfo.put(boundPackage, templateMap);
+ }
+ // declare relation between packageTemplate and bound package
+ // but: the owner of the package template is not equal to the packageTemplate (e.g. perClass)
+ // since we can extend package templates in different models.
+ standardMap.put(packageTemplate, boundPackage);
+ }
+
+ public void pushPackageTemplate() {
+ boundPackages.push(boundPackage);
+ }
+
+ public void popPackageTemplate() {
+ boundPackage = boundPackages.pop();
+ templateMap =
+ templateMapInfo.get(boundPackage);
+ }
+
+ private Stack<Namespace> boundPackages;
+
+ public void removeForCopy(EObject element) {
+ templateMap.remove(element);
+ EClass eClass = element.eClass();
+ for(int i = 0, size = eClass.getFeatureCount(); i < size; ++i)
+ {
+ EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(i);
+ if(eStructuralFeature.isChangeable() && !eStructuralFeature.isDerived())
+ {
+ if(eStructuralFeature instanceof EAttribute) {
+ // copyAttribute((EAttribute)eStructuralFeature, sourceEObj, targetEObj);
+ }
+ else {
+ EReference eReference = (EReference)eStructuralFeature;
+ if(eReference.isContainment()) {
+ for(EObject ref : getRefs(eReference, element)) {
+ removeForCopy(ref);
+ }
+ }
+ else if(!eReference.isContainer()) {
+ // not contained, but copy reference as well
+
+ }
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public EList<EObject> getRefs(EReference eReference, EObject eObject) {
+ EList<EObject> refs = new BasicEList<EObject>();
+ if(eObject.eIsSet(eReference)) {
+ if(eReference.isMany()) {
+ // @SuppressWarnings("unchecked")
+ refs.addAll((List<EObject>)eObject.eGet(eReference));
+ } else {
+ refs.add((EObject)eObject.eGet(eReference));
+ }
+ }
+ return refs;
+ }
+
+ public boolean withinTemplate(EObject element) {
+ if(boundPackage != null) {
+ EObject owner = element;
+ while(owner != null) {
+ owner = owner.eContainer();
+ if(get(owner) == boundPackage) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns a copy of the given eObject.
+ *
+ * Normally, we do not want to copy elements that are from a different
+ * resource. There are two exceptions (1) if this is explicitly specified
+ * (for producing "complete" models) (2) if we want to copy elements from a
+ * template into the target model.
+ *
+ * @param sourceEObj
+ * the object to copy.
+ * @return the copy.
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public EObject copy(EObject sourceEObj) {
+ boolean withinTemplate = withinTemplate(sourceEObj);
+
+ EObject targetEObj = get(sourceEObj);
+
+ boolean shallowCopy = (targetEObj != null) && isShallow(targetEObj);
+
+ if((targetEObj != null) && !shallowCopy) {
+ // copy already exists, return
+ return targetEObj;
+ }
+ setShallow(targetEObj, false);
+
+ if(sourceEObj == null) {
+ // this case may happen, if elements were systematcially copied without checking for
+ // null references in the application code (e.g. if we copy a part-with-port which might
+ // be null in case of delegation or connectors without ports
+ return null;
+ }
+ boolean sameResource = (sourceEObj.eResource() == source.eResource());
+ if(!sameResource && !copyExtReferences && !withinTemplate) {
+ // do not copy if within different resource, unless
+ // 1. copyImports
+ // 2. within package template
+ return sourceEObj;
+ }
+
+ if(sourceEObj instanceof Stereotype) {
+ // do not copy Stereotypes, as it would imply copying meta-model elements (the base_X
+ // attribute of the stereotype is typed with a meta-model element)
+ return sourceEObj;
+ }
+
+ for(CopyListener listener : preCopyListeners) {
+ EObject result = listener.copyEObject(this, sourceEObj);
+ if(result != sourceEObj) {
+ return result;
+ }
+ }
+
+ if(sourceEObj instanceof NamedElement) {
+ String name = ((NamedElement)sourceEObj).getQualifiedName();
+ // System.err.println("eC3Mcopier: " + name);
+ if((name != null) && name.startsWith("uml::")) {
+ Log.log(Log.ERROR_MSG, Log.TRAFO_COPY, "copy for meta-model element \"" + name + "\" requested. Return original element");
+ return sourceEObj;
+ }
+ if((name != null) && name.startsWith("ProducerConsumer")) {
+ if(Utils.getTop((NamedElement)sourceEObj) != source) {
+ System.err.println(name);
+ }
+ }
+ }
+ // additional sanity check: want to avoid copying (instead of instantiating) elements
+ // of a package template
+ if((sourceEObj instanceof Package) && (!withinTemplate)) {
+ if(((Package)sourceEObj).getOwnedTemplateSignature() != null) {
+ Log.log(Log.WARNING_MSG, Log.TRAFO_COPY, "warning: copying a package template without instantiating a template");
+ }
+ }
+
+ if(shallowCopy) {
+ // shallowCopy is true: a copy exists already
+ }
+ else {
+ targetEObj = createCopy(sourceEObj);
+ put(sourceEObj, targetEObj);
+
+ createShallowContainer(sourceEObj);
+ }
+ EClass eClass = sourceEObj.eClass();
+ for(int i = 0, size = eClass.getFeatureCount(); i < size; ++i)
+ {
+ EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(i);
+ if(eStructuralFeature.isChangeable() && !eStructuralFeature.isDerived())
+ {
+ if(eStructuralFeature instanceof EAttribute) {
+ copyAttribute((EAttribute)eStructuralFeature, sourceEObj, targetEObj);
+ }
+ else {
+ EReference eReference = (EReference)eStructuralFeature;
+ if(eReference.isContainment()) {
+ copyContainment(eReference, sourceEObj, targetEObj);
+ }
+ // some containment relationships require copying the container completely
+ // e.g. if an owned template signature is referenced, we need to follow the "template"
+ // reference, which subsets the "owner" relationship.
+ // e.g. if an operation is referenced, we need to copy the whole interface
+ // Currently: only the standard owning reference is not copied recursively.
+ // else if(!eReference.isContainer()) {
+ else if(!eReference.getName().equals("owner")) {
+ // not contained, but copy reference as well
+ Object feature = sourceEObj.eGet(eStructuralFeature);
+ if(feature instanceof Element) {
+ copy((Element)feature);
+ } else if(feature instanceof EList) {
+ copyAll((EList<Object>)feature);
+ }
+ copyReference(eReference, sourceEObj, targetEObj);
+ }
+ }
+ }
+ }
+ copyProxyURI(sourceEObj, targetEObj);
+ copyID(sourceEObj, targetEObj);
+
+ if(sourceEObj instanceof Element) {
+ // TODO: handle stereotype copy in a generic way
+ StUtils.copyStereotypes(this, (Element)sourceEObj, (Element)targetEObj);
+ }
+
+ for(CopyListener listener : postCopyListeners) {
+ EObject result = listener.copyEObject(this, targetEObj);
+ if(result != targetEObj) {
+ return result;
+ }
+ }
+
+ return targetEObj;
+ }
+
+ /**
+ * Copy the containment of an element with respect to a certain reference
+ *
+ * @see org.eclipse.emf.ecore.util.EcoreUtil.Copier#copyContainment(org.eclipse.emf.ecore.EReference, org.eclipse.emf.ecore.EObject,
+ * org.eclipse.emf.ecore.EObject)
+ * Differences to referenced function in ECoreUtil
+ * - If an element in copyAll is null, it is not added
+ * - List elements are always cleared before copying, since the list elements may already have been
+ * partially filled by a previous shallow copy
+ *
+ * @param eReference
+ * a reference, such as for instance packagedElement (the
+ * caller needs to check, is this reference is a containment reference).
+ * @param eObject
+ * the source eObject
+ * @param copyEObject
+ * the copy of this eObject
+ */
+ @Override
+ protected void copyContainment(EReference eReference, EObject eObject, EObject copyEObject) {
+ if(eObject.eIsSet(eReference)) {
+ if(eReference.isMany()) {
+ @SuppressWarnings("unchecked")
+ List<EObject> source = (List<EObject>)eObject.eGet(eReference);
+ @SuppressWarnings("unchecked")
+ List<EObject> target = (List<EObject>)copyEObject.eGet(getTarget(eReference));
+ // do not clear (would remove elements that are added by copy listeners)
+ // But: better enforce exact copy? (listeners could only add in a post-copy step)
+ // target.clear();
+ if(!source.isEmpty()) {
+ for(EObject copyEObj : copyAll(source)) {
+ if(copyEObj != null) {
+ target.add(copyEObj);
+ }
+ }
+ }
+ } else {
+ EObject childEObject = (EObject)eObject.eGet(eReference);
+ copyEObject.eSet(getTarget(eReference), childEObject == null ? null : copy(childEObject));
+ }
+ }
+ }
+
+ /**
+ * Copy the containment in a "shallow" way, i.e. copy references to contained objects, if these exist already.
+ * If called for instance for a package, it will add those elements to the packagedElements list of the
+ * target package, that have already been copied.
+ *
+ * @param eReference
+ * @param eObject
+ * @param copyEObject
+ */
+ protected void shallowCopyContainment(EReference eReference, EObject eObject, EObject copyEObject) {
+ if(eObject.eIsSet(eReference)) {
+ if(eReference.isMany()) {
+ @SuppressWarnings("unchecked")
+ List<EObject> source = (List<EObject>)eObject.eGet(eReference);
+ @SuppressWarnings("unchecked")
+ List<EObject> target = (List<EObject>)copyEObject.eGet(getTarget(eReference));
+ if(source.isEmpty()) {
+ target.clear();
+ } else {
+ for(EObject sourceEObj : source) {
+ // if eObject has already been copied, add it
+ EObject copyEObj = get(sourceEObj);
+ if((copyEObj != null) && (!target.contains(copyEObj))) {
+ target.add(copyEObj);
+ }
+ }
+ }
+ } else {
+ EObject childEObject = (EObject)eObject.eGet(eReference);
+ copyEObject.eSet(getTarget(eReference), childEObject == null ? null : copy(childEObject));
+ }
+ }
+ }
+
+ /**
+ * Create a "shallow" container for an object, i.e. create (recursively) the owner without
+ * adding all other children of this owner (e.g. in case of a package, the package itself will
+ * be created, but not all elements within that package).
+ *
+ * @param sourceEObj
+ */
+ public void createShallowContainer(EObject sourceEObj) {
+ EObject owner = sourceEObj.eContainer();
+ EObject copy = null;
+ while(owner != null) {
+ if(containsKey(owner)) {
+ // owner is in map, still need to re-copy (update) the containment
+ // references, since one of the children did not exist before
+ //
+ shallowCopy(owner);
+ return;
+ }
+ copy = shallowCopy(owner);
+ if(copy instanceof NamedElement) {
+ ((NamedElement)copy).setName(((NamedElement)owner).getName());
+ }
+ owner = owner.eContainer();
+ }
+ if(copy instanceof PackageableElement) {
+ // if we copy external resources, we might reach the "top" on the source level
+ // which becomes a sub-package of the new model.
+ target.getPackagedElements().add((PackageableElement)copy);
+ }
+ }
+
+ /**
+ * Make a shallow copy of an element, i.e. only create the element itself and not
+ * all of its contents. If a subset of the containing elements already exist in the copied
+ * model, update the containment references pointing to these. The function may be called
+ * multiple times in order to add elements to the containment references that
+ * have been copied since the previous call (i.e. it is possible to make a shallow copy
+ * of a package after a single class within it has been copied. It may be called again,
+ * once a second class within the package has been copied => the packagedElements reference
+ * of the package will be updated).
+ *
+ * @param sourceEObj
+ * @return
+ */
+ public EObject shallowCopy(EObject sourceEObj) {
+ EObject targetEObj = get(sourceEObj);
+ if(targetEObj == null) {
+ targetEObj = createCopy(sourceEObj);
+ put(sourceEObj, targetEObj);
+ setShallow(targetEObj, true);
+ }
+ if((sourceEObj instanceof Element) && (targetEObj instanceof Element)) {
+ // TODO: cannot copy stereotypes only after creation, since eContainer does
+ // not exist at this moment. Need to put that intelligently into createShallowContainer
+ StUtils.copyStereotypes(this, (Element)sourceEObj, (Element)targetEObj);
+ }
+
+ EClass eClass = sourceEObj.eClass();
+
+ for(int i = 0, size = eClass.getFeatureCount(); i < size; ++i) {
+ EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(i);
+ if(eStructuralFeature.isChangeable() && !eStructuralFeature.isDerived()) {
+ if(eStructuralFeature instanceof EAttribute) {
+ // copyAttribute((EAttribute)eStructuralFeature, sourceEObj, targetEObj);
+ } else {
+ EReference eReference = (EReference)eStructuralFeature;
+ if(eReference.isContainment()) {
+ shallowCopyContainment(eReference, sourceEObj, targetEObj);
+ }
+ }
+ }
+ }
+ return targetEObj;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends Element> T getCopy(T source) {
+ return (T)copy(source);
+ }
+
+ public EList<CopyListener> preCopyListeners;
+
+ public EList<CopyListener> postCopyListeners;
+
+ /**
+ * Called to handle the copying of a cross reference;
+ * this adds values or sets a single value as appropriate for the multiplicity
+ * while omitting any bidirectional reference that isn't in the copy map.
+ *
+ * @param eReference
+ * the reference to copy.
+ * @param eObject
+ * the object from which to copy.
+ * @param copyEObject
+ * the object to copy to.
+ */
+ @Override
+ protected void copyReference(EReference eReference, EObject eObject, EObject copyEObject)
+ {
+ if(eObject.eIsSet(eReference)) {
+ if(eReference.isMany()) {
+ @SuppressWarnings("unchecked")
+ InternalEList<EObject> source = (InternalEList<EObject>)eObject.eGet(eReference);
+ @SuppressWarnings("unchecked")
+ InternalEList<EObject> target = (InternalEList<EObject>)copyEObject.eGet(getTarget(eReference));
+ if(source.isEmpty()) {
+ target.clear();
+ }
+ else {
+ boolean isBidirectional = eReference.getEOpposite() != null;
+ int index = 0;
+ for(Iterator<EObject> k = resolveProxies ? source.iterator() : source.basicIterator(); k.hasNext();) {
+ EObject referencedEObject = k.next();
+ EObject copyReferencedEObject = get(referencedEObject);
+ if(copyReferencedEObject == null) {
+ if(useOriginalReferences && !isBidirectional) {
+ target.addUnique(index, referencedEObject);
+ ++index;
+ }
+ }
+ else {
+ if(isBidirectional) {
+ int position = target.indexOf(copyReferencedEObject);
+ if(position == -1) {
+ target.addUnique(index, copyReferencedEObject);
+ }
+ else if(index != position) {
+ target.move(index, copyReferencedEObject);
+ }
+ }
+ else if(!target.contains(copyReferencedEObject)) {
+ // TODO: does not allow multiple identical elements in the list. Problematic?
+ // Check above is necessary, since some references that are not
+ // part of the containment may have already been copied (e.g. in case of
+ // a TemplateSignature "ownedParameter" subsets "parameter", thus copying
+ // ownedParameter as part of the containment adds a template parameter)
+ target.addUnique(index, copyReferencedEObject);
+ }
+ ++index;
+ }
+ }
+ }
+ }
+ else {
+ Object referencedEObject = eObject.eGet(eReference, resolveProxies);
+ if(referencedEObject == null) {
+ copyEObject.eSet(getTarget(eReference), null);
+ }
+ else if(referencedEObject instanceof EObject) {
+ // difference to original code in EcoreUtil: we obtain a copy (which might be null or the
+ // source object) of the referenced EObject. This assures that we only set a value of a
+ // reference to something we actually want to have in the target model.
+ // Specific problematic case in original code: classifierBehavior is a reference, but assigning such
+ // a behavior will also add an owned behavior. If we assign a referencedEObject (a behavior) from the
+ // source model in the target, we will actually remove it from the source model (as it is uniquely owned).
+ EObject copyReferencedEObject = copy((EObject)referencedEObject);
+ if(copyReferencedEObject != null) {
+ copyEObject.eSet(getTarget(eReference), copyReferencedEObject);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Copy all methods from the passed source-model class.
+ * This function is useful, if the passed class only exist
+ * as a shallow copy.
+ *
+ * @param source
+ * A class within the source model
+ */
+ public void copyMethods(Class source) {
+ for(Behavior method : source.getOwnedBehaviors()) {
+ getCopy(method);
+ }
+ }
+
+ /**
+ * Copy all attributes from the source-model classifier
+ * This function is useful, if the passed class only exist
+ * as a shallow copy.
+ *
+ * @param source
+ * A classifier within the source model
+ */
+ public void copyAttributes(Classifier source) {
+ for(Property attribute : source.getAttributes()) {
+ getCopy(attribute);
+ }
+ }
+
+ /**
+ * copy all operations from the source-model classifier.
+ * This function is useful, if the passed class only exist
+ * as a shallow copy.
+ *
+ * @param source
+ * A classifier within the source model
+ */
+ public void copyOperations(Classifier source) {
+ for(Operation operation : source.getOperations()) {
+ getCopy(operation);
+ }
+ }
+
+ // TODO: the functions that follow are static and should not be part of this class
+ // as they use a different way of copying things.
+
+
+ public static void copyFeatureModifiers(Feature source, Feature target) {
+ target.setIsStatic(source.isStatic());
+ target.setIsLeaf(source.isLeaf());
+ }
+
+ public static void copyMultElemModifiers(MultiplicityElement source, MultiplicityElement target) {
+ target.setIsOrdered(source.isOrdered());
+ target.setIsUnique(source.isUnique());
+ target.setLower(source.getLower());
+ target.setUpper(source.getUpper());
+ }
+
+ /**
+ * Copy a value to a target slot
+ *
+ * @param smValue
+ * @param target
+ * @return
+ */
+ public static ValueSpecification copyValue(ValueSpecification value, Slot target) {
+ ValueSpecification newValue = target.createValue(value.getName(), value.getType(), value.eClass());
+ return copyValue(value, newValue);
+ }
+
+ public static ValueSpecification copyDefaultValue(Property source, Property target) {
+ ValueSpecification value = source.getDefaultValue();
+ if(value != null) {
+ ValueSpecification newValue = target.createDefaultValue(value.getName(), value.getType(), value.eClass());
+ return copyValue(value, newValue);
+ } else {
+ return null;
+ }
+ }
+
+ public static ValueSpecification copyValue(ValueSpecification smValue, ValueSpecification tmValue) {
+ if(smValue instanceof OpaqueExpression) {
+ OpaqueExpression oeValue = (OpaqueExpression)smValue;
+ OpaqueExpression noeValue = (OpaqueExpression)tmValue;
+ for(String language : oeValue.getLanguages()) {
+ noeValue.getLanguages().add(language);
+ }
+ for(String body : oeValue.getBodies()) {
+ noeValue.getBodies().add(body);
+ }
+ } else if(smValue instanceof LiteralString) {
+ ((LiteralString)tmValue).setValue(((LiteralString)smValue).getValue());
+ } else if(smValue instanceof LiteralInteger) {
+ ((LiteralInteger)tmValue).setValue(((LiteralInteger)smValue).getValue());
+ } else if(smValue instanceof LiteralUnlimitedNatural) {
+ ((LiteralUnlimitedNatural)tmValue).setValue(((LiteralUnlimitedNatural)smValue).getValue());
+ } else if(smValue instanceof LiteralBoolean) {
+ ((LiteralBoolean)tmValue).setValue(((LiteralBoolean)smValue).booleanValue());
+ } else if(smValue instanceof LiteralNull) {
+ }
+ return tmValue;
+ }
+
+ /**
+ * Copy the (XML) ID from the source to the destination model element. This
+ * is useful, if you want to create a diagram for (parts of) the generated
+ * target model. Otherwise, the IDs would change with each generation and
+ * references from the diagram to model elements would break (of course,
+ * they could still break, for instance if structural modifications of the
+ * source model are made).
+ *
+ * @param source
+ * source model element
+ * @param dest
+ * corresponding target model element
+ */
+ public static void copyID(EObject source, EObject target) {
+ copyID(source, target, "");
+ }
+
+ /**
+ * Copy the (XML) ID from the source to the destination model element.
+ * Prefix the ID with a string passed as parameter
+ *
+ * @param source
+ * source model element
+ * @param dest
+ * corresponding target model element
+ * @param prefix
+ * a prefix for the target model ID
+ */
+ @SuppressWarnings("deprecation")
+ public static void copyID(EObject source, EObject target, String prefix) {
+ Resource resourceSource = source.eResource();
+ Resource resourceTarget = target.eResource();
+ // TODO: use EcoreUtil getURI (InternalEObject) instead?
+
+ if((resourceSource instanceof XMLResource) && (resourceTarget instanceof XMLResource)) {
+ XMLResource xmlResSource = (XMLResource)resourceSource;
+ XMLResource xmlResTarget = (XMLResource)resourceTarget;
+ String id = prefix + xmlResSource.getID(source);
+ int counter = 0;
+ String uniqueID = id;
+ while(xmlResTarget.getIDToEObjectMap().containsKey(uniqueID)) {
+ uniqueID = id + counter;
+ counter++;
+ }
+ xmlResTarget.setID(target, uniqueID);
+ }
+ }
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepCreation.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepCreation.java
new file mode 100644
index 00000000000..89cc860f038
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepCreation.java
@@ -0,0 +1,476 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
+
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Connector;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.InstanceValue;
+import org.eclipse.uml2.uml.LiteralInteger;
+import org.eclipse.uml2.uml.Node;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.PackageableElement;
+import org.eclipse.uml2.uml.Port;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Slot;
+import org.eclipse.uml2.uml.StructuralFeature;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.ValueSpecification;
+
+public class DepCreation {
+
+ private static Map<Object, Integer> map;
+
+ /**
+ * Create a slot and add an instance value associated with a part instance
+ * specification.
+ *
+ * @param is
+ * the instance specification for which a slot should be created
+ * @param partIS
+ * the instance specification associated with the slot (to be
+ * precise with slot's instance value)
+ * @param part
+ * the part associated with the slot, i.e. its defining feature
+ * @return The created slot
+ */
+ public static Slot createSlot(InstanceSpecification is,
+ InstanceSpecification partIS, Property part) {
+ // the instance specification of the composite has a slot for each part
+ // and it points
+ // to the instance specification associated with the part.
+ Slot slot = is.createSlot();
+ slot.setDefiningFeature(part);
+
+ InstanceValue iv = (InstanceValue)slot.createValue(null, null,
+ UMLPackage.eINSTANCE.getInstanceValue());
+ iv.setInstance(partIS);
+ return slot;
+
+ }
+
+ /**
+ * Create a Slot and a value for a configuration attribute
+ *
+ * @param attribute
+ */
+ public static Slot createSlotForConfigProp(InstanceSpecification is,
+ Property attribute) {
+
+ Slot slot = is.createSlot();
+ slot.setDefiningFeature(attribute);
+ // For primitive types, the UML type does not provide sufficient
+ // information to decide
+ // whether it is a string or a numerical value. In case of the C++
+ // profile, primitive
+ // UML types denote a language specific type, but we want to avoid C++
+ // specific code, if
+ // possible.
+ // => pragmatic solution: use LiteralString as default, unless a check
+ // for some known numerical
+ // primitive types holds (in particular the UML as well as Qompass CORBA
+ // types)
+ // In addition, string values are not automatically quoted, i.e. it is
+ // possible to enter e.g.
+ // a float value as a string expression (it also means that a "real"
+ // string value must be quoted
+ // by the user).
+ Type type = attribute.getType();
+ if(type != null) {
+ String name = type.getName();
+ String qname = type.getQualifiedName();
+ if(name.equals("Integer") ) {
+ slot.createValue("value for " + attribute.getName(), type,
+ UMLPackage.eINSTANCE.getLiteralInteger());
+ } else if(name.equals("Boolean")) {
+ slot.createValue("value for " + attribute.getName(), type,
+ UMLPackage.eINSTANCE.getLiteralBoolean());
+ } else {
+ slot.createValue("value for " + attribute.getName(), type,
+ UMLPackage.eINSTANCE.getLiteralString());
+ }
+ }
+ return slot;
+ }
+
+ /**
+ * Create a string slot and a value for a configuration attribute
+ *
+ * @param attribute
+ */
+ public static Slot createStringSlotForConfigProp(InstanceSpecification is,
+ Property attribute) {
+
+ Slot slot = is.createSlot();
+ slot.setDefiningFeature(attribute);
+ Type type = attribute.getType();
+ if(type != null) {
+ slot.createValue("value for " + attribute.getName(), type,
+ UMLPackage.eINSTANCE.getLiteralString());
+ }
+ return slot;
+ }
+
+ /**
+ * create a deployment plan, i.e. a set of instances that correspond to an
+ * implementation which is potentially a composite. In case of the latter,
+ * this function is called recursively to create deployment plans for the
+ * parts. Since a composite implementation may optionally specify only the
+ * type of parts (not the concrete implementation), this function also
+ * supports that a type is passed. In this case, an implementation is
+ * automatically assigned.
+ *
+ * @param cdp
+ * the deployment plan (package) in which to create instances
+ * @param typeOrImplem
+ * the type
+ * @param nane
+ * the name of the instance
+ * @param createSlotsForConfigValues
+ * if true, create slots for configuration values
+ */
+ public static InstanceSpecification createDepPlan(Package cdp,
+ Class typeOrImplem, String name, boolean createSlotsForConfigValues)
+ throws TransformationException
+ {
+ return createDepPlan(cdp, typeOrImplem, name, createSlotsForConfigValues, new Stack<Classifier>());
+ }
+
+ public static InstanceSpecification createDepPlan(Package cdp,
+ Class typeOrImplem, String name, boolean createSlotsForConfigValues, Stack<Classifier> visitedClassifiers)
+ throws TransformationException
+ {
+ // create an instance specification for the composite
+ if(visitedClassifiers.contains(typeOrImplem)) {
+ String path = "";
+ for(Classifier cl : visitedClassifiers) {
+ if(path.length() > 0) {
+ path += ", ";
+ }
+ path += cl.getName();
+ }
+ path += ", " + typeOrImplem.getName();
+ throw new TransformationException("Class \"" + typeOrImplem.getQualifiedName() +
+ "\" is referenced in a circle! Thus, an infinite number of instance specifications would be required.\n\n" +
+ "recursion path: " + path);
+ }
+ visitedClassifiers.push(typeOrImplem);
+
+ InstanceSpecification is = (InstanceSpecification)
+ cdp.createPackagedElement(name, UMLPackage.eINSTANCE.getInstanceSpecification());
+
+ // TODO: hack, could be named differently.
+ if(name.equals("mainInstance")) {
+ DepUtils.setMainInstance(cdp, is);
+ }
+
+ Class implementation = null;
+
+ // treat HW architecture or nodes as implementations
+ if(Utils.isCompImpl(typeOrImplem)
+ || typeOrImplem instanceof Node) {
+ // implementation is known => must be able to do this.
+ if(typeOrImplem instanceof Class) {
+ implementation = (Class)typeOrImplem;
+ }
+ }
+
+ if(!(implementation instanceof Class)) {
+ throw new TransformationException(
+ "cannot find suitable implementation for instance <" + name
+ + "> (given type <" + typeOrImplem.getName() + ">)");
+ }
+ // else implementation is instance of Class (and not null)
+
+ is.getClassifiers().add(implementation);
+ // add connector and container implementations
+
+
+
+
+ for(Property attribute : implementation.getAllAttributes()) {
+ // loop over all attributes (not only parts, since we need to
+ // capture singletons)
+ if(attribute instanceof Port) {
+ continue;
+ }
+ Type type = attribute.getType();
+
+ if(Utils.isComposition(attribute)) {
+ // composition, attribute is a part
+ if(((type instanceof Class) && Utils.isComponent((Class)type)) || type instanceof Node) {
+ Class cl = (Class)type;
+
+ // hack: ad-hoc replication support. Better solution via design patterns
+ int upper = attribute.getUpper();
+ String infix = "";
+
+ // TODO: check validation constraints
+ for(int i = 0; i < upper; i++) {
+ String partName = name + "." + attribute.getName();
+ if(upper > 1) {
+ partName += "_" + infix + i;
+ }
+ InstanceSpecification partIS = createDepPlan(cdp, cl,
+ partName, createSlotsForConfigValues, visitedClassifiers);
+
+ createSlot(is, partIS, attribute);
+ }
+ }
+ } else if(type instanceof Class) {
+ // no composition - only create slot, if a singleton
+ // (otherwise, it's not clear with which instance the slot
+ // should be associated)
+ Log.log(Log.INFO_MSG, Log.DEPLOYMENT,
+ "DepCreation.createDepPlan: " + type.getQualifiedName());
+// if(Utils.isSingleton((Class)type)) {
+// // is a singleton - exactly one instance exists
+// // use a common instance prefix for singletons
+// String partName = "singleton_" + attribute.getName();
+// PackageableElement pe = cdp.getPackagedElement(partName);
+//
+// if(pe instanceof InstanceSpecification) {
+// // instance specification for singleton exists already
+// Slot slot = createSlot(is, (InstanceSpecification)pe,
+// attribute);
+// slot.setDefiningFeature(attribute);
+// } else if(type instanceof Class) {
+// // instance specification for singleton does not exist
+// // => create
+// // [case that a non-instance specification with the name
+// // <partName> exists already
+// // is not handled]
+// InstanceSpecification partIS = createDepPlan(cdp,
+// (Class)type, partName, createSlotsForConfigValues, visitedClassifiers);
+// Slot slot = createSlot(is, partIS, attribute);
+// slot.setDefiningFeature(attribute);
+// }
+// }
+ } else if(type == null) {
+ throw new TransformationException("type of attribute \""
+ + attribute.getName() + "\" within class \""
+ + implementation.getName() + "\" is not defined");
+ }
+ }
+ visitedClassifiers.pop();
+ return is;
+ }
+
+
+
+ /**
+ * create a deployment plan, i.e. a set of instances that correspond to an
+ * implementation which is potentially a composite. In case of the latter,
+ * this function is called recursively to create deployment plans for the
+ * parts. Since a composite implementation may optionally specify only the
+ * type of parts (not the concrete implementation), this function also
+ * supports that a type is passed. In this case, an implementation is
+ * automatically assigned.
+ *
+ * @param cdp
+ * the deployment plan (package) in which to create instances
+ * @param typeOrImplem
+ * the type
+ * @param nane
+ * the name of the instance
+ * @param createSlotsForConfigValues
+ * if true, create slots for configuration values
+ */
+ public static InstanceSpecification createPlatformInstances(
+ Package platform, Class implementation, String name)
+ throws TransformationException {
+ // create an instance specification for the composite
+ InstanceSpecification is = null;
+ if(name != null) {
+ // donn't create instance specification for root element (detectable via the empty name)
+ is = (InstanceSpecification)platform.createPackagedElement(name,
+ UMLPackage.eINSTANCE.getInstanceSpecification());
+ is.getClassifiers().add(implementation);
+ }
+
+ // add connector and container implementations
+
+ for(Property attribute : implementation.getAllAttributes()) {
+ // loop over all attributes (not only parts, since we need to
+ // capture singletons)
+ if(attribute instanceof Port) {
+ continue;
+ }
+ Type type = attribute.getType();
+
+ if(Utils.isComposition(attribute)) {
+ // composition, attribute is a part
+ if(type instanceof Class) { // should be a node, but do not require it
+ Class cl = (Class)type;
+
+ // hack: ad-hoc replication support. Better solution via
+ // Design patterns
+ int upper = attribute.getUpper();
+ String infix = "";
+ // TODO: check validation constraints
+ for(int i = 0; i < upper; i++) {
+ // prefix with name, unless null
+ String partName = (name != null) ? name + "." : "";
+ partName += attribute.getName();
+ if(upper > 1) {
+ partName += "_" + infix + i;
+ }
+ InstanceSpecification partIS = createPlatformInstances(
+ platform, cl, partName);
+
+ if(is != null) {
+ createSlot(is, partIS, attribute);
+ }
+ }
+ }
+ }
+ }
+ return is;
+ }
+
+ /**
+ * Initialize the automatic values within a deployment plan - and the update
+ * eventual copies of these values.
+ *
+ * @param is
+ * the main instance of the deployment plan
+ */
+ public static void initAutoValues(InstanceSpecification is) {
+ map = new HashMap<Object, Integer>();
+ initAutoValuesHelper(is);
+ Stack<InstanceSpecification> isStack = new Stack<InstanceSpecification>();
+ copyAutoValues(isStack, is);
+ }
+
+ /**
+ * Initialize the automatic values within a deployment plan.
+ *
+ * @param is
+ * the main instance of the deployment plan
+ */
+ public static void initAutoValuesHelper(InstanceSpecification is) {
+ for(Slot slot : is.getSlots()) {
+ StructuralFeature sf = slot.getDefiningFeature();
+
+ }
+ }
+
+ /**
+ * Initialize the automatic values within a deployment plan.
+ *
+ * @param is
+ * the main instance of the deployment plan
+ */
+ public static void copyAutoValues(Stack<InstanceSpecification> isStack,
+ InstanceSpecification is) {
+ isStack.push(is);
+ for(Slot slot : is.getSlots()) {
+ StructuralFeature sf = slot.getDefiningFeature();
+ if(sf == null) {
+ // throw new TransformationException (is.getName() + " has a slot without defining feature");
+ System.err.println(is.getName());
+ break;
+ }
+
+ // recursion in case of values that are instance values
+ for(ValueSpecification vs : slot.getValues()) {
+ if(vs instanceof InstanceValue) {
+ InstanceSpecification subIS = ((InstanceValue)vs).getInstance();
+ if(subIS != null) {
+ copyAutoValues(isStack, subIS);
+ }
+ }
+ }
+ }
+ isStack.pop();
+ }
+
+ /**
+ * try to find a value (ValueSpecification) for the passed source element,
+ * beginning a the "deepest" instance specification of the passed stack. If
+ * not found, continue at elements higher up in the hierarchy
+ *
+ * @param isStack
+ * a stack of instance specifications corresponding to a path
+ * within an instance tree
+ * @param source
+ * a property (defining feature) for which we search an instance
+ * specification
+ * @return The value specifications for the passed source property or null
+ */
+
+ public static ValueSpecification getNearestValue(
+ Stack<InstanceSpecification> isStack, Property source) {
+ Stack<InstanceSpecification> copy = new Stack<InstanceSpecification>();
+ copy.addAll(isStack);
+ while(!copy.isEmpty()) {
+ InstanceSpecification pop = copy.pop();
+ ValueSpecification vs = getNearestValueHelper(isStack, pop, source);
+ if(vs != null) {
+ return vs;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Helper for getNearestValue: search for an instance specification that has
+ * source as defining feature. Start at the passed instance specification,
+ * but do not recursed into elements that are contained in the stack.
+ *
+ * @param isStack
+ * A stack of instance specifications corresponding to a path
+ * within an instance tree
+ * @param is
+ * the starting instance specification
+ * @param source
+ * source a property (defining feature) for which we search an
+ * instance specification
+ * @return The value specifications for the passed source property or null
+ */
+ public static ValueSpecification getNearestValueHelper(
+ Stack<InstanceSpecification> isStack, InstanceSpecification is,
+ Property source) {
+ for(Slot slot : is.getSlots()) {
+ StructuralFeature sf = slot.getDefiningFeature();
+ if(sf == source) {
+ // found property, now return first value specification
+ for(ValueSpecification vs : slot.getValues()) {
+ return vs;
+ }
+ return null;
+ }
+
+ // recursion in case of values that are instance values
+ for(ValueSpecification vs : slot.getValues()) {
+ if(vs instanceof InstanceValue) {
+ InstanceSpecification subIS = ((InstanceValue)vs)
+ .getInstance();
+ if(!isStack.contains(subIS)) {
+ // only recurse, if not contained in stack of instance
+ // specifications (avoid traversing
+ // the same elements multiple times)
+ return getNearestValueHelper(isStack, subIS, source);
+ }
+ }
+ }
+ }
+ return null;
+ }
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepPlanSync.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepPlanSync.java
new file mode 100644
index 00000000000..0296bd68fb3
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepPlanSync.java
@@ -0,0 +1,135 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment;
+
+import java.util.Iterator;
+
+import org.eclipse.papyrus.RobotML.DeploymentPlan;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.InstanceValue;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Slot;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.ValueSpecification;
+
+
+/**
+ * Currently unused synchronization for deployment plans.
+ *
+ * @see comp.cea.ec3m.gentools.core.listeners.DepPlanListener
+ *
+ * @author ansgar
+ */
+public class DepPlanSync {
+
+ /**
+ * Synchronize a deployment plan: remove slots that refer to properties that exist no longer
+ * and add those that do not exist yet
+ *
+ * @param element
+ * an arbitrary element of the source model (i.e. the model that will
+ * store the deployment plan
+ * @throws TransformationException
+ */
+ public static void syncAllDepPlans(Element element) {
+ for(Package depPlan : DepPlanUtils.getAllDepPlans(element)) {
+ syncDepPlan(depPlan);
+ }
+ }
+
+ /**
+ * Synchronize a deployment plan: remove slots that refer to properties that exist no longer
+ * and add those that do not exist yet
+ *
+ * @param depPlan
+ * @throws TransformationException
+ */
+ public static void syncDepPlan(Package depPlan) {
+ removeUnusedSlots(depPlan);
+ // EList<InstanceSpecification> list = new BasicEList<InstanceSpecification>();
+ DeploymentPlan cdp = StUtils.getApplication(depPlan, DeploymentPlan.class);
+ if(cdp == null) {
+ return;
+ }
+ InstanceSpecification mainInstance = cdp.getMainInstance();
+ addCDP(depPlan, mainInstance, mainInstance.getName());
+ // now add elements that are not in the plan - although they should
+ // avoid to replicate code already in dep-creation. => createDepPlan(top)
+ // strategy: create new dep-plan and compare?
+ }
+
+ private static void addCDP(Package depPlan, InstanceSpecification instance, String canonicalName)
+ {
+ Class implementation = DepUtils.getImplementation(instance);
+ if(!instance.getName().equals(canonicalName)) {
+ instance.setName(canonicalName);
+ }
+ // check sub-instances
+ for(Slot slot : instance.getSlots()) {
+ InstanceSpecification subInstance = DepUtils.getInstance(slot);
+ if(subInstance != null) {
+ addCDP(depPlan, subInstance, canonicalName + "." + slot.getDefiningFeature().getName());
+ }
+ }
+ for(Property attribute : Utils.getParts(implementation)) {
+ Type type = attribute.getType();
+ if(type instanceof Class) {
+ if(!hasSlot(instance, attribute)) {
+ try {
+ InstanceSpecification partIS =
+ DepCreation.createDepPlan(depPlan, (Class)type, instance.getName() + "." + attribute.getName(), true);
+ DepPlanUtils.createSlot(depPlan, instance, partIS, attribute);
+ } catch (TransformationException e) {
+ Log.log(Log.ERROR_MSG, Log.DEPLOYMENT, e.getMessage());
+ }
+ }
+ }
+ }
+ }
+
+ private static boolean hasSlot(InstanceSpecification instance, Property attribute) {
+ for(Slot slot : instance.getSlots()) {
+ if(slot.getDefiningFeature() == attribute) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static void removeUnusedSlots(Package depPlan) {
+ // remove elements that are no longer in the plan
+ for(NamedElement member : depPlan.getMembers()) {
+ if(member instanceof InstanceSpecification) {
+ InstanceSpecification instance = (InstanceSpecification)member;
+ Iterator<Slot> slotIt = instance.getSlots().iterator();
+ while(slotIt.hasNext()) {
+ Slot slot = slotIt.next();
+ if(slot.getDefiningFeature() == null) {
+ // property has been removed => remove associated slot
+ for(ValueSpecification value : slot.getValues()) {
+ if(value instanceof InstanceValue) {
+ InstanceSpecification is = ((InstanceValue)value).getInstance();
+ DepPlanUtils.delDepPlan(is);
+ }
+ }
+ slot.destroy();
+ slotIt.remove();
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepPlanUtils.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepPlanUtils.java
new file mode 100644
index 00000000000..ba4a784a172
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepPlanUtils.java
@@ -0,0 +1,319 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.Enumerator;
+import org.eclipse.emf.ecore.ENamedElement;
+import org.eclipse.papyrus.RobotML.DeploymentPlan;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Enumeration;
+import org.eclipse.uml2.uml.EnumerationLiteral;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.InstanceValue;
+import org.eclipse.uml2.uml.LiteralInteger;
+import org.eclipse.uml2.uml.LiteralString;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Port;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Slot;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.ValueSpecification;
+
+public class DepPlanUtils {
+
+ public static final String depPlanFolder = "deployment";
+
+ /**
+ * Return the package in which deployment plans are stored. Caveat: needs to be executed within a
+ * transition, since the deployment plan package will be created, if it does not exist yet.
+ *
+ * @param element
+ * an arbitrary element of the source model (i.e. the model that will
+ * store the deployment plan
+ * @return package in which deployment plans are stored
+ */
+ public static Package getDepPlanRoot(Element element) {
+ return Utils.getRoot(element, depPlanFolder);
+ }
+
+ /**
+ * Return all deployment plans
+ *
+ * @param element
+ * an arbitrary element of the source model (i.e. the model that will
+ * store the deployment plan
+ * @return
+ */
+ public static EList<Package> getAllDepPlans(Element element) {
+ Package root = Utils.getTop(element);
+ Package depPlanRoot = root.getNestedPackage(depPlanFolder);
+ EList<Package> depPlanList = new BasicEList<Package>();
+ if(depPlanRoot != null) {
+ for(Package pkg : depPlanRoot.getNestedPackages()) {
+ if(StUtils.isApplied(pkg, DeploymentPlan.class)) {
+ depPlanList.add(pkg);
+ }
+ }
+ }
+ return depPlanList;
+ }
+
+ public static void delDepPlan(InstanceSpecification is) {
+ Iterator<Slot> slots = is.getSlots().iterator();
+ while(slots.hasNext()) {
+ Slot slot = slots.next();
+ InstanceSpecification subInstance = getInstance(slot);
+ if(subInstance != null) {
+ delDepPlan(subInstance);
+ }
+ }
+ Element owner = is.getOwner();
+ if(owner instanceof Package) {
+ ((Package)owner).getPackagedElements().remove(is);
+ }
+ }
+
+ /**
+ * Return the instance that is defined by a slot value
+ *
+ * @param slot
+ * @return the first slot that corresponds to an instance specification
+ */
+ public static InstanceSpecification getInstance(Slot slot) {
+ Iterator<ValueSpecification> values = slot.getValues().iterator();
+ while(values.hasNext()) {
+ ValueSpecification value = values.next();
+ // instances are accessible via ValueSpecification subclass InstanceValue
+ if(value instanceof InstanceValue) {
+ return ((InstanceValue)value).getInstance();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * create a slot for a given sub-instance specification.
+ *
+ * @param cdp
+ * a deployment plan
+ * @param is
+ * an instance specification for a composite class
+ * @param partIS
+ * the instance specification of a part within the composite
+ * @param part
+ * the part within the composite
+ */
+ public static Slot createSlot(Package cdp, InstanceSpecification is, InstanceSpecification partIS, Property part) {
+ // the instance specification of the composite has a slot for each part and it points
+ // to the instance specification associated with the part.
+ Slot slot = is.createSlot();
+ slot.setDefiningFeature(part);
+
+ InstanceValue iv = (InstanceValue)
+ slot.createValue(null, null, UMLPackage.eINSTANCE.getInstanceValue());
+ iv.setInstance(partIS);
+ return slot;
+
+ }
+
+ /**
+ * Apply the stereotype deployment plan and set the mainInstance value
+ *
+ * @param cdp
+ * the deployment plan
+ * @param main
+ * instance the top-level instance specification of the plan
+ */
+ public static void setMainInstance(Package cdp, InstanceSpecification mainInstance) {
+ DeploymentPlan cdpApp = StUtils.applyApp(cdp, DeploymentPlan.class);
+ if(cdpApp != null) {
+ cdpApp.setMainInstance(mainInstance);
+ }
+ }
+
+ /**
+ * Automatically choose an implementation, i.e. choose the first implementation
+ * within the component model that implements a given component type.
+ */
+ public static Class autoChooseImplementation(Classifier componentType) {
+ // choose implementation automatically: get the first one that implements the passed type
+ // (problem: further tree expansion might depend on chosen implementation)
+ // get reference to component model, then search all classes contained in it.
+ Package compModel = Utils.getRoot(componentType, "ComponentModel");
+ Iterator<Element> elements = compModel.allOwnedElements().iterator();
+ while(elements.hasNext()) {
+ Element element = elements.next();
+ if(element instanceof Class) {
+ Class candidate = (Class)element;
+ if(candidate.getSuperClass(componentType.getName()) != null) {
+ return candidate;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * create a deployment plan, i.e. a set of instances
+ * Automatic choice of implementations (otherwise leave unassigned)
+ *
+ * @param composite
+ * System composite
+ */
+ public static InstanceSpecification createDepPlan(Package cdp, Classifier composite, String name) {
+ // create an instance specification for the composite
+ InstanceSpecification is = (InstanceSpecification)
+ cdp.createPackagedElement(name, UMLPackage.eINSTANCE.getInstanceSpecification());
+
+ if(name == "mainInstance") {
+ setMainInstance(cdp, is);
+ }
+
+ Class implementation = null;
+
+ if(Utils.isCompImpl(composite)) {
+ // implementation is known => must be able to do this.
+ if(composite instanceof Class) {
+ implementation = (Class)composite;
+ }
+ } else {
+ // TODO: really need that? (better indicate to user that he needs to choose?)
+ // need hint on type level (if we want to avoid loosing information)
+ implementation = autoChooseImplementation(composite);
+ }
+
+ if(!(implementation instanceof Class)) {
+ return is;
+ }
+ // else implementation is instance of Class (and not null)
+
+ is.getClassifiers().add(implementation);
+ /*
+ * if (hasStereotype (composite), containerImplementation) {
+ * is.getClassifiers ().add (containerImplem);
+ * }
+ */
+
+ for(Property part : Utils.getParts(implementation)) {
+ if(part instanceof Port) {
+ continue;
+ }
+ InstanceSpecification partIS =
+ createDepPlan(cdp, (Classifier)part.getType(), name + "." + part.getName());
+
+ createSlot(cdp, is, partIS, part);
+ }
+ return is;
+ }
+
+ public static void configureProperty(InstanceSpecification instance, ENamedElement property, String value) {
+ configureProperty(instance, property.getName(), value);
+ }
+
+ public static void configureProperty(InstanceSpecification instance, String propertyName, String value) {
+ Classifier extension = DepUtils.getClassifier(instance);
+ Property attribute = (Property)Utils.getNamedElementFromList(extension.getAllAttributes(), propertyName);
+ if(attribute == null) {
+ throw new RuntimeException("cannot find attribute " + propertyName + " in classifier " + extension.getName());
+ }
+ if(attribute.getType() instanceof Enumeration) {
+ configureEnumProperty(instance, propertyName, value);
+ }
+ else {
+ // create a slot for a string value
+ Slot slotStringVal = DepCreation.createSlotForConfigProp(instance, attribute);
+ if(slotStringVal.getValues().get(0) instanceof LiteralString) {
+ ((LiteralString)slotStringVal.getValues().get(0)).setValue(value);
+ }
+ else {
+ // indicates that operation has been called although types do not match
+ throw new RuntimeException("configuration of property " + propertyName + " failed: type is not a string");
+ }
+ }
+
+ }
+
+ public static void configureProperty(InstanceSpecification instance, ENamedElement property, int value) {
+ configureProperty(instance, property.getName(), value);
+ }
+
+ public static void configureProperty(InstanceSpecification instance, String propertyName, int value) {
+ Classifier extension = DepUtils.getClassifier(instance);
+ Property attribute = (Property)Utils.getNamedElementFromList(extension.getAllAttributes(), propertyName);
+ if(attribute == null) {
+ throw new RuntimeException("cannot find attribute " + propertyName + " in classifier " + extension.getName());
+ }
+ Slot slotIntVal = instance.createSlot();
+ slotIntVal.setDefiningFeature(attribute);
+ LiteralInteger intValue = (LiteralInteger)
+ slotIntVal.createValue("value for " + attribute.getName(), attribute.getType(), UMLPackage.eINSTANCE.getLiteralInteger());
+ intValue.setValue(value);
+
+ }
+
+ /**
+ * Convenience function: allow that an ecore named element is passed instead of a property name. This is useful if the
+ * parameter that should be configured stems from a static profile [TODO: should not be in the general class support, but
+ * in the instance configurators for RT-Describe)
+ *
+ * @param instance
+ * @param extension
+ * @param property
+ * @param value
+ */
+ public static void configureProperty(InstanceSpecification instance, ENamedElement property, Enumerator value) {
+ configureProperty(instance, property.getName(), value);
+ }
+
+ /**
+ * configure a property for an enumeration. Enumerations are a bit difficult to handle, since the enumeration literal itself
+ * must be created first in form of an instance specification
+ *
+ * @param instance
+ * The instance of which an attribute should be configured.
+ * @param propertyName
+ * The name of the property that should be configured
+ * @param value
+ * its value in form of an element of a static profile [TODO: not general enough?]
+ */
+ public static void configureProperty(InstanceSpecification instance, String propertyName, Enumerator value) {
+ configureProperty(instance, propertyName, value.getName());
+ }
+
+ public static void configureEnumProperty(InstanceSpecification instance, String propertyName, String literalName) {
+ Classifier extension = DepUtils.getClassifier(instance);
+ Property attribute = (Property)Utils.getNamedElementFromList(extension.getAllAttributes(), propertyName);
+ if(attribute == null) {
+ throw new RuntimeException("cannot find attribute " + propertyName + " in classifier " + extension.getName());
+ }
+
+ if(attribute.getType() instanceof Enumeration) {
+ Enumeration enumeration = (Enumeration)attribute.getType();
+ for(EnumerationLiteral enumLiteral : enumeration.getOwnedLiterals()) {
+ if(enumLiteral.getLabel().equals(literalName)) {
+ Slot slotEnumVal = instance.createSlot();
+ slotEnumVal.setDefiningFeature(attribute);
+ InstanceValue enumLitValue = (InstanceValue)
+ slotEnumVal.createValue("value for " + attribute.getName(), attribute.getType(), UMLPackage.eINSTANCE.getInstanceValue());
+ enumLitValue.setInstance(enumLiteral);
+ break;
+ }
+ }
+ }
+ }
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepUtils.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepUtils.java
new file mode 100644
index 00000000000..c3946428104
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DepUtils.java
@@ -0,0 +1,309 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment;
+
+import java.util.Iterator;
+import java.util.Stack;
+
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.UniqueEList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature.Setting;
+import org.eclipse.papyrus.RobotML.DeploymentPlan;
+import org.eclipse.uml2.common.util.UML2Util;
+import org.eclipse.uml2.uml.AggregationKind;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.InstanceValue;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.PackageableElement;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Slot;
+import org.eclipse.uml2.uml.StructuralFeature;
+import org.eclipse.uml2.uml.ValueSpecification;
+
+
+/**
+ * Utilities around instances (within deployment plan)
+ * [DepPlanUtils?]
+ * [but missing: creation, ..., allocation?]
+ * Structuration ??
+ *
+ * @author ansgar
+ *
+ */
+public class DepUtils {
+
+
+
+ /**
+ * Find a sub instance via its name. This is in particular useful for connectors that cannot be
+ * found via a slot, since UML only supports structural features (a connector is only a feature)
+ * in the definingFeature attribute of a slot.
+ *
+ * @param owningInstance
+ * an owning instance
+ * @param name
+ * name of the sub-element (unqualified)
+ * @return the found sub-instance or null
+ */
+ public static InstanceSpecification getNamedSubInstance(InstanceSpecification owningInstance, String name) {
+ Element cdp = owningInstance.getOwner();
+ String candidateName = owningInstance.getName() + "." + name;
+ if(cdp instanceof Package) {
+ for(PackageableElement instance : ((Package)cdp).getPackagedElements()) {
+ if(instance instanceof InstanceSpecification) {
+ InstanceSpecification candidate = (InstanceSpecification)instance;
+
+ if(candidateName != null) {
+ if(candidateName.equals(candidate.getName())) {
+ return candidate;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+
+
+ /**
+ * return an instance specification for the main instance within
+ * a package.
+ *
+ * @param cdp
+ * the deployment plan
+ */
+ public static InstanceSpecification getMainInstance(Package cdp) {
+ DeploymentPlan dp = StUtils.getApplication(cdp, DeploymentPlan.class);
+ return dp.getMainInstance();
+ }
+
+ /**
+ * Apply the stereotype deployment plan and set the mainInstance value
+ *
+ * @param cdp
+ * the deployment plan
+ * @param main
+ * instance the top-level instance specification of the plan
+ */
+ public static void setMainInstance(Package cdp, InstanceSpecification mainInstance) {
+ StUtils.apply(cdp, DeploymentPlan.class);
+ DeploymentPlan dp = StUtils.getApplication(cdp, DeploymentPlan.class);
+ dp.setMainInstance(mainInstance);
+ }
+
+ /**
+ * return the implementation associated with an instance specification, i.e. a
+ * Class.
+ *
+ * @param instance
+ * @return
+ */
+ public static Class getImplementation(InstanceSpecification instance) {
+ Classifier cl = getClassifier(instance);
+ if(cl instanceof Class) {
+ return (Class)cl;
+ }
+ return null;
+ }
+
+
+
+ /**
+ * Return the first classifier referenced by an instance specification. Whereas UML supports
+ * a set of classifiers, we assume that that an instance specification has only one.
+ *
+ * @param instance
+ * the instance, for which we are interested in type information
+ */
+ public static Classifier getClassifier(InstanceSpecification instance) {
+ Iterator<Classifier> classifierIt = instance.getClassifiers().iterator();
+ // simply return the first element (if there is any)
+ if(classifierIt.hasNext()) {
+ return classifierIt.next();
+ }
+ return null;
+ }
+
+ /**
+ * Return the first instance specification within a deployment plan that instantiates a given
+ * classifier
+ *
+ * @param cdp
+ * the deployment plan
+ * @param cl
+ * the classifier
+ * @return
+ */
+ public static InstanceSpecification getInstanceForClassifier(Package cdp, Classifier cl) {
+ for(PackageableElement pe : cdp.getPackagedElements()) {
+ if(pe instanceof InstanceSpecification) {
+ InstanceSpecification is = (InstanceSpecification)pe;
+ if(getClassifier(is) == cl) {
+ return is;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the (unique) list of implementations that are contained within an
+ * instance specification
+ */
+ public static EList<Classifier> getContainedImplementations(InstanceSpecification is) {
+ Iterator<InstanceSpecification> instances = getContainedInstances(is).iterator();
+ EList<Classifier> list = new UniqueEList<Classifier>();
+ while(instances.hasNext()) {
+ Classifier implementation = getClassifier(instances.next());
+ list.add(implementation);
+ }
+ return list;
+ }
+
+ /**
+ * Return the slot that is associated with a property
+ *
+ * @param is
+ * an instance specification (of a class having properties)
+ * @param property
+ * A property of the classifier associated with the passed instance specification
+ * @return the associated slot or null, if it does not exist
+ */
+ public static Slot getSlot(InstanceSpecification is, Property property) {
+ Iterator<Slot> slots = is.getSlots().iterator();
+ while(slots.hasNext()) {
+ Slot slot = slots.next();
+ if(slot.getDefiningFeature() == property) {
+ return slot;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the instance referenced by a slot value, i.e. the first instance value associated
+ * with a slot
+ *
+ * @param slot
+ * @return
+ */
+ public static InstanceSpecification getInstance(Slot slot) {
+ for(ValueSpecification value : slot.getValues()) {
+ // instances are accessible via ValueSpecification subclass InstanceValue
+ if(value instanceof InstanceValue) {
+ return ((InstanceValue)value).getInstance();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * This method returns the instances contained within a composite instance
+ * specification for an assembly.
+ */
+ public static EList<InstanceSpecification> getContainedInstances(InstanceSpecification is) {
+ EList<InstanceSpecification> contained = new BasicEList<InstanceSpecification>();
+ for(Slot slot : is.getSlots()) {
+ InstanceSpecification instance = getInstance(slot);
+ if(instance != null) {
+ contained.add(instance);
+ }
+ }
+ return contained;
+ }
+
+ /**
+ * return all slots that reference an instance specification
+ *
+ * @param is
+ * @return
+ */
+ public static EList<Slot> getReferencingSlots(InstanceSpecification is) {
+ EList<Slot> list = new BasicEList<Slot>();
+ for(Setting setting : UML2Util.getNonNavigableInverseReferences(is)) {
+ // no trigger is referencing the event any more, delete call event
+ EObject eObj = setting.getEObject();
+ if(eObj instanceof ValueSpecification) {
+ ValueSpecification vs = (ValueSpecification)eObj;
+ Element owner = vs.getOwner();
+ if(owner instanceof Slot)
+ list.add((Slot)owner);
+ }
+ }
+ return list;
+ }
+
+ /**
+ * Return an instance specification that refers to the composite in which the
+ * passed instance is contained
+ *
+ * @param is
+ * an instance that is contained within an composite (i.e. that
+ * belongs to a part of this composite).
+ * @return
+ */
+ public static Slot getParentSlot(InstanceSpecification is) {
+ for(Slot slot : getReferencingSlots(is)) {
+ // no trigger is referencing the event any more, delete call event
+ if(slot.getDefiningFeature() instanceof Property) {
+ if(((Property)slot.getDefiningFeature()).getAggregation() == AggregationKind.COMPOSITE_LITERAL) {
+ return slot;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return an instance specification that refers to the composite in which the
+ * passed instance is contained
+ *
+ * @param is
+ * an instance that is contained within an composite (i.e. that
+ * belongs to a part of this composite).
+ * @return
+ */
+ public static InstanceSpecification getParentIS(InstanceSpecification is) {
+ Slot parentSlot = getParentSlot(is);
+ if(parentSlot != null) {
+ return parentSlot.getOwningInstance();
+ }
+ return null;
+ }
+
+ public static Stack<Slot> getAccessPath(InstanceSpecification is) {
+ Stack<Slot> path = new Stack<Slot>();
+ while(is != null) {
+ Slot parentSlot = getParentSlot(is);
+ if(parentSlot == null) {
+ break;
+ }
+ path.insertElementAt(parentSlot, 0);
+ is = parentSlot.getOwningInstance();
+ }
+ return path;
+ }
+
+ public static boolean isShared(Slot slot) {
+ StructuralFeature df = slot.getDefiningFeature();
+ if(df instanceof Property) {
+ return ((Property)df).getAggregation() == AggregationKind.SHARED_LITERAL;
+ }
+ return false;
+ }
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DialogUtils.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DialogUtils.java
new file mode 100644
index 00000000000..bcef553b11d
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/DialogUtils.java
@@ -0,0 +1,100 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment;
+
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.dialogs.FilteredList;
+
+
+public class DialogUtils {
+
+ public static FilteredList createFilteredList(Composite parent, ILabelProvider labelProvider,
+ int width, int height, int style) {
+ FilteredList list = new FilteredList(parent, style, labelProvider,
+ true, true, true);
+
+ GridData data = new GridData();
+ data.widthHint = width;
+ // data.heightHint = convertHeightInCharsToPixels(height);
+ data.heightHint = height;
+ data.grabExcessVerticalSpace = true;
+ data.grabExcessHorizontalSpace = true;
+ data.horizontalAlignment = GridData.FILL;
+ data.verticalAlignment = GridData.FILL;
+ list.setLayoutData(data);
+ list.setFont(parent.getFont());
+ return list;
+ }
+
+ /*
+ * public static List createList (Composite parent, ILabelProvider labelProvider,
+ * int width, int height, int style)
+ * {
+ * style = SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | style;
+ *
+ * List list = new List (parent, style);
+ *
+ * GridData data = new GridData();
+ * data.widthHint = width;
+ * // data.heightHint = convertHeightInCharsToPixels(height);
+ * data.heightHint = height;
+ * data.grabExcessVerticalSpace = true;
+ * data.grabExcessHorizontalSpace = true;
+ * data.horizontalAlignment = GridData.FILL;
+ * data.verticalAlignment = GridData.FILL;
+ * list.setLayoutData(data);
+ * list.setFont (parent.getFont());
+ * return list;
+ * }
+ */
+
+ public static Combo createComboWithText(Composite parent, String label, int flags, int compFlags) {
+ Composite comboComposite = new Composite(parent, compFlags);
+ comboComposite.setLayout(new GridLayout(2, false));
+ Label comboLabel = new Label(comboComposite, SWT.NONE);
+ comboLabel.setText(label);
+ Combo combo = new Combo(comboComposite, flags);
+ comboComposite.pack();
+ return combo;
+ }
+
+ public static Button createButtonWithText(Composite parent, String label, int flags, int compFlags) {
+ Composite buttonComposite = new Composite(parent, compFlags);
+ buttonComposite.setLayout(new GridLayout(2, false));
+ Label buttonLabel = new Label(buttonComposite, SWT.NONE);
+ buttonLabel.setText(label);
+ Button button = new Button(buttonComposite, flags);
+ buttonComposite.pack();
+ return button;
+ }
+
+ /**
+ * Create a GridData object which fills the available vertical and horizontal space
+ *
+ * @return
+ */
+ public static GridData createFillGridData() {
+ GridData gridData = new GridData();
+ gridData.grabExcessVerticalSpace = true;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ return gridData;
+ }
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Log.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Log.java
new file mode 100644
index 00000000000..8b0f1b377d7
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Log.java
@@ -0,0 +1,86 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Very simple message logging class
+ *
+ * @author ansgar
+ *
+ */
+public class Log {
+
+ public static final int ERROR_MSG = 1;
+
+ public static final int INFO_MSG = 2;
+
+ public static final int WARNING_MSG = 4;
+
+
+ public static final int TRAFO_CONNECTOR = 1;
+
+ public static final int TRAFO_CONTAINER = 2;
+
+ public static final int TRAFO_COPY = 4;
+
+ public static final int TRAFO_SYNC = 8;
+
+ public static final int TEMPLATE_BINDING = 0x10;
+
+ public static final int TEMPLATE_INSTANTIATION = 0x20;
+
+ public static final int DEPLOYMENT = 0x40;
+
+ public static final int DIALOGS = 0x80;
+
+ public static final int UTILS = 0x100;
+
+ public static final int CODEGEN = 0x200;
+
+ public static final int CALC_PORTKIND = 0x400;
+
+ static Map<Integer, String> moduleMap;
+
+ static String getModuleInfo(int moduleKind) {
+ if(moduleMap == null) {
+ moduleMap = new HashMap<Integer, String>();
+ moduleMap.put(TRAFO_CONNECTOR, "Trafo connector");
+ moduleMap.put(TRAFO_CONTAINER, "Trafo container");
+ moduleMap.put(TRAFO_COPY, "Trafo copy");
+ moduleMap.put(TRAFO_SYNC, "Synchronization");
+ moduleMap.put(TEMPLATE_BINDING, "Template binding");
+ moduleMap.put(TEMPLATE_INSTANTIATION, "Template instantiation");
+ moduleMap.put(DEPLOYMENT, "Template binding");
+ moduleMap.put(DIALOGS, "Qompass dialogs");
+ moduleMap.put(UTILS, "Utils");
+ moduleMap.put(CODEGEN, "Code generation");
+ moduleMap.put(CALC_PORTKIND, "Calculate portkind");
+ }
+ return "Module " + moduleMap.get(moduleKind) + ": ";
+ }
+
+ public static void log(int msgKind, int moduleKind, String message) {
+ if(msgKind == ERROR_MSG) {
+ System.err.println(getModuleInfo(moduleKind) + message);
+ } else if(msgKind == INFO_MSG) {
+ if((moduleKind & moduleFilter) != 0) {
+ System.out.println(getModuleInfo(moduleKind) + message);
+ }
+ }
+ }
+
+ // TODO: make it a configuration property
+ static int moduleFilter = 0;
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/RunnableWithResult.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/RunnableWithResult.java
new file mode 100644
index 00000000000..fa7c8bdfb5d
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/RunnableWithResult.java
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment;
+
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+
+public interface RunnableWithResult {
+
+ /**
+ * Execute a commad
+ *
+ * @return CommandResult.newOKCommandResult() if successful
+ * CommandResult.newErrorCommandResult(..) or
+ * CommandReuslt.newCancelCommandResult(..) otherwise
+ */
+ public CommandResult run();
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/StUtils.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/StUtils.java
new file mode 100644
index 00000000000..652e2ff4aef
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/StUtils.java
@@ -0,0 +1,441 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment;
+
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.uml2.uml.Connector;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+/**
+ * Some functions around stereotype usage.
+ * TODO: originally developed without use of static profile. It thus contains many functions
+ * that are no longer needed (e.g. getBoolean) => needs some cleanup
+ *
+ * @author ansgar
+ *
+ */
+public class StUtils {
+
+ /**
+ * This method verifies if a stereotype is applied on an UML element
+ *
+ * @param element
+ * A UML element
+ * @param str_name
+ * a qualified stereotype name
+ */
+ public static boolean isApplied(Element element, String str_name) {
+ return (element.getAppliedStereotype(str_name) != null);
+ }
+
+ /**
+ * This method verifies if a stereotype is applied on an UML element
+ *
+ * @param element
+ * A UML element
+ * @param the
+ * class of an element of a static profile
+ */
+ public static boolean isApplied(Element element, java.lang.Class<? extends EObject> clazz) {
+ for(EObject stereoApplication : element.getStereotypeApplications()) {
+ // check whether the stereotype is a subclass of the passed parameter clazz
+ if(clazz.isAssignableFrom(stereoApplication.getClass())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return the attribute of a stereotype. If the attribute type is a model reference,
+ * use the function getAttributeBase instead.
+ *
+ * @param element
+ * the element which holds the stereotype
+ * @param stereo_name
+ * the name of the stereotype
+ * @param attrib_name
+ * the name of an attribute of this stereotype
+ * @return The value that is associated with the stereotype attribute
+ */
+ public static Object getAttribute(Element element, String stereo_name, String attrib_name) {
+ Stereotype stereotype = element.getAppliedStereotype(stereo_name);
+ if(stereotype == null) {
+ return null;
+ }
+ return element.getValue(stereotype, attrib_name);
+ }
+
+ /**
+ * Set the value of a stereotype attribute
+ *
+ * @param element
+ * the element which holds the stereotype
+ * @param stereo_name
+ * the name of the stereotype
+ * @param attrib_name
+ * the name of an attribute of this stereotype
+ * @param value
+ * the value that is associated with the stereotype attribute
+ */
+ public static void setAttribute(Element element, String stereo_name, String attr_name, Object value) {
+ Stereotype st = apply(element, stereo_name);
+ if(st != null) {
+ element.setValue(st, attr_name, value);
+ }
+ }
+
+ /**
+ * Return the stereotype application. Like getApplication below, except
+ * that the passed stereotype is a string.
+ *
+ * @param element
+ * @param stereo_name
+ * the qualified name of a stereotype. Applications of compatible sub-types will be returned as well (if exact stereotype is not applied)
+ * @return
+ */
+ public static EObject getApplication(Element element, String stereo_name) {
+
+ Stereotype stereotype = element.getApplicableStereotype(stereo_name);
+ if(stereotype != null) {
+ EObject application = element.getStereotypeApplication(stereotype);
+ if(application != null) {
+ return application;
+ }
+ // not found, now try sub-stereotypes
+ for(Stereotype subStereo : element.getAppliedSubstereotypes(stereotype)) {
+ application = element.getStereotypeApplication(subStereo);
+ if(application != null) {
+ return application;
+ }
+ }
+ }
+ return null;
+
+ }
+
+ /**
+ * Return the stereotype application by passing an element of the static profile
+ *
+ * @param element
+ * the UML model element
+ * @param clazz
+ * the class of an element of a static profile. Compatible sub-types will be returned as well
+ * @return the stereotype application (first compatible with passed clazz) or null
+ */
+ @SuppressWarnings("unchecked")
+ public static <T extends EObject> T getApplication(Element element, java.lang.Class<T> clazz) {
+ for(EObject stereoApplication : element.getStereotypeApplications()) {
+ // check whether the stereotype is an instance of the passed parameter clazz
+ if(clazz.isInstance(stereoApplication)) {
+ return (T)stereoApplication;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Apply a stereotype. The stereotype is not applied, if already a sub-stereotype is applied.
+ * If you want to apply the new stereotype also in this case, use applyExact instead.
+ *
+ * @param element
+ * the element
+ * @param stereo_name
+ * the stereotype name
+ * @return
+ */
+ public static Stereotype apply(Element element, String stereo_name) {
+ Stereotype stereotype = element.getApplicableStereotype(stereo_name);
+ if(stereotype != null) {
+ EList<Stereotype> subStereos = element.getAppliedSubstereotypes(stereotype);
+ boolean alreadyApplied = (subStereos.size() > 0);
+ if(!alreadyApplied) {
+ // it seems that subSterotypes do not include the stereotype itself
+ if(element.getStereotypeApplication(stereotype) == null) {
+ element.applyStereotype(stereotype);
+ }
+ }
+ }
+ return stereotype;
+ }
+
+ /**
+ * unapply a stereotype when the name of the stereotype is given.
+ *
+ * @param element
+ * the element
+ * @param stereo_name
+ * the stereotype name
+ * @return
+ */
+ public static void unapply(Element element, String stereo_name) {
+ Stereotype stereotype = element.getApplicableStereotype(stereo_name);
+ if(stereotype != null) {
+ if(element.getStereotypeApplication(stereotype) != null) {
+ element.unapplyStereotype(stereotype);
+ }
+ }
+ }
+
+ /**
+ * Apply a stereotype and return the stereotype application (if successful).
+ * The stereotype is not applied, if already a sub-stereotype is applied.
+ * If you want to apply the new stereotype also in this case, use applyExact instead.
+ *
+ * @param element
+ * the element
+ * @param stereo_name
+ * the stereotype name
+ * @return
+ */
+ public static <T extends EObject> T applyApp(Element element, java.lang.Class<T> clazz) {
+ if(apply(element, clazz) != null) {
+ return getApplication(element, clazz);
+ }
+ return null;
+ }
+
+ /**
+ * @param element
+ * @param stereo_name
+ * @return
+ */
+ public static Stereotype applyExact(Element element, String stereo_name) {
+ Stereotype stereotype = element.getApplicableStereotype(stereo_name);
+ if(stereotype != null) {
+ Stereotype alreadyApplied = element.getAppliedSubstereotype(stereotype, stereo_name);
+ if(alreadyApplied == null) {
+ element.applyStereotype(stereotype);
+ }
+ }
+ return stereotype;
+ }
+
+ /**
+ * Apply a stereotype.
+ * Caveat: the function relies on the correspondence between the fully qualified
+ * stereotype name and the package name within the static profile. The latter may
+ * use a different prefix (as it is the case with the MARTE analysis & design profile).
+ *
+ * @param element
+ * the element
+ * @param class a class of a static profile
+ * @return
+ */
+ public static Stereotype apply(Element element, java.lang.Class<? extends EObject> clazz) {
+ return apply(element, getStereoName(element, clazz));
+ }
+
+ /**
+ * Unapply a stereotype.
+ * Caveat: the function relies on the correspondence between the fully qualified
+ * stereotype name and the package name within the static profile. The latter may
+ * use a different prefix (as it is the case with the MARTE analysis & design profile).
+ *
+ * @param element
+ * the element
+ * @param stereo_name
+ * the stereotype name
+ * @return
+ */
+ public static void unapply(Element element, java.lang.Class<? extends EObject> clazz) {
+ unapply(element, getStereoName(element, clazz));
+ }
+
+ /**
+ * Apply a stereotype.
+ * Caveat: the function relies on the correspondence between the fully qualified
+ * stereotype name and the package name within the static profile. The latter may
+ * use a different prefix (as it is the case with the MARTE analysis & design profile).
+ *
+ * @param element
+ * the element
+ * @param stereo_name
+ * the stereotype name
+ * @return
+ */
+ public static Stereotype applyExact(Element element, java.lang.Class<? extends EObject> clazz) {
+ return applyExact(element, getStereoName(element, clazz));
+ }
+
+ /**
+ * This function should be used if stereotype attributes are in turn typed by stereotyped
+ * elements and the user wants to retrieve the underlying base elements (instead of the stereotype application)
+ * The function applies the getBaseElement operation to the result of the
+ * getStereotypeAttribute function above.
+ *
+ * @param element
+ * the element while holds the stereotype
+ * @param stereo_name
+ * the name of the stereotype
+ * @param attrib_name
+ * the name of an attribute of this stereotype
+ * @return The value that is associated with the stereotype attribute
+ */
+ public static Element getAttributeBase(Element element, String stereo_name, String attrib_name) {
+ Object obj = getAttribute(element, stereo_name, attrib_name);
+ if(obj instanceof EObject) {
+ return UMLUtil.getBaseElement((EObject)obj);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Copy the stereotype application from a source to a destination element. The
+ * function will also copy the stereotype attributes.
+ *
+ * @param source
+ * @param destination
+ * @return
+ */
+ public static void copyStereotypes(Copy copy, Element source, Element destination) {
+
+ for(Stereotype stereotype : source.getAppliedStereotypes()) {
+ String stereoName = stereotype.getQualifiedName();
+
+ // Hack: do not copy derived element stereotype. Problem: when templates are instantiated,
+ // some operations are derived from interface operations which in turn are derived from the
+ // formal template parameter (e.g. FIFO). Since interface derived from ports are put into a
+ // top-level directory "derived elements", they may be outside the package template and do not
+ // get replaced.
+ copyAttributes(copy, stereotype.getQualifiedName(), source, destination);
+
+ }
+ }
+
+ public static void copyStereotypes(Element source, Element destination) {
+ copyStereotypes(null, source, destination);
+ }
+
+ /**
+ * copy stereotype attributes.
+ *
+ * TODO: verify if it is necessary to distinguish between stereoSource and stereoDest
+ * (they should be identical, if the resource sets are).
+ * => simplify code
+ *
+ * @param stereotypeName
+ * @param source
+ * @param destination
+ * @return
+ */
+ @SuppressWarnings({ "unchecked" })
+ public static boolean copyAttributes(Copy copy, String stereotypeName, Element source, Element destination) {
+ Stereotype stereoSource = source.getAppliedStereotype(stereotypeName);
+ Stereotype stereoDest = destination.getApplicableStereotype(stereotypeName);
+
+ if((stereoSource == null) || (stereoDest == null)) {
+ return false;
+ }
+ Stereotype alreadyApplied = destination.getAppliedStereotype(stereotypeName);
+ if(alreadyApplied == null) {
+ // only apply stereotype, if not already applied
+ destination.applyStereotype(stereoDest);
+ }
+
+ // getAllAttributes? (but have to avoid attribute base_Class which resets stereotype application)
+ for(Property attribute : stereoSource.getAllAttributes()) {
+ String attrName = attribute.getName();
+
+ if(attrName.length() >= 5) {
+ // do not copy base_ stereotypes (base_class, base_package and base_PackageImport)
+ if(attrName.startsWith("base_")) {
+ continue;
+ }
+ }
+ // do not copy derived attributes
+ if(attribute.isDerived()) {
+ continue;
+ }
+
+ Object value = source.getValue(stereoSource, attrName);
+ // handle specific case: need to copy referenced containerExt, since it points to element
+ // in the original model.
+ /*
+ * if ((value instanceof EObject) && (attrName.equals ("containerExt"))) {
+ * continue;
+ * }
+ */
+
+ if(value instanceof EList) {
+ // copy list
+ EList<Object> newList = new BasicEList<Object>();
+ for(Object valueEl : (EList<Object>)value) {
+ if((copy != null) && (valueEl instanceof Element)) {
+ newList.add(copy.getCopy((Element)valueEl));
+ } else {
+ newList.add(valueEl);
+ }
+ }
+ if(newList.size() > 0) {
+ destination.setValue(stereoDest, attrName, newList);
+ }
+ } else if((copy != null) && (value instanceof Element)) {
+ destination.setValue(stereoDest, attrName, copy.getCopy((Element)value));
+ } else {
+ destination.setValue(stereoDest, attrName, value);
+ }
+ }
+
+ return true;
+ }
+
+ public static boolean copyAttribute(String stereotypeName, String attribute, Element source, Element destination) {
+ Stereotype stereotype = source.getAppliedStereotype(stereotypeName);
+ if(stereotype == null) {
+ return false;
+ }
+ Object value = source.getValue(stereotype, attribute);
+ destination.applyStereotype(stereotype);
+ destination.setValue(stereotype, attribute, value);
+ return true;
+ }
+
+// public static org.eclipse.papyrus.FCM.Connector getConnector(Connector connector) {
+// return getApplication(connector, org.eclipse.papyrus.FCM.Connector.class);
+// }
+//
+// public static boolean isConnector(Connector candidate) {
+// return StUtils.isApplied(candidate, org.eclipse.papyrus.FCM.Connector.class);
+// }
+
+ public static Stereotype getStereo(Element element, java.lang.Class<? extends EObject> clazz) {
+ return element.getAppliedStereotype(getStereoName(element, clazz));
+ }
+
+ /**
+ * Get the stereotype-name that may relate to the name of an interface within a static profile.
+ * Note that the class name within a static profile might have a prefix, such as org.eclipse.papyrus. This
+ * functions tries to remove prefixes iteratively, if a stereotype is not applicable.
+ *
+ * @param clazz
+ * @return
+ */
+ public static String getStereoName(Element element, java.lang.Class<? extends EObject> clazz) {
+ String name = clazz.getName().replace(".", "::"); //$NON-NLS-1$ //$NON-NLS-2$;
+ while (element.getApplicableStereotype(name) == null) {
+ int index = name.indexOf("::"); //$NON-NLS-1$
+ if (index == -1) {
+ return null;
+ }
+ name = name.substring(index + 2);
+ }
+ return name;
+ }
+
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/TransformationException.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/TransformationException.java
new file mode 100644
index 00000000000..febaa4ad08d
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/TransformationException.java
@@ -0,0 +1,22 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment;
+
+public class TransformationException extends Exception {
+
+ public TransformationException(String reason) {
+ super(reason);
+ }
+
+ // String m_reason;
+ final static long serialVersionUID = 1234;
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Utils.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Utils.java
new file mode 100644
index 00000000000..c993bceaf8e
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/Utils.java
@@ -0,0 +1,537 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.UniqueEList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.uml2.uml.AggregationKind;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.Interface;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Namespace;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Port;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
+
+public class Utils {
+
+ /**
+ * Retrieve an element from a list of named elements via its name
+ *
+ * @param namedElementList
+ * @param name
+ * @return
+ */
+ public static NamedElement getNamedElementFromList(
+ EList<? extends NamedElement> namedElementList, String name) {
+ Iterator<? extends NamedElement> namedElements = namedElementList
+ .iterator();
+ while(namedElements.hasNext()) {
+ NamedElement namedElement = namedElements.next();
+ if(namedElement.getName().equals(name)) {
+ return namedElement;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * return the top-level owner of an element. This function returns the same
+ * value as getModel, if the top-level element is a model. While this is the
+ * case for models, model libraries have a top-level package (not a model).
+ * In this case, getTop returns the top-level package whereas getModel would
+ * return null.
+ *
+ * @param element
+ * @return the top-level owning package
+ */
+ public static Package getTop(Element element) {
+ while(element != null) {
+ Element owner = element.getOwner();
+ if(owner == null) {
+ if(element instanceof Package) {
+ return (Package)element;
+ }
+ }
+ element = owner;
+ }
+ return null;
+ }
+
+ /**
+ * @param element
+ * an element which is owned by a model.
+ * @param subfolder
+ * the name of a sub-folder within root (created, if not
+ * existent)
+ * @return a reference to the sub folder within the root of the model that
+ * belongs to the passed element.
+ */
+ public static Package getRoot(Element element, String subfolder) {
+ Package root = getTop(element);
+ if(root.getNestedPackage(subfolder) != null) {
+ return root.getNestedPackage(subfolder);
+ } else {
+ return root.createNestedPackage(subfolder);
+ }
+ }
+
+ /**
+ * Convenience method enabling to apply getOwnedOperation equally to classes
+ * and interfaces
+ *
+ * @param cl
+ * @param name
+ * @param paramNames
+ * @param paramTypes
+ * @return
+ */
+ public static Operation createOwnedOperation(Classifier cl, String name,
+ EList<String> paramNames, EList<Type> paramTypes, Type retType) {
+ if(cl instanceof Class) {
+ return ((Class)cl).createOwnedOperation(name, paramNames,
+ paramTypes, retType);
+ } else if(cl instanceof Interface) {
+ return ((Interface)cl).createOwnedOperation(name, paramNames,
+ paramTypes, retType);
+ } else {
+ return null;
+ }
+ }
+
+ public static Operation getOwnedOperation(Classifier cl, String name,
+ EList<String> paramNames, EList<Type> paramTypes) {
+ if(cl instanceof Class) {
+ return ((Class)cl).getOwnedOperation(name, paramNames, paramTypes);
+ } else if(cl instanceof Interface) {
+ return ((Interface)cl).getOwnedOperation(name, paramNames,
+ paramTypes);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * this method returns the component type of an implementation. It is based
+ * on the modeling convention that implemen tations inherit from types.
+ */
+ public static Class componentType(Class implementation) {
+ if(Utils.isCompImpl(implementation)) {
+ Iterator<Class> superclasses = implementation.getSuperClasses()
+ .iterator();
+ while(superclasses.hasNext()) {
+ Class componentType = superclasses.next();
+ if(Utils.isCompType(componentType)) {
+ return componentType;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * return true, if a component (implementation) is a composite, i.e. has
+ * inner parts
+ */
+ public static boolean isComposite(Class implementation) {
+ return Utils.isCompImpl(implementation)
+ && (getParts(implementation).size() > 0);
+ }
+
+ public static EList<Property> getParts(Class implementation) {
+
+ return implementation.getParts();
+
+ }
+
+
+ /**
+ * @param attribute
+ * an attribute
+ * @return true, if the aggregation kind is considered as a composition
+ */
+ public static boolean isComposition(Property attribute) {
+ if(treatNoneAsComposite()) {
+ return (attribute.getAggregation() != AggregationKind.SHARED_LITERAL);
+ }
+ else {
+ return (attribute.getAggregation() == AggregationKind.COMPOSITE_LITERAL);
+ }
+ }
+
+ /**
+ * return true, if an instance specification is a composite, i.e. has > 1
+ * slots TODO: distinguish parts and configuration attributes
+ */
+
+ public static boolean isComposite(InstanceSpecification is) {
+ return (is.getSlots().size() > 0);
+ }
+
+ /**
+ * Get an element via its qualified name. Will find elements from the root
+ * model and elements in imported models. Also supports target model in
+ * which imports have been copied (while keeping the top-level name)
+ *
+ * @param root
+ * @param qualifiedName
+ * @return
+ */
+ public static NamedElement getQualifiedElement(Package root,
+ String qualifiedName) {
+ NamedElement namedElement = null;
+ int index = qualifiedName.indexOf("::");
+ if(index != -1) {
+ // first try using a path without top element (since
+ // getQualifiedElement is typically used for
+ // imported elements)
+ String remainder = qualifiedName.substring(index + 2);
+ namedElement = getQualifiedElement(root, remainder, qualifiedName);
+ }
+ if(namedElement == null) {
+ // try with complete name as path name, but assume that the element
+ // has been copied into the model,
+ // i.e. qualifiedName is prefixed by model name
+ namedElement = getQualifiedElement(root, qualifiedName,
+ root.getName() + "::" + qualifiedName);
+ }
+ return namedElement;
+ }
+
+ /**
+ * Retrieve an element via its qualified name within a package The segments
+ * of the package may be non unique due to imports
+ *
+ * @return the found element, if it exists
+ */
+ public static NamedElement getQualifiedElement(Package root,
+ String remainingPath, String qualifiedName) {
+ if(root == null) {
+ return null;
+ }
+ if(!remainingPath.contains("::")) {
+ for(NamedElement candidate : root.getMembers()) {
+ String name = candidate.getName();
+ if((name != null) && name.equals(remainingPath)) {
+ if(candidate.getQualifiedName().equals(qualifiedName)) {
+ return candidate;
+ }
+ }
+ }
+ } else {
+ String segment = remainingPath.split("::")[0];
+ String remainder = remainingPath.substring(segment.length() + 2);
+ for(Element element : root.getMembers()) {
+ if(element instanceof Package) {
+ if(((NamedElement)element).getName().equals(segment)) {
+ NamedElement foundElement = getQualifiedElement(
+ (Package)element, remainder, qualifiedName);
+ // return, if not found
+ if(foundElement != null) {
+ return foundElement;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Simple check whether an element is in a different model than the passed
+ * package It will return true, whenever the the top elements do not match.
+ * This is always true, if the 2nd belongs to a different model, whether
+ * imported or not. This distinction is however not required in our context.
+ */
+ public static boolean isElementInDifferentModel(Package model,
+ NamedElement namedElement) {
+ return model != getTop(namedElement);
+ }
+
+ /**
+ * Check whether an element (referenced from the source model) is part of a
+ * package that is imported on top-level by the target model. It will always
+ * return false, if the passed element is part of the source model.
+ *
+ * @param sat
+ * source and target model information
+ * @param namedElement
+ * a named element
+ * @return true, if imported (on top level), false otherwise
+ */
+ public static boolean isElementImported(Copy sat, NamedElement namedElement) {
+ if(isElementInDifferentModel(sat.source, namedElement)) {
+ String qualifiedName = namedElement.getQualifiedName();
+ int index = qualifiedName.indexOf("::");
+ // remove top level element of name
+ if(index != -1) {
+ qualifiedName = qualifiedName.substring(index + 2);
+ }
+ // check whether the element is reachable from the target root
+ if(getQualifiedElement(sat.target, qualifiedName) != null) {
+ return true;
+ }
+ /*
+ * do not use packageImports, since import is transitiv and would
+ * not capture all cases Package top = getTop (namedElement); for
+ * (PackageImport packageImport : sat.target.getPackageImports()) {
+ * if (packageImport.getImportedPackage () == top) { return true; }
+ * }
+ */
+ }
+ return false;
+ }
+
+ /**
+ * Check whether a named element exists within the target model. This
+ * function evaluates the copyImport flag. If true, it assumes that the
+ * original model as well as imports correspond to a top level package
+ * within the target model. If imports are not copied, the function assumes
+ * that all elements of a different model are actually reachable via the
+ * import relationship
+ *
+ * @param sat
+ * @param namedElement
+ * @return the corresponding element within the target model - if it exits
+ */
+ public static NamedElement getExistingNEinTarget(Copy sat,
+ NamedElement namedElement) {
+ if(sat.copyExtReferences) {
+ // copy imports into new model
+ // return existing element (or null)
+ return getExistingElement(sat.target, namedElement, false);
+ } else {
+ // elements that are imported should not be copied.
+ // Function assumes that all elements that are in a different model
+ // are actually
+ // reachable via import relations, i.e. exist already
+ if(isElementInDifferentModel(sat.source, namedElement)) {
+ return namedElement;
+ }
+ return getExistingElement(sat.target, namedElement, false);
+ }
+ }
+
+ public static NamedElement getExistingElement(Package model,
+ NamedElement namedElement, boolean skipTop) {
+ EList<Namespace> list = namedElement.allNamespaces();
+ int offset = (skipTop ? 2 : 1);
+ // start with list size - 2, i.e. skip last element which points to the
+ // name of the
+ // (potentially) imported model, since getImportedElement will start
+ // there.
+ Package currentPkg = model;
+ for(int i = list.size() - offset; i >= 0; i--) {
+ String name = list.get(i).getName();
+ NamedElement member = currentPkg.getMember(name);
+ if(member instanceof Package) {
+ currentPkg = (Package)member;
+ } else {
+ return null;
+ }
+ }
+ String name = namedElement.getName();
+ return currentPkg.getMember(name);
+ }
+
+ /**
+ * Check whether a class contains a non-port attribute of a given name
+ *
+ * @param cl
+ * @return
+ */
+ public static boolean hasNonPortOwnedAttribute(Class cl, String name) {
+ for(Property p : cl.getOwnedAttributes()) {
+ if(!(p instanceof Port)) {
+ if(p.getName().equals(name)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public static <T extends EObject> EList<T> getAllElementsOfType(Element examineElement, java.lang.Class<T> clazz)
+ {
+ EList<Element> visitedPackages = new BasicEList<Element>();
+ return getAllElementsOfType(examineElement, clazz, visitedPackages);
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T extends EObject> EList<T> getAllElementsOfType(Element examineElement, java.lang.Class<T> clazz, EList<Element> visitedPackages)
+ {
+ EList<T> list = new UniqueEList<T>();
+ for(Element element : examineElement.allOwnedElements()) {
+ if(element instanceof Package) {
+ if(!visitedPackages.contains(element)) {
+ visitedPackages.add(element);
+ list.addAll(getAllElementsOfType((Package)element, clazz,
+ visitedPackages));
+ }
+ } else if(clazz.isInstance(element)) {
+ list.add((T)element);
+ }
+ }
+ return list;
+ }
+
+ /**
+ * Return the top element of the model that is currently edited. This function is based on the
+ * assumption that the user model is the first resource that is loaded into the model set.
+ * Use this function instead of Utils.getTop (or getModel) if you want to avoid navigating to the
+ * root of an imported model.
+ *
+ * @return the top level package of the model currently loaded into an editor.
+ */
+ public static Package getUserModel() {
+ ServiceUtilsForActionHandlers serviceUtils = ServiceUtilsForActionHandlers.getInstance();
+ try {
+ // IPath fn = serviceUtils.getModelSet().getFilenameWithoutExtension();
+ EList<Resource> resources = serviceUtils.getModelSet().getResources();
+ if(resources.size() >= 3) {
+ // check first three resources (di, notation, uml)
+ for(int i = 0; i < 3; i++) {
+ Resource userResource = resources.get(i);
+ if(userResource.getContents().size() > 0) {
+ EObject topEObj = userResource.getContents().get(0);
+ if(topEObj instanceof Package) {
+ return (Package)topEObj;
+ }
+ }
+ }
+ }
+ } catch (ServiceException e) {
+ }
+ return null;
+ }
+
+ /**
+ * @param a
+ * potential implementation
+ * @return true, if passed classifier is an implementation (i.e. declared
+ * via stereotypes as component or connector implementation (a sub-type of component implementations,
+ * therefore no additional check is required)
+ */
+ public static boolean isCompImpl(Classifier implementation) {
+ return !implementation.isAbstract();
+ }
+
+ /**
+ * Check whether the passed class is a component type (and not a component implementation).
+ * This includes connector and container types as well.
+ *
+ * @param component
+ * @return
+ */
+ public static boolean isCompType(Class component) {
+ return component.isAbstract();
+ }
+
+// public static boolean isSingleton(Class component) {
+// return StUtils.isApplied(component, Singleton.class);
+// }
+
+ public static boolean treatNoneAsComposite() {
+
+ return true;
+ }
+
+// public static boolean allAttributesAreConfigAttributs() {
+// IPreferenceStore store = org.eclipse.papyrus.qompass.designer.core.Activator.getDefault().getPreferenceStore();
+// return store.getBoolean(QompassPreferenceConstants.P_ALL_ATTRIBUTES_ARE_CONFIG_ATTRIBUTES);
+// }
+
+ /**
+ * True, if either a component implementation or a type
+ *
+ * @param component
+ * @return
+ */
+ public static boolean isComponent(Class component) {
+ return (isCompType(component) || isCompImpl(component));
+ }
+
+// /**
+// * Return the rules associated with a component
+// *
+// * @param component
+// * @return
+// */
+// public static EList<ContainerRule> getRules(Class component) {
+// RuleApplication ruleApplication = StUtils.getApplication(component, RuleApplication.class);
+// if(ruleApplication != null) {
+// return ruleApplication.getContainerRule();
+// }
+// return null;
+// }
+
+ /**
+ * Return the absolute file name to a file name given e.g. in the form platform:/plugin/xxx
+ *
+ * @param fileName
+ * the file name using eclipse elements such as platform:/plugin
+ * @return the absolute file name
+ */
+ public static String getAbsoluteFN(String fileName) {
+ try {
+ URL absoluteURL = FileLocator.toFileURL(new URL(fileName));
+ return absoluteURL.getFile();
+ } catch (MalformedURLException e) {
+ } catch (IOException e) {
+ }
+ return null;
+ }
+
+// // TODO: need a generic utility function for getting all elements obeying a certain
+// // criteria from a model
+// public static EList<ContainerRule> getAllRules(Package pkg) {
+// EList<Package> visitedPackages = new BasicEList<Package>();
+// EList<ContainerRule> contRuleList = new BasicEList<ContainerRule>();
+// getAllRules(pkg, visitedPackages, contRuleList);
+// return contRuleList;
+// }
+
+// public static void getAllRules(Package pkg, EList<Package> visitedPackages, EList<ContainerRule> contRuleList) {
+// for(Element el : pkg.getMembers()) {
+// if(el instanceof Package) {
+// if(!visitedPackages.contains(el)) {
+// visitedPackages.add((Package)el);
+// getAllRules((Package)el, visitedPackages, contRuleList);
+// }
+// }
+// else if(el instanceof Class) {
+// if(StUtils.isApplied(el, ContainerRule.class)) {
+// ContainerRule rule = StUtils.getApplication((Class)el, ContainerRule.class);
+// contRuleList.add(rule);
+// }
+// }
+// }
+// }
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/AllocationDialog.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/AllocationDialog.java
new file mode 100644
index 00000000000..5f8ebf24718
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/AllocationDialog.java
@@ -0,0 +1,304 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment.dialog;
+
+import org.eclipse.draw2d.Label;
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.papyrus.RobotML.DeploymentPlan;
+import org.eclipse.papyrus.robotml.deployment.AllocUtils;
+import org.eclipse.papyrus.robotml.deployment.DepUtils;
+import org.eclipse.papyrus.robotml.deployment.DialogUtils;
+import org.eclipse.papyrus.robotml.deployment.StUtils;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.dialogs.SelectionStatusDialog;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.Package;
+
+/**
+ * Select a connector type and implementation (group)
+ * TODO: show information about the used connector [usage, implem properties, ...]
+ * similar help for ports?
+ *
+ * @author ansgar
+ *
+ */
+
+/*
+ * ListSelectionDialog lsd = new ListSelectionDialog(window.getShell(), list, new ArrayContentProvider(), new LabelProvider(),
+ * "ListSelectionDialog Message");
+ * lsd.setInitialSelections(list.toArray());
+ * lsd.setTitle("Select # of Nobel Prize Nominations :");
+ * lsd.open();
+ */
+public class AllocationDialog extends SelectionStatusDialog {
+
+ private DeploymentPlan m_cdp;
+
+ // protected EList<Package> visitedPackages;
+ // protected FilteredList fRules;
+ private Tree fTree;
+
+ private Label fLabel;
+
+ private Combo fAlloc;
+
+ private InstanceSpecification currentIS;
+
+ private EList<InstanceSpecification> nodeOrThreadList;
+
+ public AllocationDialog(Shell parent, Package cdp) {
+ super(parent);
+ // m_cdp = cdp;
+ m_cdp = StUtils.getApplication(cdp, DeploymentPlan.class);
+ visitedPackages = new BasicEList<Package>();
+ nodeOrThreadList = new BasicEList<InstanceSpecification>();
+ nodeOrThreadList.add(null); // dummy entry for no allocation
+ getAllNodesOrThreads(cdp.getModel(), nodeOrThreadList);
+ }
+
+ /**
+ * @see SelectionStatusDialog#computeResult()
+ */
+ protected void computeResult() {
+ // nothing to do
+ }
+
+ public Control createDialogArea(Composite parent) {
+ Composite contents = (Composite)super.createDialogArea(parent);
+ // (parent, "Container rules", "Avail. extensions/interceptors");
+
+ fTree = new Tree(contents, SWT.H_SCROLL | SWT.BORDER);
+ fTree.setHeaderVisible(true);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ fTree.setLayoutData(data);
+ data.heightHint = 150;
+ // data.widthHint = 200;
+
+ // Turn off drawing to avoid flicker
+ fTree.setRedraw(false);
+
+ TreeColumn instances = new TreeColumn(fTree, SWT.LEFT);
+ instances.setText("Instance");
+ instances.setWidth(200);
+ TreeColumn explicitAlloc = new TreeColumn(fTree, SWT.LEFT);
+ explicitAlloc.setText("explicit allocation");
+ explicitAlloc.setWidth(150);
+ TreeColumn implicitAlloc = new TreeColumn(fTree, SWT.LEFT);
+ implicitAlloc.setText("implicit allocation");
+ implicitAlloc.setWidth(150);
+
+ fillTree(fTree, null, m_cdp.getMainInstance());
+
+ // Turn drawing back on!
+ fTree.setRedraw(true);
+
+ fTree.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if(fTree.getSelection().length > 0) {
+ selectInstance(fTree.getSelection()[0]);
+ }
+ }
+ });
+
+ Label label = new Label();
+ label.setText("seletected instance:");
+ fLabel = new Label();
+
+ createAllocInfo(contents);
+ return contents;
+ }
+
+ /**
+ * Helper method to fill a tree with data
+ *
+ * @param tree
+ * the tree to fill
+ */
+ private void fillTree(Tree tree, TreeItem treeItem, InstanceSpecification is) {
+ TreeItem item;
+ if(treeItem != null) {
+ item = new TreeItem(treeItem, SWT.NONE);
+ } else {
+ item = new TreeItem(tree, SWT.NONE);
+ }
+ item.setData(is);
+ setTextFromData(item);
+
+ // create children
+ for(InstanceSpecification subIS : DepUtils.getContainedInstances(is)) {
+ fillTree(tree, item, subIS);
+ }
+ }
+
+ // obtain name and explicit/implicit node Allocation
+ protected void setTextFromData(TreeItem ti) {
+ Object data = ti.getData();
+ if(data instanceof InstanceSpecification) {
+ InstanceSpecification is = (InstanceSpecification)data;
+
+ String name = is.getName();
+ int index = name.lastIndexOf(".");
+ if(index != -1) {
+ name = name.substring(index + 1);
+ }
+ InstanceSpecification explicitNodeOrThread = AllocUtils.getNodeOrThread(is);
+ Classifier cl = DepUtils.getClassifier(is);
+ String nodeName;
+ if(explicitNodeOrThread == null) {
+ nodeName = "-";
+ } else {
+ nodeName = getAllocName(explicitNodeOrThread);
+ }
+
+ EList<InstanceSpecification> implicitNodes = AllocUtils.getAllNodesOrThreadsParent(is);
+ implicitNodes.addAll(AllocUtils.getAllNodesOrThreadsParent(is));
+ String list = "";
+ for(InstanceSpecification node : implicitNodes) {
+ if(list.equals("")) {
+ list = getAllocName(node);
+ } else {
+ list += ", " + getAllocName(node);
+ }
+ }
+ ti.setText(new String[]{ name, nodeName, "[" + list + "]" });
+ }
+ }
+
+ protected void refreshTree(TreeItem ti) {
+ setTextFromData(ti);
+ for(TreeItem subItem : ti.getItems()) {
+ refreshTree(subItem);
+ }
+ }
+
+ private String getAllocName(InstanceSpecification nodeOrThread) {
+ if(nodeOrThread == null) {
+ return "no explicit allocation";
+ } else {
+ String name = nodeOrThread.getName();
+ InstanceSpecification threadNode = AllocUtils.getNode(nodeOrThread);
+ return name + (threadNode != null ? " on " + threadNode.getName() : "");
+ }
+ }
+
+ protected void createAllocInfo(Composite parent) {
+ // create extension kind combo
+ fAlloc = DialogUtils.createComboWithText(parent, "Alloc to node:",
+ SWT.DROP_DOWN | SWT.READ_ONLY, SWT.NONE);
+
+ String items[] = new String[nodeOrThreadList.size()];
+ int i = 0;
+ for(InstanceSpecification nodeOrThread : nodeOrThreadList) {
+ items[i++] = getAllocName(nodeOrThread);
+ }
+ fAlloc.setItems(items);
+ fAlloc.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent event) {
+ if(currentIS != null) {
+ updateAllocation(currentIS, fAlloc.getSelectionIndex());
+ // selectionCount should always be 1
+ for(TreeItem ti : fTree.getSelection()) {
+ refreshTree(ti);
+ }
+ }
+ }
+ });
+
+ fAlloc.setEnabled(false);
+ }
+
+ /**
+ * Select a rule, i.e. update the visual representation from the rule
+ *
+ * @param rule
+ */
+ protected void selectInstance(TreeItem item) {
+ // for (Port port : rule.getPortSet ()) {
+ // fPorts.setSelection()
+ // }
+ currentIS = (InstanceSpecification)item.getData();
+ fLabel.setText(currentIS.getName());
+
+ fAlloc.setEnabled(true);
+ InstanceSpecification nodeOrThread = AllocUtils.getNodeOrThread(currentIS);
+
+ for(int i = 0; i < nodeOrThreadList.size(); i++) {
+ if(nodeOrThreadList.get(i) == nodeOrThread) {
+ fAlloc.select(i);
+ }
+ }
+ }
+
+ private void updateAllocation(InstanceSpecification is, int index) {
+ InstanceSpecification oldNode = AllocUtils.getNodeOrThread(is);
+ InstanceSpecification newNode = nodeOrThreadList.get(index);
+
+ if(oldNode == newNode) {
+ return;
+ }
+
+ // add or update
+ if(oldNode == null) {
+
+ AllocUtils.allocate(is, newNode);
+
+
+ } else {
+ AllocUtils.updateAllocation(is, oldNode, newNode);
+ }
+ }
+
+ void getAllNodesOrThreads(Package pkg, EList<InstanceSpecification> nodeList) {
+ for(Element el : pkg.getMembers()) {
+ if(el instanceof Package) {
+ if(!visitedPackages.contains(el)) {
+ visitedPackages.add((Package)el);
+ getAllNodesOrThreads((Package)el, nodeList);
+ }
+ }
+ else if(el instanceof InstanceSpecification) {
+ Classifier cl = DepUtils.getClassifier((InstanceSpecification)el);
+ if(cl != null) {
+ if((cl instanceof Class) ) {
+ // check that instances are not part of a deployment plan
+ // [TODO:] check that owner of instance is a platform definition
+ if(!StUtils.isApplied(el.getOwner(), DeploymentPlan.class)) {
+ nodeList.add((InstanceSpecification)el);
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+
+ private EList<Package> visitedPackages;
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/AttributeLabelProvider.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/AttributeLabelProvider.java
new file mode 100644
index 00000000000..2e6f8d92ef0
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/AttributeLabelProvider.java
@@ -0,0 +1,32 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment.dialog;
+
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
+
+public class AttributeLabelProvider extends LabelProvider {
+
+ public String getText(Object element) {
+ if(element instanceof Property) {
+ Property p = (Property)element;
+ Type type = p.getType();
+ return p.getClass_().getName() + "." + p.getName() + ((type != null) ?
+ " : " + type.getQualifiedName() :
+ "");
+ }
+ else {
+ return "invalid";
+ }
+ }
+};
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/ConfigureInstanceDialog.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/ConfigureInstanceDialog.java
new file mode 100644
index 00000000000..510bb0e8f15
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/ConfigureInstanceDialog.java
@@ -0,0 +1,509 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment.dialog;
+
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.robotml.deployment.DepCreation;
+import org.eclipse.papyrus.robotml.deployment.DepPlanSync;
+import org.eclipse.papyrus.robotml.deployment.DepPlanUtils;
+import org.eclipse.papyrus.robotml.deployment.DepUtils;
+import org.eclipse.papyrus.robotml.deployment.DialogUtils;
+import org.eclipse.papyrus.robotml.deployment.StUtils;
+import org.eclipse.papyrus.robotml.deployment.Utils;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.dialogs.SelectionStatusDialog;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Connector;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Feature;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.LiteralBoolean;
+import org.eclipse.uml2.uml.LiteralInteger;
+import org.eclipse.uml2.uml.LiteralString;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.PackageableElement;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Slot;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.ValueSpecification;
+
+/**
+ * Select container rules, either from a list of globally defined rules or from
+ * local rules which may be created "on the fly" by this dialog.
+ *
+ * TODO: extend rule application to instances (problematic, since rules
+ * transformation is done on type level)
+ *
+ * @author ansgar
+ */
+public class ConfigureInstanceDialog extends SelectionStatusDialog {
+
+ protected Class m_component;
+
+ protected Label fDescriptionLabel;
+
+ protected Text fDescription;
+
+ protected TreeViewer fInstanceList;
+
+ protected TableViewer fPropertyList;
+
+ protected Property m_currentAttribute;
+
+ protected final String valueLabelPrefix = "Value:";
+
+ protected Label fValueLabel;
+
+ protected Text fValue;
+
+ protected Package m_model;
+
+ protected Feature m_feature;
+
+ protected EList<Package> visitedPackages;
+
+ protected boolean m_rulePropertiesOnly;
+
+ protected InstanceSpecification m_instance;
+
+ EList<InstanceSpecification> m_instanceList;
+
+ public ConfigureInstanceDialog(Shell parent) {
+ super(parent);
+ }
+
+ public boolean init(Class component) {
+ // visitedPackages = new BasicEList<Package> ();
+ DepPlanSync.syncAllDepPlans(component);
+ m_component = component;
+ m_instance = null;
+ m_feature = null;
+ m_model = Utils.getUserModel();
+ return checkAndGetInstances();
+ }
+
+ public boolean init(InstanceSpecification instance) {
+ // visitedPackages = new BasicEList<Package> ();
+ DepPlanSync.syncDepPlan(instance.getNearestPackage());
+ m_component = DepUtils.getImplementation(instance);
+ m_instance = instance;
+ m_feature = null;
+ m_model = Utils.getUserModel();
+ return checkAndGetInstances();
+ }
+
+ public boolean init(Feature feature) {
+ // visitedPackages = new BasicEList<Package> ();
+ m_feature = feature;
+ m_model = Utils.getUserModel();
+ m_instance = null;
+ if(feature instanceof Property) {
+ Type type = ((Property)feature).getType();
+ if(type instanceof Class) {
+ m_component = (Class)type;
+ return checkAndGetInstances();
+ }
+ }
+ return false;
+ }
+
+
+ /**
+ * retrieve the instance list. Returns false, if no deploymentplan could be found.
+ *
+ * @return
+ */
+ public boolean checkAndGetInstances() {
+ visitedPackages = new BasicEList<Package>();
+ m_instanceList = new BasicEList<InstanceSpecification>();
+
+ getInstances(m_instanceList);
+ if(m_instanceList.size() == 0) {
+ Shell shell = new Shell();
+ if(DepPlanUtils.getAllDepPlans(m_model).size() == 0) {
+ MessageDialog.openInformation(shell, "Instance configuration",
+ "No deployment plans are defined. Create a deployment plan before configuring instances");
+ return false;
+ }
+ else if(MessageDialog.openConfirm(shell, "Instance configuration",
+ "The list of available instances is empty. Synchronize deployment plans?")) {
+ DepPlanSync.syncAllDepPlans(m_model);
+ visitedPackages = new BasicEList<Package>();
+ getInstances(m_instanceList);
+ if(m_instanceList.size() == 0) {
+ MessageDialog.openInformation(shell, "Instance configuration",
+ "There are still no instances available\n" +
+ "Check whether you created already a deployment plan for your system." +
+ "Check as well, if the parts in your a composite use \"composite\" as aggregation kind\n." +
+ "(Results of deployment plan synchronizations will be unrolled)");
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * @see SelectionStatusDialog#computeResult()
+ */
+ protected void computeResult() {
+ // nothing to do
+ }
+
+ public Control createDialogArea(Composite parent) {
+ Composite contents = (Composite)super.createDialogArea(parent);
+ // (parent, "Container rules", "Avail. extensions/interceptors");
+
+ createInstanceSelectionGroup(contents);
+ createInstanceConfigurationGroup(contents);
+ return contents;
+ }
+
+ protected void createInstanceSelectionGroup(Composite parent) {
+ Composite instanceSelection = new Composite(parent, SWT.NONE);
+ GridLayout grid = new GridLayout(1, true);
+ GridData groupGridData = new GridData();
+
+ groupGridData.grabExcessVerticalSpace = true;
+ groupGridData.grabExcessHorizontalSpace = true;
+ groupGridData.horizontalAlignment = GridData.FILL;
+ groupGridData.verticalAlignment = GridData.FILL;
+ instanceSelection.setLayout(grid);
+ instanceSelection.setLayoutData(groupGridData);
+
+ /*
+ * fRules = DialogUtils.createFilteredList (ruleSelGroup, new
+ * RuleLabelProvider(), 200, 200, SWT.BORDER | SWT.V_SCROLL |
+ * SWT.H_SCROLL);
+ */
+
+ //
+ // --------------- instance selection -------------------
+ //
+ Group instanceSelGroup = new Group(instanceSelection, SWT.BORDER);
+ instanceSelGroup.setText(" associated instance specifications ");
+ // ruleGroup.setLayout(new RowLayout (SWT.VERTICAL));
+ instanceSelGroup.setLayout(new GridLayout(1, false));
+ instanceSelGroup.setLayoutData(groupGridData);
+
+ fInstanceList = new TreeViewer(instanceSelGroup, SWT.BORDER);
+
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.heightHint = 100;
+ data.widthHint = 350;
+
+ fInstanceList.getTree().setLayoutData(data);
+ fInstanceList.setLabelProvider(new InstanceLabelProvider());
+ fInstanceList.setContentProvider(new ITreeContentProvider() {
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean hasChildren(Object element) {
+ return getChildren(element).length > 0;
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return (Object[])inputElement;
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ if(parentElement instanceof InstanceSpecification) {
+ return DepUtils.getContainedInstances((InstanceSpecification)parentElement).toArray();
+ }
+ return new Object[0];
+ }
+ });
+
+ fInstanceList.setInput(m_instanceList.toArray());
+ fInstanceList.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ ISelection selection = fInstanceList.getSelection();
+ if(selection instanceof StructuredSelection) {
+ Object[] selected = ((StructuredSelection)selection)
+ .toArray();
+ if((selected.length == 1)
+ && (selected[0] instanceof InstanceSpecification)) {
+ m_instance = (InstanceSpecification)selected[0];
+ Classifier cl = DepUtils.getClassifier(m_instance);
+ fPropertyList.setInput(getConfigAttributes(cl).toArray());
+ selectProperty(m_currentAttribute);
+ }
+ }
+ }
+ });
+ if(m_instance != null) {
+ int index = m_instanceList.indexOf(m_instance);
+ if(index != -1) {
+ TreeItem treeItem = fInstanceList.getTree().getItem(index);
+ fInstanceList.getTree().setSelection(treeItem);
+ }
+ }
+ }
+
+ // create instance configuration group
+ protected void createInstanceConfigurationGroup(Composite parent) {
+ GridData groupGridData = DialogUtils.createFillGridData();
+
+ Group instanceConfigurationGroup = new Group(parent, SWT.BORDER);
+ instanceConfigurationGroup.setText(" Configuration ");
+ instanceConfigurationGroup.setLayout(new RowLayout(SWT.VERTICAL));
+ instanceConfigurationGroup.setLayout(new GridLayout(1, false));
+ instanceConfigurationGroup.setLayoutData(groupGridData);
+
+ // fRuleName = new Text (ruleInfoGroup, SWT.NONE);
+ Label configL = new Label(instanceConfigurationGroup, SWT.NONE);
+ configL.setText("Available properties:");
+
+ fPropertyList = new TableViewer(instanceConfigurationGroup, SWT.BORDER);
+ fPropertyList.setLabelProvider(new AttributeLabelProvider());
+ fPropertyList.setContentProvider(new ArrayContentProvider());
+ fPropertyList.setInput(getConfigAttributes(m_component).toArray());
+ fPropertyList
+ .addSelectionChangedListener(new ISelectionChangedListener() {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ ISelection selection = fPropertyList.getSelection();
+ if(selection instanceof StructuredSelection) {
+ Object[] selected = ((StructuredSelection)selection)
+ .toArray();
+ if((selected.length == 1)
+ && (selected[0] instanceof Property)) {
+ selectProperty((Property)selected[0]);
+ }
+ }
+ }
+ });
+
+ fValueLabel = new Label(instanceConfigurationGroup, SWT.NONE);
+
+ GridData span2 = new GridData();
+ span2.horizontalAlignment = GridData.FILL;
+ span2.grabExcessHorizontalSpace = true;
+ span2.heightHint = 70;
+ fPropertyList.getTable().setLayoutData(span2);
+
+ fValue = new Text(instanceConfigurationGroup, SWT.WRAP);
+ span2 = new GridData();
+ span2.horizontalAlignment = GridData.FILL;
+ span2.grabExcessHorizontalSpace = true;
+ fValue.setLayoutData(span2);
+ fValue.addFocusListener(new FocusListener() {
+
+ public void focusLost(FocusEvent e) {
+ // store value, once focus is lost (different element is
+ // selected)
+ String valueStr = fValue.getText();
+ Slot valueSlot = null;
+ if(m_instance == null) {
+ // no instance has been selected
+ // (field should be inactive, if not selected)
+ return;
+ }
+ for(Slot slot : m_instance.getSlots()) {
+ if(slot.getDefiningFeature() == m_currentAttribute) {
+ valueSlot = slot;
+ }
+ }
+ if(valueSlot == null) {
+ // slot does not exist yet, create
+ valueSlot = DepCreation.createSlotForConfigProp(m_instance,
+ m_currentAttribute);
+ }
+ for(ValueSpecification value : valueSlot.getValues()) {
+ if(value instanceof LiteralString) {
+ ((LiteralString)value).setValue(valueStr);
+ } else if(value instanceof LiteralInteger) {
+ ((LiteralInteger)value).setValue(Integer
+ .parseInt(valueStr));
+ } else if(value instanceof LiteralBoolean) {
+ ((LiteralBoolean)value).setValue(Boolean
+ .parseBoolean(valueStr));
+ }
+ }
+ }
+
+ public void focusGained(FocusEvent e) {
+ }
+ });
+
+ fDescriptionLabel = new Label(instanceConfigurationGroup, SWT.NONE);
+ fDescriptionLabel.setText("Description:");
+ fDescriptionLabel.setLayoutData(span2);
+
+ span2 = new GridData();
+ span2.horizontalAlignment = GridData.FILL;
+ span2.grabExcessHorizontalSpace = true;
+ span2.grabExcessVerticalSpace = true;
+ span2.verticalAlignment = GridData.FILL;
+ span2.heightHint = 80;
+
+ fDescription = new Text(instanceConfigurationGroup, SWT.NONE | SWT.WRAP
+ | SWT.V_SCROLL | SWT.READ_ONLY);
+ fDescription.setLayoutData(span2);
+ // createMessageArea (ruleInfoGroup);
+ instanceConfigurationGroup.pack();
+ setEnabled(false);
+ }
+
+ /**
+ * Select a rule, i.e. update the visual representation from the rule
+ *
+ * @param rule
+ */
+ protected void selectProperty(Property attribute) {
+ m_currentAttribute = attribute;
+ if((attribute == null) || (fValue == null)) {
+ setEnabled(false);
+ return;
+ }
+ setEnabled(true);
+ fDescription.setText(Description.getDescription(attribute, "not available"));
+ fValueLabel.setText(getValueLabel(attribute));
+ for(Slot slot : m_instance.getSlots()) {
+ if(slot.getDefiningFeature() == m_currentAttribute) {
+ for(ValueSpecification value : slot.getValues()) {
+ if(value instanceof LiteralInteger) {
+ Integer intVal = ((LiteralInteger)value).getValue();
+ fValue.setText(intVal.toString());
+ return;
+ }
+ else if(value instanceof LiteralBoolean) {
+ Boolean boolVal = ((LiteralBoolean)value).booleanValue();
+ fValue.setText(boolVal.toString());
+ return;
+ }
+ else if(value instanceof LiteralString) {
+ fValue.setText(((LiteralString)value).getValue());
+ return;
+ }
+ }
+ }
+ }
+ fValue.setText("");
+ }
+
+ private void setEnabled(boolean enabled) {
+ fDescriptionLabel.setEnabled(enabled);
+ fDescription.setEnabled(enabled);
+ fValueLabel.setEnabled(enabled);
+ fValue.setEnabled(enabled);
+ if(!enabled) {
+ fValue.setText("");
+ fDescription.setText("");
+ fValueLabel.setText(valueLabelPrefix);
+ }
+ }
+
+ private String getValueLabel(Property attribute) {
+ String label = valueLabelPrefix;
+ if(attribute.getDefault() != null) {
+ return label + " (Default = " + attribute.getDefault() + ")";
+ }
+ return label;
+ }
+
+ // TODO(?): need a generic utility function for getting all elements obeying a
+ // certain criteria from a model
+ void getInstances(EList<InstanceSpecification> instanceList) {
+ Package deploymentPlans = Utils.getRoot(m_model, "DeploymentPlans");
+ String featureCandidateName = null;
+ for(PackageableElement deploymentPlan : deploymentPlans
+ .getPackagedElements()) {
+ if(deploymentPlan instanceof Package) {
+ for(PackageableElement instance : ((Package)deploymentPlan).getPackagedElements()) {
+ if(instance instanceof InstanceSpecification) {
+ InstanceSpecification candidate = (InstanceSpecification)instance;
+ if(m_feature instanceof Property) {
+ for(Slot slot : candidate.getSlots()) {
+ if(slot.getDefiningFeature() == m_feature) {
+ instanceList
+ .add(DepUtils.getInstance(slot));
+ }
+ }
+ } else if(m_feature instanceof Connector) {
+ // Connector cannot be found directly, since there is no slot in containing composite (defining
+ // feature is a structural-feature, not a feature): find via name.
+ Element owner = m_feature.getOwner();
+ if(DepUtils.getImplementation(candidate) == owner) {
+ // instance is for owner of feature: examine name
+ featureCandidateName = candidate.getName() + "." + m_feature.getName();
+ }
+ else if(featureCandidateName != null) {
+ if(featureCandidateName.equals(candidate.getName())) {
+ instanceList.add(candidate);
+ }
+ }
+ } else if(DepUtils.getImplementation(candidate) == m_component) {
+ instanceList.add(candidate);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private EList<Property> getConfigAttributes(Classifier component) {
+ EList<Property> list = new BasicEList<Property>();
+// // add properties of component
+// list.addAll(ConfigUtils.getConfigAttributes(component));
+// // now add properties of container rules
+// // TODO: is it possible that multiple container extensions of the same
+// // type exist, and if yes, how do we configure these?
+// if(component instanceof Class) {
+// EList<ContainerRule> rules = Utils.getRules((Class)component);
+// if(rules != null) {
+// for(ContainerRule aRule : rules) {
+// // (many, in case of a composite rule)
+// try {
+// list.addAll(ConfigUtils.getConfigAttributes(aRule));
+// } catch (TransformationException e) {
+// }
+// }
+// }
+// }
+ return list;
+ }
+
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/Description.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/Description.java
new file mode 100644
index 00000000000..f3f5e8bb262
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/Description.java
@@ -0,0 +1,75 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment.dialog;
+
+import org.eclipse.uml2.uml.Comment;
+import org.eclipse.uml2.uml.Element;
+
+public class Description {
+
+ /**
+ * Return a description of an element. By default search comments that are
+ * owned by this elements owner (e.g. the class, if we search for a description of a property or the owning package,
+ * if we search for a description of a class)
+ *
+ * @param element
+ * the element for which to obtain a description
+ * @return the description of the element
+ */
+ public static String getDescription(Element element) {
+ return getDescription(element.getOwner(), element);
+ }
+
+ /**
+ * Convenience function: Return a description of an element. It will delegate to
+ * default getDescription, but returns a user specified text, if a description is
+ * not available in the model.
+ * @param element
+ * @param unavailable The text that is return, if no description is available
+ * @return
+ */
+ public static String getDescription(Element element, String unavailable) {
+ String description = getDescription(element);
+ if (description != null) {
+ return description;
+ }
+ else {
+ return unavailable;
+ }
+ }
+ /**
+ * Return a description or implementation description of an element, i.e. the
+ * first owned comment that annotated the passed element
+ *
+ * @param the owner of the comment
+ * the element for which to obtain a description
+ * @param annotated element
+ * the element for which to obtain a description
+ * @return the description of the element
+ */
+ public static String getDescription(Element owner, Element annotatedElement) {
+ if (owner == null) {
+ return null;
+ }
+ // loop over all owned comments, check those that begins with
+ // "description"
+ for(Comment comment : owner.getOwnedComments()) {
+ // identify "right" comment via annotated element ref (to a specific
+ // class of the BasicCalls library) instead?
+ if(comment.getAnnotatedElements().contains(annotatedElement)) {
+ return comment.getBody();
+ }
+
+ }
+ return "not available";
+ }
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/InstanceLabelProvider.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/InstanceLabelProvider.java
new file mode 100644
index 00000000000..31ea24cbe8c
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/dialog/InstanceLabelProvider.java
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment.dialog;
+
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+
+public class InstanceLabelProvider extends LabelProvider {
+
+ public String getText(Object element) {
+ if (element instanceof NamedElement) {
+ String instanceName = ((NamedElement)element).getName();
+ Element owner = ((Element) element).getOwner();
+ if (owner instanceof NamedElement) {
+ return "Plan " + ((NamedElement) owner).getName() + ": " + instanceName;
+ }
+ else {
+ return instanceName;
+ }
+ }
+ else {
+ return "not a named element";
+ }
+ }
+};
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/AllocateHandler.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/AllocateHandler.java
new file mode 100644
index 00000000000..164cebc41cc
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/AllocateHandler.java
@@ -0,0 +1,89 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.robotml.deployment.handlers;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.papyrus.RobotML.DeploymentPlan;
+import org.eclipse.papyrus.robotml.deployment.CommandSupport;
+import org.eclipse.papyrus.robotml.deployment.DepUtils;
+import org.eclipse.papyrus.robotml.deployment.RunnableWithResult;
+import org.eclipse.papyrus.robotml.deployment.StUtils;
+import org.eclipse.papyrus.robotml.deployment.dialog.AllocationDialog;
+
+/**
+ * Implementation class for ClassAction action
+ */
+public class AllocateHandler extends CmdHandler {
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled() {
+ updateSelectedEObject();
+ EObject selectedObj = getSelectedEObject();
+ if(selectedObj instanceof Package) {
+ return (StUtils.isApplied((Package)selectedObj, DeploymentPlan.class));
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object execute(ExecutionEvent event) {
+ if(!(getSelectedEObject() instanceof Package)) {
+ return null;
+ }
+
+ final Package cdp = (Package)getSelectedEObject();
+ final Shell shell = new Shell();
+
+ // com.cea.ec3m.vsl.ParseVSL.test();
+ if(DepUtils.getMainInstance(cdp) == null) {
+ MessageDialog.openInformation(shell, "Error",
+ "Deployment plan has no main instance (check stereotype attribute mainInstance)");
+ return null;
+ }
+
+ // 1. select possible connectors according to port types
+ // (only show compatible connectors check-box?)
+ // 2. select implementation group according to connector type
+
+ // container dialog: either extension, rule or interceptor
+ // howto select? which? (and howto add/remove?) - Std - dialog is good?
+ CommandSupport.exec("Instance allocation", new RunnableWithResult() {
+
+ public CommandResult run() {
+ AllocationDialog allocDialog =
+ new AllocationDialog(shell, cdp);
+ allocDialog.setTitle("Allocate instances");
+ allocDialog.open();
+ if(allocDialog.getReturnCode() == IDialogConstants.OK_ID) {
+ return CommandResult.newOKCommandResult();
+ }
+ else {
+ return CommandResult.newCancelledCommandResult();
+ }
+ }
+ });
+
+ return null;
+ }
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/CmdHandler.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/CmdHandler.java
new file mode 100644
index 00000000000..9ffd9f917eb
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/CmdHandler.java
@@ -0,0 +1,140 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.robotml.deployment.handlers;
+
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.Element;
+
+
+
+
+/**
+ * Handler for the command of customization of the content of the properties view
+ * The same class is used for menu actions within model explorer and diagram
+ */
+public class CmdHandler extends AbstractHandler implements IObjectActionDelegate {
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object execute(ExecutionEvent event) {
+ Display current = Display.getCurrent();
+
+ if(current == null) {
+ current = Display.getDefault();
+ }
+ Shell shell = current.getActiveShell();
+
+ if(shell == null) {
+ // Activator.log.error("impossible to find a shell to open the message dialog", null);
+ }
+
+ return null;
+ }
+
+ /**
+ * Convert each selected elements from the explorator menu, or modeling view
+ * to an EObject and add it to a list
+ *
+ * @return list of EObject
+ */
+ public void updateSelectedEObject() {
+ Vector<EObject> currentSelectedEObjects = new Vector<EObject>();
+
+ // Retrieve selected elements
+ IStructuredSelection selection = (IStructuredSelection)PlatformUI
+ .getWorkbench().getActiveWorkbenchWindow()
+ .getSelectionService().getSelection();
+
+ Iterator<?> eltIt = (Iterator<?>)selection.iterator();
+
+ while(eltIt.hasNext()) {
+ Object currentObject = eltIt.next();
+
+ // If the object is an edit part, try to get semantic bridge
+ if(currentObject instanceof GraphicalEditPart) {
+ GraphicalEditPart editPart = (GraphicalEditPart)currentObject;
+ if(editPart.getModel() instanceof View) {
+ View view = (View)editPart.getModel();
+ if(view.getElement() instanceof Element) {
+ currentObject = (Element)view.getElement();
+ }
+ }
+ }
+
+ // check whether part of model explorer
+ if(currentObject instanceof IAdaptable) {
+ // modisco ModelElementItem supports IAdaptable (cleaner than cast / dependency with modisco)
+ currentObject = ((IAdaptable)currentObject).getAdapter(EObject.class);
+ }
+
+ // If element is a UML Element
+ if(currentObject instanceof Element) {
+ currentSelectedEObjects.add((EObject)currentObject);
+ }
+
+ }
+ selectedEObjects = currentSelectedEObjects;
+ }
+
+ /**
+ * Convert each selected elements from the explorer menu, or modeling view
+ * to an EObject and add it to a list
+ *
+ * @return list of EObject
+ */
+ public EObject getSelectedEObject() {
+ if(selectedEObjects.size() > 0) {
+ return selectedEObjects.get(0);
+ }
+ return null;
+ }
+
+ public List<EObject> getSelectedEObjects() {
+ return selectedEObjects;
+ }
+
+ private List<EObject> selectedEObjects;
+
+ public void run(IAction action) {
+ // method from action-delegate
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ // method from action-delegate
+ updateSelectedEObject(); // required??
+ }
+
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ // TODO Auto-generated method stub
+ }
+} \ No newline at end of file
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/ConfigureInstanceHandler.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/ConfigureInstanceHandler.java
new file mode 100644
index 00000000000..d3828ec55ae
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/ConfigureInstanceHandler.java
@@ -0,0 +1,129 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.robotml.deployment.handlers;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.papyrus.robotml.deployment.CommandSupport;
+import org.eclipse.papyrus.robotml.deployment.RunnableWithResult;
+import org.eclipse.papyrus.robotml.deployment.dialog.ConfigureInstanceDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Connector;
+import org.eclipse.uml2.uml.Feature;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Property;
+
+/**
+ * Implementation class for ClassAction action
+ */
+public class ConfigureInstanceHandler extends CmdHandler {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isEnabled() {
+ updateSelectedEObject();
+ EObject selectedObj = getSelectedEObject();
+ if((selectedObj instanceof Class) ||
+ (selectedObj instanceof Connector) ||
+ (selectedObj instanceof Property) ||
+ (selectedObj instanceof InstanceSpecification)) {
+ return true;
+ }
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ public Object execute(ExecutionEvent event) {
+ if(!(getSelectedEObject() instanceof NamedElement)) {
+ return null;
+ }
+
+ final NamedElement element = (NamedElement)getSelectedEObject();
+ final Shell shell = new Shell();
+
+ // 1. select possible connectors according to port types
+ // (only show compatible connectors check-box?)
+ // 2. select implementation group according to connector type
+
+ if(element instanceof Class) {
+ // container dialog: either extension, rule or interceptor
+ // howto select? which? (and howto add/remove?) - Std - dialog is good?
+ CommandSupport.exec("Configure associated component instance", new RunnableWithResult() {
+
+ public CommandResult run() {
+ ConfigureInstanceDialog configureInstanceDialog =
+ new ConfigureInstanceDialog(shell);
+ if (configureInstanceDialog.init((Class)element)) {
+ configureInstanceDialog.setTitle("Configure instance");
+ configureInstanceDialog.setMessage("Configure instance for component " + element.getName());
+ configureInstanceDialog.open();
+ if(configureInstanceDialog.getReturnCode() == IDialogConstants.OK_ID) {
+ return CommandResult.newOKCommandResult();
+ }
+ }
+ return CommandResult.newCancelledCommandResult();
+ }
+ });
+ } else if(element instanceof Feature) {
+ // container dialog: either extension, rule or interceptor
+ // howto select? which? (and howto add/remove?) - Std - dialog is good?
+ CommandSupport.exec("Configure associated instance", new RunnableWithResult() {
+
+ public CommandResult run() {
+ ConfigureInstanceDialog configureInstanceDialog =
+ new ConfigureInstanceDialog(shell);
+ if (configureInstanceDialog.init((Feature)element)) {
+ configureInstanceDialog.setTitle("Configure instance");
+ configureInstanceDialog.setMessage("Configure instance for property/connector " + element.getName());
+ configureInstanceDialog.open();
+ if(configureInstanceDialog.getReturnCode() == IDialogConstants.OK_ID) {
+ return CommandResult.newOKCommandResult();
+ }
+ }
+ return CommandResult.newCancelledCommandResult();
+ }
+ });
+
+
+ } else if(element instanceof InstanceSpecification) {
+
+ CommandSupport.exec("Configure instance", new RunnableWithResult() {
+
+ public CommandResult run() {
+ ConfigureInstanceDialog configureInstanceDialog =
+ new ConfigureInstanceDialog(shell);
+ if (configureInstanceDialog.init((InstanceSpecification)element)) {
+ configureInstanceDialog.setMessage("Configure instance " + element.getName());
+ configureInstanceDialog.open();
+ if(configureInstanceDialog.getReturnCode() == IDialogConstants.OK_ID) {
+ return CommandResult.newOKCommandResult();
+ }
+ }
+ return CommandResult.newCancelledCommandResult();
+ }
+ });
+ }
+ return null;
+ }
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/CreateDepPlanHandler.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/CreateDepPlanHandler.java
new file mode 100644
index 00000000000..28299bbead0
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/CreateDepPlanHandler.java
@@ -0,0 +1,148 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment.handlers;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.papyrus.RobotML.DeploymentPlan;
+import org.eclipse.papyrus.RobotML.Environment;
+import org.eclipse.papyrus.robotml.deployment.CommandSupport;
+import org.eclipse.papyrus.robotml.deployment.DepCreation;
+import org.eclipse.papyrus.robotml.deployment.DepPlanSync;
+import org.eclipse.papyrus.robotml.deployment.DepPlanUtils;
+import org.eclipse.papyrus.robotml.deployment.RunnableWithResult;
+import org.eclipse.papyrus.robotml.deployment.StUtils;
+import org.eclipse.papyrus.robotml.deployment.TransformationException;
+import org.eclipse.papyrus.robotml.deployment.Utils;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+public class CreateDepPlanHandler extends CmdHandler {
+
+ private final String DepPlanPostfix = "DepPlan";
+
+ private Package depPlans;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isEnabled() {
+ updateSelectedEObject();
+ EObject selectedObj = getSelectedEObject();
+ if((selectedObj instanceof Class) && Utils.isCompImpl((Class)selectedObj) && isEnvironment((Class)selectedObj)) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isEnvironment(Class elt){
+ Environment environment = UMLUtil.getStereotypeApplication(elt, Environment.class);
+ if (environment != null){
+ return true;
+ }
+
+ return false;
+
+ }
+ /**
+ * {@inheritDoc}
+ */
+ public Object execute(ExecutionEvent event) {
+ if(!(getSelectedEObject() instanceof Class)) {
+ return null;
+ }
+ final Class selectedComposite = (Class)getSelectedEObject();
+
+ CommandSupport.exec("Create deployment plans", new Runnable() {
+
+ public void run() {
+ // execute with transaction support
+ depPlans = DepPlanUtils.getDepPlanRoot(selectedComposite);
+ }
+ });
+
+ try {
+ String name = selectedComposite.getName() + DepPlanPostfix;
+ if(depPlans.getMember(name) != null) {
+ Shell shell = new Shell();
+ String dialogButtonLabels[] = new String[]{
+ "Cancel",
+ "Synchronize",
+ "create new (auto number name)"
+ };
+ MessageDialog dialog = new MessageDialog(shell, "What should I do?", null,
+ "Deployment plan with name \"" + name + "\" exists already. You can always synchronize an " +
+ "existing deployment plan via the context menu \"Synchronize derived elements\"",
+ MessageDialog.QUESTION, dialogButtonLabels, 0);
+ int result = dialog.open();
+ if(result == 0) {
+ return null;
+ }
+ else if(result == 1) {
+ NamedElement existing = depPlans.getMember(name);
+ if(existing instanceof Package) {
+ DepPlanSync.syncDepPlan((Package)existing);
+ }
+ else {
+ MessageDialog.openError(shell, "Cannot synchronize", "Element with name \"" + name + "\" exists, but is not a package");
+ }
+ }
+ else {
+ for(int i = 2;; i++) {
+ name = selectedComposite.getName() + DepPlanPostfix + i;
+ if(depPlans.getMember(name) == null)
+ break;
+ }
+
+ }
+ }
+ final String depPlanName = name;
+
+ CommandSupport.exec("Create deployment plan", new RunnableWithResult() {
+
+ public CommandResult run() {
+ Package cdp = depPlans.createNestedPackage(depPlanName);
+ Stereotype st = StUtils.apply(cdp, DeploymentPlan.class);
+ if(st == null) {
+ MessageDialog.openInformation(new Shell(), "Cannot create deployment plan",
+ "Application of stereotype \"RobotML::DeploymentPlan\" failed. Check, if RobotML profile is applied");
+ return CommandResult.newErrorCommandResult("cannot create deployment plan");
+ }
+ try {
+ InstanceSpecification newRootIS =
+ DepCreation.createDepPlan(cdp, selectedComposite, "mainInstance", true);
+ DepCreation.initAutoValues(newRootIS);
+ return CommandResult.newOKCommandResult();
+ }
+ catch (TransformationException e) {
+ MessageDialog.openInformation(new Shell(), "Error during deployment plan creation",
+ e.getMessage());
+ return CommandResult.newErrorCommandResult(e.getMessage());
+ }
+ }
+ });
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/CreatePlatformHandler.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/CreatePlatformHandler.java
new file mode 100644
index 00000000000..3587d92f6ed
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/handlers/CreatePlatformHandler.java
@@ -0,0 +1,97 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment.handlers;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.papyrus.RobotML.Platform;
+import org.eclipse.papyrus.robotml.deployment.CommandSupport;
+import org.eclipse.papyrus.robotml.deployment.DepCreation;
+import org.eclipse.papyrus.robotml.deployment.TransformationException;
+import org.eclipse.papyrus.robotml.deployment.Utils;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+public class CreatePlatformHandler extends CmdHandler {
+
+ private Package platform;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isEnabled() {
+ updateSelectedEObject();
+ EObject selectedObj = getSelectedEObject();
+ if(selectedObj instanceof Class && isPlatform((Class)selectedObj)) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isPlatform(Class elt){
+ Platform platform = UMLUtil.getStereotypeApplication((Class)elt, Platform.class);
+ if (platform != null){
+ return true;
+ }
+ return false;
+
+
+ }
+ /**
+ * {@inheritDoc}
+ */
+ public Object execute(ExecutionEvent event) {
+ if(!(getSelectedEObject() instanceof Class)) {
+ return null;
+ }
+ final Class selectedComposite = (Class)getSelectedEObject();
+
+ CommandSupport.exec("Create platform model", new Runnable() {
+
+ public void run() {
+ // execute with transaction support
+ platform = Utils.getRoot(selectedComposite, "PlatformModel");
+ }
+ });
+
+ final String newPlatform = selectedComposite.getName() + "Platform";
+
+ try {
+ if(platform.getMember(newPlatform) != null) {
+ Shell shell = new Shell();
+ MessageDialog.openInformation(shell, "Error",
+ "Platform definition \"" + newPlatform + "\" exists already");
+ } else {
+ CommandSupport.exec("Create platform definition", new Runnable() {
+
+ public void run() {
+ Package platformPkg = platform.createNestedPackage(newPlatform);
+ try {
+ DepCreation.createPlatformInstances(platformPkg, selectedComposite, null);
+ }
+ catch (TransformationException e) {
+ System.err.println(e);
+ }
+ }
+ });
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/listener/CopyListener.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/listener/CopyListener.java
new file mode 100644
index 00000000000..70926fbcf3b
--- /dev/null
+++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.deployment/src/org/eclipse/papyrus/robotml/deployment/listener/CopyListener.java
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.robotml.deployment.listener;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.robotml.deployment.Copy;
+
+/**
+ * Interface for listeners that are notified for the addition of a classifier
+ * via copy
+ *
+ * @see com.cea.ec3m.gentools.core.transformations.Copy
+ */
+public interface CopyListener {
+
+ /**
+ * Is called for each EObject that is copied. If it returns null, the
+ * indicated object should not be copied. If it returns a different object
+ * than the passed EObject, this object is used (the returned object of the
+ * first listener is used).
+ *
+ * @param sourceEObj
+ * the added classifier
+ */
+ public EObject copyEObject(Copy copy, EObject sourceEObj);
+}

Back to the top