Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/helper/advice/GeneralizationHelperAdvice.java234
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/model/classdiagram.elementtypesconfigurations11
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/plugin.xml7
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/GeneralizationUtil.java (renamed from plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/helper/advice/GeneralizationUtil.java)357
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/ClassifierHelperAdvice.java71
5 files changed, 363 insertions, 317 deletions
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/helper/advice/GeneralizationHelperAdvice.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/helper/advice/GeneralizationHelperAdvice.java
index ffc539a15a7..538a2971198 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/helper/advice/GeneralizationHelperAdvice.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/helper/advice/GeneralizationHelperAdvice.java
@@ -1,116 +1,118 @@
-/*****************************************************************************
- * Copyright (c) 2011 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.blockdefinition.helper.advice;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyDependentsRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.sysml.diagram.blockdefinition.provider.ElementTypes;
-import org.eclipse.papyrus.uml.diagram.common.util.CrossReferencerUtil;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Generalization;
-import org.eclipse.uml2.uml.NamedElement;
-
-/**
- * <pre>
- * This HelperAdvice completes {@link Generalization} edit commands with diagram specific
- * commands in order to remove inconsistent views (e.g. inherited Port or Property
- * in case a {@link Generalization} is deleted or re-oriented.
- * </pre>
- */
-public class GeneralizationHelperAdvice extends AbstractEditHelperAdvice {
-
- @Override
- protected ICommand getBeforeReorientRelationshipCommand(ReorientRelationshipRequest request) {
-
- // The list of member views becoming inconsistent after re-orient that should be deleted.
- Set<View> viewsToDestroy = new HashSet<View>();
-
- if (request.getRelationship() instanceof Generalization) {
- viewsToDestroy.addAll(getMemberViewsToDestroy((Generalization) request.getRelationship()));
- }
-
- // return the command to destroy all these views
- if (!viewsToDestroy.isEmpty()) {
-
- DestroyDependentsRequest ddr = new DestroyDependentsRequest(request.getEditingDomain(), request.getRelationship(), false);
- ddr.setClientContext(request.getClientContext());
- ddr.addParameters(request.getParameters());
- return ddr.getDestroyDependentsCommand(viewsToDestroy);
-
- }
- return null;
- }
-
- @Override
- protected ICommand getBeforeDestroyDependentsCommand(DestroyDependentsRequest request) {
-
- EObject destructee = request.getElementToDestroy();
-
- Set<View> viewsToDestroy = new HashSet<View>();
-
- if (destructee instanceof Generalization) {
- viewsToDestroy = getMemberViewsToDestroy((Generalization) destructee);
- }
-
- // return the command to destroy all these views
- if (!viewsToDestroy.isEmpty()) {
- return request.getDestroyDependentsCommand(viewsToDestroy);
- }
- return null;
- }
-
- /**
- * This methods looks for inconsistent views to delete in case the generalization is deleted or
- * re-oriented.
- *
- * @param generalization
- * the modified generalization
- * @return the list of {@link View} to delete
- */
- protected Set<View> getMemberViewsToDestroy(Generalization generalization) {
- Set<View> viewsToDestroy = new HashSet<View>();
-
- Classifier general = generalization.getGeneral();
- if (general != null) {
-
- // Parse members
- EList<NamedElement> members = general.getMembers();
- for (NamedElement member : members) {
-
- // Find Views in Composite Structure Diagram that are referencing current member
- Iterator<View> viewIt = CrossReferencerUtil.getCrossReferencingViews(member, ElementTypes.DIAGRAM_ID).iterator();
- while (viewIt.hasNext()) {
- View view = viewIt.next();
-
- // Test if current view (member) is concerned by the deletion (re-orientation) of the generalization
- GeneralizationUtil util = new GeneralizationUtil();
- if (util.isConcernedByGeneralizationChanges(generalization, view)) {
- viewsToDestroy.add(view);
- }
- }
- }
- }
-
- return viewsToDestroy;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 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:
+ *
+ * CEA LIST - Initial API and implementation
+ * Fanch Bonnabesse (ALL4TEC) fanch.bonnabesse@alltec.net - Bug 481317
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.sysml.diagram.blockdefinition.helper.advice;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyDependentsRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.sysml.diagram.blockdefinition.provider.ElementTypes;
+import org.eclipse.papyrus.uml.diagram.common.util.CrossReferencerUtil;
+import org.eclipse.papyrus.uml.diagram.common.util.GeneralizationUtil;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Generalization;
+import org.eclipse.uml2.uml.NamedElement;
+
+/**
+ * <pre>
+ * This HelperAdvice completes {@link Generalization} edit commands with diagram specific
+ * commands in order to remove inconsistent views (e.g. inherited Port or Property
+ * in case a {@link Generalization} is deleted or re-oriented.
+ * </pre>
+ */
+public class GeneralizationHelperAdvice extends AbstractEditHelperAdvice {
+
+ @Override
+ protected ICommand getBeforeReorientRelationshipCommand(ReorientRelationshipRequest request) {
+
+ // The list of member views becoming inconsistent after re-orient that should be deleted.
+ Set<View> viewsToDestroy = new HashSet<View>();
+
+ if (request.getRelationship() instanceof Generalization) {
+ viewsToDestroy.addAll(getMemberViewsToDestroy((Generalization) request.getRelationship()));
+ }
+
+ // return the command to destroy all these views
+ if (!viewsToDestroy.isEmpty()) {
+
+ DestroyDependentsRequest ddr = new DestroyDependentsRequest(request.getEditingDomain(), request.getRelationship(), false);
+ ddr.setClientContext(request.getClientContext());
+ ddr.addParameters(request.getParameters());
+ return ddr.getDestroyDependentsCommand(viewsToDestroy);
+
+ }
+ return null;
+ }
+
+ @Override
+ protected ICommand getBeforeDestroyDependentsCommand(DestroyDependentsRequest request) {
+
+ EObject destructee = request.getElementToDestroy();
+
+ Set<View> viewsToDestroy = new HashSet<View>();
+
+ if (destructee instanceof Generalization) {
+ viewsToDestroy = getMemberViewsToDestroy((Generalization) destructee);
+ }
+
+ // return the command to destroy all these views
+ if (!viewsToDestroy.isEmpty()) {
+ return request.getDestroyDependentsCommand(viewsToDestroy);
+ }
+ return null;
+ }
+
+ /**
+ * This methods looks for inconsistent views to delete in case the generalization is deleted or
+ * re-oriented.
+ *
+ * @param generalization
+ * the modified generalization
+ * @return the list of {@link View} to delete
+ */
+ protected Set<View> getMemberViewsToDestroy(Generalization generalization) {
+ Set<View> viewsToDestroy = new HashSet<View>();
+
+ Classifier general = generalization.getGeneral();
+ if (general != null) {
+
+ // Parse members
+ EList<NamedElement> members = general.getMembers();
+ for (NamedElement member : members) {
+
+ // Find Views in Composite Structure Diagram that are referencing current member
+ Iterator<View> viewIt = CrossReferencerUtil.getCrossReferencingViews(member, ElementTypes.DIAGRAM_ID).iterator();
+ while (viewIt.hasNext()) {
+ View view = viewIt.next();
+
+ // Test if current view (member) is concerned by the deletion (re-orientation) of the generalization
+ GeneralizationUtil util = new GeneralizationUtil();
+ if (util.isConcernedByGeneralizationChanges(generalization, view)) {
+ viewsToDestroy.add(view);
+ }
+ }
+ }
+ }
+
+ return viewsToDestroy;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/model/classdiagram.elementtypesconfigurations b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/model/classdiagram.elementtypesconfigurations
index 7d8cf63ee0a..96b4bc6b33f 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/model/classdiagram.elementtypesconfigurations
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/model/classdiagram.elementtypesconfigurations
@@ -1208,4 +1208,15 @@
xsi:type="elementtypesconfigurations:MetamodelTypeConfiguration"
href="platform:/plugin/org.eclipse.papyrus.uml.service.types/model/uml.elementtypesconfigurations#_ScgUVlYCEeS0WsAAtVmToA"/>
</adviceBindingsConfigurations>
+ <adviceBindingsConfigurations
+ xmi:id="_VPE3UJpvEeWZOI1l_xp4vg"
+ name="GeneralizationHelperAdvice"
+ description="Generalizarion specific advices (remove inconsistent views when a Generalization is deleted)"
+ identifier="org.eclipse.papyrus.uml.diagram.clazz.GeneralizationHelperAdvice"
+ editHelperAdviceClassName="org.eclipse.papyrus.uml.diagram.clazz.custom.helper.advice.GeneralizationHelperAdvice"
+ inheritance="all">
+ <target
+ xsi:type="elementtypesconfigurations:MetamodelTypeConfiguration"
+ href="platform:/plugin/org.eclipse.papyrus.uml.service.types/model/uml.elementtypesconfigurations#_Scma8FYCEeS0WsAAtVmToA"/>
+ </adviceBindingsConfigurations>
</elementtypesconfigurations:ElementTypeSetConfiguration>
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/plugin.xml
index 8ae9da86384..fab8447e2ad 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/plugin.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/plugin.xml
@@ -1262,12 +1262,7 @@
<extension point="org.eclipse.gmf.runtime.emf.type.core.elementTypes">
<metamodel nsURI="http://www.eclipse.org/uml2/5.0.0/UML">
-
- <!-- Generalizarion specific advices (remove inconsistent views when a Generalization is deleted -->
- <adviceBinding id="org.eclipse.papyrus.uml.diagram.class.GeneralizationHelperAdvice"
- class="org.eclipse.papyrus.uml.diagram.clazz.custom.helper.advice.GeneralizationHelperAdvice"
- inheritance="all" typeId="org.eclipse.papyrus.uml.Generalization">
- </adviceBinding>
+
<adviceBinding
class="org.eclipse.papyrus.uml.diagram.clazz.custom.helper.advice.NamespaceHelperAdvice"
id="org.eclipse.papyrus.uml.diagram.class.NamespaceHelperAdvice"
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/helper/advice/GeneralizationUtil.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/GeneralizationUtil.java
index e053ec50910..3bc5829c3e9 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/helper/advice/GeneralizationUtil.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/GeneralizationUtil.java
@@ -1,178 +1,179 @@
-/*****************************************************************************
- * Copyright (c) 2011 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.blockdefinition.helper.advice;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Generalization;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Type;
-
-public class GeneralizationUtil {
-
- /**
- * Tests <code>true</code> if the classifier has this generalization in its inheritance links (directly or indirectly)
- *
- * @param generalization
- * a generalization
- * @param el
- * a {@link Classifier} or a {@link Property}
- * @return
- * <code>true</code> if the classifier has this generalization in its inheritance links (directly or indirectly) <code>false</code> if not
- */
- public boolean isConcernedByGeneralizationChanges(Generalization generalization, View view) {
- boolean isConcerned = false;
- NamedElement graphicalOwner = getGraphicalOwner(view);
-
- // If the View element is owned by its graphical owner bypass the tests
- if ((Element) view.getElement().eContainer() != graphicalOwner) {
-
- if (graphicalOwner instanceof Classifier) {
- if (graphicalOwner != null && generalization != null) {
- isConcerned = getAllGeneralization((Classifier) graphicalOwner, null).contains(generalization);
- }
- } else if (graphicalOwner instanceof Property) {
- Type type = ((Property) graphicalOwner).getType();
- if (type instanceof Classifier) {
- isConcerned = getAllGeneralization((Classifier) type, null).contains(generalization);
- }
- }
-
- if (isConcerned && existsAnotherInheritanceWay((Element) view.getElement(), generalization, graphicalOwner, null)) {
- isConcerned = false;
- }
-
- }
-
- return isConcerned;
- }
-
- /**
- * Tests if the classifier owns another way to inherit of the element
- *
- * @param inheritedElement
- * the inherited element
- * @param forbiddenPath
- * the generalization that we are destroying
- * @param el
- *
- * @return
- * <code>true</code> if another way exists to inherit of this element <code>false</code> if not
- */
- protected boolean existsAnotherInheritanceWay(Element inheritedElement, Generalization forbiddenPath, NamedElement el, Set<Element> ignoredGeneralizations) {
-
- Set<Generalization> generalizations = new HashSet<Generalization>();
-
- Classifier _classifier = null;
- if (el instanceof Property) {
- Type type = ((Property) el).getType();
- if (type instanceof Classifier) {
- _classifier = (Classifier) type;
- }
- } else if (el instanceof Classifier) {
- _classifier = (Classifier) el;
- }
-
- // List Generalization that have already been tested to avoid loop issues
- // in case of Generalization cycles (such cycle creation should be avoided)
- Set<Element> ignoredGeneralizationsTmp = new HashSet<Element>();
- if (ignoredGeneralizations != null) {
- ignoredGeneralizationsTmp.addAll(ignoredGeneralizations);
- }
-
- if (el != null) {
- generalizations.addAll(_classifier.getGeneralizations());
-
- for (Generalization generalization : generalizations) {
- if ((generalization != forbiddenPath) && (!ignoredGeneralizationsTmp.contains(generalization))) {
-
- Classifier general = generalization.getGeneral();
- if (general != null) {
- ignoredGeneralizationsTmp.add(generalization);
-
- if (general.getOwnedMembers().contains(inheritedElement)) {
- return true;
-
- } else if (existsAnotherInheritanceWay(inheritedElement, forbiddenPath, general, ignoredGeneralizationsTmp)) {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
-
- /**
- * Returns the classifier owning the view
- *
- * @param view
- * a view
- * @return
- * the Element owning this view
- * or <code>null</code> if not found
- */
- protected NamedElement getGraphicalOwner(View view) {
- // the view is in a compartment
- if (view.eContainer() instanceof View) {
- EObject graphicalParent = ((View) view.eContainer()).getElement();
- if (graphicalParent instanceof Classifier || graphicalParent instanceof Property) {
- return (NamedElement) graphicalParent;
- }
- }
- return null;
- }
-
- /**
- * Return all the generalization (direct and indirect) owning by the classifier
- *
- * @param classifier
- * a classifier
- * @return
- * all the generalization (direct and indirect) owning by the classifier
- */
- protected Set<Generalization> getAllGeneralization(Classifier classifier, Set<Classifier> alreadyParsedClassifiers) {
-
- Set<Generalization> generalizations = new HashSet<Generalization>();
-
- // Keep track of already parsed Classifiers to avoid loop in case
- // of Generalization cycle.
- Set<Classifier> parsedClassifiers = new HashSet<Classifier>();
- if (alreadyParsedClassifiers != null) {
- parsedClassifiers.addAll(alreadyParsedClassifiers);
- }
-
- Set<Generalization> generalizationsTmp = new HashSet<Generalization>();
- if (classifier != null) {
- generalizations.addAll(classifier.getGeneralizations());
-
- if (!parsedClassifiers.contains(classifier)) {
- parsedClassifiers.add(classifier);
- for (Generalization generalization : generalizations) {
- generalizationsTmp.addAll(getAllGeneralization(generalization.getGeneral(), parsedClassifiers));
- }
- }
- }
-
- generalizations.addAll(generalizationsTmp);
-
- return generalizations;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 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:
+ *
+ * CEA LIST - Initial API and implementation
+ * Fanch Bonnabesse (ALL4TEC) fanch.bonnabesse@alltec.net - Bug 481317
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.util;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Generalization;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
+
+public class GeneralizationUtil {
+
+ /**
+ * Tests <code>true</code> if the classifier has this generalization in its inheritance links (directly or indirectly)
+ *
+ * @param generalization
+ * a generalization
+ * @param el
+ * a {@link Classifier} or a {@link Property}
+ * @return
+ * <code>true</code> if the classifier has this generalization in its inheritance links (directly or indirectly) <code>false</code> if not
+ */
+ public boolean isConcernedByGeneralizationChanges(Generalization generalization, View view) {
+ boolean isConcerned = false;
+ NamedElement graphicalOwner = getGraphicalOwner(view);
+
+ // If the View element is owned by its graphical owner bypass the tests
+ if ((Element) view.getElement().eContainer() != graphicalOwner) {
+
+ if (graphicalOwner instanceof Classifier) {
+ if (graphicalOwner != null && generalization != null) {
+ isConcerned = getAllGeneralization((Classifier) graphicalOwner, null).contains(generalization);
+ }
+ } else if (graphicalOwner instanceof Property) {
+ Type type = ((Property) graphicalOwner).getType();
+ if (type instanceof Classifier) {
+ isConcerned = getAllGeneralization((Classifier) type, null).contains(generalization);
+ }
+ }
+
+ if (isConcerned && existsAnotherInheritanceWay((Element) view.getElement(), generalization, graphicalOwner, null)) {
+ isConcerned = false;
+ }
+
+ }
+
+ return isConcerned;
+ }
+
+ /**
+ * Tests if the classifier owns another way to inherit of the element
+ *
+ * @param inheritedElement
+ * the inherited element
+ * @param forbiddenPath
+ * the generalization that we are destroying
+ * @param el
+ *
+ * @return
+ * <code>true</code> if another way exists to inherit of this element <code>false</code> if not
+ */
+ protected boolean existsAnotherInheritanceWay(Element inheritedElement, Generalization forbiddenPath, NamedElement el, Set<Element> ignoredGeneralizations) {
+
+ Set<Generalization> generalizations = new HashSet<Generalization>();
+
+ Classifier _classifier = null;
+ if (el instanceof Property) {
+ Type type = ((Property) el).getType();
+ if (type instanceof Classifier) {
+ _classifier = (Classifier) type;
+ }
+ } else if (el instanceof Classifier) {
+ _classifier = (Classifier) el;
+ }
+
+ // List Generalization that have already been tested to avoid loop issues
+ // in case of Generalization cycles (such cycle creation should be avoided)
+ Set<Element> ignoredGeneralizationsTmp = new HashSet<Element>();
+ if (ignoredGeneralizations != null) {
+ ignoredGeneralizationsTmp.addAll(ignoredGeneralizations);
+ }
+
+ if (el != null) {
+ generalizations.addAll(_classifier.getGeneralizations());
+
+ for (Generalization generalization : generalizations) {
+ if ((generalization != forbiddenPath) && (!ignoredGeneralizationsTmp.contains(generalization))) {
+
+ Classifier general = generalization.getGeneral();
+ if (general != null) {
+ ignoredGeneralizationsTmp.add(generalization);
+
+ if (general.getOwnedMembers().contains(inheritedElement)) {
+ return true;
+
+ } else if (existsAnotherInheritanceWay(inheritedElement, forbiddenPath, general, ignoredGeneralizationsTmp)) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns the classifier owning the view
+ *
+ * @param view
+ * a view
+ * @return
+ * the Element owning this view
+ * or <code>null</code> if not found
+ */
+ protected NamedElement getGraphicalOwner(View view) {
+ // the view is in a compartment
+ if (view.eContainer() instanceof View) {
+ EObject graphicalParent = ((View) view.eContainer()).getElement();
+ if (graphicalParent instanceof Classifier || graphicalParent instanceof Property) {
+ return (NamedElement) graphicalParent;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return all the generalization (direct and indirect) owning by the classifier
+ *
+ * @param classifier
+ * a classifier
+ * @return
+ * all the generalization (direct and indirect) owning by the classifier
+ */
+ protected Set<Generalization> getAllGeneralization(Classifier classifier, Set<Classifier> alreadyParsedClassifiers) {
+
+ Set<Generalization> generalizations = new HashSet<Generalization>();
+
+ // Keep track of already parsed Classifiers to avoid loop in case
+ // of Generalization cycle.
+ Set<Classifier> parsedClassifiers = new HashSet<Classifier>();
+ if (alreadyParsedClassifiers != null) {
+ parsedClassifiers.addAll(alreadyParsedClassifiers);
+ }
+
+ Set<Generalization> generalizationsTmp = new HashSet<Generalization>();
+ if (classifier != null) {
+ generalizations.addAll(classifier.getGeneralizations());
+
+ if (!parsedClassifiers.contains(classifier)) {
+ parsedClassifiers.add(classifier);
+ for (Generalization generalization : generalizations) {
+ generalizationsTmp.addAll(getAllGeneralization(generalization.getGeneral(), parsedClassifiers));
+ }
+ }
+ }
+
+ generalizations.addAll(generalizationsTmp);
+
+ return generalizations;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/ClassifierHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/ClassifierHelperAdvice.java
index 6c5fae5b08f..4ff53bcde22 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/ClassifierHelperAdvice.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/ClassifierHelperAdvice.java
@@ -9,7 +9,7 @@
* Contributors:
*
* Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- * Fanch Bonnabesse (ALL4TEC) fanch.bonnabesse@alltec.net - Bug 476873
+ * Fanch Bonnabesse (ALL4TEC) fanch.bonnabesse@alltec.net - Bug 476873, 481317
*
*****************************************************************************/
package org.eclipse.papyrus.uml.service.types.helper.advice;
@@ -21,6 +21,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
@@ -37,6 +38,7 @@ import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
import org.eclipse.papyrus.uml.diagram.common.util.CrossReferencerUtil;
+import org.eclipse.papyrus.uml.diagram.common.util.GeneralizationUtil;
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
import org.eclipse.papyrus.uml.service.types.utils.ElementUtil;
import org.eclipse.papyrus.uml.service.types.utils.RequestParameterConstants;
@@ -44,6 +46,7 @@ import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.ConnectorEnd;
import org.eclipse.uml2.uml.Generalization;
+import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Port;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.UMLPackage;
@@ -131,7 +134,7 @@ public class ClassifierHelperAdvice extends AbstractEditHelperAdvice {
Collection<ConnectorEnd> referencers = EMFCoreUtil.getReferencers(movedProperty, refs);
IElementEditService provider = ElementEditServiceUtils.getCommandProvider(movedProperty);
- if (provider != null) {
+ if (null != provider) {
for (ConnectorEnd end : referencers) {
// General case, delete the ConnectorEnd
DestroyElementRequest req = new DestroyElementRequest(end, false);
@@ -186,7 +189,7 @@ public class ClassifierHelperAdvice extends AbstractEditHelperAdvice {
}
}
- if (gmfCommand != null) {
+ if (null != gmfCommand) {
gmfCommand = gmfCommand.reduce();
}
@@ -204,8 +207,7 @@ public class ClassifierHelperAdvice extends AbstractEditHelperAdvice {
* the original move request
* @return the re-factoring command
*/
- private ICommand getOppositePropertyRefactoringCommand(Property movedProperty, Association associationToRefactor, MoveRequest request) {
-
+ private ICommand getOppositePropertyRefactoringCommand(final Property movedProperty, final Association associationToRefactor, final MoveRequest request) {
Association relatedAssociation = movedProperty.getAssociation(); // Should not be null, test before calling method.
// get the opposite the property opposite
Property oppositeEnd = associationToRefactor.getMemberEnds().get(0);
@@ -219,7 +221,7 @@ public class ClassifierHelperAdvice extends AbstractEditHelperAdvice {
SetRequest setType = new SetRequest(oppositeEnd, UMLPackage.eINSTANCE.getTypedElement_Type(), request.getTargetContainer());
IElementEditService provider = ElementEditServiceUtils.getCommandProvider(relatedAssociation);
- if (provider != null) {
+ if (null != provider) {
return provider.getEditCommand(setType);
}
@@ -233,25 +235,26 @@ public class ClassifierHelperAdvice extends AbstractEditHelperAdvice {
* @return
*/
@Override
- protected ICommand getAfterMoveCommand(MoveRequest request) {
+ protected ICommand getAfterMoveCommand(final MoveRequest request) {
ICommand moveCommand = super.getAfterMoveCommand(request);
Set<View> viewsToDestroy = new HashSet<View>();
@SuppressWarnings("unchecked")
- Iterator<EObject> it = request.getElementsToMove().keySet().iterator();
+ final Iterator<EObject> it = request.getElementsToMove().keySet().iterator();
while (it.hasNext()) {
- EObject eObject = it.next();
+ final EObject eObject = it.next();
if (eObject instanceof Generalization) {
viewsToDestroy.addAll(getViewsToDestroy((Generalization) eObject));
+ viewsToDestroy.addAll(getViewsAccordingToGeneralization((Generalization) eObject));
}
}
- Iterator<View> viewToDestroyIterator = viewsToDestroy.iterator();
+ final Iterator<View> viewToDestroyIterator = viewsToDestroy.iterator();
while (viewToDestroyIterator.hasNext()) {
- View view = viewToDestroyIterator.next();
- DeleteCommand destroyViewsCommand = new DeleteCommand(request.getEditingDomain(), view);
+ final View view = viewToDestroyIterator.next();
+ final DeleteCommand destroyViewsCommand = new DeleteCommand(request.getEditingDomain(), view);
moveCommand = CompositeCommand.compose(moveCommand, destroyViewsCommand);
}
@@ -266,19 +269,53 @@ public class ClassifierHelperAdvice extends AbstractEditHelperAdvice {
* the modified Classifier
* @return the list of {@link View} to delete
*/
- private Set<View> getViewsToDestroy(Generalization movedObject) {
+ private Set<View> getViewsToDestroy(final Generalization movedObject) {
Set<View> viewsToDestroy = new HashSet<View>();
- Iterator<View> viewIt = CrossReferencerUtil.getCrossReferencingViews(movedObject, null).iterator();
+ final Iterator<View> viewIt = CrossReferencerUtil.getCrossReferencingViews(movedObject, null).iterator();
while (viewIt.hasNext()) {
- View view = viewIt.next();
+ final View view = viewIt.next();
- String containerType = ViewUtil.getViewContainer(view) != null ? ViewUtil.getViewContainer(view).getType() : null;
- if (containerType != null) {
+ final String containerType = ViewUtil.getViewContainer(view) != null ? ViewUtil.getViewContainer(view).getType() : null;
+ if (null != containerType) {
viewsToDestroy.add(view);
}
}
return viewsToDestroy;
}
+
+ /**
+ * This methods looks for inconsistent views to delete in case the generalization is deleted or
+ * re-oriented.
+ *
+ * @param generalization
+ * the modified generalization
+ * @return the list of {@link View} to delete
+ */
+ protected Set<View> getViewsAccordingToGeneralization(final Generalization generalization) {
+ Set<View> viewsToDestroy = new HashSet<View>();
+
+ final Classifier general = generalization.getGeneral();
+ if (null != general) {
+ // Parse members
+ final EList<NamedElement> members = general.getMembers();
+ for (final NamedElement member : members) {
+
+ // Find Views in Composite Structure Diagram that are referencing current member
+ final Iterator<View> viewIt = CrossReferencerUtil.getCrossReferencingViews(member, null).iterator();
+ while (viewIt.hasNext()) {
+ final View view = viewIt.next();
+
+ // Test if current view (member) is concerned by the deletion (re-orientation) of the generalization
+ final GeneralizationUtil util = new GeneralizationUtil();
+ if (util.isConcernedByGeneralizationChanges(generalization, view)) {
+ viewsToDestroy.add(view);
+ }
+ }
+ }
+ }
+
+ return viewsToDestroy;
+ }
}

Back to the top