Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Pascual2015-05-20 13:10:04 +0000
committerPatrick Tessier2018-09-17 12:15:20 +0000
commit9ca049b95b1e92c8f42238971eccdb46235b8518 (patch)
tree34617ca6b132a1abfed0ea17b267c4d1ecf9a836
parent94e436b59cf05281542a305010eda3fbacab7ed8 (diff)
downloadorg.eclipse.papyrus-9ca049b95b1e92c8f42238971eccdb46235b8518.tar.gz
org.eclipse.papyrus-9ca049b95b1e92c8f42238971eccdb46235b8518.tar.xz
org.eclipse.papyrus-9ca049b95b1e92c8f42238971eccdb46235b8518.zip
Bug 447665: [Profiles] Removing profiles definitions causing a profile
definition https://bugs.eclipse.org/bugs/show_bug.cgi?id=447665 - Add Papyrus Listener to tag unversion Profile Conflicts: plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/META-INF/MANIFEST.MF plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/plugin.xml plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/DefineProfileCommand.java plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UndefineProfileCommand.java Change-Id: Ia8c12bf721e93be5efd6381a0d623452988884aa Signed-off-by: Gabriel Pascual <gabriel.pascual@all4tec.net>
-rw-r--r--[-rwxr-xr-x]plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/META-INF/MANIFEST.MF6
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/DefineProfileCommand.java9
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/listener/ProfileDefinitionTagListener.java225
-rwxr-xr-xplugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/plugin.xml9
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/pom.xml2
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF7
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/plugin.xml16
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/pom.xml2
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UndefineProfileCommand.java195
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/decoration/UndefinedProfileDecoration.java137
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/decoration/UndefinedProfileMarker.java247
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/ProfileRedefinition.java86
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/service/IProfileDefinitionService.java44
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/service/ProfileDefinitionService.java155
14 files changed, 1097 insertions, 43 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/META-INF/MANIFEST.MF
index 7a465ad303f..caa64319c48 100755..100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/META-INF/MANIFEST.MF
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/META-INF/MANIFEST.MF
@@ -75,10 +75,12 @@ Require-Bundle: org.eclipse.papyrus.uml.profile;bundle-version="[3.0.0,4.0.0)",
org.eclipse.gef,
org.eclipse.papyrus.extensionpoints.editors;bundle-version="[3.0.0,4.0.0)",
org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="[2.0.0,4.0.0)",
- org.eclipse.papyrus.infra.architecture;bundle-version="[2.0.0,3.0.0)"
+ org.eclipse.papyrus.infra.architecture;bundle-version="[2.0.0,3.0.0)",
+ org.eclipse.papyrus.infra.services.decoration;bundle-version="[2.0.0,3.0.0)",
+ org.eclipse.papyrus.infra.services.markerlistener;bundle-version="[2.0.0,3.0.0)"
Bundle-Vendor: %providerName
Eclipse-LazyStart: true
-Bundle-Version: 3.0.100.qualifier
+Bundle-Version: 3.1.0.qualifier
Bundle-Activator: org.eclipse.papyrus.uml.diagram.profile.part.UMLDiagramEditorPlugin
Bundle-ManifestVersion: 2
Bundle-Description: %pluginDescription
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/DefineProfileCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/DefineProfileCommand.java
index 093abfcf2dc..e635477e288 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/DefineProfileCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/DefineProfileCommand.java
@@ -12,6 +12,7 @@
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
* Christian W. Damus - bug 451613
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 447665
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.profile.custom.commands;
@@ -168,6 +169,7 @@ public class DefineProfileCommand extends AbstractTransactionalCommand {
*/
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ cleanUndefineTag();
List<EPackage> profileDefinitions = defineProfiles(rootProfile, saveConstraint);
@@ -251,4 +253,11 @@ public class DefineProfileCommand extends AbstractTransactionalCommand {
IFile f = WorkspaceSynchronizer.getFile(rootProfile.eResource());
return f != null ? Collections.<IFile> singletonList(f) : Collections.<IFile> emptyList();
}
+
+ /**
+ * Clean undefine tag.
+ */
+ private void cleanUndefineTag() {
+ ProfileRedefinition.removeUndefinedVersion(rootProfile);
+ }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/listener/ProfileDefinitionTagListener.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/listener/ProfileDefinitionTagListener.java
new file mode 100644
index 00000000000..a66d6c0cb1b
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/listener/ProfileDefinitionTagListener.java
@@ -0,0 +1,225 @@
+/*****************************************************************************
+ * Copyright (c) 2018 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:
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.profile.listener;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.papyrus.infra.core.listenerservice.IPapyrusListener;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.NotFoundException;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.services.decoration.DecorationService;
+import org.eclipse.papyrus.uml.tools.Activator;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.papyrus.uml.tools.profile.definition.IPapyrusVersionConstants;
+import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation;
+import org.eclipse.papyrus.uml.tools.service.IProfileDefinitionService;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.resource.UMLResource;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+/**
+ * The purpose of this listener is to tag modifications which doesn't appear in Profile Definition.
+ *
+ * @author Gabriel Pascual
+ * @since 3.1
+ */
+public class ProfileDefinitionTagListener implements IPapyrusListener {
+
+ /** The Constant MODEL_SET_SERVICE_ERROR. */
+ private static final String MODEL_SET_SERVICE_ERROR = "Failed to get Model Set."; //$NON-NLS-1$
+
+ /** The Constant DECORATION_ACTION_ERROR. */
+ private static final String DECORATION_ACTION_ERROR = "Failed to decorate undefined Profile."; //$NON-NLS-1$
+
+ /** The Constant UNDECORATION_ACTION_ERROR. */
+ private static final String UNDECORATION_ACTION_ERROR = "Failed to remove decoration on Profile."; //$NON-NLS-1$
+
+ /** The Constant PAPYRUS_SERVICE_ERROR. */
+ private static final String ROOT_MODEL_ACCESS_ERROR = "Failed to retrieve root element of UML resource"; //$NON-NLS-1$
+
+
+
+ /**
+ * Instantiates a new profile definition tag listener.
+ */
+ public ProfileDefinitionTagListener() {
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.listenerservice.IPapyrusListener#notifyChanged(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ */
+ public void notifyChanged(final Notification notification) {
+
+ // Filter notification
+ int eventType = notification.getEventType();
+ Object notifier = notification.getNotifier();
+
+ if (Notification.RESOLVE != eventType && Notification.REMOVING_ADAPTER != eventType) {
+
+ // Case : an element is modified
+ if (notifier instanceof Element) {
+
+ Resource resource = ((Element) notifier).eResource();
+ if (resource instanceof UMLResource) {
+ EObject rootElement = getRootModel((EObject) notifier);
+
+ if (rootElement instanceof Profile) {
+ // The notification concerns an element of Profile model
+ EAnnotation umlAnnotation = ((Profile) rootElement).getEAnnotation(UMLUtil.UML2_UML_PACKAGE_2_0_NS_URI);
+ if (null != umlAnnotation) {
+ if (!isAlreadyTag(umlAnnotation)) {
+ umlAnnotation.getEAnnotations().add(PapyrusDefinitionAnnotation.UNDEFINED_ANNOTATION.convertToEAnnotation());
+ decorateProfile((Profile) rootElement);
+
+ }
+ }
+
+ }
+ }
+ } else if (Notification.ADD == eventType && notifier instanceof EAnnotation && notification.getNewValue() instanceof EAnnotation) {
+
+ // Case: an Undefined Annotation is added
+ EAnnotation umlAnnotation = (EAnnotation) notifier;
+ EAnnotation undefinedAnnotation = (EAnnotation) notification.getNewValue();
+
+ if (isUndefinedProfileTagAnnotation(umlAnnotation, undefinedAnnotation)) {
+
+ EObject rootElement = getRootModel(umlAnnotation);
+ if (rootElement instanceof Profile) {
+ decorateProfile((Profile) rootElement);
+ }
+
+ }
+
+
+
+ } else if (Notification.REMOVE == eventType && notifier instanceof EAnnotation && notification.getOldValue() instanceof EAnnotation) {
+
+ // Case : an undefined annotation is removed
+ EAnnotation undefinedAnnotation = (EAnnotation) notification.getOldValue();
+ EAnnotation umlAnnotation = (EAnnotation) notifier;
+
+ if (isUndefinedProfileTagAnnotation(umlAnnotation, undefinedAnnotation)) {
+
+ EObject rootElement = getRootModel(umlAnnotation);
+ if (rootElement instanceof Profile) {
+ undecorateProfile((Profile) rootElement);
+ }
+ }
+
+ }
+
+ }
+
+
+
+ }
+
+ /**
+ * Checks if is undefined profile tag annotation.
+ *
+ * @param umlAnnotation
+ * the uml annotation
+ * @param undefinedAnnotation
+ * the undefined annotation
+ * @return true, if is undefined profile tag annotation
+ */
+ private boolean isUndefinedProfileTagAnnotation(final EAnnotation umlAnnotation, final EAnnotation undefinedAnnotation) {
+ Resource resource = umlAnnotation.eResource();
+ PapyrusDefinitionAnnotation parsedAnnotation = PapyrusDefinitionAnnotation.parseEAnnotation(undefinedAnnotation);
+ return IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE.equals(undefinedAnnotation.getSource()) && PapyrusDefinitionAnnotation.UNDEFINED_ANNOTATION.equals(parsedAnnotation) && resource instanceof UMLResource;
+ }
+
+ /**
+ * Gets the root model.
+ *
+ * @param element
+ * the element
+ * @return the root model
+ */
+ private EObject getRootModel(final EObject element) {
+ EObject rootElement = null;
+ try {
+ ModelSet modelSet = ServiceUtilsForEObject.getInstance().getModelSet(element);
+ UmlModel umlModel = (UmlModel) modelSet.getModel(UmlModel.MODEL_ID);
+ rootElement = umlModel.lookupRoot();
+ } catch (ServiceException exception) {
+ Activator.log.error(MODEL_SET_SERVICE_ERROR, exception);
+ } catch (NotFoundException exception) {
+ Activator.log.error(ROOT_MODEL_ACCESS_ERROR, exception);
+ }
+ return rootElement;
+ }
+
+ /**
+ * Undecorate profile.
+ *
+ * @param profile
+ * the profile
+ */
+ private void undecorateProfile(final Profile profile) {
+ try {
+ DecorationService decorationService = ServiceUtilsForEObject.getInstance().getService(DecorationService.class, profile);
+ IProfileDefinitionService definitionService = ServiceUtilsForEObject.getInstance().getService(IProfileDefinitionService.class, profile);
+ decorationService.removeDecoration(definitionService.getMarker(profile).toString());
+ definitionService.disposeMarker(profile);
+ } catch (ServiceException exception) {
+ Activator.log.error(UNDECORATION_ACTION_ERROR, exception);
+ }
+ }
+
+ /**
+ * Decorate profile.
+ *
+ * @param profile
+ * the profile
+ */
+ private void decorateProfile(Profile profile) {
+ try {
+ ServiceUtilsForEObject serviceUtils = ServiceUtilsForEObject.getInstance();
+ DecorationService decorationService = serviceUtils.getService(DecorationService.class, profile);
+ IProfileDefinitionService definitionService = serviceUtils.getService(IProfileDefinitionService.class, profile);
+ decorationService.addDecoration(definitionService.getMarker(profile), profile);
+ } catch (ServiceException exception) {
+ Activator.log.error(DECORATION_ACTION_ERROR, exception);
+ }
+ }
+
+
+ /**
+ * Checks if Profile is already tag.
+ *
+ * @param umlAnnotation
+ * the uml annotation
+ * @return true, if is already tag
+ */
+ private boolean isAlreadyTag(final EAnnotation umlAnnotation) {
+ boolean alreadyTag = !umlAnnotation.getEAnnotations().isEmpty();
+
+ if (alreadyTag) {
+ EAnnotation firstAnnotation = umlAnnotation.getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
+ alreadyTag = null != firstAnnotation;
+ }
+
+ return alreadyTag;
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/plugin.xml
index f8efd494624..d5893b4f545 100755
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/plugin.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/plugin.xml
@@ -581,6 +581,11 @@
target="1.4.0">
</diagramReconciler>
</extension>
-
-
+ <extension
+ point="org.eclipse.papyrus.infra.core.modelListener">
+ <listener
+ name="org.eclipse.papyrus.uml.diagram.profile.profileDefinitionTag"
+ realization="org.eclipse.papyrus.uml.diagram.profile.listener.ProfileDefinitionTagListener">
+ </listener>
+ </extension>
</plugin>
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/pom.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/pom.xml
index ed74eff906c..f6e9f207608 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/pom.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/pom.xml
@@ -7,6 +7,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.uml.diagram.profile</artifactId>
- <version>3.0.100-SNAPSHOT</version>
+ <version>3.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF
index a3733f03bc6..e7ce3964cf0 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF
@@ -3,6 +3,7 @@ Export-Package: org.eclipse.papyrus.uml.tools,
org.eclipse.papyrus.uml.tools.adapters,
org.eclipse.papyrus.uml.tools.commands,
org.eclipse.papyrus.uml.tools.databinding,
+ org.eclipse.papyrus.uml.tools.decoration,
org.eclipse.papyrus.uml.tools.helper,
org.eclipse.papyrus.uml.tools.importsources,
org.eclipse.papyrus.uml.tools.listeners,
@@ -27,10 +28,12 @@ Require-Bundle: org.eclipse.uml2.uml;bundle-version="[5.3.0,6.0.0)";visibility:=
org.eclipse.papyrus.uml.internationalization.utils;bundle-version="[1.0.0,2.0.0)",
org.eclipse.papyrus.uml.internationalization.edit;bundle-version="[1.0.0,2.0.0)",
org.eclipse.papyrus.infra.constraints;bundle-version="[2.0.0,3.0.0)",
- org.eclipse.papyrus.infra.types;bundle-version="[4.0.0,5.0.0)"
+ org.eclipse.papyrus.infra.types;bundle-version="[4.0.0,5.0.0)",
+ org.eclipse.papyrus.infra.services.markerlistener;bundle-version="[2.0.0,3.0.0)",
+ org.eclipse.papyrus.infra.services.decoration;bundle-version="[2.0.0,3.0.0)"
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
-Bundle-Version: 4.0.0.qualifier
+Bundle-Version: 4.1.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-Activator: org.eclipse.papyrus.uml.tools.Activator
Bundle-ManifestVersion: 2
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/plugin.xml b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/plugin.xml
index f4dd9672650..e683a3f2317 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/plugin.xml
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/plugin.xml
@@ -85,6 +85,22 @@
serviceKeyRef="org.eclipse.emf.transaction.TransactionalEditingDomain">
</dependsOn>
</service>
+ <service
+ classname="org.eclipse.papyrus.uml.tools.service.ProfileDefinitionService"
+ id="org.eclipse.papyrus.uml.tools.service.IProfileDefinitionService"
+ priority="1"
+ startKind="startup">
+ <dependsOn
+ serviceKeyRef="org.eclipse.papyrus.infra.core.resource.ModelSet">
+ </dependsOn>
+ </service>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.services.decoration.decorationSpecificFunctions">
+ <client
+ class="org.eclipse.papyrus.uml.tools.decoration.UndefinedProfileDecoration"
+ decorationType="org.eclipse.papyrus.uml.tools.decoration.undefinedprofile">
+ </client>
</extension>
<extension
point="org.eclipse.papyrus.infra.core.language">
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/pom.xml b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/pom.xml
index 245fe585650..0544c78bff3 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/pom.xml
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/pom.xml
@@ -8,7 +8,7 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.uml.tools</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <version>4.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<description>This plugin contributes a set of common tools for UML</description>
</project>
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UndefineProfileCommand.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UndefineProfileCommand.java
new file mode 100644
index 00000000000..af07a8a39b9
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UndefineProfileCommand.java
@@ -0,0 +1,195 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.tools.commands;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.uml.tools.profile.definition.IPapyrusVersionConstants;
+import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+/**
+ * Removed all Profile Definitions of all Profile model.
+ *
+ * @author Gabriel Pascual
+ *
+ */
+public class UndefineProfileCommand extends RecordingCommand {
+
+ /** The Constant DECORATION_PROFILE_SERVICE_ERROR. */
+ private static final String DECORATION_PROFILE_SERVICE_ERROR = "Impossible to display decoration warning for Profile"; //$NON-NLS-1$
+
+ /** The Constant COMMAND_TITLE. */
+ private static final String COMMAND_TITLE = "Undefine Profile";
+
+ /** The profile definition. */
+ private final PapyrusDefinitionAnnotation profileDefinition;
+
+ /** The profiles stack. */
+ private final Deque<Profile> profilesStack;
+
+ /** The root profile. */
+ private final Profile rootProfile;
+
+ /**
+ * Instantiates a new undefine profile command.
+ *
+ * @param editingDomain
+ * the editing domain
+ * @param annotation
+ * the annotation
+ * @param rootProfile
+ * the root profile
+ */
+ public UndefineProfileCommand(final TransactionalEditingDomain editingDomain, final PapyrusDefinitionAnnotation annotation, final Profile rootProfile) {
+ super(editingDomain, COMMAND_TITLE, null);
+ this.rootProfile = rootProfile;
+ this.profileDefinition = annotation;
+ profilesStack = new LinkedList<Profile>(Collections.singleton(rootProfile));
+ }
+
+ /**
+ * Do execute.
+ *
+ * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
+ */
+ @Override
+ protected void doExecute() {
+ EPackage umlDefinition = rootProfile.getDefinition();
+
+ while (!profilesStack.isEmpty()) {
+ handleProfile(profilesStack.pop());
+ }
+
+ handleRemovedProfileDefinition(umlDefinition);
+
+
+ }
+
+ /**
+ * Handle removed profile definition.
+ *
+ * @param umlDefinition
+ * the uml definition
+ */
+ private void handleRemovedProfileDefinition(final EPackage umlDefinition) {
+
+ // Retrieve current Papyrus Version
+ PapyrusDefinitionAnnotation currentDefinition = null;
+
+ if (null != umlDefinition) {
+ currentDefinition = PapyrusDefinitionAnnotation.parseEAnnotation(umlDefinition.getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE));
+ }
+
+ if (null != currentDefinition && profileDefinition.equals(currentDefinition)) {
+
+ // Add UNDEFINED ANNOTATION to Profile
+ EAnnotation umlAnnotation = rootProfile.getEAnnotation(UMLUtil.UML2_UML_PACKAGE_2_0_NS_URI);
+ if (null != umlAnnotation && null == umlAnnotation.getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE)) {
+ umlAnnotation.getEAnnotations().add(PapyrusDefinitionAnnotation.UNDEFINED_ANNOTATION.convertToEAnnotation());
+ }
+
+ }
+
+
+ }
+
+ /**
+ * Handle profile.
+ *
+ * @param profile
+ * the profile
+ */
+ private void handleProfile(final Profile profile) {
+
+ EAnnotation umlAnnotation = profile.getEAnnotation(UMLUtil.UML2_UML_PACKAGE_2_0_NS_URI);
+
+ EPackage profileDefinition = retrieveProfileDefinition(umlAnnotation);
+
+ if (null != profileDefinition) {
+ umlAnnotation.getContents().remove(profileDefinition);
+ }
+
+ pileUpNestedProfiles(profile);
+
+ }
+
+ /**
+ * Retrieve profile definition.
+ *
+ * @param umlAnnotation
+ * the uml annotation
+ * @return the e package
+ */
+ private EPackage retrieveProfileDefinition(final EAnnotation umlAnnotation) {
+ Collection<EPackage> packageAnnotations = EcoreUtil.<EPackage> getObjectsByType(umlAnnotation.getContents(), EcorePackage.Literals.EPACKAGE);
+ Iterator<EPackage> definitionsIterator = packageAnnotations.iterator();
+ EPackage packageDefinition = null;
+ boolean found = false;
+
+ while (!found && definitionsIterator.hasNext()) {
+ packageDefinition = definitionsIterator.next();
+
+ PapyrusDefinitionAnnotation currentDefinition = getPapyrusDefinitionAnnotation(packageDefinition);
+ found = profileDefinition.equals(currentDefinition);
+ }
+
+ return found ? packageDefinition : null;
+ }
+
+ /**
+ * Gets the papyrus definition annotation.
+ *
+ * @param profileDefinition
+ * the profile definition
+ * @return the papyrus definition annotation
+ */
+ private PapyrusDefinitionAnnotation getPapyrusDefinitionAnnotation(final EPackage profileDefinition) {
+ PapyrusDefinitionAnnotation currentDefinition = null;
+
+ EAnnotation profileVersion = profileDefinition.getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
+ if (null != profileDefinition) {
+ currentDefinition = PapyrusDefinitionAnnotation.parseEAnnotation(profileVersion);
+ }
+
+ return currentDefinition;
+ }
+
+
+
+ /**
+ * Pile up nested profiles.
+ *
+ * @param profile
+ * the profile
+ */
+ private void pileUpNestedProfiles(final Profile profile) {
+ Collection<Profile> owningProfiles = EcoreUtil.<Profile> getObjectsByType(profile.getNestedPackages(), UMLPackage.Literals.PROFILE);
+ for (Profile owningProfile : owningProfiles) {
+ profilesStack.addLast(owningProfile);
+ }
+ }
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/decoration/UndefinedProfileDecoration.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/decoration/UndefinedProfileDecoration.java
new file mode 100644
index 00000000000..4d70d49aa85
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/decoration/UndefinedProfileDecoration.java
@@ -0,0 +1,137 @@
+/*****************************************************************************
+ * Copyright (c) 2018 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:
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.tools.decoration;
+
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.papyrus.infra.services.decoration.IDecorationSpecificFunctions;
+import org.eclipse.papyrus.infra.services.decoration.util.Decoration.PreferedPosition;
+import org.eclipse.papyrus.infra.services.decoration.util.IPapyrusDecoration;
+import org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Decoration for Undefined Profile.
+ *
+ * @author Gabriel Pascual
+ * @since 4.1
+ */
+public class UndefinedProfileDecoration implements IDecorationSpecificFunctions {
+
+ /** The Constant DECORATION_MESSAGE. */
+ private static final String DECORATION_MESSAGE = "The Profile Definition is outdated since last modifications"; //$NON-NLS-1$
+
+ /**
+ * Constructor.
+ *
+ */
+ public UndefinedProfileDecoration() {
+ }
+
+ /**
+ * Gets the image descriptor for ge.
+ *
+ * @param marker
+ * the marker
+ * @return the image descriptor for ge
+ * @see org.eclipse.papyrus.infra.services.decoration.IDecorationSpecificFunctions#getImageDescriptorForGE(org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker)
+ */
+ @Override
+ public ImageDescriptor getImageDescriptorForGE(IPapyrusMarker marker) {
+ return null;
+ }
+
+ /**
+ * Gets the image descriptor for me.
+ *
+ * @param marker
+ * the marker
+ * @return the image descriptor for me
+ * @see org.eclipse.papyrus.infra.services.decoration.IDecorationSpecificFunctions#getImageDescriptorForME(org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker)
+ */
+ @Override
+ public ImageDescriptor getImageDescriptorForME(IPapyrusMarker marker) {
+ ImageDescriptor imageDescriptor = null;
+ if (marker instanceof UndefinedProfileMarker) {
+ imageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_DEC_FIELD_WARNING);
+ }
+ return imageDescriptor;
+ }
+
+ /**
+ * Gets the prefered position.
+ *
+ * @param marker
+ * the marker
+ * @return the prefered position
+ * @see org.eclipse.papyrus.infra.services.decoration.IDecorationSpecificFunctions#getPreferedPosition(org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker)
+ */
+ @Override
+ public PreferedPosition getPreferedPosition(IPapyrusMarker marker) {
+ return PreferedPosition.NORTH_EAST;
+ }
+
+ /**
+ * Gets the message.
+ *
+ * @param marker
+ * the marker
+ * @return the message
+ * @see org.eclipse.papyrus.infra.services.decoration.IDecorationSpecificFunctions#getMessage(org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker)
+ */
+ @Override
+ public String getMessage(IPapyrusMarker marker) {
+ return DECORATION_MESSAGE;
+ }
+
+ /**
+ * Gets the priority.
+ *
+ * @param marker
+ * the marker
+ * @return the priority
+ * @see org.eclipse.papyrus.infra.services.decoration.IDecorationSpecificFunctions#getPriority(org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker)
+ */
+ @Override
+ public int getPriority(IPapyrusMarker marker) {
+ return 0;
+ }
+
+ /**
+ * Supports marker propagation.
+ *
+ * @return the mark children
+ * @see org.eclipse.papyrus.infra.services.decoration.IDecorationSpecificFunctions#supportsMarkerPropagation()
+ */
+ @Override
+ public MarkChildren supportsMarkerPropagation() {
+
+ return null;
+ }
+
+ /**
+ * Marker propagation.
+ *
+ * @param childDecorations
+ * the child decorations
+ * @return the i papyrus decoration
+ * @see org.eclipse.papyrus.infra.services.decoration.IDecorationSpecificFunctions#markerPropagation(org.eclipse.emf.common.util.EList)
+ */
+ @Override
+ public IPapyrusDecoration markerPropagation(EList<IPapyrusDecoration> childDecorations) {
+ return null;
+ }
+
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/decoration/UndefinedProfileMarker.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/decoration/UndefinedProfileMarker.java
new file mode 100644
index 00000000000..9f33f6e62e1
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/decoration/UndefinedProfileMarker.java
@@ -0,0 +1,247 @@
+/*****************************************************************************
+ * Copyright (c) 2018 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:
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.tools.decoration;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker;
+import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation;
+import org.eclipse.uml2.uml.Profile;
+
+/**
+ *
+ * Marker for undefined Profile. This marker is created when Profile is tagged with {@link PapyrusDefinitionAnnotation#UNDEFINED_ANNOTATION} .
+ *
+ * @author Gabriel Pascual
+ * @since 4.1
+ */
+public class UndefinedProfileMarker implements IPapyrusMarker {
+
+ /** The Constant MARKER_TYPE_LABEL. */
+ private static final String MARKER_TYPE_LABEL = "Undefined Profile"; //$NON-NLS-1$
+
+ /** The Constant MARKER_TYPE. */
+ private static final String MARKER_TYPE = "org.eclipse.papyrus.uml.tools.decoration.undefinedprofile"; //$NON-NLS-1$
+
+ /** The undefined profile. */
+ private final Profile undefinedProfile;
+
+
+ /**
+ * Constructor.
+ *
+ */
+ public UndefinedProfileMarker(final Profile profile) {
+ undefinedProfile = profile;
+ }
+
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#getResource()
+ *
+ * @return
+ */
+ @Override
+ public Resource getResource() {
+ return undefinedProfile.eResource();
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#getEObject()
+ *
+ * @return
+ */
+ @Override
+ public EObject getEObject() {
+ return undefinedProfile;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#exists()
+ *
+ * @return
+ */
+ @Override
+ public boolean exists() {
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#getType()
+ *
+ * @return
+ * @throws CoreException
+ */
+ @Override
+ public String getType() throws CoreException {
+ return MARKER_TYPE;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#getTypeLabel()
+ *
+ * @return
+ * @throws CoreException
+ */
+ @Override
+ public String getTypeLabel() throws CoreException {
+
+ return MARKER_TYPE_LABEL;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#delete()
+ *
+ * @throws CoreException
+ */
+ @Override
+ public void delete() throws CoreException {
+
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#getAttribute(java.lang.String)
+ *
+ * @param name
+ * @return
+ * @throws CoreException
+ */
+ @Override
+ public Object getAttribute(String name) throws CoreException {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#getAttribute(java.lang.String, java.lang.String)
+ *
+ * @param name
+ * @param defaultValue
+ * @return
+ */
+ @Override
+ public String getAttribute(String name, String defaultValue) {
+ return defaultValue;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#getAttribute(java.lang.String, boolean)
+ *
+ * @param name
+ * @param defaultValue
+ * @return
+ */
+ @Override
+ public boolean getAttribute(String name, boolean defaultValue) {
+ return defaultValue;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#getAttribute(java.lang.String, int)
+ *
+ * @param name
+ * @param defaultValue
+ * @return
+ */
+ @Override
+ public int getAttribute(String name, int defaultValue) {
+ return defaultValue;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#getAttributes()
+ *
+ * @return
+ * @throws CoreException
+ */
+ @Override
+ public Map<String, ?> getAttributes() throws CoreException {
+ return Collections.emptyMap();
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#isSubtypeOf(java.lang.String)
+ *
+ * @param type
+ * @return
+ * @throws CoreException
+ */
+ @Override
+ public boolean isSubtypeOf(String type) throws CoreException {
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#setAttribute(java.lang.String, java.lang.Object)
+ *
+ * @param name
+ * @param value
+ * @throws CoreException
+ */
+ @Override
+ public void setAttribute(String name, Object value) throws CoreException {
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#setAttribute(java.lang.String, java.lang.String)
+ *
+ * @param name
+ * @param value
+ * @throws CoreException
+ */
+ @Override
+ public void setAttribute(String name, String value) throws CoreException {
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#setAttribute(java.lang.String, boolean)
+ *
+ * @param name
+ * @param value
+ * @throws CoreException
+ */
+ @Override
+ public void setAttribute(String name, boolean value) throws CoreException {
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#setAttribute(java.lang.String, int)
+ *
+ * @param name
+ * @param value
+ * @throws CoreException
+ */
+ @Override
+ public void setAttribute(String name, int value) throws CoreException {
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker#setAttributes(java.util.Map)
+ *
+ * @param attributes
+ * @throws CoreException
+ */
+ @Override
+ public void setAttributes(Map<String, ?> attributes) throws CoreException {
+
+ }
+
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/ProfileRedefinition.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/ProfileRedefinition.java
index 7ebb7a74c4e..0cae31097f9 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/ProfileRedefinition.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/ProfileRedefinition.java
@@ -18,6 +18,7 @@ package org.eclipse.papyrus.uml.tools.profile.definition;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EAnnotation;
@@ -31,6 +32,7 @@ import org.eclipse.papyrus.uml.tools.Activator;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.util.UMLUtil;
/**
@@ -57,7 +59,7 @@ import org.eclipse.uml2.uml.Profile;
public class ProfileRedefinition {
/**
- * this method is used to redefine profile even if it contains subpackages
+ * This method is used to redefine profile even if it contains subpackages
* or subprofiles
*
* @param thepackage
@@ -67,55 +69,52 @@ public class ProfileRedefinition {
* annotation
*/
public static void redefineProfile(Package thepackage, PapyrusDefinitionAnnotation definitionAnnotation) {
- // he wants to define
+ // Handle Profile element
if (thepackage instanceof Profile) {
Profile profile = (Profile) thepackage;
- // get profile definition
+
+ // Get profile definition
EPackage profileDefinition = profile.getDefinition();
- // collect all EClassifier of the definition
- ArrayList<EClassifier> tempList = new ArrayList<EClassifier>();
- for (int i = 0; i < profileDefinition.getEClassifiers().size(); i++) {
- tempList.add(profileDefinition.getEClassifiers().get(i));
- }
- // for all EClass
- Iterator<EClassifier> eClassIter = tempList.iterator();
- while (eClassIter.hasNext()) {
- EClassifier eclassifier = eClassIter.next();
+ Iterator<EClassifier> definitionClassifiersIterator = profileDefinition.getEClassifiers().iterator();
+ while (definitionClassifiersIterator.hasNext()) {
+ EClassifier eclassifier = definitionClassifiersIterator.next();
if (eclassifier instanceof EClass) {
- // redefine Eclass
+ // Redefine Eclass
redefineEclass((EClass) eclassifier);
}
}
- // add profile definition annotation
+ // Add profile definition annotation
if (definitionAnnotation != null) {
profile.getDefinition().getEAnnotations().add(definitionAnnotation.convertToEAnnotation());
}
}
- Iterator<Package> it = thepackage.getNestedPackages().iterator();
- while (it.hasNext()) {
- Package p = it.next();
- ProfileRedefinition.redefineProfile(p, definitionAnnotation);
+
+ // Explore all nested packages
+ Iterator<Package> nestedPackagesIterator = thepackage.getNestedPackages().iterator();
+ while (nestedPackagesIterator.hasNext()) {
+ Package nextPackage = nestedPackagesIterator.next();
+ ProfileRedefinition.redefineProfile(nextPackage, definitionAnnotation);
}
}
/**
- * redefine only real definition or do nothing
+ * Redefine only real definition or do nothing
*
* @param eclass
* the given eclass that we want to redefine
*/
public static void redefineEclass(EClass eclass) {
if (isADirectDefinition(eclass)) {
+
// 1. redefine inheritances
EList<EClass> eSuperTypes = eclass.getESuperTypes();
/* copy in order to avoid concurrent access */
- ArrayList<EClass> superTypesList = new ArrayList<EClass>();
- for (int j = 0; j < eSuperTypes.size(); j++) {
- superTypesList.add(eSuperTypes.get(j));
- }
+ List<EClass> superTypesList = new ArrayList<EClass>();
+ superTypesList.addAll(eSuperTypes);
+
// for each super types :we test if this is a direct definition
// if not we remove the local copy and replace by direct definition
Iterator<EClass> superIter = superTypesList.iterator();
@@ -127,17 +126,11 @@ public class ProfileRedefinition {
eclass.getESuperTypes().add(directSuperClass);
}
}
+
// 2.redefine eReferences
- // temp copy of the list
- Iterator<EReference> iterReference = eclass.getEReferences().iterator();
- ArrayList<EReference> referenceList = new ArrayList<EReference>();
- while (iterReference.hasNext()) {
- referenceList.add(iterReference.next());
- }
- // for each reference of the EClass
- Iterator<EReference> refIterator = referenceList.iterator();
- while (refIterator.hasNext()) {
- redefineEReference(refIterator.next(), eclass.getEPackage());
+ Iterator<EReference> referencesIterator = eclass.getEReferences().iterator();
+ while (referencesIterator.hasNext()) {
+ redefineEReference(referencesIterator.next(), eclass.getEPackage());
}
}
@@ -175,7 +168,7 @@ public class ProfileRedefinition {
*/
public static boolean isADirectDefinition(EClass eclass) {
if (eclass.getEAnnotations().size() > 0) {
- EAnnotation eAnnotation = eclass.getEAnnotations().get(0);
+ EAnnotation eAnnotation = eclass.getEAnnotation(UMLUtil.UML2_UML_PACKAGE_2_0_NS_URI);
if (eAnnotation.getReferences().size() > 0) {
if (!(eAnnotation.getReferences().get(0) instanceof org.eclipse.uml2.uml.Classifier)) {
String errMsg = "Problem because of the definition of " + eclass.getName() + " in " + eclass.getEPackage().getNsURI();
@@ -254,7 +247,7 @@ public class ProfileRedefinition {
EPackage profileDefinition = profile.getDefinition();
// collect all EClassifier of the definition
- ArrayList<EClassifier> tempList = new ArrayList<EClassifier>();
+ List<EClassifier> tempList = new ArrayList<EClassifier>();
for (int i = 0; i < profileDefinition.getEClassifiers().size(); i++) {
tempList.add(profileDefinition.getEClassifiers().get(i));
}
@@ -329,4 +322,27 @@ public class ProfileRedefinition {
}
return null;
}
+
+ /**
+ * Removes the undefined version.
+ *
+ * @param profile
+ * The profile.
+ * @since 4.1
+ */
+ public static void removeUndefinedVersion(Package packageElement) {
+ if (packageElement instanceof Profile) {
+ EAnnotation umlAnnotation = ((Profile) packageElement).getEAnnotation(UMLUtil.UML2_UML_PACKAGE_2_0_NS_URI);
+ if (null != umlAnnotation) {
+ EAnnotation firstAnnotation = umlAnnotation.getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
+ if (null != firstAnnotation ) {
+ PapyrusDefinitionAnnotation tagVersion = PapyrusDefinitionAnnotation.parseEAnnotation(firstAnnotation);
+ if (PapyrusDefinitionAnnotation.UNDEFINED_ANNOTATION.equals(tagVersion)) {
+ umlAnnotation.getEAnnotations().remove(firstAnnotation);
+ }
+ }
+ }
+ }
+
+ }
}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/service/IProfileDefinitionService.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/service/IProfileDefinitionService.java
new file mode 100644
index 00000000000..66abc725c8b
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/service/IProfileDefinitionService.java
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * Copyright (c) 2018 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:
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.tools.service;
+
+import org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker;
+import org.eclipse.uml2.uml.Profile;
+
+/**
+ *
+ * Definition of Profile Definition service.
+ *
+ * @author Gabriel Pascual
+ * @since 4.1
+ */
+public interface IProfileDefinitionService {
+
+ /**
+ * Get associated marker of Profile.
+ *
+ * @param profile
+ * Profile which have to decorate or which is already decorate.
+ * @return Existing marker or create one.
+ */
+ IPapyrusMarker getMarker(Profile profile);
+
+ /**
+ * Dispose marker on Profile.
+ *
+ * @param profile
+ * Profile which is decorated.
+ */
+ void disposeMarker(Profile profile);
+
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/service/ProfileDefinitionService.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/service/ProfileDefinitionService.java
new file mode 100644
index 00000000000..8ecbf6f6312
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/service/ProfileDefinitionService.java
@@ -0,0 +1,155 @@
+/*****************************************************************************
+ * Copyright (c) 2018 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:
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.tools.service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.NotFoundException;
+import org.eclipse.papyrus.infra.core.services.IService;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.services.decoration.DecorationService;
+import org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker;
+import org.eclipse.papyrus.uml.tools.Activator;
+import org.eclipse.papyrus.uml.tools.decoration.UndefinedProfileMarker;
+import org.eclipse.papyrus.uml.tools.model.ExtendedUmlModel;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.papyrus.uml.tools.profile.definition.IPapyrusVersionConstants;
+import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+/**
+ * Implementation of Profile Definition service.
+ *
+ * @author Gabriel Pascual
+ * @since 4.1
+ */
+public class ProfileDefinitionService implements IService, IProfileDefinitionService {
+
+
+ /** The model set. */
+ private ModelSet modelSet = null;
+
+ /** The map instance. */
+ private static Map<Profile, IPapyrusMarker> mapInstance = new HashMap<Profile, IPapyrusMarker>();
+
+ /**
+ * Constructor.
+ *
+ */
+ public ProfileDefinitionService() {
+ }
+
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
+ *
+ * @param servicesRegistry
+ * @throws ServiceException
+ */
+ @Override
+ public void init(final ServicesRegistry servicesRegistry) throws ServiceException {
+ modelSet = servicesRegistry.getService(ModelSet.class);
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#startService()
+ *
+ * @throws ServiceException
+ */
+ @Override
+ public void startService() throws ServiceException {
+
+ UmlModel umlModel = (UmlModel) modelSet.getModel(ExtendedUmlModel.MODEL_ID);
+ try {
+ EObject rootElement = umlModel.lookupRoot();
+
+
+ if (rootElement instanceof Profile) {
+ EAnnotation umlAnnotation = ((Profile) rootElement).getEAnnotation(UMLUtil.UML2_UML_PACKAGE_2_0_NS_URI);
+ if (null != umlAnnotation && !umlAnnotation.getEAnnotations().isEmpty()) {
+ EAnnotation emptyAnnotation = umlAnnotation.getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
+ if (null != emptyAnnotation) {
+ PapyrusDefinitionAnnotation parsedAnnotation = PapyrusDefinitionAnnotation.parseEAnnotation(emptyAnnotation);
+ if (PapyrusDefinitionAnnotation.UNDEFINED_ANNOTATION.equals(parsedAnnotation)) {
+ DecorationService decorationService = ServiceUtilsForEObject.getInstance().getService(DecorationService.class, rootElement);
+ decorationService.addDecoration(getMarker((Profile) rootElement), rootElement);
+ }
+ }
+
+ }
+ }
+ } catch (NotFoundException e) {
+ Activator.log.error(e);
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+
+
+
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
+ *
+ * @throws ServiceException
+ */
+ @Override
+ public void disposeService() throws ServiceException {
+ mapInstance.clear();
+ }
+
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.uml.tools.service.IProfileDefinitionService#getMarker(org.eclipse.uml2.uml.Profile)
+ *
+ * @param profile
+ * @return
+ */
+ @Override
+ public IPapyrusMarker getMarker(final Profile profile) {
+
+ IPapyrusMarker marker = mapInstance.get(profile);
+ if (marker == null) {
+ marker = new UndefinedProfileMarker(profile);
+ mapInstance.put(profile, marker);
+ }
+
+ return marker;
+ }
+
+
+ /**
+ * {@inheritDoc }
+ *
+ * @see org.eclipse.papyrus.uml.tools.service.IProfileDefinitionService#disposeMarker(org.eclipse.uml2.uml.Profile)
+ *
+ * @param profile
+ */
+ @Override
+ public void disposeMarker(final Profile profile) {
+ mapInstance.remove(profile);
+ }
+
+}

Back to the top