Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2014-10-24 14:50:24 +0000
committerCamille Letavernier2014-10-24 14:50:24 +0000
commitc28280bacd87ca81c3dcfe8afd0cc9896d36907d (patch)
treebed54a72f3a9c684878f3a95226be52ff14f5523 /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence
parenta49796c8296ef7b91428c15f717dc88a462cd813 (diff)
downloadorg.eclipse.papyrus-c28280bacd87ca81c3dcfe8afd0cc9896d36907d.tar.gz
org.eclipse.papyrus-c28280bacd87ca81c3dcfe8afd0cc9896d36907d.tar.xz
org.eclipse.papyrus-c28280bacd87ca81c3dcfe8afd0cc9896d36907d.zip
448732: [Sequence Diagram] NullPointerException when opening the context
menu on a Lifeline https://bugs.eclipse.org/bugs/show_bug.cgi?id=448732
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CustomDiagramDragDropEditPolicy.java112
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CombinedFragmentMoveHelper.java83
2 files changed, 106 insertions, 89 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CustomDiagramDragDropEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CustomDiagramDragDropEditPolicy.java
index 3a3546c4512..9996c227f40 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CustomDiagramDragDropEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CustomDiagramDragDropEditPolicy.java
@@ -215,12 +215,17 @@ public class CustomDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPo
}
boolean someCombinedFragment = false;
- boolean someNonCombinedFragment = false;
- for (Object part : ((ChangeBoundsRequest)request).getEditParts()) {
- someCombinedFragment |= (part instanceof CustomCombinedFragmentEditPart);
- someNonCombinedFragment |= !(part instanceof CustomCombinedFragmentEditPart);
+ boolean someNonCombinedFragment = false;
+
+ List<?> editParts = ((ChangeBoundsRequest) request).getEditParts();
+
+ if (editParts != null) {
+ for (Object part : editParts) {
+ someCombinedFragment |= (part instanceof CustomCombinedFragmentEditPart);
+ someNonCombinedFragment |= !(part instanceof CustomCombinedFragmentEditPart);
+ }
}
-
+
if (someCombinedFragment && someNonCombinedFragment) {
// Can't Drop CombinedFragment and other nodes at the same time
return UnexecutableCommand.INSTANCE;
@@ -229,49 +234,52 @@ public class CustomDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPo
return command;
}
else {
- return getMoveCombinedFragmentCommand((ChangeBoundsRequest)request);
+ return getMoveCombinedFragmentCommand((ChangeBoundsRequest) request);
}
}
/*
* "In-place" drag-and-drop command for Combined Fragment
- *
*/
protected Command getMoveCombinedFragmentCommand(ChangeBoundsRequest request) {
- CompoundCommand cc = new CompoundCommand("move CombinedFragments to new parent"); //$NON-NLS-1$
-
+ CompoundCommand cc = new CompoundCommand("move CombinedFragments to new parent"); //$NON-NLS-1$
+
Rectangle rectangleDroppedCombined = CombinedFragmentMoveHelper.calcCombinedRect(request);
GraphicalEditPart newParentEP = CombinedFragmentMoveHelper.findNewParentEP(request, getHost());
-
+
+ List<?> editParts = request.getEditParts();
+
// Move the request's CFs models and views
- for (Object part : ((ChangeBoundsRequest)request).getEditParts()) {
- CustomCombinedFragmentEditPart combinedFragmentEP = (CustomCombinedFragmentEditPart)part;
- CombinedFragment combinedFragment = (CombinedFragment)ViewUtil.
- resolveSemanticElement((View)((IGraphicalEditPart)combinedFragmentEP).getModel());
-
- if (combinedFragmentEP.getParent() == newParentEP) {
- continue; // no change of the parent
- }
-
- View containerNewParent = (View)newParentEP.getModel();
- EObject contextNewParent = ViewUtil.resolveSemanticElement(containerNewParent);
- TransactionalEditingDomain editingDomain = ((IGraphicalEditPart)getHost()).getEditingDomain();
-
- // Move semantic
- Command moveSemanticCmd = getHost().getCommand(new EditCommandRequestWrapper(
- new MoveRequest(editingDomain, contextNewParent, combinedFragment)));
- if (moveSemanticCmd == null) {
- return UnexecutableCommand.INSTANCE;
+ if (editParts != null) {
+ for (Object part : editParts) {
+ CustomCombinedFragmentEditPart combinedFragmentEP = (CustomCombinedFragmentEditPart) part;
+ CombinedFragment combinedFragment = (CombinedFragment) ViewUtil.
+ resolveSemanticElement((View) ((IGraphicalEditPart) combinedFragmentEP).getModel());
+
+ if (combinedFragmentEP.getParent() == newParentEP) {
+ continue; // no change of the parent
+ }
+
+ View containerNewParent = (View) newParentEP.getModel();
+ EObject contextNewParent = ViewUtil.resolveSemanticElement(containerNewParent);
+ TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
+
+ // Move semantic
+ Command moveSemanticCmd = getHost().getCommand(new EditCommandRequestWrapper(
+ new MoveRequest(editingDomain, contextNewParent, combinedFragment)));
+ if (moveSemanticCmd == null) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ cc.add(moveSemanticCmd);
+
+ // Move view
+ View container = (View) newParentEP.getModel();
+ View view = (View) combinedFragmentEP.getModel();
+ cc.add(new ICommandProxy(new AddCommand(combinedFragmentEP.getEditingDomain(), new EObjectAdapter(container),
+ new EObjectAdapter(view))));
}
- cc.add(moveSemanticCmd);
+ }
- // Move view
- View container = (View)newParentEP.getModel();
- View view = (View)combinedFragmentEP.getModel();
- cc.add(new ICommandProxy(new AddCommand(combinedFragmentEP.getEditingDomain(), new EObjectAdapter(container),
- new EObjectAdapter(view))));
- }
-
// Calc new parent rect
Rectangle newParentOldRect = newParentEP.getFigure().getBounds().getCopy();
newParentEP.getFigure().translateToAbsolute(newParentOldRect);
@@ -279,9 +287,9 @@ public class CustomDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPo
if (getHost().getParent() instanceof CustomCombinedFragmentEditPart) {
CombinedFragmentMoveHelper.adjustNewParentOperands(cc, newParentNewRect, newParentOldRect, getHost());
- }
+ }
// TODO: resize parent's parent (and so on)
-
+
// Move & resize parent CF
Point newParentOffsetSW = new Point(newParentNewRect.x - newParentOldRect.x, newParentNewRect.y - newParentOldRect.y);
if (newParentEP.getParent().getParent() != null) {
@@ -294,15 +302,17 @@ public class CustomDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPo
moveParentRequest.setResizeDirection(PositionConstants.SOUTH_WEST);
cc.add(newParentEP.getParent().getParent().getCommand(moveParentRequest));
}
-
- for (Object part : ((ChangeBoundsRequest)request).getEditParts()) {
- CustomCombinedFragmentEditPart combinedFragmentEP = (CustomCombinedFragmentEditPart)part;
- CombinedFragmentMoveHelper.moveCombinedFragmentEP(cc, request, combinedFragmentEP, newParentEP, newParentOffsetSW);
- }
+
+ if (editParts != null) {
+ for (Object part : request.getEditParts()) {
+ CustomCombinedFragmentEditPart combinedFragmentEP = (CustomCombinedFragmentEditPart) part;
+ CombinedFragmentMoveHelper.moveCombinedFragmentEP(cc, request, combinedFragmentEP, newParentEP, newParentOffsetSW);
+ }
+ }
return cc;
}
-
+
@Override
protected IUndoableOperation getDropObjectCommand(DropObjectsRequest dropRequest, final EObject droppedObject) {
IUndoableOperation dropObjectCommand = super.getDropObjectCommand(dropRequest, droppedObject);
@@ -500,18 +510,18 @@ public class CustomDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPo
/*
* To extend the method in superclass with an option Dimension size,
- *
- *
+ *
+ *
* @param hostEP
- *
+ *
* @param nodeVISUALID
- *
+ *
* @param absoluteLocation
- *
+ *
* @param size
- *
+ *
* @param droppedObject
- *
+ *
* @return
*/
protected ICommand dropCombinedFragment(EditPart hostEP, int nodeVISUALID, Point absoluteLocation, Dimension size, EObject droppedObject) {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CombinedFragmentMoveHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CombinedFragmentMoveHelper.java
index b313fc856fa..1a0698a3915 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CombinedFragmentMoveHelper.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CombinedFragmentMoveHelper.java
@@ -1,7 +1,7 @@
/*****************************************************************************
* Copyright (c) 2009 CEA
*
- *
+ *
* 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
@@ -40,27 +40,33 @@ import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandEdi
import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.InteractionCompartmentXYLayoutEditPolicy;
public class CombinedFragmentMoveHelper {
-
+
protected final static int CF_PADDING = 10;
-
+
/**
* Calculate combined rect
- *
+ *
*/
public static Rectangle calcCombinedRect(ChangeBoundsRequest request) {
- Rectangle rectangleDroppedCombined = new Rectangle();
- for (Object part : request.getEditParts()) {
- CombinedFragmentEditPart combinedFragmentEP = (CombinedFragmentEditPart)part;
- Rectangle rectangleDropped = combinedFragmentEP.getFigure().getBounds().getCopy();
- combinedFragmentEP.getFigure().translateToAbsolute(rectangleDropped);
-
- if (!rectangleDroppedCombined.isEmpty()) {
- rectangleDroppedCombined = new Rectangle(rectangleDropped.getUnion(rectangleDroppedCombined));
- }
- else {
- rectangleDroppedCombined = rectangleDropped;
+ Rectangle rectangleDroppedCombined = new Rectangle();
+
+ List<?> editParts = request.getEditParts();
+
+ if (editParts != null) {
+ for (Object part : editParts) {
+ CombinedFragmentEditPart combinedFragmentEP = (CombinedFragmentEditPart) part;
+ Rectangle rectangleDropped = combinedFragmentEP.getFigure().getBounds().getCopy();
+ combinedFragmentEP.getFigure().translateToAbsolute(rectangleDropped);
+
+ if (!rectangleDroppedCombined.isEmpty()) {
+ rectangleDroppedCombined = new Rectangle(rectangleDropped.getUnion(rectangleDroppedCombined));
+ }
+ else {
+ rectangleDroppedCombined = rectangleDropped;
+ }
}
}
+
rectangleDroppedCombined.translate(request.getMoveDelta());
rectangleDroppedCombined.expand(CF_PADDING, CF_PADDING);
return rectangleDroppedCombined;
@@ -68,13 +74,13 @@ public class CombinedFragmentMoveHelper {
/**
* Find the EP that we're dropping to
- *
+ *
*/
public static GraphicalEditPart findNewParentEP(ChangeBoundsRequest request, EditPart hostEP) {
- GraphicalEditPart parentEP = (GraphicalEditPart)hostEP;
+ GraphicalEditPart parentEP = (GraphicalEditPart) hostEP;
if (hostEP.getParent() instanceof CustomCombinedFragmentEditPart) {
// Select which InteractionOperand we're dropping to
- CustomCombinedFragmentEditPart hostCFEP = (CustomCombinedFragmentEditPart)hostEP.getParent();
+ CustomCombinedFragmentEditPart hostCFEP = (CustomCombinedFragmentEditPart) hostEP.getParent();
List<CustomInteractionOperandEditPart> operands = hostCFEP.getOperandChildrenEditParts();
if (!operands.isEmpty()) {
Point location = request.getLocation();
@@ -90,14 +96,14 @@ public class CombinedFragmentMoveHelper {
}
return parentEP;
}
-
+
/**
* Move new parent's operands
- *
+ *
*/
public static void adjustNewParentOperands(CompoundCommand cc, Rectangle newParentNewRect, Rectangle newParentOldRect, EditPart hostEP) {
Set<Object> alreadyMovedBlocks = new HashSet<Object>();
- CustomCombinedFragmentEditPart hostCFEP = (CustomCombinedFragmentEditPart)hostEP.getParent();
+ CustomCombinedFragmentEditPart hostCFEP = (CustomCombinedFragmentEditPart) hostEP.getParent();
List<CustomInteractionOperandEditPart> operands = hostCFEP.getOperandChildrenEditParts();
int moveUpperYOffset = newParentNewRect.y - newParentOldRect.y;
int moveLowerYOffset = newParentNewRect.height - newParentOldRect.height;
@@ -120,23 +126,23 @@ public class CombinedFragmentMoveHelper {
}
ICommand resizeOperandCommand = OperandBoundsComputeHelper.createUpdateEditPartBoundsCommand(operand, operandRect);
cc.add(new ICommandProxy(resizeOperandCommand));
- Command adjustInnerCFsCommand = getShiftEnclosedCFsCommand(operand, offsetInnerCFs);
+ Command adjustInnerCFsCommand = getShiftEnclosedCFsCommand(operand, offsetInnerCFs);
if (adjustInnerCFsCommand != null) {
cc.add(adjustInnerCFsCommand);
}
Command shiftExecutions = OperandBoundsComputeHelper.getForcedShiftEnclosedFragmentsCommand(operand, moveItemsOffset, alreadyMovedBlocks);
- if(shiftExecutions != null) {
+ if (shiftExecutions != null) {
cc.add(new ICommandProxy(new EMFtoGMFCommandWrapper(new GEFtoEMFCommandWrapper(shiftExecutions))));
}
}
}
-
+
/**
* Shift inner CFs so that they don't change absolute coords
- *
+ *
*/
public static Command getShiftEnclosedCFsCommand(InteractionOperandEditPart editPart, Point offset) {
- if(editPart == null || offset.x == 0 && offset.y == 0) {
+ if (editPart == null || offset.x == 0 && offset.y == 0) {
return null;
}
CompoundCommand cc = new CompoundCommand("shift inner CFs"); //$NON-NLS-1$
@@ -145,24 +151,25 @@ public class CombinedFragmentMoveHelper {
if (false == children.get(i) instanceof CustomCombinedFragmentEditPart) {
continue;
}
- CustomCombinedFragmentEditPart childCF = (CustomCombinedFragmentEditPart)children.get(i);
-
+ CustomCombinedFragmentEditPart childCF = (CustomCombinedFragmentEditPart) children.get(i);
+
final ChangeBoundsRequest moveChildCFRequest = new ChangeBoundsRequest();
moveChildCFRequest.setType(RequestConstants.REQ_MOVE);
moveChildCFRequest.setMoveDelta(offset);
moveChildCFRequest.setEditParts(childCF);
moveChildCFRequest.setResizeDirection(PositionConstants.SOUTH_WEST);
cc.add(childCF.getCommand(moveChildCFRequest));
-
+
}
- if (cc.size() == 0)
+ if (cc.size() == 0) {
return null;
+ }
return cc;
}
-
+
/**
* Move CombinedFragment EP
- *
+ *
*/
public static void moveCombinedFragmentEP(CompoundCommand cc, ChangeBoundsRequest request, CustomCombinedFragmentEditPart combinedFragmentEP, GraphicalEditPart newParentEP, Point newParentOffsetSW) {
// Calc CF moveDelta
@@ -172,24 +179,24 @@ public class CombinedFragmentMoveHelper {
// CFs children moveDelta need special processing (no need to translate coords)
Point childrenMoveDelta = moveDelta.getCopy();
- HashMap<String,Object> extData = new HashMap<String,Object>();
+ HashMap<String, Object> extData = new HashMap<String, Object>();
forceLocationRequest.setExtendedData(extData);
extData.put(InteractionCompartmentXYLayoutEditPolicy.CHILDREN_MOVEDELTA, childrenMoveDelta);
// Translate moveDelta into new parents coords
- Rectangle oldParentBounds = ((GraphicalEditPart)combinedFragmentEP.getParent()).getFigure().getBounds().getCopy();
- ((GraphicalEditPart)combinedFragmentEP.getParent()).getFigure().translateToAbsolute(oldParentBounds);
+ Rectangle oldParentBounds = ((GraphicalEditPart) combinedFragmentEP.getParent()).getFigure().getBounds().getCopy();
+ ((GraphicalEditPart) combinedFragmentEP.getParent()).getFigure().translateToAbsolute(oldParentBounds);
moveDelta.translate(oldParentBounds.x, oldParentBounds.y);
Rectangle parentBounds = newParentEP.getFigure().getBounds().getCopy();
newParentEP.getFigure().translateToAbsolute(parentBounds);
moveDelta.translate(-parentBounds.x - newParentOffsetSW.x, -parentBounds.y - newParentOffsetSW.y);
forceLocationRequest.setMoveDelta(moveDelta);
-
+
Point moveLocation = request.getLocation();
- //newParentEP.getFigure().translateToRelative(moveLocation);
+ // newParentEP.getFigure().translateToRelative(moveLocation);
forceLocationRequest.setLocation(moveLocation);
forceLocationRequest.setEditParts(combinedFragmentEP);
cc.add(combinedFragmentEP.getParentInteractionCompartmentEditPart().getCommand(forceLocationRequest));
}
-
+
}

Back to the top