Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordservat2011-05-24 12:29:39 +0000
committerdservat2011-05-24 12:29:39 +0000
commitefc11504a81ec2ee4f8dc901904c6bbe29ee32b0 (patch)
tree4d0b3579079751acf3987d039dcd66dc0a51af14
parentdc31741eb81e58cf1cea7820d8481239f4d378b3 (diff)
downloadorg.eclipse.papyrus-efc11504a81ec2ee4f8dc901904c6bbe29ee32b0.tar.gz
org.eclipse.papyrus-efc11504a81ec2ee4f8dc901904c6bbe29ee32b0.tar.xz
org.eclipse.papyrus-efc11504a81ec2ee4f8dc901904c6bbe29ee32b0.zip
NEW - bug 330469: [Statemachine Diagram] Papyrus state machine diagram editor shall support Drag and Drop for transitions
https://bugs.eclipse.org/bugs/show_bug.cgi?id=330469 Additional support for drag and drop. To only limitation now is that the owner of the source/target of the link is present on the diagram, e.g. if the region owning a state which is the target of the link is not shown on the diagram, the drag and drop will not be allowed. Also the duplication of state in case of looping transition is removed. This fix is also done for associations, etc. in the diagram.common plugin. Besides, the patched code corrects some graphical malfunctions of the previous code, when showing/hiding information such as qualified names, changing fonts, etc. on state machines and composite states.
-rw-r--r--plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/editpolicies/OldCommonDiagramDragDropEditPolicy.java33
-rw-r--r--plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomCompositeStateSetBoundsCommand.java131
-rw-r--r--plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomFirstRegionInCompositeStateCreateElementCommand.java9
-rw-r--r--plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomStateMachineResizeCommand.java2
-rw-r--r--plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomStateResizeCommand.java2
-rw-r--r--plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/edit/part/CustomStateMachineNameEditPart.java83
-rw-r--r--plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/edit/part/CustomStateNameEditPart.java43
-rw-r--r--plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/figures/CustomShapeCompartmentFigure.java4
-rw-r--r--plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/figures/StateFigure.java2
-rw-r--r--plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/policies/CustomStateMachineDiagramDragDropEditPolicy.java131
10 files changed, 317 insertions, 123 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/editpolicies/OldCommonDiagramDragDropEditPolicy.java b/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/editpolicies/OldCommonDiagramDragDropEditPolicy.java
index 4f162bc4f68..d2885f111e6 100644
--- a/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/editpolicies/OldCommonDiagramDragDropEditPolicy.java
+++ b/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/editpolicies/OldCommonDiagramDragDropEditPolicy.java
@@ -168,19 +168,26 @@ public abstract class OldCommonDiagramDragDropEditPolicy extends DiagramDragDrop
} else {
sourceAdapter = new SemanticAdapter(null, sourceEditPart.getModel());
}
- if(targetEditPart == null) {
- // creation of the node
- ViewDescriptor descriptor = new ViewDescriptor(new EObjectAdapter(target), Node.class, null, ViewUtil.APPEND, false, ((IGraphicalEditPart)getHost()).getDiagramPreferencesHint());
-
- // get the command and execute it.
- CreateCommand nodeCreationCommand = new CreateCommand(((IGraphicalEditPart)getHost()).getEditingDomain(), descriptor, ((View)getHost().getModel()));
- cc.compose(nodeCreationCommand);
- SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x, location.y - 100)); //$NON-NLS-1$
- cc.compose(setBoundsCommand);
- targetAdapter = (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue();
-
- } else {
- targetAdapter = new SemanticAdapter(null, targetEditPart.getModel());
+ //additional check to ensure we do not create twice the same node when links are "loops" on the same element
+ if((target != null) && !target.equals(source)){
+ if(targetEditPart == null) {
+ // creation of the node
+ ViewDescriptor descriptor = new ViewDescriptor(new EObjectAdapter(target), Node.class, null, ViewUtil.APPEND, false, ((IGraphicalEditPart)getHost()).getDiagramPreferencesHint());
+
+ // get the command and execute it.
+ CreateCommand nodeCreationCommand = new CreateCommand(((IGraphicalEditPart)getHost()).getEditingDomain(), descriptor, ((View)getHost().getModel()));
+ cc.compose(nodeCreationCommand);
+ SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x, location.y - 100)); //$NON-NLS-1$
+ cc.compose(setBoundsCommand);
+ targetAdapter = (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue();
+
+ } else {
+ targetAdapter = new SemanticAdapter(null, targetEditPart.getModel());
+ }
+ }
+ //in case of loop links (see above) we pass on the same adapter for both source and target
+ if((target != null) && target.equals(source)){
+ targetAdapter = sourceAdapter;
}
CommonDeferredCreateConnectionViewCommand aLinkCommand = new CommonDeferredCreateConnectionViewCommand(getEditingDomain(), ((IHintedType)getUMLElementType(linkVISUALID)).getSemanticHint(), sourceAdapter, targetAdapter, getViewer(), getDiagramPreferencesHint(), linkdescriptor, null);
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomCompositeStateSetBoundsCommand.java b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomCompositeStateSetBoundsCommand.java
index 523f40c31a6..32489ddcd77 100644
--- a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomCompositeStateSetBoundsCommand.java
+++ b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomCompositeStateSetBoundsCommand.java
@@ -33,7 +33,9 @@ public class CustomCompositeStateSetBoundsCommand extends AbstractTransactionalC
Dimension size;
- public CustomCompositeStateSetBoundsCommand(TransactionalEditingDomain domain, String label, CreateViewRequest.ViewDescriptor viewDescriptor, Rectangle rect) {
+ boolean isComposite = false;
+
+ public CustomCompositeStateSetBoundsCommand(TransactionalEditingDomain domain, String label, CreateViewRequest.ViewDescriptor viewDescriptor, Rectangle rect, boolean isComposite) {
super(domain, label, null);
this.viewDescriptor = viewDescriptor;
@@ -42,6 +44,8 @@ public class CustomCompositeStateSetBoundsCommand extends AbstractTransactionalC
location = rect.getLocation();
size = rect.getSize();
+ this.isComposite = isComposite;
+
// make sure the return object is available even before
// executing/undoing/redoing
setResult(CommandResult.newOKCommandResult(viewDescriptor));
@@ -63,60 +67,91 @@ public class CustomCompositeStateSetBoundsCommand extends AbstractTransactionalC
Zone.setHeight(stateView, Zone.defaultHeight);
}
- Iterator<Node> it = stateView.getChildren().iterator();
+ if(!isComposite){
+ Iterator<Node> it = stateView.getChildren().iterator();
+
+ while(it.hasNext()) {
+ Node currentNode = it.next();
+ if(currentNode.getLayoutConstraint() == null) {
+ currentNode.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
+ }
+ if(UMLVisualIDRegistry.getVisualID(currentNode.getType()) == StateNameEditPart.VISUAL_ID) {
+ if((size != null) && !size.equals(-1, -1)) {
+ Zone.setWidth(currentNode, size.width);
+ Zone.setHeight(currentNode, size.height);
+ } else {
+ Zone.setWidth(currentNode, 40);
+ Zone.setHeight(currentNode, 40);
+ }
+ } else if(UMLVisualIDRegistry.getVisualID(currentNode.getType()) == StateCompartmentEditPart.VISUAL_ID) {
+ Zone.setY(currentNode, 40);
+ if((size != null) && !size.equals(-1, -1)) {
+ Zone.setWidth(currentNode, size.width);
+ Zone.setHeight(currentNode, 0);
+ } else {
+ Zone.setWidth(currentNode, 40);
+ Zone.setHeight(currentNode, 0);
+ }
- while(it.hasNext()) {
- Node currentNode = it.next();
- if(currentNode.getLayoutConstraint() == null) {
- currentNode.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
- }
- if(UMLVisualIDRegistry.getVisualID(currentNode.getType()) == StateNameEditPart.VISUAL_ID) {
- if((size != null) && !size.equals(-1, -1)) {
- Zone.setWidth(currentNode, size.width);
- Zone.setHeight(currentNode, Zone.defaultHeader);
- } else {
- Zone.setWidth(currentNode, Zone.defaultWidth);
- Zone.setHeight(currentNode, Zone.defaultHeader);
}
- } else if(UMLVisualIDRegistry.getVisualID(currentNode.getType()) == StateCompartmentEditPart.VISUAL_ID) {
- Zone.setY(currentNode, Zone.defaultHeader);
- if((size != null) && !size.equals(-1, -1)) {
- Zone.setWidth(currentNode, size.width);
- Zone.setHeight(currentNode, size.height - Zone.defaultHeader);
- } else {
- Zone.setWidth(currentNode, Zone.defaultWidth);
- Zone.setHeight(currentNode, Zone.defaultHeight - Zone.defaultHeader);
+ }
+ }
+ else{
+ Iterator<Node> it = stateView.getChildren().iterator();
+
+ while(it.hasNext()) {
+ Node currentNode = it.next();
+ if(currentNode.getLayoutConstraint() == null) {
+ currentNode.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
}
- int nRegions = currentNode.getChildren().size();
- String prefix = "";
- String zone = "";
- int i = 0;
- int width = 0;
- Iterator<Node> subit = currentNode.getChildren().iterator();
- while(subit.hasNext()) {
- Node subCurrentNode = subit.next();
- if(subCurrentNode.getLayoutConstraint() == null) {
- subCurrentNode.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
+ if(UMLVisualIDRegistry.getVisualID(currentNode.getType()) == StateNameEditPart.VISUAL_ID) {
+ if((size != null) && !size.equals(-1, -1)) {
+ Zone.setWidth(currentNode, size.width);
+ Zone.setHeight(currentNode, Zone.defaultHeader);
+ } else {
+ Zone.setWidth(currentNode, Zone.defaultWidth);
+ Zone.setHeight(currentNode, Zone.defaultHeader);
+ }
+ } else if(UMLVisualIDRegistry.getVisualID(currentNode.getType()) == StateCompartmentEditPart.VISUAL_ID) {
+ Zone.setY(currentNode, Zone.defaultHeader);
+ if((size != null) && !size.equals(-1, -1)) {
+ Zone.setWidth(currentNode, size.width);
+ Zone.setHeight(currentNode, size.height - Zone.defaultHeader);
+ } else {
+ Zone.setWidth(currentNode, Zone.defaultWidth);
+ Zone.setHeight(currentNode, Zone.defaultHeight - Zone.defaultHeader);
}
- if(UMLVisualIDRegistry.getVisualID(subCurrentNode.getType()) == RegionEditPart.VISUAL_ID) {
- if((size != null) && !size.equals(-1, -1)) {
- Zone.setWidth(subCurrentNode, (i == nRegions - 1) ? size.width - width : size.width / nRegions);
- Zone.setHeight(subCurrentNode, size.height - Zone.defaultHeader);
- Zone.setX(subCurrentNode, width);
- width += size.width / nRegions;
- } else {
- Zone.setWidth(subCurrentNode, (i == nRegions - 1) ? Zone.defaultWidth - width : Zone.defaultWidth / nRegions);
- Zone.setHeight(subCurrentNode, Zone.defaultHeight - Zone.defaultHeader);
- Zone.setX(subCurrentNode, width);
- width += Zone.defaultWidth / nRegions;
+ int nRegions = currentNode.getChildren().size();
+ String prefix = "";
+ String zone = "";
+ int i = 0;
+ int width = 0;
+ Iterator<Node> subit = currentNode.getChildren().iterator();
+ while(subit.hasNext()) {
+ Node subCurrentNode = subit.next();
+ if(subCurrentNode.getLayoutConstraint() == null) {
+ subCurrentNode.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
+ }
+ if(UMLVisualIDRegistry.getVisualID(subCurrentNode.getType()) == RegionEditPart.VISUAL_ID) {
+ if((size != null) && !size.equals(-1, -1)) {
+ Zone.setWidth(subCurrentNode, (i == nRegions - 1) ? size.width - width : size.width / nRegions);
+ Zone.setHeight(subCurrentNode, size.height - Zone.defaultHeader);
+ Zone.setX(subCurrentNode, width);
+ width += size.width / nRegions;
+ } else {
+ Zone.setWidth(subCurrentNode, (i == nRegions - 1) ? Zone.defaultWidth - width : Zone.defaultWidth / nRegions);
+ Zone.setHeight(subCurrentNode, Zone.defaultHeight - Zone.defaultHeader);
+ Zone.setX(subCurrentNode, width);
+ width += Zone.defaultWidth / nRegions;
+ }
+ zone = (i == nRegions - 1) ? prefix : prefix + Zone.LEFT;
+ Zone.setZone(subCurrentNode, zone);
+ prefix = prefix + Zone.RIGHT;
+ i++;
}
- zone = (i == nRegions - 1) ? prefix : prefix + Zone.LEFT;
- Zone.setZone(subCurrentNode, zone);
- prefix = prefix + Zone.RIGHT;
- i++;
}
- }
+ }
}
}
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomFirstRegionInCompositeStateCreateElementCommand.java b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomFirstRegionInCompositeStateCreateElementCommand.java
index bafe1f43461..bcbfba5d083 100644
--- a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomFirstRegionInCompositeStateCreateElementCommand.java
+++ b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomFirstRegionInCompositeStateCreateElementCommand.java
@@ -94,6 +94,15 @@ public class CustomFirstRegionInCompositeStateCreateElementCommand extends Abstr
// get state bounds
int height = Zone.getHeight(ownerView);
int width = Zone.getWidth(ownerView);
+ if(height < Zone.defaultHeight){
+ height = Zone.defaultHeight;
+ Zone.setHeight(ownerView, height);
+ }
+ if(width < Zone.defaultWidth){
+ width = Zone.defaultWidth;
+ Zone.setWidth(ownerView, width);
+ }
+
if(adaptableForDropped == null) {
Region umlRegion = UMLFactory.eINSTANCE.createRegion();
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomStateMachineResizeCommand.java b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomStateMachineResizeCommand.java
index 86bfa8fe73d..4b4a1310575 100644
--- a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomStateMachineResizeCommand.java
+++ b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomStateMachineResizeCommand.java
@@ -71,7 +71,7 @@ public class CustomStateMachineResizeCommand extends AbstractTransactionalComman
if(internalResize) {
Zone.setHeight(stateMachineLabel, Zone.getHeight(stateMachineLabel) + dy);
- dy = 0;
+// dy = 0;
}
// first resize the state machine node with the constraint provided
Zone.setX(stateMachine, newX);
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomStateResizeCommand.java b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomStateResizeCommand.java
index 6af628e3483..1524b6abd68 100644
--- a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomStateResizeCommand.java
+++ b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/commands/CustomStateResizeCommand.java
@@ -81,7 +81,7 @@ public class CustomStateResizeCommand extends AbstractTransactionalCommand {
if(internalResize) {
Zone.setHeight(stateLabel, Zone.getHeight(stateLabel) + dy);
- dy = 0;
+// dy = 0;
}
// first resize the state node with the constraint provided
Zone.setBounds(state, bounds);
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/edit/part/CustomStateMachineNameEditPart.java b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/edit/part/CustomStateMachineNameEditPart.java
index 0026fe89b29..1743a58d9a1 100644
--- a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/edit/part/CustomStateMachineNameEditPart.java
+++ b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/edit/part/CustomStateMachineNameEditPart.java
@@ -1,10 +1,14 @@
package org.eclipse.papyrus.diagram.statemachine.custom.edit.part;
import java.util.Collections;
+import java.util.Iterator;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.common.notify.Notification;
@@ -16,7 +20,10 @@ import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.diagram.common.commands.SemanticAdapter;
+import org.eclipse.papyrus.diagram.common.figure.node.StereotypePropertiesCompartment;
import org.eclipse.papyrus.diagram.statemachine.custom.commands.CustomStateMachineResizeCommand;
+import org.eclipse.papyrus.diagram.statemachine.custom.figures.CustomShapeCompartmentFigure;
+import org.eclipse.papyrus.diagram.statemachine.custom.figures.StateMachineFigure;
import org.eclipse.papyrus.diagram.statemachine.custom.helpers.Zone;
import org.eclipse.papyrus.diagram.statemachine.edit.parts.StateMachineNameEditPart;
@@ -41,44 +48,50 @@ public class CustomStateMachineNameEditPart extends StateMachineNameEditPart {
// TODO Auto-generated method stub
super.handleNotificationEvent(notification);
- if(((notification.getFeature() instanceof EAttribute) && ((EAttribute)notification.getFeature()).getName().equals("fontHeight"))){
- WrappingLabel stateMachineLabel = (WrappingLabel)getFigure();
- Dimension stateMachineLabelBounds = stateMachineLabel.getPreferredSize().getCopy();
- View stateMachineLabelView = (View)getModel();
- View stateMachineView = (View)stateMachineLabelView.eContainer();
- View stateMachineCompartView = (View)stateMachineView.getChildren().get(1);
-
- int stateMachineHeight = Zone.getHeight(stateMachineView);
- int stateMachineWidth = Zone.getWidth(stateMachineView);
-
- int stateMachineCompartHeight = Zone.getHeight(stateMachineCompartView);
-
- // Zone.setHeight(stateMachineLabelView,
- // stateMachineLabelBounds.height);
- int dx = stateMachineLabelBounds.width - stateMachineWidth;
- int dy = stateMachineCompartHeight + stateMachineLabelBounds.height - stateMachineHeight;
- int x = Zone.getX(stateMachineView);
- int y = Zone.getY(stateMachineView);
-
- if((stateMachineHeight != -1) && (stateMachineLabelBounds.width != 0) && (dy != 0)) {
- dx = (dx > 0) ? dx : 0;
- // a resize request, which we route to the specific ResizeCommand
- IAdaptable adaptableForStateMachine = new SemanticAdapter(null, stateMachineView);
- ChangeBoundsRequest internalResizeRequest = new ChangeBoundsRequest();
- internalResizeRequest.setResizeDirection(PositionConstants.EAST);
- internalResizeRequest.setSizeDelta(new Dimension(dx, dy));
- Rectangle rect = new Rectangle(x, y, stateMachineWidth + dx, stateMachineHeight + dy);
-
- CustomStateMachineResizeCommand internalResizeCommand = new CustomStateMachineResizeCommand(adaptableForStateMachine, getDiagramPreferencesHint(), getEditingDomain(), DiagramUIMessages.CreateCommand_Label, internalResizeRequest, rect, true);
- internalResizeCommand.setOptions(Collections.singletonMap(Transaction.OPTION_UNPROTECTED, Boolean.TRUE));
- try {
- internalResizeCommand.execute(null, null);
- } catch (ExecutionException e) {
- }
+ int height = 0;
+ int width = 0;
+ Iterator<IFigure> it = (Iterator<IFigure>)getFigure().getParent().getChildren().iterator();
+ while(it.hasNext()){
+ IFigure current = it.next();
+ if((current instanceof Label) || (current instanceof WrappingLabel) || (current instanceof StereotypePropertiesCompartment)){
+ Dimension d = current.getPreferredSize().getCopy();
+ height += d.height;
+ width = Math.max(width, d.width);
+ }
+ }
+
+ View stateMachineLabelView = (View)getModel();
+ View stateMachineView = (View)stateMachineLabelView.eContainer();
+ View stateMachineCompartView = (View)stateMachineView.getChildren().get(1);
+
+ int stateMachineHeight = Zone.getHeight(stateMachineView);
+ int stateMachineWidth = Zone.getWidth(stateMachineView);
+ int stateMachineCompartHeight = Zone.getHeight(stateMachineCompartView);
+
+ int dx = width - stateMachineWidth;
+ int dy = stateMachineCompartHeight + height - stateMachineHeight;
+ int x = Zone.getX(stateMachineView);
+ int y = Zone.getY(stateMachineView);
+
+ if((stateMachineHeight != -1) && (width != 0) && (dy != 0)) {
+ dx = (dx > 0) ? dx : 0;
+ // a resize request, which we route to the specific ResizeCommand
+ IAdaptable adaptableForStateMachine = new SemanticAdapter(null, stateMachineView);
+ ChangeBoundsRequest internalResizeRequest = new ChangeBoundsRequest();
+ internalResizeRequest.setResizeDirection(PositionConstants.EAST);
+ internalResizeRequest.setSizeDelta(new Dimension(dx, dy));
+ Rectangle rect = new Rectangle(x, y, stateMachineWidth + dx, stateMachineHeight + dy);
+
+ CustomStateMachineResizeCommand internalResizeCommand = new CustomStateMachineResizeCommand(adaptableForStateMachine, getDiagramPreferencesHint(), getEditingDomain(), DiagramUIMessages.CreateCommand_Label, internalResizeRequest, rect, true);
+ internalResizeCommand.setOptions(Collections.singletonMap(Transaction.OPTION_UNPROTECTED, Boolean.TRUE));
+ try {
+ internalResizeCommand.execute(null, null);
+ } catch (ExecutionException e) {
}
- refreshVisuals();
+
}
+ refreshVisuals();
}
@Override
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/edit/part/CustomStateNameEditPart.java b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/edit/part/CustomStateNameEditPart.java
index 474f4fd2712..ddcd2e818a3 100644
--- a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/edit/part/CustomStateNameEditPart.java
+++ b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/edit/part/CustomStateNameEditPart.java
@@ -1,9 +1,12 @@
package org.eclipse.papyrus.diagram.statemachine.custom.edit.part;
import java.util.Collections;
+import java.util.Iterator;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
@@ -16,6 +19,7 @@ import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.diagram.common.commands.SemanticAdapter;
+import org.eclipse.papyrus.diagram.common.figure.node.StereotypePropertiesCompartment;
import org.eclipse.papyrus.diagram.statemachine.custom.commands.CustomStateResizeCommand;
import org.eclipse.papyrus.diagram.statemachine.custom.figures.StateFigure;
import org.eclipse.papyrus.diagram.statemachine.custom.helpers.Zone;
@@ -82,37 +86,54 @@ public class CustomStateNameEditPart extends StateNameEditPart {
protected void handleNotificationEvent(Notification notification) {
// TODO Auto-generated method stub
super.handleNotificationEvent(notification);
+
StateFigure stateFigure = ((StateEditPart)getParent()).getPrimaryShape();
State state = (State)((View)getModel()).getElement();
View stateLabelView = (View)getModel();
View stateView = (View)stateLabelView.eContainer();
View stateCompartView = (View)stateView.getChildren().get(1);
-
-
+
+ if(stateCompartView.getChildren().isEmpty())
+ stateFigure.getStateCompartmentFigure().setVisible(false);
+ else
+ stateFigure.getStateCompartmentFigure().setVisible(true);
stateFigure.fillInformation(getInformationFromState(state));
- WrappingLabel stateLabel = (WrappingLabel)getFigure();
- WrappingLabel infoLabel = stateFigure.getInformationLabel();
+ int height = 5;
+ int width = 15;
+ Iterator<IFigure> it = (Iterator<IFigure>)getFigure().getParent().getChildren().iterator();
+ while(it.hasNext()){
+ IFigure current = it.next();
+ if((current instanceof Label) || (current instanceof WrappingLabel) || (current instanceof StereotypePropertiesCompartment)){
+ Dimension d = current.getPreferredSize().getCopy();
+ height += d.height;
+ width = Math.max(width, d.width);
+ }
+ }
- Dimension infoLabelBounds = infoLabel.getPreferredSize().getCopy();
- Dimension stateLabelBounds = stateLabel.getPreferredSize().getCopy();
- stateLabelBounds.width = Math.max(stateLabelBounds.width, infoLabelBounds.width);
- stateLabelBounds.height = stateLabelBounds.height + infoLabelBounds.height;
+// WrappingLabel stateLabel = (WrappingLabel)getFigure();
+// WrappingLabel infoLabel = stateFigure.getInformationLabel();
+//
+// Dimension infoLabelBounds = infoLabel.getPreferredSize().getCopy();
+// Dimension stateLabelBounds = stateLabel.getPreferredSize().getCopy();
+// stateLabelBounds.expand(15, 5);
+// stateLabelBounds.width = Math.max(stateLabelBounds.width, infoLabelBounds.width);
+// stateLabelBounds.height = stateLabelBounds.height + infoLabelBounds.height;
int stateHeight = Zone.getHeight(stateView);
int stateWidth = Zone.getWidth(stateView);
int stateCompartHeight = Zone.getHeight(stateCompartView);
- int dx = stateLabelBounds.width - stateWidth;
- int dy = stateCompartHeight + stateLabelBounds.height - stateHeight;
+ int dx = width - stateWidth;
+ int dy = stateCompartHeight + height - stateHeight;
int x = Zone.getX(stateView);
int y = Zone.getY(stateView);
- if((stateHeight != -1) && (stateLabelBounds.width != 0) && (dy != 0)) {
+ if((stateHeight != -1) && (width != 0) && (dy != 0)) {
dx = (dx > 0) ? dx : 0;
// a resize request, which we route to the specific ResizeCommand
IAdaptable adaptableForState = new SemanticAdapter(null, stateView);
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/figures/CustomShapeCompartmentFigure.java b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/figures/CustomShapeCompartmentFigure.java
index f212bc5a5fa..9956fd723ba 100644
--- a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/figures/CustomShapeCompartmentFigure.java
+++ b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/figures/CustomShapeCompartmentFigure.java
@@ -1,5 +1,7 @@
package org.eclipse.papyrus.diagram.statemachine.custom.figures;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.ScrollPane;
import org.eclipse.gmf.runtime.diagram.ui.figures.ShapeCompartmentFigure;
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
@@ -20,5 +22,7 @@ public class CustomShapeCompartmentFigure extends ShapeCompartmentFigure {
super.configureFigure(mm);
scrollPane.setScrollBarVisibility(ScrollPane.NEVER);
scrollPane.setBorder(null);
+ setBorder(null);
}
+
}
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/figures/StateFigure.java b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/figures/StateFigure.java
index 09a15e4e45e..2a207d889f7 100644
--- a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/figures/StateFigure.java
+++ b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/figures/StateFigure.java
@@ -3,6 +3,7 @@ package org.eclipse.papyrus.diagram.statemachine.custom.figures;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PositionConstants;
@@ -15,6 +16,7 @@ import org.eclipse.gmf.runtime.notation.GradientStyle;
import org.eclipse.papyrus.diagram.common.figure.node.AutomaticCompartmentLayoutManager;
import org.eclipse.papyrus.diagram.common.figure.node.CompartmentFigure;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
/**
* Represents a classifier.
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/policies/CustomStateMachineDiagramDragDropEditPolicy.java b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/policies/CustomStateMachineDiagramDragDropEditPolicy.java
index 6e3bfe98c2d..e71cc18c1df 100644
--- a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/policies/CustomStateMachineDiagramDragDropEditPolicy.java
+++ b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/policies/CustomStateMachineDiagramDragDropEditPolicy.java
@@ -36,14 +36,18 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
+import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.diagram.common.commands.CommonDeferredCreateConnectionViewCommand;
import org.eclipse.papyrus.diagram.common.commands.SemanticAdapter;
import org.eclipse.papyrus.diagram.common.editpolicies.OldCommonDiagramDragDropEditPolicy;
+import org.eclipse.papyrus.diagram.common.helper.PreferenceInitializerForElementHelper;
import org.eclipse.papyrus.diagram.common.util.DiagramEditPartsUtil;
import org.eclipse.papyrus.diagram.statemachine.custom.commands.CreateViewCommand;
import org.eclipse.papyrus.diagram.statemachine.custom.commands.CustomCompositeStateSetBoundsCommand;
@@ -70,6 +74,7 @@ import org.eclipse.papyrus.diagram.statemachine.edit.parts.StateMachineEditPart;
import org.eclipse.papyrus.diagram.statemachine.edit.parts.TransitionEditPart;
import org.eclipse.papyrus.diagram.statemachine.part.UMLVisualIDRegistry;
import org.eclipse.papyrus.diagram.statemachine.providers.UMLElementTypes;
+import org.eclipse.papyrus.preferences.utils.PreferenceConstantHelper;
import org.eclipse.uml2.uml.ConnectionPointReference;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Pseudostate;
@@ -266,6 +271,8 @@ public class CustomStateMachineDiagramDragDropEditPolicy extends OldCommonDiagra
View stateView = (View)graphicalParentEditPart.getModel();
// check whether any region is already shown in the state compartment
+ if(stateView.getChildren().size()<2)
+ return UnexecutableCommand.INSTANCE;
View compartment = (View)stateView.getChildren().get(1);
if(!compartment.getChildren().isEmpty())
//then do not allow the drag and drop on state, this forces the drag and drop on an displayed region (see above)
@@ -358,8 +365,15 @@ public class CustomStateMachineDiagramDragDropEditPolicy extends OldCommonDiagra
CustomCompositeStateWithDefaultRegionCreateNodeCommand createRegion = new CustomCompositeStateWithDefaultRegionCreateNodeCommand((IAdaptable)createState.getCommandResult().getReturnValue(), ((IGraphicalEditPart)getHost()).getDiagramPreferencesHint(), getEditingDomain(), DiagramUIMessages.CreateCommand_Label, createState.getAffectedFiles());
- CustomCompositeStateSetBoundsCommand setBoundsCommand = new CustomCompositeStateSetBoundsCommand(getEditingDomain(), null, descriptor, new Rectangle(location.x, location.y, -1, -1));
-
+ CustomCompositeStateSetBoundsCommand setBoundsCommand;
+
+ //take care of the case when a simple state is dropped, then we should provide a reasonable size
+ if(droppedElement.getRegions().isEmpty()){
+ setBoundsCommand = new CustomCompositeStateSetBoundsCommand(getEditingDomain(), null, descriptor, new Rectangle(location.x, location.y, 40, 40), false);
+ }
+ else{
+ setBoundsCommand = new CustomCompositeStateSetBoundsCommand(getEditingDomain(), null, descriptor, new Rectangle(location.x, location.y, -1, -1), true);
+ }
cc.compose(createState);
cc.compose(createRegion);
cc.compose(setBoundsCommand);
@@ -381,6 +395,12 @@ public class CustomStateMachineDiagramDragDropEditPolicy extends OldCommonDiagra
* @return the drop command
*/
protected Command dropTransition(DropObjectsRequest dropRequest, Transition droppedElement, int linkVISUALID) {
+ //we restrict drop to be over the owning region
+ GraphicalEditPart graphicalParentEditPart = (GraphicalEditPart)getHost();
+ EObject graphicalParentObject = graphicalParentEditPart.resolveSemanticElement();
+ if(!(graphicalParentObject instanceof Region) || !((Region)graphicalParentObject).getTransitions().contains(droppedElement)){
+ return UnexecutableCommand.INSTANCE;
+ }
Vertex source = droppedElement.getSource();
Vertex target = droppedElement.getTarget();
@@ -390,16 +410,15 @@ public class CustomStateMachineDiagramDragDropEditPolicy extends OldCommonDiagra
GraphicalEditPart targetEditPart = (GraphicalEditPart)lookForEditPart(target);
// when the vertex are not represented on the diagram, we look for their parents.
DiagramEditPart diagram = DiagramEditPartsUtil.getDiagramEditPart(getHost());
+ // the parents of the vertex, we use them when the VertexEditPart are not on the diagram
+ EditPart sourceParent = null;
+ EditPart targetParent = null;
if(sourceEditPart == null || targetEditPart == null) {
List<IGraphicalEditPart> AllEP = DiagramEditPartsUtil.getAllEditParts(diagram);
EObject srcParent = source.eContainer();
EObject tgtParent = target.eContainer();
- // the parents of the vertex, we use them when the VertexEditPart are not on the diagram
- EditPart sourceParent = null;
- EditPart targetParent = null;
-
for(IGraphicalEditPart iGraphicalEditPart : AllEP) {
EObject object = ViewUtil.resolveSemanticElement((View)(iGraphicalEditPart).getModel());//method getHostObject
if(object == srcParent && !(iGraphicalEditPart instanceof CompartmentEditPart)) {
@@ -409,30 +428,114 @@ public class CustomStateMachineDiagramDragDropEditPolicy extends OldCommonDiagra
targetParent = iGraphicalEditPart;
}
if(targetParent != null && sourceParent != null) {
+ sourceParent = (EditPart)sourceParent.getChildren().get(0);
+ targetParent = (EditPart)targetParent.getChildren().get(0);
break;
}
}
- // the parent of the vertex shall be identical otherwise we do not support drag and drop
- if((targetParent == null) || (sourceParent == null) || (sourceParent != targetParent)) {
- return UnexecutableCommand.INSTANCE;
- }
- // and neither vertex to be created shall be a composite state
- if(((sourceEditPart == null) && ((source instanceof State) && !((State)source).getRegions().isEmpty())) ||
- ((targetEditPart == null) && ((target instanceof State) && !((State)target).getRegions().isEmpty()))) {
+ // the parent of the vertex shall be present in the diagram otherwise we do not support drag and drop
+ if((targetParent == null) || (sourceParent == null)){
return UnexecutableCommand.INSTANCE;
}
}
return new ICommandProxy(dropBinaryLink(new CompositeCommand("drop Transition"), source, target, //$NON-NLS-1$
- linkVISUALID, dropRequest.getLocation(), droppedElement));
+ linkVISUALID, dropRequest.getLocation(), droppedElement, sourceParent, targetParent));
} else {
return UnexecutableCommand.INSTANCE;
}
}
+
+ /**
+ * the method provides command to create the binary link into the diagram. If the source and the
+ * target views do not exist, these views will be created.
+ *
+ * @param cc
+ * the composite command that will contain the set of command to create the binary
+ * link
+ * @param source
+ * the source the element source of the link
+ * @param target
+ * the target the element target of the link
+ * @param linkVISUALID
+ * the link VISUALID used to create the view
+ * @param location
+ * the location the location where the view will be be created
+ * @param semanticLink
+ * the semantic link that will be attached to the view
+ * @param sourceParent
+ * the editPart of the source parent
+ * @param targetParent
+ * the editPart of the target parent
+ *
+ * @return the composite command
+ */
+ public CompositeCommand dropBinaryLink(CompositeCommand cc, Element source, Element target, int linkVISUALID, Point location, Element semanticLink, EditPart sourceParent, EditPart targetParent) {
+ // look for editpart
+ GraphicalEditPart sourceEditPart = (GraphicalEditPart)lookForEditPart(source);
+ GraphicalEditPart targetEditPart = (GraphicalEditPart)lookForEditPart(target);
+
+ // descriptor of the link
+ CreateConnectionViewRequest.ConnectionViewDescriptor linkdescriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(getUMLElementType(linkVISUALID), ((IHintedType)getUMLElementType(linkVISUALID)).getSemanticHint(), getDiagramPreferencesHint());
+
+ IAdaptable sourceAdapter = null;
+ IAdaptable targetAdapter = null;
+ if(sourceEditPart == null) {
+ // creation of the node
+ ViewDescriptor descriptor = new ViewDescriptor(new EObjectAdapter(source), Node.class, null, ViewUtil.APPEND, false, ((IGraphicalEditPart)getHost()).getDiagramPreferencesHint());
+
+ // get the command and execute it.
+ CreateCommand nodeCreationCommand = new CreateCommand(((IGraphicalEditPart)getHost()).getEditingDomain(), descriptor, (View)sourceParent.getModel());
+ cc.compose(nodeCreationCommand);
+ SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x, location.y + 30)); //$NON-NLS-1$
+ cc.compose(setBoundsCommand);
+
+ sourceAdapter = (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue();
+ } else {
+ sourceAdapter = new SemanticAdapter(null, sourceEditPart.getModel());
+ }
+ //additional check to ensure we do not create twice the same node when links are "loops" on the same element
+ if((target != null) && !target.equals(source)){
+ if(targetEditPart == null) {
+ // creation of the node
+ ViewDescriptor descriptor = new ViewDescriptor(new EObjectAdapter(target), Node.class, null, ViewUtil.APPEND, false, ((IGraphicalEditPart)getHost()).getDiagramPreferencesHint());
+
+ // get the command and execute it.
+ CreateCommand nodeCreationCommand = new CreateCommand(((IGraphicalEditPart)getHost()).getEditingDomain(), descriptor, ((View)targetParent.getModel()));
+ cc.compose(nodeCreationCommand);
+ //take care of the location for the cases when the target is not in the same container as the source
+ SetBoundsCommand setBoundsCommand;
+ if((targetParent != null) && !targetParent.equals(sourceParent)){
+ setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue(), new Point(10, 10)); //$NON-NLS-1$
+ }
+ else{
+ setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x, location.y - 30)); //$NON-NLS-1$
+ }
+ cc.compose(setBoundsCommand);
+ targetAdapter = (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue();
+
+ } else {
+ targetAdapter = new SemanticAdapter(null, targetEditPart.getModel());
+ }
+ }
+ //in case of loop links (see above) we pass on the same adapter for both source and target
+ if((target != null) && target.equals(source)){
+ targetAdapter = sourceAdapter;
+ }
+
+ CommonDeferredCreateConnectionViewCommand aLinkCommand = new CommonDeferredCreateConnectionViewCommand(getEditingDomain(), ((IHintedType)getUMLElementType(linkVISUALID)).getSemanticHint(), sourceAdapter, targetAdapter, getViewer(), getDiagramPreferencesHint(), linkdescriptor, null);
+ aLinkCommand.setElement(semanticLink);
+ cc.compose(aLinkCommand);
+ return cc;
+
+ }
+
+
+
@Override
public void eraseTargetFeedback(Request request) {
if(sizeOnDropFeedback != null) {

Back to the top