Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Schnekenburger2016-06-20 03:30:08 -0400
committerGerrit Code Review @ Eclipse.org2016-07-05 09:05:23 -0400
commitc2a95d4fb294a1b6f94674bd56b366ab2600d356 (patch)
tree9e1eac3a5e0ec11e33dbbf7729994e907482dd4a
parenta48c48333e21d6fd32bf807d118c6b7631b86a83 (diff)
downloadorg.eclipse.papyrus-c2a95d4fb294a1b6f94674bd56b366ab2600d356.tar.gz
org.eclipse.papyrus-c2a95d4fb294a1b6f94674bd56b366ab2600d356.tar.xz
org.eclipse.papyrus-c2a95d4fb294a1b6f94674bd56b366ab2600d356.zip
bug 496252: [Composite Diagram] NPE in BehaviorPortEditPolicy when port
is not available vie getUMLElement() - remove call to edit policies on refreshvisuals, as edit policies may not be activated at that time - Checks if the policy is active on the refresh of the behavior Port Change-Id: I9d932b7b78afa997bd07fc817d488b4c1368778b Signed-off-by: Remi Schnekenburger <remi.schnekenburger@cea.fr>
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPortEditPart.java6
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/ResizablePortEditPart.java12
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/BehaviorPortEditPolicy.java41
3 files changed, 26 insertions, 33 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPortEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPortEditPart.java
index a6d15f90141..c444cef4a98 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPortEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPortEditPart.java
@@ -27,10 +27,4 @@ public class CustomPortEditPart extends PortEditPart {
super(view);
}
- @Override
- protected void refreshVisuals() {
- BehaviorPortEditPolicy policy = (BehaviorPortEditPolicy)getEditPolicy(BehaviorPortEditPolicy.BEHAVIOR_PORT);
- policy.udaptePortBehavior();
- super.refreshVisuals();
- }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/ResizablePortEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/ResizablePortEditPart.java
index fb11b04c6bf..1462490b640 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/ResizablePortEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/ResizablePortEditPart.java
@@ -103,16 +103,4 @@ public class ResizablePortEditPart extends PortEditPart {
}
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.papyrus.uml.diagram.common.editparts.RoundedBorderNamedElementEditPart#refreshVisuals()
- */
- @Override
- protected void refreshVisuals() {
- BehaviorPortEditPolicy policy = (BehaviorPortEditPolicy) getEditPolicy(BehaviorPortEditPolicy.BEHAVIOR_PORT);
- policy.udaptePortBehavior();
- super.refreshVisuals();
- }
-
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/BehaviorPortEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/BehaviorPortEditPolicy.java
index 0ac0b7e4364..08caedb70b4 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/BehaviorPortEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/BehaviorPortEditPolicy.java
@@ -51,19 +51,22 @@ import org.eclipse.uml2.uml.UMLPackage;
*/
public class BehaviorPortEditPolicy extends GraphicalEditPolicy implements NotificationListener, IPapyrusListener {
public static final String BEHAVIOR_PORT = "BehaviorPortPolicy";
+ private Port port;
@Override
public void notifyChanged(Notification notification) {
// Don't react to notifications for unvisualized ports
if (UMLPackage.eINSTANCE.getPort_IsBehavior().equals(notification.getFeature())
- && getHost().isActive()) {
-
+ && getHost().isActive() && isActive()) {
udaptePortBehavior();
}
}
public void udaptePortBehavior() {
+ if (!isActive()) {
+ return;
+ }
GraphicalEditPart parentEditPart = (GraphicalEditPart) ((GraphicalEditPart) getHost()).getParent();
ShapeCompartmentEditPart targetEditPart = (parentEditPart == null) ? null : getPossibleCompartment(parentEditPart);
if (targetEditPart != null) {
@@ -76,22 +79,28 @@ public class BehaviorPortEditPolicy extends GraphicalEditPolicy implements Notif
IFigure hostFigure = ((PortEditPart) getHost()).getContentPane();
if (hostFigure instanceof PortFigure) {
PortFigure portFigure = (PortFigure) hostFigure;
- Port port = getUMLElement();
- if (port != null) {
- if (port.isBehavior()) {
- if (parentEditPart.resolveSemanticElement() instanceof Classifier || targetEditPart != null) {
- portFigure.restoreBehaviorFigure();
- } else {
- portFigure.removeBehavior();
- }
+ if (port.isBehavior()) {
+ if (parentEditPart.resolveSemanticElement() instanceof Classifier || targetEditPart != null) {
+ portFigure.restoreBehaviorFigure();
} else {
portFigure.removeBehavior();
}
+ } else {
+ portFigure.removeBehavior();
}
}
}
}
+ /**
+ * Checks if current edit policy is active, e.g. it has been already activated.
+ *
+ * @return <code>true</code> if the edit policy has been activated. It will be <code>false</code> when ti has been deactivated also.
+ */
+ protected boolean isActive() {
+ return port != null;
+ }
+
protected void executeBehaviorPortDeletion(final TransactionalEditingDomain domain, final View behaviorNode) {
if ((behaviorNode != null) && (TransactionUtil.getEditingDomain(behaviorNode) == domain)) {
DeleteCommand command = new DeleteCommand(behaviorNode);
@@ -166,18 +175,20 @@ public class BehaviorPortEditPolicy extends GraphicalEditPolicy implements Notif
// adds a listener on the view and the element controlled by the
// editpart
getDiagramEventBroker().addNotificationListener(view, this);
- if (getUMLElement() == null) {
- return;
+ port = getUMLElement();
+ if (port != null) {
+ getDiagramEventBroker().addNotificationListener(port, this);
}
- getDiagramEventBroker().addNotificationListener(getUMLElement(), this);
udaptePortBehavior();
}
@Override
public void deactivate() {
// remove notification on element
- getDiagramEventBroker().removeNotificationListener(getUMLElement(), this);
-
+ getDiagramEventBroker().removeNotificationListener(port, this);
+ getDiagramEventBroker().removeNotificationListener(getView(), this);
+ // release link to the semantic element
+ port = null;
super.deactivate();
}

Back to the top