diff options
Diffstat (limited to 'plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/utils/FixPortsLocationOnOpening.java')
-rw-r--r-- | plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/utils/FixPortsLocationOnOpening.java | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/utils/FixPortsLocationOnOpening.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/utils/FixPortsLocationOnOpening.java index a42389d0cdf..81ffe6d66fb 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/utils/FixPortsLocationOnOpening.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/utils/FixPortsLocationOnOpening.java @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * + * * CEA LIST - Initial API and implementation * *****************************************************************************/ @@ -40,33 +40,35 @@ public class FixPortsLocationOnOpening { /** * This method fix the diagram Port and FlowPort locations. - * @param diagram the diagram + * + * @param diagram + * the diagram */ public void fix(Diagram diagram) { - + // Parse diagram content Iterator<EObject> it = diagram.eAllContents(); - while(it.hasNext()) { + while (it.hasNext()) { EObject current = it.next(); - + // Select Port and FlowPorts - if (! (current instanceof Shape)) { + if (!(current instanceof Shape)) { continue; } - Shape portView = (Shape)current; + Shape portView = (Shape) current; String currentType = (portView).getType(); if (SysMLGraphicalTypes.SHAPE_SYSML_FLOWPORT_AS_AFFIXED_ID.equals(currentType) || UMLGraphicalTypes.SHAPE_UML_PORT_AS_AFFIXED_ID.equals(currentType)) { - + int borderItemOffset = 10; View parentView = ViewUtil.getViewContainer(portView); - - if (parentView instanceof Shape){ - Shape parentShape = (Shape)parentView; + + if (parentView instanceof Shape) { + Shape parentShape = (Shape) parentView; Bounds portViewBounds = (Bounds) portView.getLayoutConstraint(); Bounds parentViewBounds = (Bounds) parentShape.getLayoutConstraint(); - + final Rectangle portBounds = new Rectangle(portViewBounds.getX(), portViewBounds.getY(), portViewBounds.getWidth(), portViewBounds.getHeight()); - + int parentWidth = parentViewBounds.getWidth(); int parentHeight = parentViewBounds.getHeight(); if ((parentWidth == -1) && (parentHeight == -1)) { @@ -76,13 +78,13 @@ public class FixPortsLocationOnOpening { parentHeight = Activator.getInstance().getPreferenceStore().getInt(PreferencesConstantsHelper.getElementConstant(parentPrefKey, PreferencesConstantsHelper.HEIGHT)); } final Rectangle parentBounds = new Rectangle(parentViewBounds.getX(), parentViewBounds.getY(), parentWidth, parentHeight); - + // Calculate the valid location based on currently stored location and parent bounds final Rectangle validLocation = PortPositionLocatorUtils.getBorderLocation(parentBounds, portBounds, borderItemOffset); - + // Fix when current location is not the valid location (only possible if parent size is set) - if (! portBounds.equals(validLocation)) { - + if (!portBounds.equals(validLocation)) { + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(diagram); Command fixCommand = new FixLocationCommand(editingDomain, "Fix Port location on opening", portViewBounds, validLocation); editingDomain.getCommandStack().execute(fixCommand); @@ -92,20 +94,20 @@ public class FixPortsLocationOnOpening { } } } - + /** * This command set the Port view with valid locations. */ public class FixLocationCommand extends RecordingCommand { - + /** Port view bounds. */ private Bounds portViewBounds; - + /** Port valid bounds (only the location is used here). */ private Rectangle portValidBounds; - + /** Constructor. */ - public FixLocationCommand(TransactionalEditingDomain domain,String label, Bounds portViewBounds, Rectangle portValidBounds) { + public FixLocationCommand(TransactionalEditingDomain domain, String label, Bounds portViewBounds, Rectangle portValidBounds) { super(domain, label); this.portViewBounds = portViewBounds; this.portValidBounds = portValidBounds; @@ -121,6 +123,6 @@ public class FixPortsLocationOnOpening { public boolean canUndo() { return false; } - + } } |