diff options
author | Quentin Le Menez | 2017-05-18 13:19:22 +0000 |
---|---|---|
committer | Quentin Le Menez | 2017-05-19 11:56:14 +0000 |
commit | 44a31f0d0cfad7a0fd890ede9d7497b9e6ccbcf1 (patch) | |
tree | 3fc4c5a4ac40a411189729df706e6b1297718733 /plugins | |
parent | 6907a978e6db9caa8a5f80c5177354395bc4326f (diff) | |
download | org.eclipse.papyrus-44a31f0d0cfad7a0fd890ede9d7497b9e6ccbcf1.tar.gz org.eclipse.papyrus-44a31f0d0cfad7a0fd890ede9d7497b9e6ccbcf1.tar.xz org.eclipse.papyrus-44a31f0d0cfad7a0fd890ede9d7497b9e6ccbcf1.zip |
Bug 516865 - [Releng] [Oxygen] remove unnecessary syso/syse
- update for the sequece diagram
Change-Id: Iebcfa503af52d6c271252e742ee8be722fcb8795
Signed-off-by: Quentin Le Menez <quentin.lemenez@cea.fr>
Diffstat (limited to 'plugins')
9 files changed, 528 insertions, 482 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/.options b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/.options index e280f1a9a6b..c9d7b1bb8b4 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/.options +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/.options @@ -5,3 +5,8 @@ org.eclipse.papyrus.uml.diagram.sequence/debug=false # Visual IDs
org.eclipse.papyrus.uml.diagram.sequence/debug/visualID=false
+
+# Traces #
+org.eclipse.papyrus.uml.diagram.sequence/debug/SequenceDebug=false
+org.eclipse.papyrus.uml.diagram.sequence/debug/SequenceDebugUtil=false
+org.eclipse.papyrus.uml.diagram.sequence/debug/SequenceDebugGrid=false
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/CustomMessages.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/CustomMessages.java index 398afdc5c80..4814eefb2bb 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/CustomMessages.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/CustomMessages.java @@ -83,27 +83,34 @@ public class CustomMessages extends NLS { * */ public static String Warning_ResizeInteractionOperandTxt; - + /** * Preference messages */ public static String DiagramsPreferencePage_notificationGroup_label = "Automatic creations"; - + public static String DiagramsPreferencePage_executionSpecificationWithSyncMsg_label = "When creating a synchronous message, also create:"; - + public static String DiagramsPreferencePage_executionSpecificationWithAsyncMsg_label = "When creating an asynchronous message, also create:"; public static String DiagramsPreferencePage_createBehaviorExecutionSpecification = "A Behavior Execution Specification"; - + public static String DiagramsPreferencePage_createActionExecutionSpecification = "An Action Execution Specification"; - + public static String DiagramsPreferencePage_createNoExecutionSpecification = "Nothing"; - + /** - * the preferences + * the preferences */ - public static String PREF_EXECUTION_SPECIFICATION_SYNC_MSG = "org.eclipse.papyrus.uml.diagram.sequence.executionSpecificationWithSyncMsg"; - + public static String PREF_EXECUTION_SPECIFICATION_SYNC_MSG = "org.eclipse.papyrus.uml.diagram.sequence.executionSpecificationWithSyncMsg"; + public static String PREF_EXECUTION_SPECIFICATION_ASYNC_MSG = "org.eclipse.papyrus.uml.diagram.sequence.executionSpecificationWithAsyncMsg"; //$NON-NLS-1$ + /** trace massages */ + public static String SEQUENCE_DEBUG = "SequenceDebug"; // //$NON-NLS-0$ + + public static String SEQUENCE_DEBUG_REFERENCEGRID = "SequenceDebugGrid"; // //$NON-NLS-0$ + + public static String SEQUENCE_DEBUG_UTIL = "SequenceDebugUtil"; // //$NON-NLS-0$ + } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/CreateCoordinateCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/CreateCoordinateCommand.java index 99cd7d76ac9..5bef3e05bde 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/CreateCoordinateCommand.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/CreateCoordinateCommand.java @@ -22,6 +22,8 @@ import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant; import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil; import org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.GrillingEditpart; +import org.eclipse.papyrus.uml.diagram.sequence.CustomMessages; +import org.eclipse.papyrus.uml.diagram.sequence.part.UMLDiagramEditorPlugin; import org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.GridManagementEditPolicy; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.Stereotype; @@ -51,9 +53,9 @@ public class CreateCoordinateCommand extends RecordingCommand { public CreateCoordinateCommand(TransactionalEditingDomain domain, BasicCompartment compartment, String name, Element semantic, int position) { super(domain, "create Grilling Structure"); this.compartment = compartment; - this.name= name; - this.position=position; - this.semantic=semantic; + this.name = name; + this.position = position; + this.semantic = semantic; } @@ -61,20 +63,20 @@ public class CreateCoordinateCommand extends RecordingCommand { @Override public void doExecute() { - //create One line - Node coordinate= NotationFactory.eINSTANCE.createDecorationNode(); - Location linelocation=NotationFactory.eINSTANCE.createLocation(); - + // create One line + Node coordinate = NotationFactory.eINSTANCE.createDecorationNode(); + Location linelocation = NotationFactory.eINSTANCE.createLocation(); + coordinate.setType(name); - if (name.startsWith(GridManagementEditPolicy.COLUMN)){ + if (name.startsWith(GridManagementEditPolicy.COLUMN)) { linelocation.setX(position); } - if (name.startsWith(GridManagementEditPolicy.ROW)){ + if (name.startsWith(GridManagementEditPolicy.ROW)) { linelocation.setY(position); - System.out.println(">>>Create row at "+position); + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG, ">>>Create row at " + position); //$NON-NLS-1$ } coordinate.setLayoutConstraint(linelocation); - if( semantic!=null){ + if (semantic != null) { coordinate.setElement(semantic); } ViewUtil.insertChildView(compartment, coordinate, ViewUtil.APPEND, true); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentCombinedFragmentCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentCombinedFragmentCompartmentEditPart.java index e8f81c553d8..06c3a23dd55 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentCombinedFragmentCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentCombinedFragmentCompartmentEditPart.java @@ -22,6 +22,8 @@ import org.eclipse.gef.GraphicalEditPart; import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.sequence.CustomMessages;
+import org.eclipse.papyrus.uml.diagram.sequence.part.UMLDiagramEditorPlugin;
import org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.BoundForEditPart;
/**
@@ -81,7 +83,7 @@ public class CCombinedFragmentCombinedFragmentCompartmentEditPart extends Combin if (ratio >= 1.0) {
ratio = 0.95;
}
- System.out.println("ratio" + ratio);
+ UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG, "ratio" + ratio); //$NON-NLS-1$
childFigure.getParent().setConstraint(childFigure, ratio);
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ConnectMessageToGridEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ConnectMessageToGridEditPolicy.java index 056c2df82d1..7ea448ede6e 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ConnectMessageToGridEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ConnectMessageToGridEditPolicy.java @@ -39,6 +39,7 @@ import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.AutomaticNotationEd import org.eclipse.papyrus.infra.gmfdiag.common.helper.IdentityAnchorHelper; import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper; import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.sequence.CustomMessages; import org.eclipse.papyrus.uml.diagram.sequence.part.UMLDiagramEditorPlugin; import org.eclipse.uml2.uml.Message; import org.eclipse.uml2.uml.NamedElement; @@ -48,15 +49,16 @@ import org.eclipse.uml2.uml.NamedElement; */ public class ConnectMessageToGridEditPolicy extends GraphicalEditPolicyEx implements AutomaticNotationEditPolicy, NotificationListener, IGrillingEditpolicy { - protected GrillingEditpart grillingCompartment=null; + protected GrillingEditpart grillingCompartment = null; - public static String CONNECT_TO_GRILLING_MANAGEMENT="CONNECT_TO_GRILLING_MANAGEMENT"; - protected int displayImprecision=2; + public static String CONNECT_TO_GRILLING_MANAGEMENT = "CONNECT_TO_GRILLING_MANAGEMENT"; + protected int displayImprecision = 2; private View rowSource; private View rowTarget; + /** * Constructor. * @@ -67,22 +69,27 @@ public class ConnectMessageToGridEditPolicy extends GraphicalEditPolicyEx implem /** * update an axis of the grid from coordinate X or Y - * @param axis the axis to update - * @param x the coordinate x - * @param y the coordinate y + * + * @param axis + * the axis to update + * @param x + * the coordinate x + * @param y + * the coordinate y */ protected void updatePositionGridAxis(DecorationNode axis, int x, int y) { - Location currentBounds=(Location) axis.getLayoutConstraint(); - if(x<currentBounds.getX()-displayImprecision||x>currentBounds.getX()+displayImprecision){ - //System.out.println("+---->ACTION: modifiy AXIS to x="+x+" y="+y); - execute( new SetBoundsCommand(getDiagramEditPart(getHost()).getEditingDomain(), "update Column", new EObjectAdapter(axis), new Point(x,y))); + Location currentBounds = (Location) axis.getLayoutConstraint(); + if (x < currentBounds.getX() - displayImprecision || x > currentBounds.getX() + displayImprecision) { + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, "+---->ACTION: modifiy AXIS to x=" + x + " y=" + y);//$NON-NLS-1$ + execute(new SetBoundsCommand(getDiagramEditPart(getHost()).getEditingDomain(), "update Column", new EObjectAdapter(axis), new Point(x, y))); } - if(y<currentBounds.getY()-displayImprecision||y>currentBounds.getY()+displayImprecision){ - //System.out.println("+---->ACTION: modifiy AXIS to x="+x+" y="+y); - execute( new SetBoundsCommand(getDiagramEditPart(getHost()).getEditingDomain(), "update row", new EObjectAdapter(axis), new Point(x,y))); + if (y < currentBounds.getY() - displayImprecision || y > currentBounds.getY() + displayImprecision) { + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, "+---->ACTION: modifiy AXIS to x=" + x + " y=" + y);//$NON-NLS-1$ + execute(new SetBoundsCommand(getDiagramEditPart(getHost()).getEditingDomain(), "update row", new EObjectAdapter(axis), new Point(x, y))); } } + /** * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#activate() * @@ -90,58 +97,59 @@ public class ConnectMessageToGridEditPolicy extends GraphicalEditPolicyEx implem @Override public void activate() { super.activate(); - getDiagramEventBroker().addNotificationListener(((EObject)getHost().getModel()), this); - DiagramEditPart diagramEditPart=getDiagramEditPart(getHost()); - try{ - GridManagementEditPolicy grilling=(GridManagementEditPolicy)diagramEditPart.getEditPolicy(GridManagementEditPolicy.GRILLING_MANAGEMENT); - if (grilling!=null){ - ConnectionEditPart connectionEditPart= (ConnectionEditPart)getHost(); - Edge edge=(Edge)connectionEditPart.getModel(); - IdentityAnchor sourceAnchor=(IdentityAnchor)edge.getSourceAnchor(); - IdentityAnchor targetAnchor=(IdentityAnchor)edge.getSourceAnchor(); - if( sourceAnchor!=null && targetAnchor!=null){ + getDiagramEventBroker().addNotificationListener(((EObject) getHost().getModel()), this); + DiagramEditPart diagramEditPart = getDiagramEditPart(getHost()); + try { + GridManagementEditPolicy grilling = (GridManagementEditPolicy) diagramEditPart.getEditPolicy(GridManagementEditPolicy.GRILLING_MANAGEMENT); + if (grilling != null) { + ConnectionEditPart connectionEditPart = (ConnectionEditPart) getHost(); + Edge edge = (Edge) connectionEditPart.getModel(); + IdentityAnchor sourceAnchor = (IdentityAnchor) edge.getSourceAnchor(); + IdentityAnchor targetAnchor = (IdentityAnchor) edge.getSourceAnchor(); + if (sourceAnchor != null && targetAnchor != null) { - //source - if(sourceAnchor.getId()!=null&& !(sourceAnchor.getId().equals(""))){ - View viewsr=edge.getSource(); - Message m= (Message)connectionEditPart.resolveSemanticElement(); - double ypercent=IdentityAnchorHelper.getYPercentage(sourceAnchor); - PrecisionRectangle bounds= NotationHelper.getAbsoluteBounds((Node)viewsr); - double localY=(bounds.preciseHeight()*ypercent); - double absoluteY=localY+bounds.preciseY(); - if(m.getSendEvent()==null){ - rowSource=grilling.createRowTolisten((int)absoluteY,m); - }else{ - rowSource=grilling.createRowTolisten((int)absoluteY,m.getSendEvent()); + // source + if (sourceAnchor.getId() != null && !(sourceAnchor.getId().equals(""))) { + View viewsr = edge.getSource(); + Message m = (Message) connectionEditPart.resolveSemanticElement(); + double ypercent = IdentityAnchorHelper.getYPercentage(sourceAnchor); + PrecisionRectangle bounds = NotationHelper.getAbsoluteBounds((Node) viewsr); + double localY = (bounds.preciseHeight() * ypercent); + double absoluteY = localY + bounds.preciseY(); + if (m.getSendEvent() == null) { + rowSource = grilling.createRowTolisten((int) absoluteY, m); + } else { + rowSource = grilling.createRowTolisten((int) absoluteY, m.getSendEvent()); } getDiagramEventBroker().addNotificationListener(rowSource, this); } - //target - if(targetAnchor.getId()!=null&& !(targetAnchor.getId().equals(""))){ - View viewtg=edge.getTarget(); - double ypercent=IdentityAnchorHelper.getYPercentage(targetAnchor); - Message m= (Message)connectionEditPart.resolveSemanticElement(); - PrecisionRectangle bounds= NotationHelper.getAbsoluteBounds((Node)viewtg); - double localY=(bounds.preciseHeight()*ypercent); - double absoluteY=localY+bounds.preciseY(); - if(m.getReceiveEvent()==null){ - rowTarget=grilling.createRowTolisten((int)absoluteY,m);} - else{ - rowTarget=grilling.createRowTolisten((int)absoluteY,m.getReceiveEvent()); + // target + if (targetAnchor.getId() != null && !(targetAnchor.getId().equals(""))) { + View viewtg = edge.getTarget(); + double ypercent = IdentityAnchorHelper.getYPercentage(targetAnchor); + Message m = (Message) connectionEditPart.resolveSemanticElement(); + PrecisionRectangle bounds = NotationHelper.getAbsoluteBounds((Node) viewtg); + double localY = (bounds.preciseHeight() * ypercent); + double absoluteY = localY + bounds.preciseY(); + if (m.getReceiveEvent() == null) { + rowTarget = grilling.createRowTolisten((int) absoluteY, m); + } else { + rowTarget = grilling.createRowTolisten((int) absoluteY, m.getReceiveEvent()); } getDiagramEventBroker().addNotificationListener(rowTarget, this); } } } - }catch (NoGrillElementFound e) { + } catch (NoGrillElementFound e) { UMLDiagramEditorPlugin.log.error(e); } } - /** Gets the diagram event broker from the editing domain. + /** + * Gets the diagram event broker from the editing domain. * * @return the diagram event broker */ @@ -160,7 +168,7 @@ public class ConnectMessageToGridEditPolicy extends GraphicalEditPolicyEx implem */ @Override public void deactivate() { - getDiagramEventBroker().removeNotificationListener(((EObject)getHost().getModel()), this); + getDiagramEventBroker().removeNotificationListener(((EObject) getHost().getModel()), this); super.deactivate(); } @@ -171,150 +179,149 @@ public class ConnectMessageToGridEditPolicy extends GraphicalEditPolicyEx implem */ @Override public void notifyChanged(Notification notification) { - DiagramEditPart diagramEditPart=getDiagramEditPart(getHost()); - if( diagramEditPart!=null){ - //CREATION - if( notification.getNotifier().equals(((EObject)getHost().getModel())) && NotationPackage.eINSTANCE.getEdge_SourceAnchor().equals(notification.getFeature())&& notification.getNewValue()!=null){ - //System.out.println("+ EVENT :CREATION add SourceAnchor "+notification.getNotifier()); - IdentityAnchor anchor=(IdentityAnchor)notification.getNewValue(); - if(anchor.getId()!=null&& !(anchor.getId().equals(""))){ - ConnectionEditPart connectionEditPart= (ConnectionEditPart)getHost(); - Message m= (Message)connectionEditPart.resolveSemanticElement(); - NamedElementEditPart sourceEditpart=(NamedElementEditPart)connectionEditPart.getSource(); - int anchorY=computeAnchorPositionNotation(anchor, sourceEditpart); - try{ - GridManagementEditPolicy grilling=(GridManagementEditPolicy)diagramEditPart.getEditPolicy(GridManagementEditPolicy.GRILLING_MANAGEMENT); - if (grilling!=null){ - if( rowSource==null) { - if(m.getSendEvent()==null){ - rowSource=grilling.createRowTolisten(anchorY,m); - }else{ - rowSource=grilling.createRowTolisten(anchorY,m.getSendEvent()); + DiagramEditPart diagramEditPart = getDiagramEditPart(getHost()); + if (diagramEditPart != null) { + // CREATION + if (notification.getNotifier().equals(((EObject) getHost().getModel())) && NotationPackage.eINSTANCE.getEdge_SourceAnchor().equals(notification.getFeature()) && notification.getNewValue() != null) { + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, "+ EVENT :CREATION add SourceAnchor " + notification.getNotifier());//$NON-NLS-1$ + IdentityAnchor anchor = (IdentityAnchor) notification.getNewValue(); + if (anchor.getId() != null && !(anchor.getId().equals(""))) { + ConnectionEditPart connectionEditPart = (ConnectionEditPart) getHost(); + Message m = (Message) connectionEditPart.resolveSemanticElement(); + NamedElementEditPart sourceEditpart = (NamedElementEditPart) connectionEditPart.getSource(); + int anchorY = computeAnchorPositionNotation(anchor, sourceEditpart); + try { + GridManagementEditPolicy grilling = (GridManagementEditPolicy) diagramEditPart.getEditPolicy(GridManagementEditPolicy.GRILLING_MANAGEMENT); + if (grilling != null) { + if (rowSource == null) { + if (m.getSendEvent() == null) { + rowSource = grilling.createRowTolisten(anchorY, m); + } else { + rowSource = grilling.createRowTolisten(anchorY, m.getSendEvent()); } } getDiagramEventBroker().addNotificationListener(rowSource, this); } - }catch (NoGrillElementFound e) { + } catch (NoGrillElementFound e) { UMLDiagramEditorPlugin.log.error(e); } } } - //CREATION - if( notification.getNotifier().equals(((EObject)getHost().getModel())) && NotationPackage.eINSTANCE.getEdge_TargetAnchor().equals(notification.getFeature()) && notification.getNewValue()!=null){ - //System.out.println("+ EVENT: CREATION add targetAnchor "+notification.getNotifier()); - IdentityAnchor anchor=(IdentityAnchor)notification.getNewValue(); - if(anchor.getId()!=null&& !(anchor.getId().equals(""))){ - ConnectionEditPart connectionEditPart= (ConnectionEditPart)getHost(); - NamedElementEditPart editpart=(NamedElementEditPart)connectionEditPart.getTarget(); - Message m= (Message)connectionEditPart.resolveSemanticElement(); - int anchorY=computeAnchorPositionNotation(anchor, editpart); - try{ - GridManagementEditPolicy grilling=(GridManagementEditPolicy)diagramEditPart.getEditPolicy(GridManagementEditPolicy.GRILLING_MANAGEMENT); - if (grilling!=null){ - if( rowTarget==null) { - if(m.getReceiveEvent()==null){ - rowTarget=grilling.createRowTolisten(anchorY, m); - } - else{ - rowTarget=grilling.createRowTolisten(anchorY, m.getReceiveEvent()); + // CREATION + if (notification.getNotifier().equals(((EObject) getHost().getModel())) && NotationPackage.eINSTANCE.getEdge_TargetAnchor().equals(notification.getFeature()) && notification.getNewValue() != null) { + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, "+ EVENT: CREATION add targetAnchor " + notification.getNotifier());//$NON-NLS-1$ + IdentityAnchor anchor = (IdentityAnchor) notification.getNewValue(); + if (anchor.getId() != null && !(anchor.getId().equals(""))) { + ConnectionEditPart connectionEditPart = (ConnectionEditPart) getHost(); + NamedElementEditPart editpart = (NamedElementEditPart) connectionEditPart.getTarget(); + Message m = (Message) connectionEditPart.resolveSemanticElement(); + int anchorY = computeAnchorPositionNotation(anchor, editpart); + try { + GridManagementEditPolicy grilling = (GridManagementEditPolicy) diagramEditPart.getEditPolicy(GridManagementEditPolicy.GRILLING_MANAGEMENT); + if (grilling != null) { + if (rowTarget == null) { + if (m.getReceiveEvent() == null) { + rowTarget = grilling.createRowTolisten(anchorY, m); + } else { + rowTarget = grilling.createRowTolisten(anchorY, m.getReceiveEvent()); } } getDiagramEventBroker().addNotificationListener(rowTarget, this); } - }catch (NoGrillElementFound e) { + } catch (NoGrillElementFound e) { UMLDiagramEditorPlugin.log.error(e); } } } - //A move has been done by the user - if( notification.getEventType()==Notification.SET&& notification.getNotifier() instanceof IdentityAnchor ){ - //System.out.println("+EVENT IdentificationAnchor change "+notification.getNotifier()); - ConnectionEditPart connectionEditPart= (ConnectionEditPart)getHost(); - Edge edge= (Edge)connectionEditPart.getNotationView(); - if( notification.getNotifier().equals(edge.getSourceAnchor())&& rowSource!=null){ - IdentityAnchor anchor=(IdentityAnchor)edge.getSourceAnchor(); - NamedElementEditPart sourceEditpart=(NamedElementEditPart)connectionEditPart.getSource(); - int anchorY=computeAnchorPositionNotation(anchor, sourceEditpart); - //System.out.println("+--> SOURCE change for "+((NamedElement)connectionEditPart.resolveSemanticElement()).getName()+" to "+anchorY+ " "); - updatePositionGridAxis((DecorationNode)rowSource, 0, anchorY); + // A move has been done by the user + if (notification.getEventType() == Notification.SET && notification.getNotifier() instanceof IdentityAnchor) { + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, "+EVENT IdentificationAnchor change " + notification.getNotifier());//$NON-NLS-1$ + ConnectionEditPart connectionEditPart = (ConnectionEditPart) getHost(); + Edge edge = (Edge) connectionEditPart.getNotationView(); + if (notification.getNotifier().equals(edge.getSourceAnchor()) && rowSource != null) { + IdentityAnchor anchor = (IdentityAnchor) edge.getSourceAnchor(); + NamedElementEditPart sourceEditpart = (NamedElementEditPart) connectionEditPart.getSource(); + int anchorY = computeAnchorPositionNotation(anchor, sourceEditpart); + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, "+--> SOURCE change for " + ((NamedElement) connectionEditPart.resolveSemanticElement()).getName() + " to " + anchorY + " ");//$NON-NLS-1$ + updatePositionGridAxis((DecorationNode) rowSource, 0, anchorY); } - if( notification.getNotifier().equals(edge.getTargetAnchor())&& rowTarget!=null){ - IdentityAnchor anchor=(IdentityAnchor)edge.getTargetAnchor(); - NamedElementEditPart editpart=(NamedElementEditPart)connectionEditPart.getTarget(); - int anchorY=computeAnchorPositionNotation(anchor, editpart); - //System.out.println("+-->TARGET change "+((NamedElement)connectionEditPart.resolveSemanticElement()).getName()+" to "+anchorY+ " "); - updatePositionGridAxis((DecorationNode)rowTarget, 0, anchorY); + if (notification.getNotifier().equals(edge.getTargetAnchor()) && rowTarget != null) { + IdentityAnchor anchor = (IdentityAnchor) edge.getTargetAnchor(); + NamedElementEditPart editpart = (NamedElementEditPart) connectionEditPart.getTarget(); + int anchorY = computeAnchorPositionNotation(anchor, editpart); + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, "+-->TARGET change " + ((NamedElement) connectionEditPart.resolveSemanticElement()).getName() + " to " + anchorY + " ");//$NON-NLS-1$ + updatePositionGridAxis((DecorationNode) rowTarget, 0, anchorY); } } - //a ROW AXIS has changed at Source - if( notification.getEventType()==Notification.SET && notification.getNotifier() instanceof Location &&(((EObject)notification.getNotifier()).eContainer().equals(rowSource)) ){ - //System.out.println("+ EVENT source Axis modified :" +notification); - GridManagementEditPolicy grilling=(GridManagementEditPolicy)diagramEditPart.getEditPolicy(GridManagementEditPolicy.GRILLING_MANAGEMENT); - if (grilling!=null){ - if(Math.abs(notification.getOldIntValue()-notification.getNewIntValue())>grilling.threshold){ - ConnectionEditPart connectionEditPart= (ConnectionEditPart)getHost(); - Edge edge=(Edge)connectionEditPart.getModel(); - IdentityAnchor sourceAchor=(IdentityAnchor)edge.getSourceAnchor(); - View viewsr=edge.getSource(); - modifyAnchor(sourceAchor,(Node)viewsr,(DecorationNode) rowSource); + // a ROW AXIS has changed at Source + if (notification.getEventType() == Notification.SET && notification.getNotifier() instanceof Location && (((EObject) notification.getNotifier()).eContainer().equals(rowSource))) { + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, "+ EVENT source Axis modified :" + notification);//$NON-NLS-1$ + GridManagementEditPolicy grilling = (GridManagementEditPolicy) diagramEditPart.getEditPolicy(GridManagementEditPolicy.GRILLING_MANAGEMENT); + if (grilling != null) { + if (Math.abs(notification.getOldIntValue() - notification.getNewIntValue()) > grilling.threshold) { + ConnectionEditPart connectionEditPart = (ConnectionEditPart) getHost(); + Edge edge = (Edge) connectionEditPart.getModel(); + IdentityAnchor sourceAchor = (IdentityAnchor) edge.getSourceAnchor(); + View viewsr = edge.getSource(); + modifyAnchor(sourceAchor, (Node) viewsr, (DecorationNode) rowSource); } } } - //a ROW has changed at target - if( notification.getEventType()==Notification.SET && notification.getNotifier() instanceof Location &&(((EObject)notification.getNotifier()).eContainer().equals(rowTarget)) ){ - // System.out.println("+ EVENT target axis modified:" +notification); - GridManagementEditPolicy grilling=(GridManagementEditPolicy)diagramEditPart.getEditPolicy(GridManagementEditPolicy.GRILLING_MANAGEMENT); - if (grilling!=null){ - if(Math.abs(notification.getOldIntValue()-notification.getNewIntValue())>grilling.threshold){ - ConnectionEditPart connectionEditPart= (ConnectionEditPart)getHost(); - Edge edge=(Edge)connectionEditPart.getModel(); - IdentityAnchor targetAchor=(IdentityAnchor)edge.getTargetAnchor(); - View viewtg=edge.getTarget(); - modifyAnchor( targetAchor, (Node)viewtg,(DecorationNode)rowTarget); + // a ROW has changed at target + if (notification.getEventType() == Notification.SET && notification.getNotifier() instanceof Location && (((EObject) notification.getNotifier()).eContainer().equals(rowTarget))) { + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, "+ EVENT target Axis modified :" + notification);//$NON-NLS-1$ + GridManagementEditPolicy grilling = (GridManagementEditPolicy) diagramEditPart.getEditPolicy(GridManagementEditPolicy.GRILLING_MANAGEMENT); + if (grilling != null) { + if (Math.abs(notification.getOldIntValue() - notification.getNewIntValue()) > grilling.threshold) { + ConnectionEditPart connectionEditPart = (ConnectionEditPart) getHost(); + Edge edge = (Edge) connectionEditPart.getModel(); + IdentityAnchor targetAchor = (IdentityAnchor) edge.getTargetAnchor(); + View viewtg = edge.getTarget(); + modifyAnchor(targetAchor, (Node) viewtg, (DecorationNode) rowTarget); } } } } } - protected void modifyAnchor( IdentityAnchor anchor, Node connectedView, DecorationNode axis) { - double xpercent=IdentityAnchorHelper.getXPercentage(anchor); - PrecisionRectangle bounds= NotationHelper.getAbsoluteBounds(connectedView); - bounds.height=BoundForEditPart.getHeightFromView(connectedView); - Location boundsRow=(Location) ((Node)axis).getLayoutConstraint(); - Integer intergerY= new Integer(boundsRow.getY()); - double newY= intergerY.doubleValue(); - double localY=(newY-bounds.preciseY()); + protected void modifyAnchor(IdentityAnchor anchor, Node connectedView, DecorationNode axis) { + double xpercent = IdentityAnchorHelper.getXPercentage(anchor); + PrecisionRectangle bounds = NotationHelper.getAbsoluteBounds(connectedView); + bounds.height = BoundForEditPart.getHeightFromView(connectedView); + Location boundsRow = (Location) ((Node) axis).getLayoutConstraint(); + Integer intergerY = new Integer(boundsRow.getY()); + double newY = intergerY.doubleValue(); + double localY = (newY - bounds.preciseY()); - double newPercentY = localY/bounds.preciseHeight(); - double oldPercentY=IdentityAnchorHelper.getYPercentage(anchor); - if( Math.abs(oldPercentY-newPercentY)>0.05) { - if(newPercentY>1){ - newPercentY=0.99; + double newPercentY = localY / bounds.preciseHeight(); + double oldPercentY = IdentityAnchorHelper.getYPercentage(anchor); + if (Math.abs(oldPercentY - newPercentY) > 0.05) { + if (newPercentY > 1) { + newPercentY = 0.99; } - if(newPercentY<0){ - newPercentY=0.01; + if (newPercentY < 0) { + newPercentY = 0.01; } if (newPercentY <= 1 && newPercentY >= 0 && newPercentY <= 1 && newPercentY >= 0) { final String newIdValue = IdentityAnchorHelper.createNewAnchorIdValue(xpercent, newPercentY); - //System.out.println("+---->ACTION: modify anchor to precentY="+newPercentY); + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, "+---->ACTION: modify anchor to precentY=" + newPercentY);//$NON-NLS-1$ execute(new SetCommand(getDiagramEditPart(getHost()).getEditingDomain(), anchor, NotationPackage.eINSTANCE.getIdentityAnchor_Id(), newIdValue)); } } } - public static int computeAnchorPositionNotation(IdentityAnchor anchor,GraphicalEditPart nodeEditPart){ - double yPercent=IdentityAnchorHelper.getYPercentage(anchor); - Node node=(Node)nodeEditPart.getNotationView(); - PrecisionRectangle bounds= NotationHelper.getAbsoluteBounds(node); - double height=BoundForEditPart.getHeightFromView(node); - int anchorY= (int) (height*yPercent)+bounds.y; + public static int computeAnchorPositionNotation(IdentityAnchor anchor, GraphicalEditPart nodeEditPart) { + double yPercent = IdentityAnchorHelper.getYPercentage(anchor); + Node node = (Node) nodeEditPart.getNotationView(); + PrecisionRectangle bounds = NotationHelper.getAbsoluteBounds(node); + double height = BoundForEditPart.getHeightFromView(node); + int anchorY = (int) (height * yPercent) + bounds.y; return anchorY; - } + } }
\ No newline at end of file diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/GridManagementEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/GridManagementEditPolicy.java index b3922a9225d..81c8b64b58a 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/GridManagementEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/GridManagementEditPolicy.java @@ -46,9 +46,11 @@ import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.AutomaticNotationEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramEditPartsUtil; +import org.eclipse.papyrus.uml.diagram.sequence.CustomMessages; import org.eclipse.papyrus.uml.diagram.sequence.command.CreateCoordinateCommand; import org.eclipse.papyrus.uml.diagram.sequence.command.CreateGrillingStructureCommand; import org.eclipse.papyrus.uml.diagram.sequence.keyboardlistener.KeyToSetMoveLinesListener; +import org.eclipse.papyrus.uml.diagram.sequence.part.UMLDiagramEditorPlugin; import org.eclipse.swt.SWT; import org.eclipse.ui.PlatformUI; import org.eclipse.uml2.uml.Element; @@ -61,27 +63,27 @@ import org.eclipse.uml2.uml.UMLPackage; * This edit policy is used to manage the referential grid of the sequence diagram * */ -public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements AutomaticNotationEditPolicy, NotificationListener, IGrillingEditpolicy{ +public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements AutomaticNotationEditPolicy, NotificationListener, IGrillingEditpolicy { public static final String GRILL_CONNECTION = "Grill Connection"; - protected GrillingEditpart grillingCompartment=null; + protected GrillingEditpart grillingCompartment = null; - public static String GRILLING_MANAGEMENT="GRILLING_MANAGEMENT"; - public static String COLUMN="COLUMN_"; - public static String ROW="ROW_"; + public static String GRILLING_MANAGEMENT = "GRILLING_MANAGEMENT"; + public static String COLUMN = "COLUMN_"; + public static String ROW = "ROW_"; - public int threshold=10; - public int margin=50; - public boolean respectMargin=true; - public boolean moveAllLinesAtSamePosition=false; - - public ArrayList<DecorationNode> rows= new ArrayList<DecorationNode>(); - public ArrayList<DecorationNode> columns= new ArrayList<DecorationNode>(); + public int threshold = 10; + public int margin = 50; + public boolean respectMargin = true; + public boolean moveAllLinesAtSamePosition = false; - //ok if the creation a X is free - public boolean CREATION_X_FREE=true; - /**if the CREATION_X_FREE == false COLUMN are created at fixed position**/ - public int X_SPACING=100; + public ArrayList<DecorationNode> rows = new ArrayList<DecorationNode>(); + public ArrayList<DecorationNode> columns = new ArrayList<DecorationNode>(); + + // ok if the creation a X is free + public boolean CREATION_X_FREE = true; + /** if the CREATION_X_FREE == false COLUMN are created at fixed position **/ + public int X_SPACING = 100; private ContentDiagramListener contentDiagramListener; private CommandStackListener commandStackListener; @@ -93,11 +95,12 @@ public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements A } /** - * @param moveAllLinesAtSamePosition the moveAllLinesAtSamePosition to set + * @param moveAllLinesAtSamePosition + * the moveAllLinesAtSamePosition to set */ public void setMoveAllLinesAtSamePosition(boolean moveAllLinesAtSamePosition) { - ////System.out.println(">> set moveAllLinesAtSamePosition="+moveAllLinesAtSamePosition); + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, ">> set moveAllLinesAtSamePosition=" + moveAllLinesAtSamePosition);//$NON-NLS-1$ this.moveAllLinesAtSamePosition = moveAllLinesAtSamePosition; } @@ -109,7 +112,8 @@ public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements A } /** - * @param respectMargin the respectMargin to set + * @param respectMargin + * the respectMargin to set */ public void setRespectMargin(boolean respectMargin) { this.respectMargin = respectMargin; @@ -117,38 +121,38 @@ public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements A - public boolean strictRespectMargin=true; + public boolean strictRespectMargin = true; - public Comparator<DecorationNode> RowComparator =new Comparator<DecorationNode>(){ + public Comparator<DecorationNode> RowComparator = new Comparator<DecorationNode>() { @Override public int compare(DecorationNode o1, DecorationNode o2) { - LayoutConstraint layoutConstrainto1=((Node)o1).getLayoutConstraint(); - LayoutConstraint layoutConstrainto2=((Node)o2).getLayoutConstraint(); - if( layoutConstrainto1!=null && layoutConstrainto2!=null){ - return ((Integer)((Location)layoutConstrainto1).getY()).compareTo(((Integer)((Location)layoutConstrainto2).getY())); + LayoutConstraint layoutConstrainto1 = ((Node) o1).getLayoutConstraint(); + LayoutConstraint layoutConstrainto2 = ((Node) o2).getLayoutConstraint(); + if (layoutConstrainto1 != null && layoutConstrainto2 != null) { + return ((Integer) ((Location) layoutConstrainto1).getY()).compareTo(((Integer) ((Location) layoutConstrainto2).getY())); } return 0; } }; - public Comparator<DecorationNode> ColumnComparator =new Comparator<DecorationNode>(){ + public Comparator<DecorationNode> ColumnComparator = new Comparator<DecorationNode>() { @Override public int compare(DecorationNode o1, DecorationNode o2) { - LayoutConstraint layoutConstrainto1=((Node)o1).getLayoutConstraint(); - LayoutConstraint layoutConstrainto2=((Node)o2).getLayoutConstraint(); - if( layoutConstrainto1!=null && layoutConstrainto2!=null){ - return ((Integer)((Location)layoutConstrainto1).getX()).compareTo(((Integer)((Location)layoutConstrainto2).getX())); + LayoutConstraint layoutConstrainto1 = ((Node) o1).getLayoutConstraint(); + LayoutConstraint layoutConstrainto2 = ((Node) o2).getLayoutConstraint(); + if (layoutConstrainto1 != null && layoutConstrainto2 != null) { + return ((Integer) ((Location) layoutConstrainto1).getX()).compareTo(((Integer) ((Location) layoutConstrainto2).getX())); } return 0; } }; - + /** @@ -165,41 +169,42 @@ public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements A @Override public void activate() { super.activate(); - getDiagramEventBroker().addNotificationListener(((EObject)getHost().getModel()), this); + getDiagramEventBroker().addNotificationListener(((EObject) getHost().getModel()), this); contentDiagramListener = new ContentDiagramListener(this); - commandStackListener =new GridCommandStackListener(this); - ((EObject)getHost().getModel()).eResource().eAdapters().add(contentDiagramListener); + commandStackListener = new GridCommandStackListener(this); + ((EObject) getHost().getModel()).eResource().eAdapters().add(contentDiagramListener); getDiagramEditPart(getHost()).getEditingDomain().getCommandStack().addCommandStackListener(commandStackListener); - PlatformUI.getWorkbench().getDisplay().addFilter(SWT.KeyDown, new KeyToSetMoveLinesListener(this,SWT.SHIFT,false)); - PlatformUI.getWorkbench().getDisplay().addFilter(SWT.KeyUp, new KeyToSetMoveLinesListener(this,SWT.SHIFT,true)); + PlatformUI.getWorkbench().getDisplay().addFilter(SWT.KeyDown, new KeyToSetMoveLinesListener(this, SWT.SHIFT, false)); + PlatformUI.getWorkbench().getDisplay().addFilter(SWT.KeyUp, new KeyToSetMoveLinesListener(this, SWT.SHIFT, true)); refreshGrillingStructure(); } + /** * */ private void refreshGrillingStructure() { - EditPart host= getHost(); - int i=0; - while( grillingCompartment==null && i <host.getChildren().size()){ - if( host.getChildren().get(i) instanceof GrillingEditpart){ - grillingCompartment=(GrillingEditpart) (host.getChildren().get(i)); + EditPart host = getHost(); + int i = 0; + while (grillingCompartment == null && i < host.getChildren().size()) { + if (host.getChildren().get(i) instanceof GrillingEditpart) { + grillingCompartment = (GrillingEditpart) (host.getChildren().get(i)); } i++; } - if( grillingCompartment==null){ - CreateGrillingStructureCommand createGrillingStructureCommand= new CreateGrillingStructureCommand(((IGraphicalEditPart) getHost()).getEditingDomain(), (View)getHost().getModel()); + if (grillingCompartment == null) { + CreateGrillingStructureCommand createGrillingStructureCommand = new CreateGrillingStructureCommand(((IGraphicalEditPart) getHost()).getEditingDomain(), (View) getHost().getModel()); // Record for undo if possible, otherwise unprotected execute(createGrillingStructureCommand); } - while( grillingCompartment==null && i <host.getChildren().size()){ - if( host.getChildren().get(i) instanceof GrillingEditpart){ - grillingCompartment=(GrillingEditpart) (host.getChildren().get(i)); + while (grillingCompartment == null && i < host.getChildren().size()) { + if (host.getChildren().get(i) instanceof GrillingEditpart) { + grillingCompartment = (GrillingEditpart) (host.getChildren().get(i)); } i++; } - //cleanUnusedRowAndColumn(); + // cleanUnusedRowAndColumn(); updateRowsAndColumns(); } @@ -211,50 +216,51 @@ public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements A rows.clear(); columns.clear(); - if(grillingCompartment!=null){ - for (int j=0;j<grillingCompartment.getNotationView().getChildren().size(); j++){ - if(grillingCompartment.getNotationView().getChildren().get(j) instanceof DecorationNode ){ - DecorationNode decorationNode=(DecorationNode)grillingCompartment.getNotationView().getChildren().get(j); - if(decorationNode.getType().startsWith(ROW) ){ + if (grillingCompartment != null) { + for (int j = 0; j < grillingCompartment.getNotationView().getChildren().size(); j++) { + if (grillingCompartment.getNotationView().getChildren().get(j) instanceof DecorationNode) { + DecorationNode decorationNode = (DecorationNode) grillingCompartment.getNotationView().getChildren().get(j); + if (decorationNode.getType().startsWith(ROW)) { rows.add(decorationNode); } - if(decorationNode.getType().startsWith(COLUMN) ){ + if (decorationNode.getType().startsWith(COLUMN)) { columns.add(decorationNode); } } } } - Collections.sort(new ArrayList<>(rows),RowComparator ); - Collections.sort(new ArrayList<>(columns),ColumnComparator ); + Collections.sort(new ArrayList<>(rows), RowComparator); + Collections.sort(new ArrayList<>(columns), ColumnComparator); } - /** this class is very specific the the sequence diagram + /** + * this class is very specific the the sequence diagram * this purpose of this method is to ensure the consistency of event in the the represented diagram - * **/ - public void updateSemanticAfterUpdate(){ - //1. look for all Lifelines - //There are columns. - HashSet<Lifeline> lifelineList= new HashSet<Lifeline>(); + **/ + public void updateSemanticAfterUpdate() { + // 1. look for all Lifelines + // There are columns. + HashSet<Lifeline> lifelineList = new HashSet<Lifeline>(); for (DecorationNode column : columns) { - if ((getRef(column))!=null){ + if ((getRef(column)) != null) { for (EObject referedElement : getRef(column)) { - if( referedElement instanceof Lifeline){ - lifelineList.add((Lifeline)referedElement); + if (referedElement instanceof Lifeline) { + lifelineList.add((Lifeline) referedElement); } } } } - //for each lifeline recreat the list of covered element + // for each lifeline recreat the list of covered element for (Lifeline lifeline : lifelineList) { - ArrayList<InteractionFragment> covered= new ArrayList<InteractionFragment>(); + ArrayList<InteractionFragment> covered = new ArrayList<InteractionFragment>(); for (DecorationNode row : rows) { - if ((getRef(row))!=null){ + if ((getRef(row)) != null) { for (EObject referedElement : getRef(row)) { - if( referedElement instanceof InteractionFragment && (!(referedElement instanceof InteractionOperand))){ - InteractionFragment interactionFragment=(InteractionFragment)(referedElement); - if( lifeline.getCoveredBys().contains(interactionFragment)){ + if (referedElement instanceof InteractionFragment && (!(referedElement instanceof InteractionOperand))) { + InteractionFragment interactionFragment = (InteractionFragment) (referedElement); + if (lifeline.getCoveredBys().contains(interactionFragment)) { covered.add(interactionFragment); } @@ -265,22 +271,21 @@ public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements A } - //3. managment of InteractionOperand - //There are columns. + // 3. managment of InteractionOperand + // There are columns. - ArrayList<InteractionOperand> coveredbyInteractionOperand=new ArrayList<InteractionOperand>(); + ArrayList<InteractionOperand> coveredbyInteractionOperand = new ArrayList<InteractionOperand>(); for (DecorationNode column : columns) { - if ((getRef(column))!=null){ + if ((getRef(column)) != null) { for (EObject referedElement : getRef(column)) { - if( referedElement instanceof InteractionOperand){ - if(!(coveredbyInteractionOperand.contains(referedElement))){ - coveredbyInteractionOperand.add((InteractionOperand)referedElement); - } - else{ - coveredbyInteractionOperand.remove((InteractionOperand)referedElement); + if (referedElement instanceof InteractionOperand) { + if (!(coveredbyInteractionOperand.contains(referedElement))) { + coveredbyInteractionOperand.add((InteractionOperand) referedElement); + } else { + coveredbyInteractionOperand.remove((InteractionOperand) referedElement); } } - if( referedElement.equals(lifeline)){ + if (referedElement.equals(lifeline)) { covered.addAll(coveredbyInteractionOperand); } } @@ -288,17 +293,15 @@ public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements A } - if(covered.size()== lifeline.getCoveredBys().size()){ - ////System.err.println("equality"); + if (covered.size() == lifeline.getCoveredBys().size()) { + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, "equality");//$NON-NLS-1$ execute(new SetCommand(((IGraphicalEditPart) getHost()).getEditingDomain(), lifeline, UMLPackage.eINSTANCE.getLifeline_CoveredBy(), covered)); - } - else if( covered.size()<lifeline.getCoveredBys().size()){ - ////System.err.println("Event not managed or in being created"); - //covered.addAll(lifeline.getCoveredBys()); + } else if (covered.size() < lifeline.getCoveredBys().size()) { + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, "Event not managed or being created");//$NON-NLS-1$ + // covered.addAll(lifeline.getCoveredBys()); execute(new SetCommand(((IGraphicalEditPart) getHost()).getEditingDomain(), lifeline, UMLPackage.eINSTANCE.getLifeline_CoveredBy(), covered)); - } - else if( covered.size()>lifeline.getCoveredBys().size()){ - ////System.err.println("more event that in the lifeline due to combined fragment"); + } else if (covered.size() > lifeline.getCoveredBys().size()) { + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, "more event than in the lifeline due to combined fragment");//$NON-NLS-1$ execute(new SetCommand(((IGraphicalEditPart) getHost()).getEditingDomain(), lifeline, UMLPackage.eINSTANCE.getLifeline_CoveredBy(), covered)); } } @@ -306,7 +309,8 @@ public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements A } - /** Gets the diagram event broker from the editing domain. + /** + * Gets the diagram event broker from the editing domain. * * @return the diagram event broker */ @@ -317,13 +321,14 @@ public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements A } return null; } + /** * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#deactivate() * */ @Override public void deactivate() { - getDiagramEventBroker().removeNotificationListener(((EObject)getHost().getModel()), this); + getDiagramEventBroker().removeNotificationListener(((EObject) getHost().getModel()), this); super.deactivate(); } @@ -334,34 +339,33 @@ public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements A */ @Override public void notifyChanged(Notification notification) { - if( notification instanceof CommandExecutionNotification) { - //after a command execution moveAllLinesAtSamePosition is set to false + if (notification instanceof CommandExecutionNotification) { + // after a command execution moveAllLinesAtSamePosition is set to false // we must explicitly set to true if we want to move it as a line setMoveAllLinesAtSamePosition(true); - //System.out.println("executed Commmand"); - } - else { + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, "executed Command");//$NON-NLS-1$ + } else { - if( notification.getEventType()==Notification.SET && notification.getNotifier() instanceof Location){ + if (notification.getEventType() == Notification.SET && notification.getNotifier() instanceof Location) { updateRowsAndColumns(); - if((((EObject)notification.getNotifier()).eContainer()) instanceof DecorationNode && rows.contains((((EObject)notification.getNotifier()).eContainer()))){ - if(notification.getFeature().equals(NotationPackage.eINSTANCE.getLocation_Y())) { - //when we move line we disconnect listeners to avoid problems of infinite loop - if( moveAllLinesAtSamePosition) { - ArrayList<DecorationNode> rowlist=getRowAtPosition(notification.getOldIntValue()); - ((EObject)getHost().getModel()).eResource().eAdapters().remove(contentDiagramListener); - - //maybe we must move other lines - //it exist other lines - if( rows.size()>rowlist.size()) { - updateYpositionForRow((DecorationNode)(((EObject)notification.getNotifier()).eContainer()),notification.getOldIntValue()); + if ((((EObject) notification.getNotifier()).eContainer()) instanceof DecorationNode && rows.contains((((EObject) notification.getNotifier()).eContainer()))) { + if (notification.getFeature().equals(NotationPackage.eINSTANCE.getLocation_Y())) { + // when we move line we disconnect listeners to avoid problems of infinite loop + if (moveAllLinesAtSamePosition) { + ArrayList<DecorationNode> rowlist = getRowAtPosition(notification.getOldIntValue()); + ((EObject) getHost().getModel()).eResource().eAdapters().remove(contentDiagramListener); + + // maybe we must move other lines + // it exist other lines + if (rows.size() > rowlist.size()) { + updateYpositionForRow((DecorationNode) (((EObject) notification.getNotifier()).eContainer()), notification.getOldIntValue()); } for (Iterator<DecorationNode> iterator = rowlist.iterator(); iterator.hasNext();) { DecorationNode axis = (DecorationNode) iterator.next(); - execute(new SetBoundsCommand(getDiagramEditPart(getHost()).getEditingDomain(), "update Line", new EObjectAdapter(axis), new Point(0,notification.getNewIntValue()))); + execute(new SetBoundsCommand(getDiagramEditPart(getHost()).getEditingDomain(), "update Line", new EObjectAdapter(axis), new Point(0, notification.getNewIntValue()))); } - ((EObject)getHost().getModel()).eResource().eAdapters().add(contentDiagramListener); + ((EObject) getHost().getModel()).eResource().eAdapters().add(contentDiagramListener); } } @@ -374,36 +378,39 @@ public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements A /** * get the decoration node that represents a column from a position (absolute) - * @param x the position x for the column + * + * @param x + * the position x for the column * @return the decoration node */ - public DecorationNode createColumnTolisten( int x, Element semantic) throws NoGrillElementFound{ - execute(new CreateCoordinateCommand(((IGraphicalEditPart) getHost()).getEditingDomain(),((BasicCompartment)grillingCompartment.getNotationView()),COLUMN+columns.size(), semantic,x)); - return getLastCreatedAxis(); + public DecorationNode createColumnTolisten(int x, Element semantic) throws NoGrillElementFound { + execute(new CreateCoordinateCommand(((IGraphicalEditPart) getHost()).getEditingDomain(), ((BasicCompartment) grillingCompartment.getNotationView()), COLUMN + columns.size(), semantic, x)); + return getLastCreatedAxis(); } /** * get the decoration node that represents a line from a position (absolute) - * @param y the position y for the line + * + * @param y + * the position y for the line * @return the decoration node */ - public DecorationNode createRowTolisten( int y, Element semantic) throws NoGrillElementFound{ - execute(new CreateCoordinateCommand(((IGraphicalEditPart) getHost()).getEditingDomain(),((BasicCompartment)grillingCompartment.getNotationView()),ROW+rows.size(), semantic,y)); - DecorationNode row= getLastCreatedAxis(); + public DecorationNode createRowTolisten(int y, Element semantic) throws NoGrillElementFound { + execute(new CreateCoordinateCommand(((IGraphicalEditPart) getHost()).getEditingDomain(), ((BasicCompartment) grillingCompartment.getNotationView()), ROW + rows.size(), semantic, y)); + DecorationNode row = getLastCreatedAxis(); return row; } - /** + /** * @return get the last created Axis - * **/ - public DecorationNode getLastCreatedAxis() throws NoGrillElementFound{ - BasicCompartment grid=((BasicCompartment)grillingCompartment.getNotationView()); - if(grid.getChildren().size()==0) { + **/ + public DecorationNode getLastCreatedAxis() throws NoGrillElementFound { + BasicCompartment grid = ((BasicCompartment) grillingCompartment.getNotationView()); + if (grid.getChildren().size() == 0) { throw new NoGrillElementFound(); - } - else { - return (DecorationNode)grid.getChildren().get(grid.getChildren().size()-1); + } else { + return (DecorationNode) grid.getChildren().get(grid.getChildren().size() - 1); } } @@ -411,51 +418,52 @@ public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements A /** * - * @param y the position y where we look for a row + * @param y + * the position y where we look for a row * @return the rows that exists at the position [y- threshold, y+threshold]s */ - public ArrayList<DecorationNode> getRowAtPosition(int y){ - ArrayList<DecorationNode> sameLines= new ArrayList<DecorationNode>(); + public ArrayList<DecorationNode> getRowAtPosition(int y) { + ArrayList<DecorationNode> sameLines = new ArrayList<DecorationNode>(); for (Iterator<DecorationNode> iterator = rows.iterator(); iterator.hasNext();) { - DecorationNode currentRow = iterator.next(); - int Yposition=getPositionY(currentRow); - if( Yposition-threshold<=y&& y<=Yposition+threshold){ + DecorationNode currentRow = iterator.next(); + int Yposition = getPositionY(currentRow); + if (Yposition - threshold <= y && y <= Yposition + threshold) { sameLines.add(currentRow); } } return sameLines; } - + /** * @param decorationNode * @return the Position Y for a decoration node */ - public int getPositionY(DecorationNode decorationNode){ - LayoutConstraint constraint=decorationNode.getLayoutConstraint(); - if( constraint instanceof Location){ - return((Location)constraint).getY(); + public int getPositionY(DecorationNode decorationNode) { + LayoutConstraint constraint = decorationNode.getLayoutConstraint(); + if (constraint instanceof Location) { + return ((Location) constraint).getY(); } return 0; } - protected void updateYpositionForRow(DecorationNode movedRow, int y){ - LayoutConstraint newconstraint=movedRow.getLayoutConstraint(); - DecorationNode nextRow=getDistanceWithNextRow(movedRow,y); - if( nextRow==null) { + protected void updateYpositionForRow(DecorationNode movedRow, int y) { + LayoutConstraint newconstraint = movedRow.getLayoutConstraint(); + DecorationNode nextRow = getDistanceWithNextRow(movedRow, y); + if (nextRow == null) { return; } - LayoutConstraint nextConstraint=nextRow.getLayoutConstraint(); - int nextDistance=((Location)nextConstraint).getY()-((Location)newconstraint).getY(); + LayoutConstraint nextConstraint = nextRow.getLayoutConstraint(); + int nextDistance = ((Location) nextConstraint).getY() - ((Location) newconstraint).getY(); int margin = getGridSpacing(); - if( nextDistance<margin){ - ArrayList<DecorationNode> rowsCopy= new ArrayList<DecorationNode>(); + if (nextDistance < margin) { + ArrayList<DecorationNode> rowsCopy = new ArrayList<DecorationNode>(); rowsCopy.addAll(rows); - for (int i=rowsCopy.indexOf(nextRow); i<rowsCopy.size();i++) { - LayoutConstraint aConstraint=rowsCopy.get(i).getLayoutConstraint(); - if( aConstraint instanceof Location){ - execute(new SetCommand(((IGraphicalEditPart) getHost()).getEditingDomain(), aConstraint, NotationPackage.eINSTANCE.getLocation_Y(), ((Location)aConstraint).getY()+margin)); + for (int i = rowsCopy.indexOf(nextRow); i < rowsCopy.size(); i++) { + LayoutConstraint aConstraint = rowsCopy.get(i).getLayoutConstraint(); + if (aConstraint instanceof Location) { + execute(new SetCommand(((IGraphicalEditPart) getHost()).getEditingDomain(), aConstraint, NotationPackage.eINSTANCE.getLocation_Y(), ((Location) aConstraint).getY() + margin)); } } } @@ -467,23 +475,22 @@ public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements A * @param currentRowPosition * @return get the next row that has not the same position */ - protected DecorationNode getDistanceWithNextRow(DecorationNode currentRow, int currentRowPosition){ - Object[] arrayRow= rows.toArray(); - List<Object> orderedRows= Arrays.asList(arrayRow); - int index=orderedRows.indexOf(currentRow); - if(index==orderedRows.size()-1){ + protected DecorationNode getDistanceWithNextRow(DecorationNode currentRow, int currentRowPosition) { + Object[] arrayRow = rows.toArray(); + List<Object> orderedRows = Arrays.asList(arrayRow); + int index = orderedRows.indexOf(currentRow); + if (index == orderedRows.size() - 1) { return null; - } - else{ + } else { - LayoutConstraint currentConstraint=currentRow.getLayoutConstraint(); - DecorationNode nextRow=null; - //look for the next row + LayoutConstraint currentConstraint = currentRow.getLayoutConstraint(); + DecorationNode nextRow = null; + // look for the next row for (Iterator<DecorationNode> iterator = rows.iterator(); iterator.hasNext();) { - DecorationNode aRow = iterator.next(); - int Yposition=getPositionY(aRow); - if( currentRowPosition+threshold<Yposition&& (!aRow.equals(currentRow))){ - nextRow=aRow; + DecorationNode aRow = iterator.next(); + int Yposition = getPositionY(aRow); + if (currentRowPosition + threshold < Yposition && (!aRow.equals(currentRow))) { + nextRow = aRow; return nextRow; } @@ -492,33 +499,32 @@ public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements A } } - protected int getGridSpacing(){ - if(DiagramEditPartsUtil.isSnapToGridActive(getHost())){ + protected int getGridSpacing() { + if (DiagramEditPartsUtil.isSnapToGridActive(getHost())) { - RootEditPart drep=getHost().getRoot(); - if( drep instanceof DiagramRootEditPart){ - return (int) ((DiagramRootEditPart)drep).getGridSpacing(); + RootEditPart drep = getHost().getRoot(); + if (drep instanceof DiagramRootEditPart) { + return (int) ((DiagramRootEditPart) drep).getGridSpacing(); } } return margin; } - public static Point getLocation(DecorationNode current) throws NoGrillElementFound{ - LayoutConstraint currentConstraint=current.getLayoutConstraint(); - if( currentConstraint instanceof Location){ - return new Point (((Location)currentConstraint).getX(), ((Location)currentConstraint).getY()); - } - else{ + + public static Point getLocation(DecorationNode current) throws NoGrillElementFound { + LayoutConstraint currentConstraint = current.getLayoutConstraint(); + if (currentConstraint instanceof Location) { + return new Point(((Location) currentConstraint).getX(), ((Location) currentConstraint).getY()); + } else { throw new NoGrillElementFound(); } } - public static List<EObject> getRef(DecorationNode current){ - EAnnotation eAnnotation =current.getEAnnotation(GRILL_CONNECTION); - if(eAnnotation==null){ + public static List<EObject> getRef(DecorationNode current) { + EAnnotation eAnnotation = current.getEAnnotation(GRILL_CONNECTION); + if (eAnnotation == null) { return null; - } - else{ - if(eAnnotation.getReferences().size()!=0){ + } else { + if (eAnnotation.getReferences().size() != 0) { return eAnnotation.getReferences(); } return null; diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/LifeLineXYLayoutEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/LifeLineXYLayoutEditPolicy.java index 510dcc297d3..12453548e59 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/LifeLineXYLayoutEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/LifeLineXYLayoutEditPolicy.java @@ -59,9 +59,11 @@ import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.XYLayoutWithConstra import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramEditPartsUtil; import org.eclipse.papyrus.uml.diagram.common.figure.node.EllipseFigure; import org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeCreationTool; +import org.eclipse.papyrus.uml.diagram.sequence.CustomMessages; import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.AbstractExecutionSpecificationEditPart; import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CLifeLineEditPart; import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart; +import org.eclipse.papyrus.uml.diagram.sequence.part.UMLDiagramEditorPlugin; import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceRequestConstant; import org.eclipse.papyrus.uml.service.types.element.UMLDIElementTypes; import org.eclipse.papyrus.uml.service.types.utils.ElementUtil; @@ -71,9 +73,10 @@ import org.eclipse.uml2.uml.MessageOccurrenceSpecification; * This class is used to manage node element in the compartment by using grill system. * */ -public class LifeLineXYLayoutEditPolicy extends XYLayoutWithConstrainedResizedEditPolicy implements IGrillingEditpolicy{ +public class LifeLineXYLayoutEditPolicy extends XYLayoutWithConstrainedResizedEditPolicy implements IGrillingEditpolicy { protected DisplayEvent displayEvent; + /** * Constructor. * @@ -92,44 +95,47 @@ public class LifeLineXYLayoutEditPolicy extends XYLayoutWithConstrainedResizedEd public void setHost(EditPart host) { // TODO Auto-generated method stub super.setHost(host); - displayEvent= new DisplayEvent(getHost()); + displayEvent = new DisplayEvent(getHost()); } - - /* Override to use to deal with causes where the point is UNDERFINED + + /* + * Override to use to deal with causes where the point is UNDERFINED * we will ask the layout helper to find a location for us + * * @see org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#getConstraintFor(org.eclipse.gef.requests.CreateRequest) */ protected Object getConstraintFor(CreateRequest request) { // Used during the creation from the palette Object constraint = super.getConstraintFor(request); - if(request instanceof CreateViewAndElementRequest){ - CreateViewAndElementRequest req=(CreateViewAndElementRequest)request; - ViewAndElementDescriptor descriptor=(req).getViewAndElementDescriptor(); + if (request instanceof CreateViewAndElementRequest) { + CreateViewAndElementRequest req = (CreateViewAndElementRequest) request; + ViewAndElementDescriptor descriptor = (req).getViewAndElementDescriptor(); IElementType elementType = (IElementType) descriptor.getElementAdapter().getAdapter(IElementType.class); - if (ElementUtil.isTypeOf(elementType, UMLDIElementTypes.ACTION_EXECUTION_SPECIFICATION_SHAPE)|| - ElementUtil.isTypeOf(elementType, UMLDIElementTypes.BEHAVIOR_EXECUTION_SPECIFICATION_SHAPE)){ - Rectangle parentBound=getHostFigure().getBounds(); - if(constraint instanceof Rectangle){ - Rectangle constraintRect= (Rectangle)constraint; - RootEditPart drep=getHost().getRoot(); - if( drep instanceof DiagramRootEditPart){ - - double spacing = ((DiagramRootEditPart)drep).getGridSpacing(); - if( constraintRect.height==-1){ - constraintRect.height=AbstractExecutionSpecificationEditPart.DEFAUT_HEIGHT; + if (ElementUtil.isTypeOf(elementType, UMLDIElementTypes.ACTION_EXECUTION_SPECIFICATION_SHAPE) || + ElementUtil.isTypeOf(elementType, UMLDIElementTypes.BEHAVIOR_EXECUTION_SPECIFICATION_SHAPE)) { + Rectangle parentBound = getHostFigure().getBounds(); + if (constraint instanceof Rectangle) { + Rectangle constraintRect = (Rectangle) constraint; + RootEditPart drep = getHost().getRoot(); + if (drep instanceof DiagramRootEditPart) { + + double spacing = ((DiagramRootEditPart) drep).getGridSpacing(); + if (constraintRect.height == -1) { + constraintRect.height = AbstractExecutionSpecificationEditPart.DEFAUT_HEIGHT; } - constraintRect.width= AbstractExecutionSpecificationEditPart.DEFAUT_WIDTH; - constraintRect.x=(parentBound.width/2)-(constraintRect.width/2); - if(DiagramEditPartsUtil.isSnapToGridActive(getHost())){ - int modulo= AbstractExecutionSpecificationEditPart.DEFAUT_HEIGHT/(int)spacing; - constraintRect.height=modulo*(int)spacing; + constraintRect.width = AbstractExecutionSpecificationEditPart.DEFAUT_WIDTH; + constraintRect.x = (parentBound.width / 2) - (constraintRect.width / 2); + if (DiagramEditPartsUtil.isSnapToGridActive(getHost())) { + int modulo = AbstractExecutionSpecificationEditPart.DEFAUT_HEIGHT / (int) spacing; + constraintRect.height = modulo * (int) spacing; } } } } } - return constraint; + return constraint; } + /** * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#showLayoutTargetFeedback(org.eclipse.gef.Request) * @@ -140,35 +146,35 @@ public class LifeLineXYLayoutEditPolicy extends XYLayoutWithConstrainedResizedEd // feed back during the creation from the palette - RootEditPart drep=getHost().getRoot(); - Rectangle parentBound=getHostFigure().getBounds().getCopy(); + RootEditPart drep = getHost().getRoot(); + Rectangle parentBound = getHostFigure().getBounds().getCopy(); getHostFigure().getParent().translateToAbsolute(parentBound); - //System.out.println("LifeLineBounds On Screen:"+parentBound); - if( drep instanceof DiagramRootEditPart){ - double spacing = ((DiagramRootEditPart)drep).getGridSpacing(); - if(request instanceof org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeCreationTool.CreateAspectUnspecifiedTypeRequest){ - IElementType elementType = (IElementType)((org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeCreationTool.CreateAspectUnspecifiedTypeRequest)request).getElementTypes().get(0); - if (ElementUtil.isTypeOf(elementType, UMLDIElementTypes.ACTION_EXECUTION_SPECIFICATION_SHAPE)|| - ElementUtil.isTypeOf(elementType, UMLDIElementTypes.BEHAVIOR_EXECUTION_SPECIFICATION_SHAPE)){ - ((CreateRequest)request).setLocation(new Point((parentBound.x+(parentBound.width/2)-AbstractExecutionSpecificationEditPart.DEFAUT_WIDTH/2),((CreateRequest)request).getLocation().y)); - int modulo= AbstractExecutionSpecificationEditPart.DEFAUT_HEIGHT/(int)spacing; - ((CreateRequest)request).setSize(new Dimension(AbstractExecutionSpecificationEditPart.DEFAUT_WIDTH,modulo*(int)spacing)); - - - displayEvent.addFigureEvent(getHostFigure().getParent().getParent(), ((CreateRequest)request).getLocation()); + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_REFERENCEGRID, "LifeLineBounds On Screen:" + parentBound);//$NON-NLS-1$ + if (drep instanceof DiagramRootEditPart) { + double spacing = ((DiagramRootEditPart) drep).getGridSpacing(); + if (request instanceof org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeCreationTool.CreateAspectUnspecifiedTypeRequest) { + IElementType elementType = (IElementType) ((org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeCreationTool.CreateAspectUnspecifiedTypeRequest) request).getElementTypes().get(0); + if (ElementUtil.isTypeOf(elementType, UMLDIElementTypes.ACTION_EXECUTION_SPECIFICATION_SHAPE) || + ElementUtil.isTypeOf(elementType, UMLDIElementTypes.BEHAVIOR_EXECUTION_SPECIFICATION_SHAPE)) { + ((CreateRequest) request).setLocation(new Point((parentBound.x + (parentBound.width / 2) - AbstractExecutionSpecificationEditPart.DEFAUT_WIDTH / 2), ((CreateRequest) request).getLocation().y)); + int modulo = AbstractExecutionSpecificationEditPart.DEFAUT_HEIGHT / (int) spacing; + ((CreateRequest) request).setSize(new Dimension(AbstractExecutionSpecificationEditPart.DEFAUT_WIDTH, modulo * (int) spacing)); + + + displayEvent.addFigureEvent(getHostFigure().getParent().getParent(), ((CreateRequest) request).getLocation()); } } - if(request instanceof ChangeBoundsRequest){ - //test - ((ChangeBoundsRequest)request).setMoveDelta(new Point(0, ((ChangeBoundsRequest)request).getMoveDelta().y)); + if (request instanceof ChangeBoundsRequest) { + // test + ((ChangeBoundsRequest) request).setMoveDelta(new Point(0, ((ChangeBoundsRequest) request).getMoveDelta().y)); } } super.showLayoutTargetFeedback(request); } - + /** * @see org.eclipse.gef.editpolicies.GraphicalEditPolicy#addFeedback(org.eclipse.draw2d.IFigure) * @@ -181,6 +187,7 @@ public class LifeLineXYLayoutEditPolicy extends XYLayoutWithConstrainedResizedEd } + /** * @see org.eclipse.gef.editpolicies.GraphicalEditPolicy#removeFeedback(org.eclipse.draw2d.IFigure) * @@ -194,14 +201,16 @@ public class LifeLineXYLayoutEditPolicy extends XYLayoutWithConstrainedResizedEd } - /** + /** * Called in response to a <tt>REQ_RESIZE_CHILDREN</tt> request. * * This implementation creates a <tt>SetPropertyCommand</i> and sets * the <tt>ID_BOUNDS</tt> property value to the supplied constraints. * - * @param child the element being resized. - * @param constraint the elements new bounds. + * @param child + * the element being resized. + * @param constraint + * the elements new bounds. * @return {@link SetBoundsCommand} */ protected Command createChangeConstraintCommand( @@ -210,18 +219,18 @@ public class LifeLineXYLayoutEditPolicy extends XYLayoutWithConstrainedResizedEd Rectangle newBounds = (Rectangle) constraint; View shapeView = (View) child.getModel(); - if( child instanceof AbstractExecutionSpecificationEditPart){ - RootEditPart drep=getHost().getRoot(); - if( drep instanceof DiagramRootEditPart){ - double spacing = ((DiagramRootEditPart)drep).getGridSpacing(); - Rectangle parentBound=getHostFigure().getBounds(); - newBounds.setLocation(new Point((parentBound.width/2)-(AbstractExecutionSpecificationEditPart.DEFAUT_WIDTH/2),newBounds.getLocation().y)); - if( newBounds.height==-1){ - newBounds.height=AbstractExecutionSpecificationEditPart.DEFAUT_HEIGHT; + if (child instanceof AbstractExecutionSpecificationEditPart) { + RootEditPart drep = getHost().getRoot(); + if (drep instanceof DiagramRootEditPart) { + double spacing = ((DiagramRootEditPart) drep).getGridSpacing(); + Rectangle parentBound = getHostFigure().getBounds(); + newBounds.setLocation(new Point((parentBound.width / 2) - (AbstractExecutionSpecificationEditPart.DEFAUT_WIDTH / 2), newBounds.getLocation().y)); + if (newBounds.height == -1) { + newBounds.height = AbstractExecutionSpecificationEditPart.DEFAUT_HEIGHT; } - if(DiagramEditPartsUtil.isSnapToGridActive(getHost())){ - int modulo= newBounds.height/(int)spacing; - newBounds.setSize(new Dimension(AbstractExecutionSpecificationEditPart.DEFAUT_WIDTH,modulo*(int)spacing)); + if (DiagramEditPartsUtil.isSnapToGridActive(getHost())) { + int modulo = newBounds.height / (int) spacing; + newBounds.setSize(new Dimension(AbstractExecutionSpecificationEditPart.DEFAUT_WIDTH, modulo * (int) spacing)); } } @@ -229,13 +238,12 @@ public class LifeLineXYLayoutEditPolicy extends XYLayoutWithConstrainedResizedEd TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()) .getEditingDomain(); - ICommand boundsCommand = - new SetBoundsCommand(editingDomain, - DiagramUIMessages.SetLocationCommand_Label_Resize, - new EObjectAdapter(shapeView), - newBounds); - CompoundCommand compoundCommand= new CompoundCommand(); - compoundCommand.add( new ICommandProxy(boundsCommand)); + ICommand boundsCommand = new SetBoundsCommand(editingDomain, + DiagramUIMessages.SetLocationCommand_Label_Resize, + new EObjectAdapter(shapeView), + newBounds); + CompoundCommand compoundCommand = new CompoundCommand(); + compoundCommand.add(new ICommandProxy(boundsCommand)); return compoundCommand; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/MessageConnectionHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/MessageConnectionHelper.java index 3295fb90f14..63b1e3b51b3 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/MessageConnectionHelper.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/MessageConnectionHelper.java @@ -15,6 +15,8 @@ package org.eclipse.papyrus.uml.diagram.sequence.util; import org.eclipse.emf.common.util.EList; +import org.eclipse.papyrus.uml.diagram.sequence.CustomMessages; +import org.eclipse.papyrus.uml.diagram.sequence.part.UMLDiagramEditorPlugin; import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.ExecutionOccurrenceSpecification; @@ -49,7 +51,7 @@ public class MessageConnectionHelper { if (!covereds.isEmpty()) { target = covereds.get(0); } - } else if (receiveEvent instanceof Gate + } else if (receiveEvent instanceof Gate // special handling of SyncMessages due to #425666 && MessageSort.SYNCH_CALL_LITERAL != message.getMessageSort()) { target = ((Gate) receiveEvent).getOwner(); @@ -86,7 +88,7 @@ public class MessageConnectionHelper { } return canExist(message, getMessageSource(message), newTarget); } - + public static boolean canExist(Message message, Element source, Element target) { MessageSort messageSort = null; if (message != null) { @@ -153,7 +155,7 @@ public class MessageConnectionHelper { buf.append("null"); } buf.append("]"); - System.out.println(new String(buf)); + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_UTIL, buf.toString());// $NON-NLS-1$ } public static boolean canExistReplyMessage(Message message, Element source, Element target) { @@ -175,7 +177,7 @@ public class MessageConnectionHelper { // Not available for StateInvariant. if (source instanceof StateInvariant || target instanceof StateInvariant) { return false; - } + } return true; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SelectMessagesEditPartTracker.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SelectMessagesEditPartTracker.java index 9ade1b08048..98638240ef4 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SelectMessagesEditPartTracker.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SelectMessagesEditPartTracker.java @@ -25,7 +25,9 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.papyrus.infra.gmfdiag.common.selection.SelectSeveralLinksEditPartTracker; +import org.eclipse.papyrus.uml.diagram.sequence.CustomMessages; import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.AbstractMessageEditPart; +import org.eclipse.papyrus.uml.diagram.sequence.part.UMLDiagramEditorPlugin; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; @@ -37,7 +39,7 @@ import org.eclipse.ui.PlatformUI; * */ public class SelectMessagesEditPartTracker extends SelectSeveralLinksEditPartTracker { - protected Listener KeyDownListener = new Listener() { + protected Listener KeyDownListener = new Listener() { @Override public void handleEvent(Event event) { @@ -48,7 +50,7 @@ public class SelectMessagesEditPartTracker extends SelectSeveralLinksEditPartTra } }; - protected Listener KeyUPListener = new Listener() { + protected Listener KeyUPListener = new Listener() { @Override public void handleEvent(Event event) { @@ -59,9 +61,10 @@ public class SelectMessagesEditPartTracker extends SelectSeveralLinksEditPartTra } }; - protected int MinDistancetop= Integer.MAX_VALUE; - protected int MinDistancebottom=Integer.MAX_VALUE; - protected Dimension delta= null; + protected int MinDistancetop = Integer.MAX_VALUE; + protected int MinDistancebottom = Integer.MAX_VALUE; + protected Dimension delta = null; + /** * @see org.eclipse.gef.tools.AbstractTool#activate() * @@ -70,6 +73,7 @@ public class SelectMessagesEditPartTracker extends SelectSeveralLinksEditPartTra public void activate() { super.activate(); } + /** * @see org.eclipse.papyrus.infra.gmfdiag.common.selection.SelectSeveralLinksEditPartTracker#handleButtonDown(int) * @@ -78,64 +82,63 @@ public class SelectMessagesEditPartTracker extends SelectSeveralLinksEditPartTra */ @Override protected boolean handleButtonDown(int button) { - Dimension delta= null; - MinDistancetop= Integer.MAX_VALUE; - MinDistancebottom=Integer.MAX_VALUE; - //1. look for all Nodes connected by connections - //and find the MinDistancetop (maximum mouvment without reorder to the top) and the MinDistancebottom (maximum distance without reorder to the bottom) + Dimension delta = null; + MinDistancetop = Integer.MAX_VALUE; + MinDistancebottom = Integer.MAX_VALUE; + // 1. look for all Nodes connected by connections + // and find the MinDistancetop (maximum mouvment without reorder to the top) and the MinDistancebottom (maximum distance without reorder to the bottom) + - - ArrayList<GraphicalEditPart> nodeEditPart= new ArrayList<GraphicalEditPart>(); + ArrayList<GraphicalEditPart> nodeEditPart = new ArrayList<GraphicalEditPart>(); List selectedEditparts = getOperationSet(); - for (int i=0; i<selectedEditparts.size();i++){ + for (int i = 0; i < selectedEditparts.size(); i++) { Object currentEditPart = selectedEditparts.get(i); - if(currentEditPart instanceof org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart ){ - org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart currentConnectionEdiPart=(org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart) currentEditPart; - nodeEditPart.add((GraphicalEditPart)currentConnectionEdiPart.getSource()); + if (currentEditPart instanceof org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart) { + org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart currentConnectionEdiPart = (org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart) currentEditPart; + nodeEditPart.add((GraphicalEditPart) currentConnectionEdiPart.getSource()); - } + } } - //2. take all messages between this nodes + // 2. take all messages between this nodes ArrayList<AbstractMessageEditPart> messageEditPartList = new ArrayList<AbstractMessageEditPart>(); for (GraphicalEditPart anodeEditPart : nodeEditPart) { - for (Object connection:anodeEditPart.getSourceConnections()){ + for (Object connection : anodeEditPart.getSourceConnections()) { - if(connection instanceof AbstractMessageEditPart){ - if(!(selectedEditparts.contains(connection))){ - messageEditPartList.add((AbstractMessageEditPart)connection); + if (connection instanceof AbstractMessageEditPart) { + if (!(selectedEditparts.contains(connection))) { + messageEditPartList.add((AbstractMessageEditPart) connection); } } } - for (Object connection:anodeEditPart.getTargetConnections()){ - if(!(selectedEditparts.contains(connection))){ - if(connection instanceof AbstractMessageEditPart){ - messageEditPartList.add((AbstractMessageEditPart)connection); + for (Object connection : anodeEditPart.getTargetConnections()) { + if (!(selectedEditparts.contains(connection))) { + if (connection instanceof AbstractMessageEditPart) { + messageEditPartList.add((AbstractMessageEditPart) connection); } } } } - //3 calculate minimum distance + // 3 calculate minimum distance for (AbstractMessageEditPart abstractMessageEditPart : messageEditPartList) { Point currentConnectionPosition = abstractMessageEditPart.getConnectionFigure().getPoints().getFirstPoint().getCopy(); for (Object selectedEditPart : selectedEditparts) { - if( selectedEditPart instanceof AbstractMessageEditPart){ - AbstractMessageEditPart currentSelectedMessage=(AbstractMessageEditPart)selectedEditPart; + if (selectedEditPart instanceof AbstractMessageEditPart) { + AbstractMessageEditPart currentSelectedMessage = (AbstractMessageEditPart) selectedEditPart; Point currentSelectedConnectionPosition = currentSelectedMessage.getConnectionFigure().getPoints().getFirstPoint().getCopy(); // selected Message is below the currentConnection - if( currentConnectionPosition.y<currentSelectedConnectionPosition.y){ - if(MinDistancetop> (currentSelectedConnectionPosition.y-currentConnectionPosition.y)){ - MinDistancetop=(currentSelectedConnectionPosition.y-currentConnectionPosition.y); + if (currentConnectionPosition.y < currentSelectedConnectionPosition.y) { + if (MinDistancetop > (currentSelectedConnectionPosition.y - currentConnectionPosition.y)) { + MinDistancetop = (currentSelectedConnectionPosition.y - currentConnectionPosition.y); } - } - else{ + } else { // selected Message is above the currentConnection - if(MinDistancebottom> (currentConnectionPosition.y-currentSelectedConnectionPosition.y)){ - MinDistancebottom=(currentConnectionPosition.y-currentSelectedConnectionPosition.y); + if (MinDistancebottom > (currentConnectionPosition.y - currentSelectedConnectionPosition.y)) { + MinDistancebottom = (currentConnectionPosition.y - currentSelectedConnectionPosition.y); } } } @@ -145,6 +148,7 @@ public class SelectMessagesEditPartTracker extends SelectSeveralLinksEditPartTra return super.handleButtonDown(button); } + /** * Constructor. * @@ -155,12 +159,14 @@ public class SelectMessagesEditPartTracker extends SelectSeveralLinksEditPartTra PlatformUI.getWorkbench().getDisplay().addFilter(SWT.KeyDown, KeyDownListener); PlatformUI.getWorkbench().getDisplay().addFilter(SWT.KeyUp, KeyUPListener); } - private boolean allowReoder=false; + private boolean allowReoder = false; - /* + + /* * (non-Javadoc) + * * @see org.eclipse.gef.Tool#deactivate() */ public void deactivate() { @@ -168,54 +174,55 @@ public class SelectMessagesEditPartTracker extends SelectSeveralLinksEditPartTra PlatformUI.getWorkbench().getDisplay().removeFilter(SWT.KeyUp, KeyUPListener); super.deactivate(); } + /** * @see org.eclipse.gef.tools.SimpleDragTracker#updateSourceRequest() */ protected void updateSourceRequest() { - if(!allowReoder){ - Dimension computedDelta = getLocation().getDifference(getStartLocation()); - delta=null; - if( computedDelta.height<0){ - System.out.println("Move "+computedDelta.height+" MinDistancetop"+MinDistancetop); - if( MinDistancetop+computedDelta.height<0){ - computedDelta.height=-MinDistancetop; - delta=computedDelta.getCopy(); + if (!allowReoder) { + Dimension computedDelta = getLocation().getDifference(getStartLocation()); + delta = null; + if (computedDelta.height < 0) { + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_UTIL, "Move " + computedDelta.height + " MinDistancetop" + MinDistancetop);//$NON-NLS-1$ + if (MinDistancetop + computedDelta.height < 0) { + computedDelta.height = -MinDistancetop; + delta = computedDelta.getCopy(); } - } - else{ - System.out.println("Move "+computedDelta.height+" MinDistancebottom"+MinDistancebottom); - if( MinDistancebottom-computedDelta.height-10<0){ - computedDelta.height=MinDistancebottom-10; - delta=computedDelta.getCopy(); + } else { + UMLDiagramEditorPlugin.log.trace(CustomMessages.SEQUENCE_DEBUG_UTIL, "Move " + computedDelta.height + " MinDistancebottom" + MinDistancebottom);//$NON-NLS-1$ + if (MinDistancebottom - computedDelta.height - 10 < 0) { + computedDelta.height = MinDistancebottom - 10; + delta = computedDelta.getCopy(); } } - + } super.updateSourceRequest(); } protected Dimension getDragMoveDelta() { - if( delta==null){ - return getLocation().getDifference(getStartLocation());} - else{ + if (delta == null) { + return getLocation().getDifference(getStartLocation()); + } else { return delta; } } + /** * Walks up the editpart hierarchy to find and return the * <code>TopGraphicEditPart</code> instance. */ - public DiagramEditPart getDiagramEditPart(EditPart editPart) { + public DiagramEditPart getDiagramEditPart(EditPart editPart) { while (editPart instanceof IGraphicalEditPart) { - if (editPart instanceof DiagramEditPart){ + if (editPart instanceof DiagramEditPart) { return (DiagramEditPart) editPart; } - + editPart = editPart.getParent(); } - if(editPart instanceof DiagramRootEditPart){ - return (DiagramEditPart)((DiagramRootEditPart)editPart).getChildren().get(0); + if (editPart instanceof DiagramRootEditPart) { + return (DiagramEditPart) ((DiagramRootEditPart) editPart).getChildren().get(0); } return null; } |