Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaud Cuccuru2014-06-19 14:11:52 +0000
committerCamille Letavernier2014-06-20 14:14:47 +0000
commitb2fa931fa3a228cdbe674bd0f687cf3d92551ddf (patch)
tree8323389c1018debb39bb2cc2a0786144abf41047 /extraplugins
parent8d81e2def6f259e4a20b621e612593e414056807 (diff)
downloadorg.eclipse.papyrus-b2fa931fa3a228cdbe674bd0f687cf3d92551ddf.tar.gz
org.eclipse.papyrus-b2fa931fa3a228cdbe674bd0f687cf3d92551ddf.tar.xz
org.eclipse.papyrus-b2fa931fa3a228cdbe674bd0f687cf3d92551ddf.zip
405391: [Moka] Moka shall provide an implementation of the fUML
Execution Model https://bugs.eclipse.org/bugs/show_bug.cgi?id=405391 First commit of Composite Utils. It includes utilities for generating a constructor from a class, through a dialog similar to the JDT "Generate constructor using fields" dialog. It also includes a Factory generator. To be fixed: - Icons are duplicated from other plugins - There is a call to a deprecated method ( Util.getResourceSet(modelElement) )
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/.classpath7
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/.project28
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/META-INF/MANIFEST.MF24
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/build.properties6
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/Activity.gifbin0 -> 1016 bytes
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/Operation.gifbin0 -> 1035 bytes
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/PapyrusLogo16x16.pngbin0 -> 825 bytes
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/moka_icon.pngbin0 -> 539 bytes
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/plugin.xml97
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/Activator.java57
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/AbstractCompositeUtilsHandler.java78
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/GenerateConstructorUsingFieldsHandler.java45
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/GenerateFactoryHandler.java40
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/Utils.java249
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/ui/GenerateConstructorUsingFieldsDialog.java421
16 files changed, 1059 insertions, 0 deletions
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/.classpath b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/.classpath
new file mode 100644
index 00000000000..ad32c83a788
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/.project b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/.project
new file mode 100644
index 00000000000..71dd9012134
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.moka.composites.utils</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/moka/org.eclipse.papyrus.moka.composites.utils/.settings/org.eclipse.jdt.core.prefs b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..c537b63063c
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+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.compliance=1.6
+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/moka/org.eclipse.papyrus.moka.composites.utils/META-INF/MANIFEST.MF b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..2690087d0f4
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/META-INF/MANIFEST.MF
@@ -0,0 +1,24 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Utils
+Bundle-SymbolicName: org.eclipse.papyrus.moka.composites.utils;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.moka.composites.utils.Activator
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.emf;bundle-version="2.6.0",
+ org.eclipse.uml2.uml;bundle-version="4.0.1",
+ org.junit,
+ org.eclipse.emf.transaction;bundle-version="1.4.0",
+ org.eclipse.papyrus.uml.tools.utils;bundle-version="0.9.1",
+ org.eclipse.papyrus.uml.extensionpoints;bundle-version="0.9.1",
+ org.eclipse.papyrus.infra.emf;bundle-version="0.9.1",
+ org.eclipse.papyrus.infra.core.log;bundle-version="0.9.1",
+ org.eclipse.papyrus.moka.fuml;bundle-version="0.10.0",
+ org.eclipse.ui;bundle-version="3.106.0",
+ org.eclipse.gmf.runtime.diagram.ui,
+ org.eclipse.papyrus.uml.icons;bundle-version="1.0.0"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Import-Package: org.eclipse.jdt.internal.ui.actions,
+ org.eclipse.papyrus.moka.composites.Semantics.CompositeStructures.InvocationActions
+
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/build.properties b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/build.properties
new file mode 100644
index 00000000000..b5c529a3c31
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/build.properties
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ build.properties
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/Activity.gif b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/Activity.gif
new file mode 100644
index 00000000000..7d019de7662
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/Activity.gif
Binary files differ
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/Operation.gif b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/Operation.gif
new file mode 100644
index 00000000000..dfb60d981dc
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/Operation.gif
Binary files differ
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/PapyrusLogo16x16.png b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/PapyrusLogo16x16.png
new file mode 100644
index 00000000000..3447e03cbe2
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/PapyrusLogo16x16.png
Binary files differ
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/moka_icon.png b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/moka_icon.png
new file mode 100644
index 00000000000..67391356053
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/icons/moka_icon.png
Binary files differ
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/plugin.xml b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/plugin.xml
new file mode 100644
index 00000000000..4196d87d5ef
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/plugin.xml
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.views.modelexplorer.popup.moka">
+ <menu
+ icon="icons/PapyrusLogo16x16.png"
+ id="org.eclipse.papyrus.views.modelexplorer.popup.moka.utils"
+ label="Modeling Utils">
+ </menu>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.views.modelexplorer.popup.moka.utils">
+ <command
+ commandId="org.eclipse.papyrus.moka.composites.utils.handlers.GenerateFactoryHandlerCommand"
+ icon="icons/Activity.gif"
+ id="org.eclipse.papyrus.moka.composites.utils.handlers.GenerateFactoryHandlerMenu"
+ label="Generate Factory"
+ style="push"
+ tooltip="Generate Factory">
+ <visibleWhen
+ checkEnabled="false">
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.moka.composites.utils.generatorconstructorusingfieldscommand"
+ icon="icons/Operation.gif"
+ label="Generate Constructor Using Fields"
+ style="push"
+ tooltip="Generate Constructor Using Fields">
+ <visibleWhen
+ checkEnabled="false">
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu.moka">
+ <menu
+ icon="icons/PapyrusLogo16x16.png"
+ id="org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu.moka.utils"
+ label="Modeling Utils">
+ </menu>
+ </menuContribution>
+ <menuContribution
+ allPopups="true"
+ locationURI="popup:org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu.moka.utils">
+ <command
+ commandId="org.eclipse.papyrus.moka.composites.utils.handlers.GenerateFactoryHandlerCommand"
+ icon="icons/Activity.gif"
+ id="org.eclipse.papyrus.moka.composites.utils.handlers.GenerateFactoryHandlerMenu"
+ label="Generate Factory"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.moka.composites.utils.generatorconstructorusingfieldscommand"
+ icon="icons/Operation.gif"
+ label="Generate Constructor Using Fields"
+ style="push"
+ tooltip="Generate Constructor Using Fields">
+ <visibleWhen
+ checkEnabled="false">
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ </extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.moka.composites.utils.handlers.GenerateFactoryHandler"
+ description="Generate Factory"
+ id="org.eclipse.papyrus.moka.composites.utils.handlers.GenerateFactoryHandlerCommand"
+ name="Generate Factory">
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.moka.composites.utils.handlers.GenerateConstructorUsingFieldsHandler"
+ description="Generate Constructor Using Fields"
+ id="org.eclipse.papyrus.moka.composites.utils.generatorconstructorusingfieldscommand"
+ name="Generate Constructor Using Fields">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.startup">
+ <startup
+ class="org.eclipse.papyrus.moka.composites.utils.Activator"></startup>
+ </extension>
+
+</plugin>
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/Activator.java b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/Activator.java
new file mode 100644
index 00000000000..0eb25f0c5ff
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/Activator.java
@@ -0,0 +1,57 @@
+package org.eclipse.papyrus.moka.composites.utils;
+
+import org.eclipse.ui.IStartup;
+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 implements IStartup{
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.moka.composites.utils"; //$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;
+ }
+
+ @Override
+ public void earlyStartup() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/AbstractCompositeUtilsHandler.java b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/AbstractCompositeUtilsHandler.java
new file mode 100644
index 00000000000..1754f06b4ee
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/AbstractCompositeUtilsHandler.java
@@ -0,0 +1,78 @@
+package org.eclipse.papyrus.moka.composites.utils.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.uml2.uml.Behavior;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+
+public abstract class AbstractCompositeUtilsHandler extends AbstractHandler {
+
+
+ /**
+ * Moka Modeling Utils menu are enable only if selected object refer as a Class
+ *
+ * (non-Javadoc)
+ * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+ */
+ @Override
+ public boolean isEnabled() {
+ Element selectedElement = Utils.getSelection();
+ if (selectedElement != null) {
+ return selectedElement instanceof Class && !(selectedElement instanceof Behavior);
+ }
+ return false;
+ }
+
+ /**
+ * Return the class associated with the selection object or null whether
+ * no class could have been found
+ *
+ * @param selected
+ * @return Class
+ */
+ protected Class getClassFromSelection(ISelection selected) {
+ if(selected.isEmpty()) {
+ return null;
+ } else {
+ // Every object retrieved from the model explorer is an IAdaptable
+ IAdaptable adaptableObj = (IAdaptable)((IStructuredSelection)selected).getFirstElement();
+ // Get the model object behind the adaptable object
+ EObject modelObj = (EObject)adaptableObj.getAdapter(org.eclipse.emf.ecore.EObject.class);
+ NamedElement nElem = (NamedElement)modelObj;
+ return nElem instanceof Class ? (Class)nElem : null;
+ }
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Class context = null;
+ context = this.getClassFromSelection(HandlerUtil.getCurrentSelection(event));
+ if(context != null) {
+ this.start(context);
+ }
+ return null;
+ }
+
+ /**
+ * Launch the ConstructorBehaviorCreationCompiler
+ * @param myClass which is the class who need to create the constructor
+ *
+ */
+ public void start(Class myClass) {
+ TransactionalEditingDomain domain = (TransactionalEditingDomain)EMFHelper.resolveEditingDomain(myClass) ;
+ RecordingCommand updateCommand = this.getUpdateCommand(myClass, domain);
+ domain.getCommandStack().execute(updateCommand) ;
+ }
+
+ public abstract RecordingCommand getUpdateCommand(Class myClass, TransactionalEditingDomain domain);
+}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/GenerateConstructorUsingFieldsHandler.java b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/GenerateConstructorUsingFieldsHandler.java
new file mode 100644
index 00000000000..58553d626ae
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/GenerateConstructorUsingFieldsHandler.java
@@ -0,0 +1,45 @@
+package org.eclipse.papyrus.moka.composites.utils.handlers;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.moka.composites.utils.ui.GenerateConstructorUsingFieldsDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.Class;
+
+
+public class GenerateConstructorUsingFieldsHandler extends AbstractCompositeUtilsHandler {
+
+ @Override
+ public RecordingCommand getUpdateCommand(Class context, TransactionalEditingDomain domain) {
+ return new GenerateConstructorUsingFieldsCommand(context, domain);
+ }
+
+ /**
+ * A command that generates a Constructor for a Class, from a dialog box.
+ * @see GenerateConstructorUsingFieldsDialog
+ *
+ */
+ protected class GenerateConstructorUsingFieldsCommand extends RecordingCommand {
+
+ protected Class context ;
+
+ public GenerateConstructorUsingFieldsCommand(Class context, TransactionalEditingDomain domain) {
+ super(domain) ;
+ this.context = context ;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor
+ * , org.eclipse.core.runtime.IAdaptable)
+ */
+ @Override
+ protected void doExecute() {
+ GenerateConstructorUsingFieldsDialog dialog = new GenerateConstructorUsingFieldsDialog(Display.getCurrent().getActiveShell(), context);
+ dialog.open();
+ }
+ }
+
+}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/GenerateFactoryHandler.java b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/GenerateFactoryHandler.java
new file mode 100644
index 00000000000..7a215050bde
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/GenerateFactoryHandler.java
@@ -0,0 +1,40 @@
+package org.eclipse.papyrus.moka.composites.utils.handlers;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.uml2.uml.Class;
+
+
+public class GenerateFactoryHandler extends AbstractCompositeUtilsHandler {
+
+ @Override
+ public RecordingCommand getUpdateCommand(Class context, TransactionalEditingDomain domain) {
+ return new GenerateFactoryCommand(context, domain);
+ }
+
+ /**
+ * Command that generate factory for a given class.
+ * @see Utils.getFactory
+ */
+ protected class GenerateFactoryCommand extends RecordingCommand {
+
+ protected Class context ;
+
+ public GenerateFactoryCommand(Class context, TransactionalEditingDomain domain) {
+ super(domain) ;
+ this.context = context ;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor
+ * , org.eclipse.core.runtime.IAdaptable)
+ */
+ @Override
+ protected void doExecute() {
+ Utils.getFactory(context);
+ }
+ }
+}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/Utils.java b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/Utils.java
new file mode 100644
index 00000000000..8db14700343
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/Utils.java
@@ -0,0 +1,249 @@
+package org.eclipse.papyrus.moka.composites.utils.handlers;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.uml.extensionpoints.profile.IRegisteredProfile;
+import org.eclipse.papyrus.uml.extensionpoints.profile.RegisteredProfile;
+import org.eclipse.papyrus.uml.extensionpoints.utils.Util;
+import org.eclipse.papyrus.uml.tools.utils.PackageUtil;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.Activity;
+import org.eclipse.uml2.uml.ActivityParameterNode;
+import org.eclipse.uml2.uml.Behavior;
+import org.eclipse.uml2.uml.CallOperationAction;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.CreateObjectAction;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.InputPin;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.ObjectFlow;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.OutputPin;
+import org.eclipse.uml2.uml.Parameter;
+import org.eclipse.uml2.uml.ParameterDirectionKind;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.StartObjectBehaviorAction;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.UMLPackage;
+
+public class Utils {
+
+ public static Profile standardProfile;
+
+ public static String STANDARD_PROFILE_NAME = "Standard";
+
+
+ /**
+ * Generates (or retrieve) a factory Activity for the given context Class.
+ * A factory Activity consists in a CreateObjectAction for the given context Class,
+ * followed by a CallOperationAction for the default constructor of this class.
+ *
+ * @param context The class for which a Factory is requested
+ * @return A factory Activity for the given context Class
+ */
+ public static Activity getFactory(Class context) {
+
+ // First try to retrieve the factory
+ // Retrieval is based on name.
+ Activity factory = null ;
+ String contextName = context.getName() == null ? "" : context.getName() ;
+ for (Iterator<Behavior> i = context.getOwnedBehaviors().iterator() ; i.hasNext() && factory == null ; ) {
+ Behavior cddFactory = i.next() ;
+ String cddName = cddFactory.getName() == null ? "" : cddFactory.getName() ;
+ if (cddFactory instanceof Activity && cddName.equals(contextName + "_Factory")) {
+ factory = (Activity)cddFactory ;
+ }
+ }
+
+ Parameter returnParam = null ;
+ // if the factory does not exist, then creates it, otherwise "cleans" it
+ if (factory == null) {
+ factory = (Activity)context.createOwnedBehavior(context.getName() + "_Factory", UMLPackage.eINSTANCE.getActivity()) ;
+ returnParam = factory.createOwnedParameter("result", context) ;
+ returnParam.setDirection(ParameterDirectionKind.RETURN_LITERAL) ;
+ }
+ else {
+ factory.getNodes().clear();
+ factory.getEdges().clear();
+ for (Iterator<Parameter> i = factory.getOwnedParameters().iterator() ; i.hasNext() && returnParam == null ; ) {
+ Parameter cddReturn = i.next() ;
+ if (cddReturn.getDirection() == ParameterDirectionKind.RETURN_LITERAL) {
+ returnParam = cddReturn ;
+ }
+ }
+ if (returnParam == null) {
+ returnParam = factory.createOwnedParameter("result", context) ;
+ returnParam.setDirection(ParameterDirectionKind.RETURN_LITERAL) ;
+ }
+ }
+
+ ActivityParameterNode returnParamNode = (ActivityParameterNode)factory.createOwnedNode("resultParameterNode", UMLPackage.eINSTANCE.getActivityParameterNode()) ;
+ returnParamNode.setParameter(returnParam) ;
+ returnParamNode.setType(context) ;
+
+ // Retrieves the default constructor of context
+ Operation defaultConstructor = getDefaultConstructor(context) ;
+
+ CreateObjectAction createObject = (CreateObjectAction)factory.createOwnedNode("createObject", UMLPackage.eINSTANCE.getCreateObjectAction()) ;
+ OutputPin createObjectResultPin = createObject.createResult("result", context) ;
+ createObject.setClassifier(context) ;
+
+ CallOperationAction callConstructor = (CallOperationAction)factory.createOwnedNode("callConstructor", UMLPackage.eINSTANCE.getCallOperationAction()) ;
+ callConstructor.setOperation(defaultConstructor) ;
+ InputPin callConstructorTargetPin = callConstructor.createTarget("target", context) ;
+ OutputPin callConstructorResultPin = callConstructor.createResult("result", context) ;
+
+ ObjectFlow createObjectAction_callConstructor = (ObjectFlow)factory.createEdge("createObjectAction to callConstructor", UMLPackage.eINSTANCE.getObjectFlow()) ;
+ createObjectAction_callConstructor.setSource(createObjectResultPin) ;
+ createObjectAction_callConstructor.setTarget(callConstructorTargetPin) ;
+
+ ObjectFlow toReturnParamNode = (ObjectFlow)factory.createEdge("callConstructor to returnParamNode", UMLPackage.eINSTANCE.getObjectFlow()) ;
+ toReturnParamNode.setTarget(returnParamNode) ;
+ if (! context.isActive()) {
+ toReturnParamNode.setSource(callConstructorResultPin) ;
+ }
+ else {
+ StartObjectBehaviorAction startBehavior = (StartObjectBehaviorAction)factory.createOwnedNode("start classifier behavior", UMLPackage.eINSTANCE.getStartObjectBehaviorAction()) ;
+ InputPin startBehaviorInputPin = startBehavior.createObject("object", context) ;
+ OutputPin startBehaviorResultPin = startBehavior.createResult("result", context) ;
+ toReturnParamNode.setSource(startBehaviorResultPin) ;
+ ObjectFlow callConstructor_startBehavior = (ObjectFlow)factory.createEdge("callConstructor to startBehavior", UMLPackage.eINSTANCE.getObjectFlow()) ;
+ callConstructor_startBehavior.setSource(callConstructorResultPin) ;
+ callConstructor_startBehavior.setTarget(startBehaviorInputPin) ;
+ }
+
+ return factory ;
+ }
+
+ /**
+ * Returns the default constructor of the given UML Class context.
+ * If the default constructor does not exist, it is the generated, with side effects
+ * on the given context Class (i.e., the generated constructor is added to the list of
+ * operations of the given context Class.
+ * A default constructor for a given context Class is a UML Operation with:
+ * - constructor.name == context.name
+ * - a single parameter p such that: p.direction == Return and p.type = context
+ *
+ * @param context A UML Class
+ * @return the default constructor Operation for the given context Class
+ */
+ public static Operation getDefaultConstructor(Class context) {
+ // Returns the default constructor if it exists.
+ // Creates it otherwise.
+ Operation createdOp = null;
+
+ // Find operation with "Create" Stereotype
+ for(int i = 0; i < context.getOwnedOperations().size() && createdOp == null; i++) {
+ Operation cddOperation = context.getOwnedOperations().get(i);
+ for(int j = 0; j < cddOperation.getAppliedStereotypes().size(); j++) {
+ Stereotype createStereotype = cddOperation.getAppliedStereotypes().get(j);
+ if(createStereotype.getName().equals("Create")) {
+ if (cddOperation.getName().equals(context.getName())) {
+ if (cddOperation.getOwnedParameters().size() == 1) {
+ Parameter returnParameter = cddOperation.getOwnedParameters().get(0);
+ if (returnParameter.getDirection().equals(ParameterDirectionKind.RETURN_LITERAL)) {
+ if (returnParameter.getType().getName().equals(context.getName())) {
+ createdOp = cddOperation;
+ }
+ }
+ }
+ }
+
+ }
+ }
+ }
+
+ // No operation with "Create" Stereotype found : => Creation of the operation.
+ if(createdOp == null) {
+ Stereotype appliedStereotype = null;
+ if (!isStandardProfileApplied(context)) {
+ PackageUtil.applyProfile((org.eclipse.uml2.uml.Package)context.getModel(), standardProfile, true);
+ }
+
+ createdOp = UMLFactory.eINSTANCE.createOperation();
+ context.getOwnedOperations().add(createdOp);
+
+
+
+ for(int j = 0; j < createdOp.getApplicableStereotypes().size() && appliedStereotype == null; j++) {
+ Stereotype cddStereotype = createdOp.getApplicableStereotypes().get(j);
+ if(cddStereotype.getName().equals("Create")) {
+ appliedStereotype = cddStereotype;
+ }
+ }
+
+ Parameter result = UMLFactory.eINSTANCE.createParameter();
+ result.setDirection(ParameterDirectionKind.RETURN_LITERAL);
+ result.setType(context);
+ result.setName("return");
+
+ createdOp.setName(context.getName());
+ createdOp.getOwnedParameters().add(result);
+ createdOp.applyStereotype(appliedStereotype);
+ }
+
+ return createdOp;
+ }
+
+ /**
+ * Returns true if the Standard profile is applied on the Model containing the given element
+ *
+ * @param element A UML model element
+ * @return true if the Standard profile is applied on the Model containing the given element
+ */
+ public static boolean isStandardProfileApplied(Element element) {
+ if(standardProfile == null) {
+ IRegisteredProfile registeredProfile = RegisteredProfile.getRegisteredProfile(STANDARD_PROFILE_NAME);
+ URI modelUri = registeredProfile.getUri();
+ Model root = element.getModel();
+ Resource modelResource = Util.getResourceSet(root).getResource(modelUri, true);
+ if(modelResource.getContents().get(0) instanceof Profile) {
+ standardProfile = (Profile)modelResource.getContents().get(0);
+ }
+ }
+ List<Profile> appliedProfiles = element.getModel().getAppliedProfiles();
+ return appliedProfiles.contains(standardProfile);
+ }
+
+ /**
+ * Duplicated from SequoiaAbstractHandler. @author Patrick Tessier (CEA).
+ * getSelected element in the diagram or in hte model explorer
+ * @return Element or null
+ */
+ public static Element getSelection(){
+ Element selectedElement =null;
+ ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
+ ISelection selection = selectionService.getSelection();
+
+ if(selection instanceof IStructuredSelection) {
+ Object selectedobject = ((IStructuredSelection)selection).getFirstElement();
+ if(selectedobject instanceof GraphicalEditPart) {
+ Object graphicalElement = ((GraphicalEditPart)selectedobject).getModel();
+ if((graphicalElement instanceof View) && ((View)graphicalElement).getElement() instanceof org.eclipse.uml2.uml.Element) {
+ selectedElement = (org.eclipse.uml2.uml.Element)((View)graphicalElement).getElement();
+ }
+ }
+ else if(selectedobject instanceof IAdaptable) {
+ EObject selectedEObject = (EObject)((IAdaptable)selectedobject).getAdapter(EObject.class);
+ if (selectedEObject instanceof org.eclipse.uml2.uml.Element){
+ selectedElement=(Element)selectedEObject;
+ }
+ }
+
+ return selectedElement;
+ }
+ return null;
+ }
+
+}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/ui/GenerateConstructorUsingFieldsDialog.java b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/ui/GenerateConstructorUsingFieldsDialog.java
new file mode 100644
index 00000000000..2a904ed0f70
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/ui/GenerateConstructorUsingFieldsDialog.java
@@ -0,0 +1,421 @@
+package org.eclipse.papyrus.moka.composites.utils.ui;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.TrayDialog;
+import org.eclipse.jface.viewers.BaseLabelProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.moka.composites.utils.handlers.Utils;
+import org.eclipse.papyrus.moka.fuml.presentation.FUMLPresentationUtils;
+import org.eclipse.papyrus.uml.tools.utils.PackageUtil;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Parameter;
+import org.eclipse.uml2.uml.ParameterDirectionKind;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.UMLFactory;
+
+public class GenerateConstructorUsingFieldsDialog extends TrayDialog {
+
+ protected Class context;
+
+ protected CheckboxTableViewer viewer;
+
+ private Button btUP;
+
+ private Button btDown;
+
+ private List<Object> checkList = new ArrayList<Object>();
+
+ public GenerateConstructorUsingFieldsDialog(Shell shell, Class context) {
+ super(shell);
+ setShellStyle(SWT.CLOSE | SWT.RESIZE);
+ this.context = context;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ parent.getShell().setText("Generate Constructor Using Fields");
+ parent.getShell().setMinimumSize(500, 500);
+
+ /*
+ * Create composite which contains all controls, composites, & others
+ * stuff.
+ */
+ Composite mainLayout = new Composite(parent, SWT.FILL);
+ mainLayout.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ mainLayout.setLayout(new GridLayout(1, true));
+
+ // Create Label Using Fields
+ Label lblSelectFields = new Label(mainLayout, SWT.NONE);
+ lblSelectFields.setText("Select fields to initialize :");
+
+ /* Create composite which contains compositeCheckBox & compositeButtons */
+ Composite cpCenter = new Composite(mainLayout, SWT.RESIZE);
+
+ // Set Layout and position
+ GridData gdCenter = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gdCenter.widthHint = 514;
+ gdCenter.heightHint = 274;
+ cpCenter.setLayoutData(gdCenter);
+ cpCenter.setLayout(new GridLayout(2, false));
+
+ /* Create left "panel" which contains bindings with check box controls */
+ Composite cpCheckBox = new Composite(cpCenter, SWT.RESIZE | SWT.BORDER);
+ cpCheckBox.setLayout(new GridLayout(1, false));
+
+ // Set Layout and position
+ GridData gdCheckBox = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gdCheckBox.widthHint = 370;
+ cpCheckBox.setLayoutData(gdCheckBox);
+
+ /* Add all attributes on a CheckboxTableViewer */
+ viewer = CheckboxTableViewer.newCheckList(cpCheckBox, SWT.FULL_SELECTION | SWT.FILL);
+ viewer.setContentProvider(new StruturedContentProvider());
+ viewer.setLabelProvider(new TableLabelProvider());
+ viewer.setInput(this.context.getOwnedAttributes());
+
+ // Listen which box is checked.
+ viewer.addCheckStateListener(new ICheckStateListener() {
+
+ @Override
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ if(event.getChecked() == true) {
+ viewer.setChecked(event.getElement(), true);
+ checkList.add(event.getElement());
+ } else {
+ viewer.setChecked(event.getElement(), false);
+ checkList.remove(event.getElement());
+ }
+ }
+ });
+
+ viewer.getTable().addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ List<?> elements = (List<?>)viewer.getInput();
+ Property data = null;
+
+ if(event.item.getData() instanceof Property) {
+ data = (Property)event.item.getData();
+
+ if(data == elements.get(0)) {
+ btUP.setEnabled(false);
+ btDown.setEnabled(true);
+ } else if(data == elements.get(elements.size() - 1)) {
+ btDown.setEnabled(false);
+ btUP.setEnabled(true);
+ } else {
+ btUP.setEnabled(true);
+ btDown.setEnabled(true);
+ }
+ }
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ viewer.setAllChecked(true);
+ Object[] tmp = viewer.getCheckedElements();
+ for(int i = 0; i < tmp.length; i++) {
+ checkList.add(tmp[i]);
+ }
+
+ /* Create right "panel" which contains Select/Deselect Buttons */
+ Composite cpButtons = new Composite(cpCenter, SWT.RESIZE);
+
+ // Set Layout and position
+ GridData gdButtons = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gdButtons.widthHint = 144;
+ cpButtons.setLayoutData(gdButtons);
+ cpButtons.setLayout(new GridLayout(1, false));
+
+ /* Create Select-Deselect buttons */
+ /* Push Button Select All */
+ Button btSelect = new Button(cpButtons, SWT.PUSH);
+ btSelect.setText("Select All");
+
+ // Set size and position
+ GridData gdSelect = new GridData(SWT.FILL, SWT.FILL, false, false);
+ gdSelect.widthHint = 100;
+ gdSelect.heightHint = 25;
+ btSelect.setLayoutData(gdSelect);
+
+ // Add Listener
+ btSelect.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ viewer.setAllChecked(true);
+
+ if(checkList.size() != 0) {
+ checkList.removeAll(checkList);
+ Object[] tmp = viewer.getCheckedElements();
+ for(int i = 0; i < tmp.length; i++) {
+ checkList.add(tmp[i]);
+ }
+ }
+ System.out.println(event.toString());
+ }
+ });
+
+ /* Push Button Deselect All */
+ Button btDeSelect = new Button(cpButtons, SWT.PUSH);
+ btDeSelect.setText("Deselect All");
+
+ // Set size and position
+ GridData gdDeSelect = new GridData(SWT.FILL, SWT.FILL, false, false);
+ gdDeSelect.widthHint = 100;
+ gdDeSelect.heightHint = 25;
+ btDeSelect.setLayoutData(gdDeSelect);
+
+ // Add Listener
+ btDeSelect.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ viewer.setAllChecked(false);
+
+ if(checkList.size() != 0) {
+ checkList.removeAll(checkList);
+ }
+
+ System.out.println(event.toString());
+ }
+ });
+
+ /* Create Up-Down buttons */
+ /* Push Button Up */
+ btUP = new Button(cpButtons, SWT.PUSH);
+ btUP.setText("Up");
+
+ // Set size and position
+ GridData gdUP = new GridData(SWT.FILL, SWT.FILL, false, false);
+ gdUP.widthHint = 100;
+ gdUP.heightHint = 25;
+ btUP.setLayoutData(gdUP);
+ btUP.setEnabled(false);
+
+ btUP.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ viewer.setInput(getElementListUP());
+ System.out.println(event.toString());
+ }
+ });
+
+ /* Push Button Down */
+ btDown = new Button(cpButtons, SWT.PUSH);
+ btDown.setText("Down");
+
+ // Set size and position
+ GridData gdDown = new GridData(SWT.FILL, SWT.FILL, false, false);
+ gdDown.widthHint = 100;
+ gdDown.heightHint = 25;
+ btDown.setLayoutData(gdDown);
+
+ btDown.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ viewer.setInput(getElementListDown());
+ System.out.println(event.toString());
+ }
+ });
+
+ return mainLayout;
+ }
+
+ protected boolean isCreate(Operation operation) {
+ for(int j = 0; j < operation.getAppliedStereotypes().size(); j++) {
+ Stereotype st_tmp = operation.getAppliedStereotypes().get(j);
+ if(st_tmp.getName().equals("Create")) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ static class StruturedContentProvider implements IStructuredContentProvider {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object[] getElements(Object inputElement) {
+ ArrayList<Property> result = new ArrayList<Property>();
+ if(inputElement instanceof List) {
+ result.addAll((Collection<? extends Property>)inputElement);
+ }
+ return result.toArray();
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ }
+
+ static class TableLabelProvider extends BaseLabelProvider implements ITableLabelProvider {
+
+ @Override
+ public Image getColumnImage(Object element, int columnIndex) {
+ if(element instanceof Property) {
+ Property current = (Property)element;
+ switch(columnIndex) {
+ case 0:
+ FUMLPresentationUtils.init(current);
+ Image image = FUMLPresentationUtils.getImage(current);
+ return image;
+ default:
+ return null;
+ }
+ }
+ return null;
+
+ }
+
+ @Override
+ public String getColumnText(Object element, int columnIndex) {
+ if(element instanceof Property) {
+ Property current = (Property)element;
+ switch(columnIndex) {
+ case 0:
+ return current.getName();
+ default:
+ return "";
+ }
+ }
+ return "";
+ }
+
+ }
+
+ protected List<?> getElementListUP() {
+
+ List<?> elements = (List<?>)viewer.getInput();
+ IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+ List<?> element = selection.toList();
+ ArrayList<Object> elementList = new ArrayList<Object>();
+ ArrayList<Object> elementListTMP = new ArrayList<Object>();
+
+ for(int i = 0; i < elements.size(); i++) {
+ if(element.get(0) == elements.get(i)) {
+ elementListTMP.remove(elements.get(i - 1));
+ elementListTMP.add(element.get(0));
+ elementListTMP.add(elements.get(i - 1));
+
+ } else {
+ elementListTMP.add(elements.get(i));
+
+ }
+ }
+
+ elementList.addAll(elementListTMP);
+ return elementList;
+ }
+
+ protected List<?> getElementListDown() {
+
+ List<?> elements = (List<?>)viewer.getInput();
+ IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+ List<?> element = selection.toList();
+ ArrayList<Object> elementList = new ArrayList<Object>();
+ ArrayList<Object> elementListTMP = new ArrayList<Object>();
+
+ for(int i = 0; i < elements.size(); i++) {
+ if(element.get(0) == elements.get(i)) {
+ elementListTMP.add(elements.get(i + 1));
+ elementListTMP.add(element.get(0));
+ i++;
+ } else {
+ elementListTMP.add(elements.get(i));
+ }
+ }
+
+ elementList.addAll(elementListTMP);
+ return elementList;
+ }
+
+ @Override
+ protected void okPressed() {
+ //System.err.println("Ok pressed");
+
+ // Check if the right profile is applied.
+ //List<Profile> appliedProfiles = context.getModel().getAppliedProfiles();
+ //for(int i = 0; i < appliedProfiles.size(); i++) {
+ //System.out.println(appliedProfiles.get(i).getQualifiedName());
+ //}
+
+ if(!Utils.isStandardProfileApplied(context)) {
+ PackageUtil.applyProfile((org.eclipse.uml2.uml.Package)context.getModel(), Utils.standardProfile, true);
+ }
+
+ // Creating operation and method with "Create" stereotype
+ Operation operation = Utils.getDefaultConstructor(context);
+
+ int flagParamOp = 0;
+
+ // Add parameters to instantiate
+ for(int i = 0; i < checkList.size(); i++) {
+ if(checkList.get(i) instanceof Property) {
+ Property prop = (Property)checkList.get(i);
+ Parameter in = UMLFactory.eINSTANCE.createParameter();
+ in.setDirection(ParameterDirectionKind.IN_LITERAL);
+ in.setType(prop.getType());
+ in.setName(prop.getName());
+
+ /* Check if parameter is already exist on the operation. */
+ flagParamOp = 0;
+
+ if(operation.getOwnedParameters().size() <= 1) {
+ operation.getOwnedParameters().add(operation.getOwnedParameters().size() - 1, in);
+ }
+
+ else {
+ for(int j = 0; j < operation.getOwnedParameters().size() && flagParamOp == 0; j++) {
+ Parameter opParameter = operation.getOwnedParameters().get(j);
+ if(!opParameter.getName().equals(in.getName())) {
+ flagParamOp = 0;
+ } else {
+ flagParamOp = -1;
+ }
+ }
+
+ if(flagParamOp == 0) {
+ operation.getOwnedParameters().add(operation.getOwnedParameters().size() - 1, in);
+ }
+ }
+ }
+ }
+
+ super.okPressed();
+ }
+
+}

Back to the top