Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.classpath7
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.project28
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.svnignore1
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/META-INF/MANIFEST.MF22
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/about.html28
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/build.properties5
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/plugin.xml6
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/schema/profileDiagram.exsd143
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/Activator.java65
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/controller/ProfileDiagramController.java208
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/dnd/ProfileDragDropEditPolicy.java153
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/dnd/ProfileDropTargetListener.java42
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/parsers/ResourceEObjectParser.java152
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/parsers/ResourceEObjectParserProvider.java71
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/utils/OCLUtils.java67
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/utils/StereotypeUtils.java91
17 files changed, 1097 insertions, 0 deletions
diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.classpath b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.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/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.project b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.project
new file mode 100644
index 00000000000..4ed4e112799
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.diagramprofile</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/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.settings/org.eclipse.jdt.core.prefs b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..60cc9b00ecc
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Tue Sep 22 09:17:03 CEST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.svnignore b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.svnignore
new file mode 100644
index 00000000000..c5e82d74585
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/.svnignore
@@ -0,0 +1 @@
+bin \ No newline at end of file
diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/META-INF/MANIFEST.MF b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..812e80d5a67
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/META-INF/MANIFEST.MF
@@ -0,0 +1,22 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Profile management Plugin
+Bundle-SymbolicName: org.eclipse.papyrus.diagramprofile;singleton:=true
+Bundle-Version: 0.7.0.vqualifier
+Bundle-Activator: org.eclipse.papyrus.diagramprofile.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.uml2.uml,
+ org.eclipse.papyrus.core,
+ org.eclipse.ocl.ecore,
+ org.eclipse.papyrus.resource,
+ org.eclipse.gmf.runtime.common.ui.services.dnd;visibility:=reexport,
+ org.eclipse.papyrus.diagram.common;visibility:=reexport
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Export-Package: org.eclipse.papyrus.diagramprofile,
+ org.eclipse.papyrus.diagramprofile.controller,
+ org.eclipse.papyrus.diagramprofile.dnd,
+ org.eclipse.papyrus.diagramprofile.parsers,
+ org.eclipse.papyrus.diagramprofile.utils
+Bundle-Vendor: Eclipse.org
diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/about.html b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/about.html
new file mode 100644
index 00000000000..50d9eae0154
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/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>December 15, 2009</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> \ No newline at end of file
diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/build.properties b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/build.properties
new file mode 100644
index 00000000000..6f20375d6c7
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/plugin.xml b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/plugin.xml
new file mode 100644
index 00000000000..edd1cf05707
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/plugin.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension-point id="profileDiagram" name="Profile Diagram" schema="schema/profileDiagram.exsd"/>
+
+</plugin>
diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/schema/profileDiagram.exsd b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/schema/profileDiagram.exsd
new file mode 100644
index 00000000000..fe9bc8bdbcf
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/schema/profileDiagram.exsd
@@ -0,0 +1,143 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.papyrus.diagramprofile" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.papyrus.diagramprofile" id="profileDiagram" name="Profile Diagram"/>
+ </appinfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <element ref="profileDiagram"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="profileDiagram">
+ <complexType>
+ <attribute name="classeCandidatesForNewDiagram" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.emf.ecore.EClass"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="diagramName" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="profileToMatchName" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="icon" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="resource"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="creationCommand" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.papyrus.core.extension.commands.ICreationCommand"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="commandId" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/Activator.java b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/Activator.java
new file mode 100644
index 00000000000..b34be6a4054
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/Activator.java
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * 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:
+ * Tristan Faure (Atos Origin) tristan.faure@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.diagramprofile;
+
+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.diagramprofile";
+
+ // 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/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/controller/ProfileDiagramController.java b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/controller/ProfileDiagramController.java
new file mode 100644
index 00000000000..78afee7152c
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/controller/ProfileDiagramController.java
@@ -0,0 +1,208 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * 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:
+ * Tristan Faure (Atos Origin) tristan.faure@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.diagramprofile.controller;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.InvalidRegistryObjectException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.papyrus.core.editor.BackboneException;
+import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor;
+import org.eclipse.papyrus.core.extension.commands.ICreationCommand;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.PackageableElement;
+import org.eclipse.uml2.uml.Profile;
+import org.osgi.framework.Bundle;
+
+public class ProfileDiagramController {
+
+ private static final String ATTR_ICON = "icon";
+
+ private static final String ATTR_DIAGRAM_NAME = "diagramName";
+
+ private static final String ATTR_CLASSES_CANDIDATES_FOR_NEW_DIAGRAM = "classeCandidatesForNewDiagram";
+
+ private static final String ATTR_PROFILE_AVAILABLE = "profileToMatchName";
+
+ private static final String ATTR_CREATION_COMMAND = "creationCommand";
+
+ private static final String ATTR_COMMAND_ID = "commandId";
+
+ private static String extension_point_diagram_profile = "org.eclipse.papyrus.diagramprofile.profileDiagram";
+
+ private Collection<CreationCommandDescriptor> descriptors = null;
+
+ public Collection<CreationCommandDescriptor> getDiagramDescriptors(PackageableElement packageableElement) {
+ if (descriptors == null) {
+ descriptors = initDescriptors();
+ }
+ Collection<CreationCommandDescriptor> result = new LinkedList<CreationCommandDescriptor>(descriptors);
+ filter(result, packageableElement.getClass());
+ filterDependingOnProfile(result, packageableElement);
+ return result;
+ }
+
+ private void filterDependingOnProfile(Collection<CreationCommandDescriptor> result, PackageableElement context) {
+ for (Iterator<CreationCommandDescriptor> i = result.iterator(); i.hasNext();) {
+ CreationCommandDescriptor crea = i.next();
+ if (crea instanceof ProfileCreationCommandDescriptor) {
+ ProfileCreationCommandDescriptor proCre = (ProfileCreationCommandDescriptor) crea;
+ Package aPackage = null;
+ if (context instanceof Package) {
+ aPackage = (Package) context;
+ } else {
+ aPackage = context.getNearestPackage();
+ }
+ List<Profile> allProfiles = aPackage.getAllAppliedProfiles();
+ boolean keep = false;
+ for (Profile p : allProfiles) {
+ keep |= (p.getName() != null && p.getName().equals(proCre.getToMatch()));
+ }
+ if (!keep) {
+ i.remove();
+ }
+ }
+ }
+ }
+
+ private void filter(Collection<CreationCommandDescriptor> result, Class<? extends PackageableElement> class1) {
+ for (Iterator<CreationCommandDescriptor> i = result.iterator(); i.hasNext();) {
+ CreationCommandDescriptor crea = i.next();
+ if (crea instanceof ProfileCreationCommandDescriptor) {
+ ProfileCreationCommandDescriptor proCre = (ProfileCreationCommandDescriptor) crea;
+ if (!proCre.getTheClassApplicable().isAssignableFrom(class1)) {
+ i.remove();
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private Collection<CreationCommandDescriptor> initDescriptors() {
+ Collection<CreationCommandDescriptor> tmpDescriptors = new LinkedList<CreationCommandDescriptor>();
+ IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(
+ extension_point_diagram_profile);
+ for (IConfigurationElement e : elements) {
+ try {
+ Bundle bundle = Platform.getBundle(e.getContributor().getName());
+ Class<? extends EClass> classApplicable = bundle.loadClass(e
+ .getAttribute(ATTR_CLASSES_CANDIDATES_FOR_NEW_DIAGRAM));
+ String profileURi = e.getAttribute(ATTR_PROFILE_AVAILABLE);
+ String diagramName = e.getAttribute(ATTR_DIAGRAM_NAME);
+ String icon = e.getAttribute(ATTR_ICON);
+ ICreationCommand command = (ICreationCommand) e.createExecutableExtension(ATTR_CREATION_COMMAND);
+ String commandId = e.getAttribute(ATTR_COMMAND_ID);
+ // IContextChecker checker = (IContextChecker) e
+ // .createExecutableExtension(ATTR_PROFILE_AVAILABLE);
+ ProfileCreationCommandDescriptor desc = new ProfileCreationCommandDescriptor(classApplicable,
+ profileURi, command, commandId);
+ if (icon != null && icon.length() > 0) {
+ try {
+ final Image image = new Image(Display.getDefault(), bundle.getResource(icon).openStream());
+ ImageDescriptor imageD = new ImageDescriptor() {
+
+ @Override
+ public ImageData getImageData() {
+ return image.getImageData();
+ }
+ };
+ desc.setImageDescriptor(imageD);
+ } catch (IOException e1) {
+ }
+ }
+ desc.setLabel(diagramName);
+ tmpDescriptors.add(desc);
+ } catch (InvalidRegistryObjectException e1) {
+ e1.printStackTrace();
+ } catch (ClassNotFoundException e1) {
+ e1.printStackTrace();
+ } catch (CoreException e1) {
+ e1.printStackTrace();
+ }
+ }
+ return tmpDescriptors;
+ }
+
+ private class ProfileCreationCommandDescriptor extends CreationCommandDescriptor {
+
+ private Class<? extends EClass> theClassApplicable;
+
+ private String toMatch;
+
+ private ICreationCommand command;
+
+ private String commandIdToCreateDiagram;
+
+ public ProfileCreationCommandDescriptor(Class<? extends EClass> classApplicable, String profileToMatch,
+ ICreationCommand comm, String commandIdToCreateDiagram) {
+ theClassApplicable = classApplicable;
+ toMatch = profileToMatch;
+ this.command = comm;
+ this.commandIdToCreateDiagram = commandIdToCreateDiagram;
+ }
+
+ @SuppressWarnings("unused")
+ public void setTheClassApplicable(Class<? extends EClass> theClassApplicable) {
+ this.theClassApplicable = theClassApplicable;
+ }
+
+ public Class<? extends EClass> getTheClassApplicable() {
+ return theClassApplicable;
+ }
+
+ @SuppressWarnings("unused")
+ public void setToMatch(String toMatch) {
+ this.toMatch = toMatch;
+ }
+
+ public String getToMatch() {
+ return toMatch;
+ }
+
+ public void setLabel(String lab) {
+ label = lab;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setImageDescriptor(ImageDescriptor imageD) {
+ icon = imageD;
+ }
+
+ @Override
+ protected ICreationCommand getCommand() throws BackboneException {
+ return command;
+ }
+
+ @Override
+ public String getCommandId() {
+ return commandIdToCreateDiagram;
+ }
+
+ }
+
+}
diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/dnd/ProfileDragDropEditPolicy.java b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/dnd/ProfileDragDropEditPolicy.java
new file mode 100644
index 00000000000..dcd3f42b8b6
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/dnd/ProfileDragDropEditPolicy.java
@@ -0,0 +1,153 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * 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:
+ * Tristan Faure (Atos Origin) tristan.faure@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.diagramprofile.dnd;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.diagram.common.editpolicies.CommonDiagramDragDropEditPolicy;
+import org.eclipse.papyrus.diagram.common.helper.ILinkMappingHelper;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Package;
+
+public abstract class ProfileDragDropEditPolicy extends CommonDiagramDragDropEditPolicy {
+
+ public ProfileDragDropEditPolicy() {
+ super(new ILinkMappingHelper() {
+
+ public Collection<?> getTarget(Element link) {
+ return Collections.EMPTY_LIST;
+ }
+
+ public Collection<?> getSource(Element link) {
+ return Collections.EMPTY_LIST;
+ }
+ });
+ }
+
+ public ProfileDragDropEditPolicy(ILinkMappingHelper helper) {
+ super(helper);
+ }
+
+ @Override
+ public int getLinkWithClassVisualID(EObject domainElement) {
+ return 0;
+ }
+
+ public EObject getApplication(EObject domainElement) {
+ if (getStereotypeAvailable() != null && domainElement instanceof Element) {
+ Element element = (Element) domainElement;
+ List<EObject> applications = element.getStereotypeApplications();
+ for (EObject e : applications) {
+ if (getStereotypeAvailable().equals(e.eClass())) {
+ return e;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public int getNodeVisualID(View containerView, EObject domainElement) {
+ if (domainElement instanceof Element) {
+ EObject e = getApplication(domainElement);
+ if (e != null) {
+ return getNodeVisualID();
+ }
+ }
+ return -1;
+ }
+
+ @Override
+ public abstract IElementType getUMLElementType(int elementID);
+
+ @Override
+ public Command getDropObjectsCommand(DropObjectsRequest dropRequest) {
+ // Create a view request from the drop request and then forward getting
+ // the command for that.
+ CompositeCommand cc = new CompositeCommand("Drop");
+ List viewDescriptors = new ArrayList();
+ Iterator iter = dropRequest.getObjects().iterator();
+ if (dropRequest.getObjects().size() > 0 && dropRequest.getObjects().get(0) instanceof String) {
+ return getDropFileCommand(dropRequest);
+ }
+ Point location = dropRequest.getLocation().getCopy();
+ ((GraphicalEditPart) getHost()).getContentPane().translateToRelative(location);
+ ((GraphicalEditPart) getHost()).getContentPane().translateFromParent(location);
+ location.translate(((GraphicalEditPart) getHost()).getContentPane().getClientArea().getLocation().getNegated());
+ while (iter.hasNext()) {
+ EObject next = (EObject) iter.next();
+ EObject droppedObject = getApplication(next);
+ int nodeVISUALID = getNodeVisualID(((IGraphicalEditPart) getHost()).getNotationView(), next);
+ // int linkVISUALID = getLinkWithClassVisualID(droppedObject);
+ // if (specificDrop.contains(nodeVISUALID) || specificDrop.contains(linkVISUALID)) {
+ // return getSpecificDropCommand(dropRequest, (Element) droppedObject, nodeVISUALID,
+ // linkVISUALID);
+ // }
+
+ if (nodeVISUALID != -1) {
+ // The element to drop is a node
+ // Retrieve it's expected graphical parent
+ EObject graphicalParent = ((GraphicalEditPart) getHost()).resolveSemanticElement();
+
+ // Restrict the default node creation to the following cases:
+ // . Take the containment relationship into consideration
+ // . Release the constraint when GraphicalParent is a Package (Canvas for most
+ // diagrams)
+ if (graphicalParent instanceof Package) {
+ cc = getDefaultDropNodeCommand(nodeVISUALID, location, droppedObject);
+
+ } else if ((graphicalParent instanceof Element)
+ && ((Element) graphicalParent).getOwnedElements().contains(droppedObject)) {
+ cc = getDefaultDropNodeCommand(nodeVISUALID, location, droppedObject);
+
+ } else {
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ }
+ // Collection sources = get.getSource((Element) droppedObject);
+ // Collection targets = linkmappingHelper.getTarget((Element) droppedObject);
+ // if (sources.size() == 0 || targets.size() == 0) {
+ // return UnexecutableCommand.INSTANCE;
+ // }
+ // binary association
+ // Element source = (Element) sources.toArray()[0];
+ // Element target = (Element) targets.toArray()[0];
+ // cc = dropBinaryLink(cc, source, target, linkVISUALID, dropRequest.getLocation(),
+ // (Element) droppedObject);
+ }
+ return new ICommandProxy(cc);
+ }
+
+ public abstract int getNodeVisualID();
+
+ public abstract EClass getStereotypeAvailable();
+
+}
diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/dnd/ProfileDropTargetListener.java b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/dnd/ProfileDropTargetListener.java
new file mode 100644
index 00000000000..5a7d18f2321
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/dnd/ProfileDropTargetListener.java
@@ -0,0 +1,42 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * 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:
+ * Tristan Faure (Atos Origin) tristan.faure@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.diagramprofile.dnd;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.jface.util.LocalSelectionTransfer;
+import org.eclipse.papyrus.diagram.common.listeners.DropTargetListener;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.dnd.TransferData;
+
+public class ProfileDropTargetListener extends DropTargetListener {
+
+ private final TransactionalEditingDomain domain;
+
+ public ProfileDropTargetListener(EditPartViewer viewer, Transfer xfer, TransactionalEditingDomain domain) {
+ super(viewer, xfer);
+ this.domain = domain;
+ }
+
+ @Override
+ protected Object getJavaObject(TransferData data) {
+ return LocalSelectionTransfer.getTransfer().nativeToJava(data);
+ }
+
+ @Override
+ protected TransactionalEditingDomain getTransactionalEditingDomain() {
+ return domain;
+ }
+
+}
diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/parsers/ResourceEObjectParser.java b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/parsers/ResourceEObjectParser.java
new file mode 100644
index 00000000000..a3b45239129
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/parsers/ResourceEObjectParser.java
@@ -0,0 +1,152 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * 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:
+ * Tristan Faure (Atos Origin) tristan.faure@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.diagramprofile.parsers;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
+import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
+import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
+import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.papyrus.diagramprofile.Activator;
+import org.eclipse.papyrus.resource.ResourceEObject;
+
+public class ResourceEObjectParser implements ISemanticParser {
+
+ private static final Pattern patternForBaseElement = Pattern.compile("base_.*");
+
+ private final EStructuralFeature eStructuralFeature;
+
+ private String oclRule = "";
+
+ public ResourceEObjectParser(String oclRule, EStructuralFeature eStructuralFeature) {
+ this.oclRule = oclRule;
+ this.eStructuralFeature = eStructuralFeature;
+ }
+
+ public IContentAssistProcessor getCompletionProcessor(IAdaptable element) {
+ return null;
+ }
+
+ public String getEditString(IAdaptable element, int flags) {
+ return getString(element);
+ }
+
+ public ICommand getParseCommand(IAdaptable element, String newString, int flags) {
+ ICommand result = null;
+ if (element instanceof EObjectAdapter) {
+ EObjectAdapter adapter = (EObjectAdapter) element;
+ if (adapter.getRealObject() instanceof EObject) {
+ Object runOcl = getEobjectFromOCLRUle(element);
+ if (runOcl instanceof EObject) {
+ EObject eobject = (EObject) runOcl;
+ result = new SetValueCommand(new SetRequest(eobject, eStructuralFeature, newString));
+ }
+ }
+ }
+ return result;
+ }
+
+ public String getPrintString(IAdaptable element, int flags) {
+ return getString(element);
+ }
+
+ private Object getEobjectFromOCLRUle(IAdaptable element) {
+ Object result = null;
+ if (element instanceof EObjectAdapter) {
+ EObjectAdapter adapter = (EObjectAdapter) element;
+ if (adapter.getRealObject() instanceof ResourceEObject) {
+ ResourceEObject rEobject = (ResourceEObject) adapter.getRealObject();
+ result = org.eclipse.papyrus.diagramprofile.utils.OCLUtils.runOclRule(oclRule, rEobject);
+ }
+ }
+ return result;
+ }
+
+ private String getString(IAdaptable element) {
+ Object result = getEobjectFromOCLRUle(element);
+ if (result != null && result instanceof EObject) {
+ Object object = ((EObject) result).eGet(eStructuralFeature);
+ return object == null ? "" : object.toString();
+ }
+ return "";
+ }
+
+ private EObject getBaseElement(ResourceEObject rEobject) {
+ for (EStructuralFeature f : rEobject.eClass().getEAllStructuralFeatures()) {
+ if (patternForBaseElement.matcher(f.getName()).matches()) {
+ Object result = rEobject.eGet(f);
+ if (result != null && result instanceof EObject) {
+ return (EObject) result;
+ }
+ }
+ }
+ return null;
+ }
+
+ public boolean isAffectingEvent(Object event, int flags) {
+ return getEStructuralFeature(event).equals(eStructuralFeature);
+ }
+
+ public IParserEditStatus isValidEditString(IAdaptable element, String editString) {
+ if (element instanceof EObjectAdapter) {
+ EObjectAdapter eobjectAdapter = (EObjectAdapter) element;
+ if (eobjectAdapter.getRealObject() instanceof ResourceEObject) {
+ return new ParserEditStatus(Status.OK, Activator.PLUGIN_ID, ParserEditStatus.EDITABLE, "ok", null);
+ }
+ }
+ return new ParserEditStatus(Status.ERROR, Activator.PLUGIN_ID, ParserEditStatus.EDITABLE, "error", null);
+ }
+
+ /**
+ * Get the EStructuralFeature of the given notification
+ *
+ * @param notification
+ * the notification
+ * @return the EStructuralFeature
+ */
+ protected EStructuralFeature getEStructuralFeature(Object notification) {
+ EStructuralFeature featureImpl = null;
+ if (notification instanceof Notification) {
+ Object feature = ((Notification) notification).getFeature();
+ if (feature instanceof EStructuralFeature) {
+ featureImpl = (EStructuralFeature) feature;
+ }
+ }
+ return featureImpl;
+ }
+
+ public boolean areSemanticElementsAffected(EObject listener, Object notification) {
+ return true;
+ }
+
+ public List getSemanticElementsBeingParsed(EObject element) {
+ List result = new ArrayList();
+ result.add(element);
+ result.add(org.eclipse.papyrus.diagramprofile.utils.OCLUtils.runOclRule(oclRule, element));
+ return result;
+ }
+
+}
diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/parsers/ResourceEObjectParserProvider.java b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/parsers/ResourceEObjectParserProvider.java
new file mode 100644
index 00000000000..e655fed420a
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/parsers/ResourceEObjectParserProvider.java
@@ -0,0 +1,71 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * 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:
+ * Tristan Faure (Atos Origin) tristan.faure@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.diagramprofile.parsers;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.common.ui.services.parser.GetParserOperation;
+import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
+import org.eclipse.gmf.runtime.common.ui.services.parser.IParserProvider;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.papyrus.resource.ResourcePackage;
+
+public abstract class ResourceEObjectParserProvider extends AbstractProvider implements IParserProvider {
+
+ //private IProviderChangeListener myListener;
+
+ private ResourceEObjectParser resourceEObjectParser;
+
+ /**
+ * returns the label from the current eobject to access base element please do self.base_...
+ *
+ * @return
+ */
+ public abstract String getOclRule();
+
+ /**
+ * @return the target type to determine if the operation can be performed
+ */
+ public abstract String getTargetType();
+
+ /**
+ * @return the structural feature to display and edit
+ */
+ public abstract EStructuralFeature getEStructuralFeatureFromOCLResult();
+
+ /**
+ * @see org.eclipse.gmf.runtime.common.ui.services.parser.IParserProvider#getParser(org.eclipse.core.runtime.IAdaptable)
+ */
+ public IParser getParser(IAdaptable hint) {
+ resourceEObjectParser = new ResourceEObjectParser(getOclRule(), getEStructuralFeatureFromOCLResult());
+ return resourceEObjectParser;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.common.core.service.IProvider#provides(org.eclipse.gmf.runtime.common.core.service.IOperation)
+ */
+ public boolean provides(IOperation operation) {
+ if (operation instanceof GetParserOperation) {
+ GetParserOperation pOperation = (GetParserOperation) operation;
+ IElementType type = (IElementType) pOperation.getHint().getAdapter(IElementType.class);
+ return getTargetType() != null
+ && getTargetType().equals((String) pOperation.getHint().getAdapter(String.class))
+ && ResourcePackage.Literals.RESOURCE_EOBJECT.isSuperTypeOf(type.getEClass());
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/utils/OCLUtils.java b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/utils/OCLUtils.java
new file mode 100644
index 00000000000..faa3c08a364
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/utils/OCLUtils.java
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * 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:
+ * Tristan Faure (Atos Origin) tristan.faure@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.diagramprofile.utils;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EEnumLiteral;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EOperation;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EParameter;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.ocl.ParserException;
+import org.eclipse.ocl.ecore.CallOperationAction;
+import org.eclipse.ocl.ecore.EcoreEnvironmentFactory;
+import org.eclipse.ocl.ecore.OCL;
+import org.eclipse.ocl.ecore.OCLExpression;
+import org.eclipse.ocl.ecore.SendSignalAction;
+import org.eclipse.ocl.helper.OCLHelper;
+
+public class OCLUtils {
+
+ /**
+ * variables for ocl
+ */
+ private static org.eclipse.ocl.OCL<EPackage, EClassifier, EOperation, EStructuralFeature, EEnumLiteral, EParameter, EObject, CallOperationAction, SendSignalAction, org.eclipse.ocl.ecore.Constraint, EClass, EObject> ocl = OCL
+ .newInstance(new EcoreEnvironmentFactory());
+
+ private static OCLHelper<EClassifier, ?, ?, ?> oclHelper = ocl.createOCLHelper();
+
+ /**
+ * The Ocl rule is evaluated to the eobject argument this methods returns an object and the type
+ * depends of the input rule
+ *
+ * @param oclRule
+ * the ocl rule
+ * @param object
+ * the object
+ *
+ * @return the object, result of the query
+ */
+ public static Object runOclRule(String oclRule, EObject object) {
+ if (object != null) {
+ oclHelper.setContext(object.eClass());
+ }
+ OCLExpression exp;
+ try {
+ exp = (OCLExpression) oclHelper.createQuery(oclRule);
+ Object result = ocl.evaluate(object, exp);
+ return result;
+ } catch (ParserException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/utils/StereotypeUtils.java b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/utils/StereotypeUtils.java
new file mode 100644
index 00000000000..b8cf28d84d9
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/utils/StereotypeUtils.java
@@ -0,0 +1,91 @@
+/*****************************************************************************
+ * Copyright (c) 2009 ATOS ORIGIN.
+ *
+ *
+ * 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:
+ * Tristan FAURE (ATOS ORIGIN) tristan.faure@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.diagramprofile.utils;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * The Class StereotypeUtils.
+ */
+public class StereotypeUtils {
+
+ /**
+ * Get the base Element from a stereotype application.
+ *
+ * @param e
+ * , the stereotype application
+ *
+ * @return the base element
+ */
+ public static EObject getBaseElement(EObject e) {
+ if (e != null) {
+ for (EStructuralFeature f : e.eClass().getEAllStructuralFeatures()) {
+ if (f.getName().startsWith("base_")) {
+ Object b = e.eGet(f);
+ if (b instanceof EObject && b != null) {
+ return (EObject) b;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Checks if is profile applied.
+ *
+ * @param qualifiedName
+ * the qualified name of the profile
+ * @param e
+ * the element
+ *
+ * @return true, if the profile is applied
+ */
+ public static boolean isProfileApplied(String qualifiedName, Element e) {
+ if (qualifiedName == null || e == null || qualifiedName.length() == 0) {
+ return false;
+ }
+ Package p = e.getNearestPackage();
+ for (Profile pr : p.getAllAppliedProfiles()) {
+ if (qualifiedName.equals(pr.getQualifiedName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks if the is stereotype applied.
+ *
+ * @param qualifiedName
+ * the qualified name of the stereotype
+ * @param e
+ * the element to check
+ *
+ * @return true, if the stereotype is applied
+ */
+ public static boolean isStereotypeApplied(String qualifiedName, Element e) {
+ if (qualifiedName == null || e == null || qualifiedName.length() == 0) {
+ return false;
+ }
+ Stereotype s = e.getAppliedStereotype(qualifiedName);
+ return s != null;
+ }
+
+}

Back to the top