diff options
author | Benoit Maggi | 2015-05-22 14:17:37 +0000 |
---|---|---|
committer | Camille Letavernier | 2015-05-26 08:46:55 +0000 |
commit | 2c9c0be82ea09f7d7b99c1fda3a5b45bd5ebc19a (patch) | |
tree | 3a654230edf0f2af39e51a21fd728fec40eb6e57 | |
parent | c515778f4b0cafabe00f018040d146c8571b2514 (diff) | |
download | org.eclipse.papyrus-2c9c0be82ea09f7d7b99c1fda3a5b45bd5ebc19a.tar.gz org.eclipse.papyrus-2c9c0be82ea09f7d7b99c1fda3a5b45bd5ebc19a.tar.xz org.eclipse.papyrus-2c9c0be82ea09f7d7b99c1fda3a5b45bd5ebc19a.zip |
Bug 468026 - ClassCastException when opening a diagram
- patch exception when opening a diagram
(Exception comming from an edge between a Model and a Class)
Change-Id: If9547f2f89ed79e3d57d46e14b320278f0d2da60
Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
Reviewed-on: https://git.eclipse.org/r/48468
Tested-by: Hudson CI
Reviewed-by: Camille Letavernier <camille.letavernier@cea.fr>
3 files changed, 356 insertions, 343 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/edit/part/AbstractAssociationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/edit/part/AbstractAssociationEditPart.java index 8ac8c8f1f08..0ffc4d324d8 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/edit/part/AbstractAssociationEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/edit/part/AbstractAssociationEditPart.java @@ -1,172 +1,175 @@ -/*****************************************************************************
- * Copyright (c) 2009 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.clazz.custom.edit.part;
-
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.uml.diagram.clazz.custom.figure.AssociationFigure;
-import org.eclipse.papyrus.uml.diagram.common.editparts.UMLConnectionNodeEditPart;
-import org.eclipse.uml2.uml.AggregationKind;
-import org.eclipse.uml2.uml.Association;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Property;
-
-/**
- * this a abstract editpart use to add listeners
- */
-public abstract class AbstractAssociationEditPart extends UMLConnectionNodeEditPart {
-
- protected static final String ASSOCIATION_END_LISTENERS_SOURCE = "AssociationEndListenersSource";
-
- protected static final String ASSOCIATION_END_LISTENERS_TARGET = "AssociationEndListenersTarget";
-
- public AbstractAssociationEditPart(View view) {
- super(view);
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- public void activate() {
- super.activate();
- addAssociationEndListeners();
- }
-
- /**
- * this methods add listeners on targets and sources
- */
- protected void addAssociationEndListeners() {
- EObject semanticElement = resolveSemanticElement();
- if (semanticElement instanceof Association) {
- Association association = (Association) semanticElement;
- if (association.getMemberEnds().size() >= 2) {
- EObject sourceEnd = association.getMemberEnds().get(0);
- EObject targetEnd = association.getMemberEnds().get(1);
- addListenerFilter(ASSOCIATION_END_LISTENERS_SOURCE, this, sourceEnd);
- addListenerFilter(ASSOCIATION_END_LISTENERS_TARGET, this, targetEnd);
- }
- }
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- public void deactivate() {
- removeAssociationEndListeners();
- super.deactivate();
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- protected void handleNotificationEvent(Notification event) {
- super.handleNotificationEvent(event);
- // set the good ends for the association figure
- if (resolveSemanticElement() != null) {
- refreshVisuals();
- }
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- protected void refreshVisuals() {
- if (resolveSemanticElement() != null) {
- if (getSource() == null || getTarget() == null) {
- return;
- }
- if (!(getSource() instanceof GraphicalEditPart && getTarget() instanceof GraphicalEditPart)) {
- return;
- }
- // FIXME: This is a quick fix to avoid model corruption when an associationClass is drawn between an association and a Class.
- // A better solution would probably be to forbid this behavior. Currently, it is not possible to draw directly an Association Class between
- // an association and a class, but it is possible to retarget an AssociationClass' end to an Association (Which would lead to a diagram corruption)
- if (((GraphicalEditPart) getSource()).resolveSemanticElement() == null || ((GraphicalEditPart) getTarget()).resolveSemanticElement() == null) {
- return;
- }
- Property source = null;
- Property target = null;
- // Get the association
- Element umlElement = getUMLElement();
- if (umlElement instanceof Association) {
- Association association = (Association) getUMLElement();
- assert (association.getMemberEnds().size() >= 2);
- if (association.getMemberEnds() != null && association.getMemberEnds().size() >= 2) {
- if ((association.getMemberEnds().get(0)).getType().equals(((GraphicalEditPart) getSource()).resolveSemanticElement())) {
- source = ((association.getMemberEnds().get(0)));
- target = ((association.getMemberEnds().get(1)));
- } else {
- source = ((association.getMemberEnds().get(1)));
- target = ((association.getMemberEnds().get(0)));
- }
- int sourceType = 0;
- int targetType = 0;
- // to display the dot.
- // owned?
- if (!source.getOwner().equals(resolveSemanticElement())) {
- sourceType += AssociationFigure.owned;
- sourceType += AssociationFigure.navigable;
- }
- if (!target.getOwner().equals(resolveSemanticElement())) {
- targetType += AssociationFigure.owned;
- targetType += AssociationFigure.navigable;
- }
- // aggregation? for it the opposite is changed
- if (source.getAggregation() == AggregationKind.SHARED_LITERAL) {
- targetType += AssociationFigure.aggregation;
- }
- if (target.getAggregation() == AggregationKind.SHARED_LITERAL) {
- sourceType += AssociationFigure.aggregation;
- }
- // composite? for it the opposite is changed
- if (source.getAggregation() == AggregationKind.COMPOSITE_LITERAL) {
- targetType += AssociationFigure.composition;
- }
- if (target.getAggregation() == AggregationKind.COMPOSITE_LITERAL) {
- sourceType += AssociationFigure.composition;
- }
- // navigable?
- if (association.getNavigableOwnedEnds().contains(source)) {
- sourceType += AssociationFigure.navigable;
- }
- if (association.getNavigableOwnedEnds().contains(target)) {
- targetType += AssociationFigure.navigable;
- }
- if (getPrimaryShape() instanceof AssociationFigure) {
- ((AssociationFigure) getPrimaryShape()).setEnd(sourceType, targetType);
- }
- }
- }
- }
- super.refreshVisuals();
- }
-
- /**
- * this method is used to remove listener on ends
- */
- protected void removeAssociationEndListeners() {
- removeListenerFilter(ASSOCIATION_END_LISTENERS_SOURCE);
- removeListenerFilter(ASSOCIATION_END_LISTENERS_TARGET);
- }
-}
+/***************************************************************************** + * Copyright (c) 2009 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: + * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation + * Benoit Maggi (CEA LIST) - Bug 468026 + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.clazz.custom.edit.part; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.uml.diagram.clazz.custom.figure.AssociationFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.UMLConnectionNodeEditPart; +import org.eclipse.uml2.uml.AggregationKind; +import org.eclipse.uml2.uml.Association; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Type; + +/** + * this abstract editpart is used to add listeners + */ +public abstract class AbstractAssociationEditPart extends UMLConnectionNodeEditPart { + + protected static final String ASSOCIATION_END_LISTENERS_SOURCE = "AssociationEndListenersSource"; //$NON-NLS-1$ + + protected static final String ASSOCIATION_END_LISTENERS_TARGET = "AssociationEndListenersTarget"; //$NON-NLS-1$ + + public AbstractAssociationEditPart(View view) { + super(view); + } + + /** + * + * {@inheritDoc} + */ + @Override + public void activate() { + super.activate(); + addAssociationEndListeners(); + } + + /** + * this methods add listeners on targets and sources + */ + protected void addAssociationEndListeners() { + EObject semanticElement = resolveSemanticElement(); + if (semanticElement instanceof Association) { + Association association = (Association) semanticElement; + if (association.getMemberEnds().size() >= 2) { + EObject sourceEnd = association.getMemberEnds().get(0); + EObject targetEnd = association.getMemberEnds().get(1); + addListenerFilter(ASSOCIATION_END_LISTENERS_SOURCE, this, sourceEnd); + addListenerFilter(ASSOCIATION_END_LISTENERS_TARGET, this, targetEnd); + } + } + } + + /** + * + * {@inheritDoc} + */ + @Override + public void deactivate() { + removeAssociationEndListeners(); + super.deactivate(); + } + + /** + * + * {@inheritDoc} + */ + @Override + protected void handleNotificationEvent(Notification event) { + super.handleNotificationEvent(event); + // set the good ends for the association figure + if (resolveSemanticElement() != null) { + refreshVisuals(); + } + } + + /** + * + * {@inheritDoc} + */ + @Override + protected void refreshVisuals() { + if (resolveSemanticElement() != null) { + if (getSource() == null || getTarget() == null) { + return; + } + if (!(getSource() instanceof GraphicalEditPart && getTarget() instanceof GraphicalEditPart)) { + return; + } + // FIXME: This is a quick fix to avoid model corruption when an associationClass is drawn between an association and a Class. + // A better solution would probably be to forbid this behavior. Currently, it is not possible to draw directly an Association Class between + // an association and a class, but it is possible to retarget an AssociationClass' end to an Association (Which would lead to a diagram corruption) + if (((GraphicalEditPart) getSource()).resolveSemanticElement() == null || ((GraphicalEditPart) getTarget()).resolveSemanticElement() == null) { + return; + } + Property source = null; + Property target = null; + // Get the association + Element umlElement = getUMLElement(); + if (umlElement instanceof Association) { + Association association = (Association) getUMLElement(); + assert (association.getMemberEnds().size() >= 2); + if (association.getMemberEnds() != null && association.getMemberEnds().size() >= 2) { + Property firstProperty = association.getMemberEnds().get(0); + Type firstPropertyType = firstProperty.getType(); + if (firstPropertyType!= null && firstPropertyType.equals(((GraphicalEditPart) getSource()).resolveSemanticElement())) { + source = (firstProperty); + target = ((association.getMemberEnds().get(1))); + } else { + source = ((association.getMemberEnds().get(1))); + target = (firstProperty); + } + int sourceType = 0; + int targetType = 0; + // to display the dot. + // owned? + if (!source.getOwner().equals(resolveSemanticElement())) { + sourceType += AssociationFigure.owned; + sourceType += AssociationFigure.navigable; + } + if (!target.getOwner().equals(resolveSemanticElement())) { + targetType += AssociationFigure.owned; + targetType += AssociationFigure.navigable; + } + // aggregation? for it the opposite is changed + if (source.getAggregation() == AggregationKind.SHARED_LITERAL) { + targetType += AssociationFigure.aggregation; + } + if (target.getAggregation() == AggregationKind.SHARED_LITERAL) { + sourceType += AssociationFigure.aggregation; + } + // composite? for it the opposite is changed + if (source.getAggregation() == AggregationKind.COMPOSITE_LITERAL) { + targetType += AssociationFigure.composition; + } + if (target.getAggregation() == AggregationKind.COMPOSITE_LITERAL) { + sourceType += AssociationFigure.composition; + } + // navigable? + if (association.getNavigableOwnedEnds().contains(source)) { + sourceType += AssociationFigure.navigable; + } + if (association.getNavigableOwnedEnds().contains(target)) { + targetType += AssociationFigure.navigable; + } + if (getPrimaryShape() instanceof AssociationFigure) { + ((AssociationFigure) getPrimaryShape()).setEnd(sourceType, targetType); + } + } + } + } + super.refreshVisuals(); + } + + /** + * this method is used to remove listener on ends + */ + protected void removeAssociationEndListeners() { + removeListenerFilter(ASSOCIATION_END_LISTENERS_SOURCE); + removeListenerFilter(ASSOCIATION_END_LISTENERS_TARGET); + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/AssociationEndSourceLabelHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/AssociationEndSourceLabelHelper.java index d9a994074c8..dd3045d0d61 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/AssociationEndSourceLabelHelper.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/AssociationEndSourceLabelHelper.java @@ -1,83 +1,88 @@ -/*****************************************************************************
- * Copyright (c) 2008 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:
- * Patrick Tessier (CEA LIST) - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.helper;
-
-import java.util.Iterator;
-
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.Edge;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.uml2.uml.Association;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Property;
-
-/**
- * Helper for labels displaying {@link Property}
- */
-public class AssociationEndSourceLabelHelper extends AssociationEndPropertyLabelHelper {
-
- private static AssociationEndSourceLabelHelper labelHelper;
-
- public static AssociationEndSourceLabelHelper getInstance() {
- if (labelHelper == null) {
- labelHelper = new AssociationEndSourceLabelHelper();
- }
- return labelHelper;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Property getUMLElement(GraphicalEditPart editPart) {
- if ((View) editPart.getModel() != null && ((View) editPart.getModel()).eContainer() != null) {
- if (((Edge) ((View) editPart.getModel()).eContainer()).getSource() == null) {
- return null;
- }
- Classifier source = (Classifier) ((Edge) ((View) editPart.getModel()).eContainer()).getSource().getElement();
- Property propertyToDisplay = null;
- if (((View) editPart.getModel()) != null && (((View) editPart.getModel()).getElement() instanceof Association)) {
- // look for the property that is typed by the classifier
- Iterator<Property> propertiesIterator = ((Association) ((View) editPart.getModel()).getElement()).getMemberEnds().iterator();
- // find the first
- while (propertiesIterator.hasNext() && propertyToDisplay == null) {
- Property currentProperty = propertiesIterator.next();
- if (EcoreUtil.equals(currentProperty.getType(), source)) {
- propertyToDisplay = currentProperty;
- }
- }
- }
- if (propertyToDisplay != null) {
- return propertyToDisplay;
- }
- // /in the case of reorient the property must be not found,
- // so we have to find the property that is different from the source.
- Classifier target = (Classifier) ((Edge) ((View) editPart.getModel()).eContainer()).getSource().getElement();
- if (((View) editPart.getModel()) != null && (((View) editPart.getModel()).getElement() instanceof Association)) {
- // look for the property that is typed by the classifier
- Iterator<Property> propertiesIterator = ((Association) ((View) editPart.getModel()).getElement()).getMemberEnds().iterator();
- // find the last
- while (propertiesIterator.hasNext()) {
- Property currentProperty = propertiesIterator.next();
- if (!EcoreUtil.equals(currentProperty.getType(), target)) {
- propertyToDisplay = currentProperty;
- }
- }
- }
- return propertyToDisplay;
- }
- return null;
- }
-}
+/***************************************************************************** + * Copyright (c) 2008 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: + * Patrick Tessier (CEA LIST) - Initial API and implementation + * Benoit Maggi (CEA LIST) - Bug 468026 + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.common.helper; + +import java.util.Iterator; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.uml2.uml.Association; +import org.eclipse.uml2.uml.Property; + +/** + * Helper for labels displaying {@link Property} + */ +public class AssociationEndSourceLabelHelper extends AssociationEndPropertyLabelHelper { + + private static AssociationEndSourceLabelHelper labelHelper; + + public static AssociationEndSourceLabelHelper getInstance() { + if (labelHelper == null) { + labelHelper = new AssociationEndSourceLabelHelper(); + } + return labelHelper; + } + + /** + * {@inheritDoc} + */ + @Override + public Property getUMLElement(GraphicalEditPart editPart) { + View model = (View) editPart.getModel(); + if (model != null && model.eContainer() != null) { + Edge eContainer = (Edge) model.eContainer(); + View sourceContainer = eContainer.getSource(); + if (sourceContainer == null) { + return null; + } + + Property propertyToDisplay = null; + if (model != null && (model.getElement() instanceof Association)) { + // look for the property that is typed by the classifier + Iterator<Property> propertiesIterator = ((Association) model.getElement()).getMemberEnds().iterator(); + // find the first + EObject source = sourceContainer.getElement(); + while (propertiesIterator.hasNext() && propertyToDisplay == null) { + Property currentProperty = propertiesIterator.next(); + if (EcoreUtil.equals(currentProperty.getType(), source)) { + propertyToDisplay = currentProperty; + } + } + } + if (propertyToDisplay != null) { + return propertyToDisplay; + } + // /in the case of reorient the property must be not found, + // so we have to find the property that is different from the source. + + if (model != null && (model.getElement() instanceof Association)) { + // look for the property that is typed by the classifier + Iterator<Property> propertiesIterator = ((Association) model.getElement()).getMemberEnds().iterator(); + // find the last + EObject target = sourceContainer.getElement(); + while (propertiesIterator.hasNext()) { + Property currentProperty = propertiesIterator.next(); + if (!EcoreUtil.equals(currentProperty.getType(), target)) { + propertyToDisplay = currentProperty; + } + } + } + return propertyToDisplay; + } + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/AssociationEndTargetLabelHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/AssociationEndTargetLabelHelper.java index e8cc9d6f0f3..7b5452f6848 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/AssociationEndTargetLabelHelper.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/AssociationEndTargetLabelHelper.java @@ -1,88 +1,93 @@ -/*****************************************************************************
- * Copyright (c) 2008 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:
- * Patrick Tessier (CEA LIST) - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.helper;
-
-import java.util.Iterator;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.Edge;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.uml2.uml.Association;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Property;
-
-/**
- * Helper for labels displaying {@link Property}
- */
-public class AssociationEndTargetLabelHelper extends AssociationEndPropertyLabelHelper {
-
- private static AssociationEndTargetLabelHelper labelHelper;
-
- public static AssociationEndTargetLabelHelper getInstance() {
- if (labelHelper == null) {
- labelHelper = new AssociationEndTargetLabelHelper();
- }
- return labelHelper;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Property getUMLElement(GraphicalEditPart editPart) {
- if ((View) editPart.getModel() != null && ((View) editPart.getModel()).eContainer() != null) {
- EObject container = ((View) editPart.getModel()).eContainer();
- if (!(container instanceof Edge)) {
- return null; // Happens e.g. when redoing the suppression of an association's end. The association is contained in a ChangeDescription
- }
- if (((Edge) ((View) editPart.getModel()).eContainer()).getTarget() == null) {
- return null;
- }
- Classifier target = (Classifier) ((Edge) ((View) editPart.getModel()).eContainer()).getTarget().getElement();
- Property propertyToDisplay = null;
- if (((View) editPart.getModel()) != null && (((View) editPart.getModel()).getElement() instanceof Association)) {
- // look for the property that is typed by the classifier
- Iterator<Property> propertiesIterator = ((Association) ((View) editPart.getModel()).getElement()).getMemberEnds().iterator();
- // find the last
- while (propertiesIterator.hasNext()) {
- Property currentProperty = propertiesIterator.next();
- if (EcoreUtil.equals(currentProperty.getType(), target)) {
- propertyToDisplay = currentProperty;
- }
- }
- }
- if (propertyToDisplay != null) {
- return propertyToDisplay;
- }
- // /in the case of reorient the property must be not found,
- // so we have to find the property that is different from the source.
- Classifier source = (Classifier) ((Edge) ((View) editPart.getModel()).eContainer()).getSource().getElement();
- if (((View) editPart.getModel()) != null && (((View) editPart.getModel()).getElement() instanceof Association)) {
- // look for the property that is typed by the classifier
- Iterator<Property> propertiesIterator = ((Association) ((View) editPart.getModel()).getElement()).getMemberEnds().iterator();
- // find the last
- while (propertiesIterator.hasNext()) {
- Property currentProperty = propertiesIterator.next();
- if (!EcoreUtil.equals(currentProperty.getType(), source)) {
- propertyToDisplay = currentProperty;
- }
- }
- }
- return propertyToDisplay;
- }
- return null;
- }
-}
+/***************************************************************************** + * Copyright (c) 2008 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: + * Patrick Tessier (CEA LIST) - Initial API and implementation + * Benoit Maggi (CEA LIST) - Bug 468026 + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.common.helper; + +import java.util.Iterator; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.uml2.uml.Association; +import org.eclipse.uml2.uml.Property; + +/** + * Helper for labels displaying {@link Property} + */ +public class AssociationEndTargetLabelHelper extends AssociationEndPropertyLabelHelper { + + private static AssociationEndTargetLabelHelper labelHelper; + + public static AssociationEndTargetLabelHelper getInstance() { + if (labelHelper == null) { + labelHelper = new AssociationEndTargetLabelHelper(); + } + return labelHelper; + } + + /** + * {@inheritDoc} + */ + @Override + public Property getUMLElement(GraphicalEditPart editPart) { + View model = (View) editPart.getModel(); + if (model != null && model.eContainer() != null) { + EObject container = model.eContainer(); + if (!(container instanceof Edge)) { + return null; // Happens e.g. when redoing the suppression of an association's end. The association is contained in a ChangeDescription + } + Edge eContainer = (Edge) model.eContainer(); + View targetContainer = eContainer.getTarget(); + if (targetContainer == null) { + return null; + } + + Property propertyToDisplay = null; + if (model != null && (model.getElement() instanceof Association)) { + // look for the property that is typed by the classifier + Iterator<Property> propertiesIterator = ((Association) model.getElement()).getMemberEnds().iterator(); + // find the last + EObject element = targetContainer.getElement(); + while (propertiesIterator.hasNext()) { + Property currentProperty = propertiesIterator.next(); + if (EcoreUtil.equals(currentProperty.getType(), element)) { + propertyToDisplay = currentProperty; + } + } + } + if (propertyToDisplay != null) { + return propertyToDisplay; + } + // in the case of reorient the property must be not found, + // so we have to find the property that is different from the source. + + if (model != null && (model.getElement() instanceof Association)) { + // look for the property that is typed by the classifier + Iterator<Property> propertiesIterator = ((Association) model.getElement()).getMemberEnds().iterator(); + // find the last + View sourceContainer = eContainer.getSource(); + EObject element = sourceContainer.getElement(); + while (propertiesIterator.hasNext()) { + Property currentProperty = propertiesIterator.next(); + if (!EcoreUtil.equals(currentProperty.getType(), element)) { + propertyToDisplay = currentProperty; + } + } + } + return propertyToDisplay; + } + return null; + } +} |