Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2015-06-03 11:21:28 +0000
committerCamille Letavernier2015-06-03 11:21:28 +0000
commit95507f53deadeac399984a8424614695473814db (patch)
tree4383121f8df1b6a8b936a70681ded469f835540b
parent23eb8565b8e5b99be652f75353bd5e525fdb8c41 (diff)
downloadorg.eclipse.papyrus-1.1.0_RC3.tar.gz
org.eclipse.papyrus-1.1.0_RC3.tar.xz
org.eclipse.papyrus-1.1.0_RC3.zip
469170: [Activity Diagram, others?] NullPointerException in1.1.0_RC3
AbstractMaskManagedEditPolicy.getView (159) https://bugs.eclipse.org/bugs/show_bug.cgi?id=469170 - Add NPE checks in MaskManaged edit policies Change-Id: Idaa58864fe89fc112da8be4382cf08bb12daba18 Signed-off-by: Camille Letavernier <camille.letavernier@cea.fr>
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ActivityParameterMaskEditPolicy.java27
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractMaskManagedEditPolicy.java21
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/IndirectPortLabelEditPolicy.java14
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/IndirectPropertyLabelEditPolicy.java14
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/MaskManagedFloatingLabelEditPolicy.java14
5 files changed, 63 insertions, 27 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ActivityParameterMaskEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ActivityParameterMaskEditPolicy.java
index 58f03bc792f..6bfe9c1073f 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ActivityParameterMaskEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ActivityParameterMaskEditPolicy.java
@@ -1,6 +1,6 @@
/*****************************************************************************
* 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
@@ -8,7 +8,7 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
- *
+ *
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.activity.edit.policies;
@@ -46,11 +46,11 @@ public class ActivityParameterMaskEditPolicy extends AbstractMaskManagedEditPoli
if (node == null) {
return;
}
- //add listner to parameter
+ // add listner to parameter
addListener(node.getParameter());
- //add listner to type
+ // add listner to type
addListener(node.getType());
- //add listner to states
+ // add listner to states
for (State state : node.getInStates()) {
addListener(state);
}
@@ -58,11 +58,13 @@ public class ActivityParameterMaskEditPolicy extends AbstractMaskManagedEditPoli
/**
* Add this class to target's listners.
- * @param target may be null
+ *
+ * @param target
+ * may be null
*/
protected void addListener(Object target) {
if (target instanceof EObject) {
- getDiagramEventBroker().addNotificationListener((EObject)target, this);
+ getDiagramEventBroker().addNotificationListener((EObject) target, this);
}
}
@@ -256,12 +258,12 @@ public class ActivityParameterMaskEditPolicy extends AbstractMaskManagedEditPoli
// remove listner from type
removeListenerFromElement(activityParameterNode.getType());
// remove listner from states
- for (State state: activityParameterNode.getInStates()) {
+ for (State state : activityParameterNode.getInStates()) {
removeListenerFromElement(state);
}
}
-
- protected void removeListenerFromElement(Object target) {
+
+ protected void removeListenerFromElement(Object target) {
if (target instanceof EObject) {
getDiagramEventBroker().removeNotificationListener((EObject) target, this);
}
@@ -285,9 +287,12 @@ public class ActivityParameterMaskEditPolicy extends AbstractMaskManagedEditPoli
@Override
protected View getView() {
View view = super.getView();
+ if (view == null) {
+ return null;
+ }
if (view instanceof Shape) {
return view;
}
- return (View)view.eContainer();
+ return (View) view.eContainer();
}
} \ No newline at end of file
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractMaskManagedEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractMaskManagedEditPolicy.java
index 74512d241c9..c95ff196656 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractMaskManagedEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractMaskManagedEditPolicy.java
@@ -46,16 +46,22 @@ public abstract class AbstractMaskManagedEditPolicy extends GraphicalEditPolicyE
protected Element hostSemanticElement;
/**
+ * Store the view to be able to remove the listener afterwards
+ */
+ protected View view;
+
+ /**
*
* {@inheritDoc}
*/
@Override
public void activate() {
// retrieve the view and the element managed by the edit part
- View view = getView();
+ view = getView();
if (view == null) {
return;
}
+
hostSemanticElement = initSemanticElement();
if (hostSemanticElement != null) {
@@ -103,13 +109,10 @@ public abstract class AbstractMaskManagedEditPolicy extends GraphicalEditPolicyE
*/
@Override
public void deactivate() {
- // retrieve the view and the element managed by the edit part
- View view = getView();
- if (view == null) {
- return;
- }
// remove notification on element and view
- getDiagramEventBroker().removeNotificationListener(view, this);
+ if (view != null) {
+ getDiagramEventBroker().removeNotificationListener(view, this);
+ }
if (hostSemanticElement != null) {
getDiagramEventBroker().removeNotificationListener(hostSemanticElement, this);
@@ -118,6 +121,7 @@ public abstract class AbstractMaskManagedEditPolicy extends GraphicalEditPolicyE
// removes the reference to the semantic element
hostSemanticElement = null;
+ view = null;
}
/**
@@ -156,6 +160,9 @@ public abstract class AbstractMaskManagedEditPolicy extends GraphicalEditPolicyE
* @return the view controlled by the host edit part
*/
protected View getView() {
+ if (getHost() == null) {
+ return null;
+ }
return (View) getHost().getModel();
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/IndirectPortLabelEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/IndirectPortLabelEditPolicy.java
index 43e278c9242..aaa5f2a5b88 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/IndirectPortLabelEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/IndirectPortLabelEditPolicy.java
@@ -12,6 +12,7 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.editpolicies;
+import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy;
@@ -29,9 +30,16 @@ public class IndirectPortLabelEditPolicy extends PortLabelEditPolicy implements
*/
@Override
protected View getView() {
- if (getHost().getModel() instanceof View) {
- if (((View) getHost().getModel()).eContainer() instanceof View) {
- return (View) ((View) getHost().getModel()).eContainer();
+ EditPart host = getHost();
+ if (host == null) {
+ return null;
+ }
+
+ Object hostView = host.getModel();
+ if (hostView instanceof View) {
+ Object parentView = ((View) hostView).eContainer();
+ if (parentView instanceof View) {
+ return (View) parentView;
}
return null;
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/IndirectPropertyLabelEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/IndirectPropertyLabelEditPolicy.java
index 7ee8305d6fa..c6097d4a9c8 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/IndirectPropertyLabelEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/IndirectPropertyLabelEditPolicy.java
@@ -12,6 +12,7 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.editpolicies;
+import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy;
@@ -29,9 +30,16 @@ public class IndirectPropertyLabelEditPolicy extends PropertyLabelEditPolicy imp
*/
@Override
protected View getView() {
- if (getHost().getModel() instanceof View) {
- if (((View) getHost().getModel()).eContainer() instanceof View) {
- return (View) ((View) getHost().getModel()).eContainer();
+ EditPart host = getHost();
+ if (host == null) {
+ return null;
+ }
+
+ Object hostView = host.getModel();
+ if (hostView instanceof View) {
+ Object parentView = ((View) hostView).eContainer();
+ if (parentView instanceof View) {
+ return (View) parentView;
}
return null;
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/MaskManagedFloatingLabelEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/MaskManagedFloatingLabelEditPolicy.java
index 450abb48d6e..d8e4ecaaab8 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/MaskManagedFloatingLabelEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/MaskManagedFloatingLabelEditPolicy.java
@@ -18,6 +18,7 @@ import java.util.Map;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.common.Activator;
@@ -161,9 +162,16 @@ public class MaskManagedFloatingLabelEditPolicy extends AbstractMaskManagedEditP
*/
@Override
protected View getView() {
- if (getHost().getModel() instanceof View) {
- if (((View) getHost().getModel()).eContainer() instanceof View) {
- return (View) ((View) getHost().getModel()).eContainer();
+ EditPart host = getHost();
+ if (host == null) {
+ return null;
+ }
+
+ Object hostView = host.getModel();
+ if (hostView instanceof View) {
+ Object parentView = ((View) hostView).eContainer();
+ if (parentView instanceof View) {
+ return (View) parentView;
}
return null;
}

Back to the top