diff options
| author | Maxime Porhel | 2015-08-27 13:38:06 +0000 |
|---|---|---|
| committer | Maxime Porhel | 2015-08-28 07:40:03 +0000 |
| commit | 7e4f1861459da4d9d4f6b194572efa2422c23ce1 (patch) | |
| tree | 2052493ce496b3cea5bad3820ec8c4541755785f | |
| parent | d1f3210d8708d8350f8813b7d99bed431894cd98 (diff) | |
| download | org.eclipse.sirius-7e4f1861459da4d9d4f6b194572efa2422c23ce1.tar.gz org.eclipse.sirius-7e4f1861459da4d9d4f6b194572efa2422c23ce1.tar.xz org.eclipse.sirius-7e4f1861459da4d9d4f6b194572efa2422c23ce1.zip | |
[test] Avoid NPE occuring during DNodeList font color refresh in undo()
This NPE seems to occur only during in
KeyboardDeletionFromLabelTests.testDeleteFromLabelWithStandardTool(),
I did not succeed to reproduce with manual steps.
Remove dead code:
. DNodeListElementEditPart will never have children
parts
. Add isActive() guard before calling refresh(). This should be similar
to a getParent() call. This refresh call seems weird: the refresh() is
already called at the begining of the handleNotificationEvent() method.
Fursthermore, ADD_MANY and REMOVE_MANY cases are forgotten.
The NPE occured because an inactive part receive notification from its
GMF node, but it should have been removed from the DiagramEventBroker
listener during deactivate().
I did not find why this is not the case when the test fails.
Change-Id: I4b40f842df0be370fe2a32b4411bf6ff0cae3da0
Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
3 files changed, 8 insertions, 15 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/DiagramNameEditPartOperation.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/DiagramNameEditPartOperation.java index bba31fcdb3..47ceb1b38f 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/DiagramNameEditPartOperation.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/DiagramNameEditPartOperation.java @@ -114,7 +114,7 @@ public final class DiagramNameEditPartOperation { RGBValues labelRGBColor = lStyle.getLabelColor(); Color labelColor = VisualBindingManager.getDefault().getLabelColorFromRGBValues(labelRGBColor); - if (!figure.getForegroundColor().equals(labelColor)) { + if (!(figure.getForegroundColor() != null && figure.getForegroundColor().equals(labelColor))) { figure.setForegroundColor(labelColor); } if (self instanceof IBorderItemEditPart) { diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/DiagramElementEditPartOperation.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/DiagramElementEditPartOperation.java index f8c5984996..69af47f08a 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/DiagramElementEditPartOperation.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/DiagramElementEditPartOperation.java @@ -515,7 +515,7 @@ public final class DiagramElementEditPartOperation { RGBValues labelRGBColor = lStyle.getLabelColor(); Color labelColor = VisualBindingManager.getDefault().getLabelColorFromRGBValues(labelRGBColor); - if (!figure.getForegroundColor().equals(labelColor)) { + if (!(figure.getForegroundColor() != null && figure.getForegroundColor().equals(labelColor))) { figure.setForegroundColor(labelColor); } } @@ -659,7 +659,7 @@ public final class DiagramElementEditPartOperation { if (nodeLabel != null) { nodeLabel.setLabelAlignment(LabelAlignmentHelper.getAsPositionConstant(alignment)); } - } else { + } else if (figure != null) { LayoutManager layoutManager = figure.getLayoutManager(); if (layoutManager instanceof ConstrainedToolbarLayout) { ConstrainedToolbarLayout ctl = (ConstrainedToolbarLayout) layoutManager; diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/DNodeListElementEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/DNodeListElementEditPart.java index 0842982bba..80e38c04b2 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/DNodeListElementEditPart.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/DNodeListElementEditPart.java @@ -14,11 +14,9 @@ import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EObject; import org.eclipse.gef.DragTracker; -import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; import org.eclipse.gef.Request; import org.eclipse.gef.requests.SelectionRequest; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx; @@ -166,14 +164,6 @@ public class DNodeListElementEditPart extends AbstractGeneratedDiagramNameEditPa */ @Override protected void handleNotificationEvent(Notification notification) { - final EditPart styleEditPart = getStyleEditPart(); - // Refreshes edit part. - if (styleEditPart != null) { - final EObject element = ((IGraphicalEditPart) styleEditPart).resolveSemanticElement(); - if (element != null && element.eResource() != null) { - styleEditPart.refresh(); - } - } final EObject element = resolveSemanticElement(); if (element != null && element.eResource() != null && getParent() != null) { refresh(); @@ -185,8 +175,11 @@ public class DNodeListElementEditPart extends AbstractGeneratedDiagramNameEditPa } super.handleNotificationEvent(notification); - if (notification.getEventType() == Notification.SET || notification.getEventType() == Notification.UNSET || notification.getEventType() == Notification.ADD) - refresh(); + if (notification.getEventType() == Notification.SET || notification.getEventType() == Notification.UNSET || notification.getEventType() == Notification.ADD) { + if (isActive()) { + refresh(); + } + } } /** |
