Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrung-Truc NGUYEN2016-01-25 22:48:31 +0000
committerGerrit Code Review @ Eclipse.org2016-02-10 08:34:16 +0000
commiteeccb08c415e2091bce608043aeaff14bd7f6690 (patch)
treed8408ba354ea03f59e659b8c7e8b2582788a161c
parentaa593b9a2870da6662ac032b7b3dd0e779374952 (diff)
downloadorg.eclipse.papyrus-eeccb08c415e2091bce608043aeaff14bd7f6690.tar.gz
org.eclipse.papyrus-eeccb08c415e2091bce608043aeaff14bd7f6690.tar.xz
org.eclipse.papyrus-eeccb08c415e2091bce608043aeaff14bd7f6690.zip
Bug 473722 - [Composite Diagram] Papyrus should support graphical
resizable ports Change-Id: I4743f4166f33e15a45df427406e10fefc9bf5241 Signed-off-by: Trung-Truc NGUYEN<truc.ensma@gmail.com>
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/ResizeParentFigureCommand.java104
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AllowResizeAffixedNodeAlignmentEditPolicy.java38
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/PortResizableEditPolicy.java146
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomClassCompositeEditPart.java66
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomEditPartFactory.java8
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomFullPortAffixedEditPart.java86
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPropertyPartEditPartCN.java58
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/locators/CustomPortPositionLocator.java225
8 files changed, 730 insertions, 1 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/ResizeParentFigureCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/ResizeParentFigureCommand.java
new file mode 100644
index 00000000000..d3657be045f
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/ResizeParentFigureCommand.java
@@ -0,0 +1,104 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
+
+/**
+ * This class serves to resize the figure bound of a edit part (at this moment, used only for Port Edit Part)
+ *
+ * @author Trung-Truc Nguyen
+ *
+ */
+public class ResizeParentFigureCommand extends AbstractTransactionalCommand {
+
+ private DefaultSizeNodeFigure parent = null;
+ private ChangeBoundsRequest request;
+
+ //for undo - redo
+ private int oldWidth;
+ private int oldHeight;
+
+ private int newWidth = -1;
+ private int newHeight = -1;
+ /**
+ *
+ * Constructor.
+ *
+ * @param domain
+ * @param portFigure the port figure to change its bound
+ * @param iFigure
+ * @param request
+ */
+ public ResizeParentFigureCommand(TransactionalEditingDomain domain, DefaultSizeNodeFigure portFigure, ChangeBoundsRequest request) {
+ super(domain, "Resize Full Port Figure", null);
+ this.parent = portFigure;
+ this.request = request;
+ oldHeight = portFigure.getBounds().height;
+ oldWidth = portFigure.getBounds().width;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ *
+ * @param monitor
+ * @param info
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ newWidth = oldWidth + request.getSizeDelta().width;
+ newHeight = oldHeight + request.getSizeDelta().height;
+
+ parent.getBounds().setSize(newWidth, newHeight);
+ parent.getDefaultSize().setSize(newWidth, newHeight);
+
+ return CommandResult.newOKCommandResult();
+ }
+
+ protected IStatus doUndo(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+
+ if(parent != null) {
+ parent.getBounds().setSize(oldWidth, oldHeight);
+ parent.getDefaultSize().setSize(oldWidth, oldHeight);
+ }
+ return super.doUndo(monitor, info);
+ }
+
+ /**
+ * Overrides superclass to set the command result.
+ */
+ protected IStatus doRedo(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+
+ if(parent != null && newHeight != -1) {
+ parent.getBounds().setSize(newWidth, newHeight);
+ parent.getDefaultSize().setSize(newWidth, newHeight);
+ }
+
+ return super.doRedo(monitor, info);
+ }
+
+} \ No newline at end of file
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AllowResizeAffixedNodeAlignmentEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AllowResizeAffixedNodeAlignmentEditPolicy.java
new file mode 100644
index 00000000000..f6ca2c95435
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AllowResizeAffixedNodeAlignmentEditPolicy.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.editpolicies;
+
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+
+/**
+ * This class replaces the original AffixedNodeAlignmentEditPolicy
+ * it just overrides the command (that is null in the class AffixedNodeAlignmentEditPolicy) that
+ * causes to resize a child figure.
+ * see the class CustomFullPortAffixedEditPart
+ *
+ * @author Trung-Truc Nguyen
+ *
+ */
+public class AllowResizeAffixedNodeAlignmentEditPolicy extends AffixedNodeAlignmentEditPolicy{
+
+ // without this command, port resize command will never be called.
+ public Command getCommand(Request request) {
+ if (REQ_RESIZE_CHILDREN.equals(request.getType())) {
+ return getResizeChildrenCommand((ChangeBoundsRequest) request);
+ }
+ return super.getCommand(request);
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/PortResizableEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/PortResizableEditPolicy.java
new file mode 100644
index 00000000000..5034943479d
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/PortResizableEditPolicy.java
@@ -0,0 +1,146 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.editpolicies;
+
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
+import org.eclipse.gmf.runtime.notation.Shape;
+import org.eclipse.papyrus.uml.diagram.common.commands.FixPortLocationCommand;
+import org.eclipse.papyrus.uml.diagram.common.commands.ResizeParentFigureCommand;
+import org.eclipse.papyrus.uml.diagram.common.commands.UpdatePortLocationCommand;
+import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedBorderNamedElementEditPart;
+
+/**
+ * BorderItemResizableEditPolicy is a policy which takes over the resize command of an item on the
+ * border of another item.
+ * This class serves to override the resize command (which is null) of a port item.
+ * @author Trung-Truc Nguyen
+ *
+ */
+public class PortResizableEditPolicy extends BorderItemResizableEditPolicy {
+
+ protected Command getResizeCommand(ChangeBoundsRequest request) {
+
+ // Create the complete resize command
+ CompoundCommand resizeCommand = new CompoundCommand(
+ "Resize command"); //$NON-NLS-1$
+
+ // Prepare command to move the affixed children as well (and an optional
+ // fix command)
+ CompoundCommand updatePortLocationsCommand = new CompoundCommand(
+ "Update border test location"); //$NON-NLS-1$
+ CompoundCommand fixPortLocationsCommand = new CompoundCommand(
+ "Fix border items location"); //$NON-NLS-1$
+
+
+
+
+
+ Command res = getResizePortCommand(request);
+
+ if(request.getEditParts() == null) return null;
+
+ for (Object object : request.getEditParts()) {
+ if(object instanceof RoundedBorderNamedElementEditPart){
+ RoundedBorderNamedElementEditPart editpart = (RoundedBorderNamedElementEditPart) object;
+ Shape view = (Shape) editpart.getNotationView();
+ TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(view);
+
+ ICommand updatePortSize = new ResizeParentFigureCommand(editingDomain, (DefaultSizeNodeFigure) editpart.getPrimaryShape().getParent(), request);
+ resizeCommand.add(new ICommandProxy(
+ updatePortSize));
+
+ ICommand fixPortLocationCommand = new FixPortLocationCommand(editingDomain, editpart, (GraphicalEditPart) getHost());
+ if (fixPortLocationCommand.canExecute()) {
+ fixPortLocationsCommand.add(new ICommandProxy(fixPortLocationCommand));
+ }
+
+ ICommand updatePortLocationCommand = new UpdatePortLocationCommand(editingDomain, request, (GraphicalEditPart) getHost(), editpart, editpart.getBorderItemLocator().getCurrentSideOfParent());
+ if (updatePortLocationCommand.canExecute()) {
+ updatePortLocationsCommand.add(new ICommandProxy(updatePortLocationCommand));
+ }
+ }
+ }
+ if (!fixPortLocationsCommand.isEmpty()) {
+ resizeCommand.add(fixPortLocationsCommand);
+ }
+ if (!updatePortLocationsCommand.isEmpty()) {
+ resizeCommand.add(updatePortLocationsCommand);
+ }
+ resizeCommand.add(res);
+
+// resizeCommand.add(getMoveCommand(request));
+
+ return resizeCommand;
+ }
+
+ /**
+ * This method makes sure that the minimum dimension of the port figure is 20x20
+ * and setting the port figure size due to the request.
+ * @param request change size bound request
+ * @return
+ */
+ protected Command getResizePortCommand(ChangeBoundsRequest request) {
+ ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_RESIZE_CHILDREN);
+ req.setCenteredResize(request.isCenteredResize());
+ req.setConstrainedMove(request.isConstrainedMove());
+ req.setConstrainedResize(request.isConstrainedResize());
+ req.setSnapToEnabled(request.isSnapToEnabled());
+ req.setEditParts(getHost());
+
+ req.setMoveDelta(request.getMoveDelta());
+
+ req.setLocation(request.getLocation());
+ req.setExtendedData(request.getExtendedData());
+ req.setResizeDirection(request.getResizeDirection());
+
+ if (getHost().getParent() == null) {
+ return null;
+ }
+
+ if(request.getEditParts() == null) return null;
+
+ for (Object object : request.getEditParts()) {
+ if(object instanceof RoundedBorderNamedElementEditPart) {
+ RoundedBorderNamedElementEditPart editPart = (RoundedBorderNamedElementEditPart) object;
+
+ int w = editPart.getFigure().getBounds().width + request.getSizeDelta().width;
+ int h = editPart.getFigure().getBounds().height + request.getSizeDelta().height;
+
+ //check if size is too small? make sure minimum size is 20x20
+ int wdelta = 20 - editPart.getFigure().getBounds().width;
+ int hdelta = 20 - editPart.getFigure().getBounds().height;
+
+ Dimension sizeDelta = request.getSizeDelta();
+ if(w < 20) {
+ sizeDelta.setWidth(wdelta);
+ }
+ if(h < 20)
+ sizeDelta.setHeight(hdelta);
+ req.setSizeDelta(sizeDelta);
+ }
+ }
+ Command cm = getHost().getParent().getCommand(req);
+
+ return cm;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomClassCompositeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomClassCompositeEditPart.java
new file mode 100644
index 00000000000..7130c8170ff
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomClassCompositeEditPart.java
@@ -0,0 +1,66 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.composite.custom.edit.parts;
+
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedBorderNamedElementEditPart;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.AllowResizeAffixedNodeAlignmentEditPolicy;
+import org.eclipse.papyrus.uml.diagram.composite.custom.locators.CustomPortPositionLocator;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ClassCompositeEditPart;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PortEditPart;
+
+
+/**
+ *
+ * This class just takes care of installing a new policy that calls the resize command of a child item (a port in this case).
+ *
+ * @author Trung-Truc Nguyen
+ *
+ */
+public class CustomClassCompositeEditPart extends ClassCompositeEditPart{
+
+ /**
+ * Constructor.
+ *
+ * @param view
+ */
+ public CustomClassCompositeEditPart(View view) {
+ super(view);
+ installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AllowResizeAffixedNodeAlignmentEditPolicy());
+ }
+
+ public void installEditPolicy(Object key, EditPolicy editPolicy) {
+ if (AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE.equals(key)) {
+ if (editPolicy instanceof AllowResizeAffixedNodeAlignmentEditPolicy)
+ super.installEditPolicy(key, editPolicy);
+ }
+ else
+ super.installEditPolicy(key, editPolicy);
+ }
+
+ protected boolean addFixedChild(EditPart childEditPart) {
+ //Papyrus Gencode :Affixed Port locator
+ if(childEditPart instanceof PortEditPart) {
+ IBorderItemLocator locator = new CustomPortPositionLocator(getMainFigure(), (RoundedBorderNamedElementEditPart) childEditPart, PositionConstants.NONE);
+ getBorderedFigure().getBorderItemContainer().add(((PortEditPart)childEditPart).getFigure(), locator);
+ return true;
+ }
+ return super.addFixedChild(childEditPart);
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomEditPartFactory.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomEditPartFactory.java
index ef0899bffe3..fdc9719c420 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomEditPartFactory.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomEditPartFactory.java
@@ -15,6 +15,7 @@ package org.eclipse.papyrus.uml.diagram.composite.custom.edit.parts;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ClassCompositeEditPart;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorMultiplicitySourceEditPart;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorMultiplicityTargetEditPart;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConstraintEditPartCN;
@@ -23,6 +24,7 @@ import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ParameterAppliedSter
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PortAppliedStereotypeEditPart;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PortEditPart;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PortNameEditPart;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PropertyPartEditPartCN;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.TimeObservationStereotypeLabelEditPart;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.UMLEditPartFactory;
import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry;
@@ -48,7 +50,7 @@ public class CustomEditPartFactory extends UMLEditPartFactory {
case ConstraintEditPartCN.VISUAL_ID:
return new CustomConstraintEditPartCN(view);
case PortEditPart.VISUAL_ID:
- return new CustomPortEditPart(view);
+ return new CustomFullPortAffixedEditPart(view);
case PortNameEditPart.VISUAL_ID:
return new CustomPortNameEditPart(view);
case DurationObservationStereotypeLabelEditPart.VISUAL_ID:
@@ -57,8 +59,12 @@ public class CustomEditPartFactory extends UMLEditPartFactory {
return new CustomParameterAppliedStereotypeEditPart(view);
case PortAppliedStereotypeEditPart.VISUAL_ID:
return new CustomPortAppliedStereotypeEditPart(view);
+ case ClassCompositeEditPart.VISUAL_ID:
+ return new CustomClassCompositeEditPart(view);
case TimeObservationStereotypeLabelEditPart.VISUAL_ID:
return new CustomTimeObservationStereotypeLabelEditPart(view);
+ case PropertyPartEditPartCN.VISUAL_ID:
+ return new CustomPropertyPartEditPartCN(view);
}
}
return super.createEditPart(context, model);
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomFullPortAffixedEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomFullPortAffixedEditPart.java
new file mode 100644
index 00000000000..d6fcdd8c59f
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomFullPortAffixedEditPart.java
@@ -0,0 +1,86 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.composite.custom.edit.parts;
+
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
+import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.infra.gmfdiag.common.preferences.PreferencesConstantsHelper;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.PortResizableEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.helper.PreferenceInitializerForElementHelper;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PortEditPart;
+
+
+/**
+ * This class is used for 2 purposes.
+ * 1. Install new ResizablePolicy for port
+ * 2. Override Affixed_child_alignment_role policy for resize commands
+ * @author Trung-Truc Nguyen
+ *
+ */
+public class CustomFullPortAffixedEditPart extends PortEditPart{
+
+ /**
+ * Constructor.
+ *
+ * @param view
+ */
+ public CustomFullPortAffixedEditPart(View view) {
+ super(view);
+ installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PortResizableEditPolicy());
+ installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new PortResizableEditPolicy());
+ }
+
+ public void installEditPolicy(Object key, EditPolicy editPolicy){
+ if(EditPolicy.PRIMARY_DRAG_ROLE.equals(key)) {
+ //prevent its parents from overriding this policy
+ if(editPolicy instanceof PortResizableEditPolicy)
+ super.installEditPolicy(key, editPolicy);
+ }
+ else
+ super.installEditPolicy(key, editPolicy);
+ }
+
+ /**
+ * this override method serves to resize the DefaultSizeNodeFigure each time the diagram is opened.
+ * without this, the DefaultNodeFigure size is 20x20 by default although the size of port figure is different.
+ */
+ protected NodeFigure createNodePlate() {
+ String prefElementId = getNotationView().getType();
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ String preferenceConstantWitdh = PreferenceInitializerForElementHelper.getpreferenceKey(getNotationView(), prefElementId, PreferencesConstantsHelper.WIDTH);
+ String preferenceConstantHeight = PreferenceInitializerForElementHelper.getpreferenceKey(getNotationView(), prefElementId, PreferencesConstantsHelper.HEIGHT);
+ DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(store.getInt(preferenceConstantWitdh), store.getInt(preferenceConstantHeight));
+
+ int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue();
+ int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue();
+
+// Dimension size = new Dimension(width, height);
+ // FIXME: workaround for #154536
+
+ int w = width > 20 ? width : 20;
+ int h = height > 20 ? height : 20;
+
+ result.getBounds().setSize(w, h);
+ result.setDefaultSize(w, h);
+
+
+ return result;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPropertyPartEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPropertyPartEditPartCN.java
new file mode 100644
index 00000000000..44405447291
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPropertyPartEditPartCN.java
@@ -0,0 +1,58 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.composite.custom.edit.parts;
+
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedBorderNamedElementEditPart;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.AllowResizeAffixedNodeAlignmentEditPolicy;
+import org.eclipse.papyrus.uml.diagram.composite.custom.locators.CustomPortPositionLocator;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PortEditPart;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PropertyPartEditPartCN;
+
+public class CustomPropertyPartEditPartCN extends PropertyPartEditPartCN {
+
+ /**
+ * Constructor.
+ *
+ * @param view
+ */
+ public CustomPropertyPartEditPartCN(View view) {
+ super(view);
+ installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AllowResizeAffixedNodeAlignmentEditPolicy());
+ }
+ public void installEditPolicy(Object key, EditPolicy editPolicy) {
+ if (AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE.equals(key)) {
+ if (editPolicy instanceof AllowResizeAffixedNodeAlignmentEditPolicy)
+ super.installEditPolicy(key, editPolicy);
+ }
+ else
+ super.installEditPolicy(key, editPolicy);
+ }
+
+ protected boolean addFixedChild(EditPart childEditPart) {
+
+ //Papyrus Gencode :Affixed Port locator
+ if(childEditPart instanceof PortEditPart) {
+ IBorderItemLocator locator = new CustomPortPositionLocator(getMainFigure(), (RoundedBorderNamedElementEditPart) childEditPart, PositionConstants.NONE);
+ getBorderedFigure().getBorderItemContainer().add(((PortEditPart)childEditPart).getFigure(), locator);
+ return true;
+ }
+ return super.addFixedChild(childEditPart);
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/locators/CustomPortPositionLocator.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/locators/CustomPortPositionLocator.java
new file mode 100644
index 00000000000..a1ed9e68e64
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/locators/CustomPortPositionLocator.java
@@ -0,0 +1,225 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.composite.custom.locators;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedBorderNamedElementEditPart;
+import org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator;
+
+/**
+ * This class helps to set the port location on a figure border.
+ * If the port size is 20x20 -> it keeps the same value with the PortPositionLocator class. (10 inside and 10 outside
+ * of the figure)
+ * If the port size is different from 20x20, it will set the inside part of the port on the figure
+ * border is always 10. If using the PortPositionLocator, the inside part of the port may bigger than
+ * the outside and may cause some difficulties for other parts location inside of the figure border.
+ *
+ * @author Trung-Truc Nguyen
+ *
+ */
+public class CustomPortPositionLocator extends PortPositionLocator {
+
+ protected RoundedBorderNamedElementEditPart portEditPart = null;
+
+
+
+ public CustomPortPositionLocator(IFigure parentFigure, RoundedBorderNamedElementEditPart childEditPart,
+ int none) {
+ super(parentFigure, none);
+ portEditPart = childEditPart;
+ }
+
+ /**
+ * This method helps to set the Port location which is satisfied the criterion on the top of the class.
+ * @param proposedLocation
+ * the proposed location
+ * @return a possible location on parent figure border
+ */
+ public final Rectangle getPreferredLocation(Rectangle proposedLocation) {
+
+ // Initialize port location with proposed location
+ // and resolve the bounds of it graphical parent
+ Rectangle realLocation = new Rectangle(proposedLocation);
+
+ Rectangle parentRec = getParentFigure().getBounds().getCopy();
+
+ Rectangle thisRec = portEditPart.getFigure().getBounds().getCopy();
+
+ // Calculate Max position around the graphical parent (1/2 size or the port around
+ // the graphical parent bounds.
+// int xMin = parentRec.x - thisRec.width + borderItemOffset;
+ int xMin = parentRec.x - thisRec.width/2;
+// int xMax = parentRec.x - borderItemOffset + parentRec.width;
+ int xMax = parentRec.x + parentRec.width - thisRec.width/2;
+
+// int yMin = parentRec.y - thisRec.height + borderItemOffset;
+ int yMin = parentRec.y - thisRec.height/2;
+// int yMax = parentRec.y - borderItemOffset + parentRec.height;
+ int yMax = parentRec.y + parentRec.height - thisRec.height/2;
+
+ // Modify Port location if MAX X or Y are exceeded
+ if (realLocation.x < xMin) {
+ realLocation.x = xMin;
+ }
+
+ if (realLocation.x > xMax) {
+ realLocation.x = xMax;
+ }
+
+ if (realLocation.y < yMin) {
+ realLocation.y = yMin;
+ }
+
+ if (realLocation.y > yMax) {
+ realLocation.y = yMax;
+ }
+
+ // commented by V. Lorenzo to allow to create port on the top of a figure
+ // replaced by the next block of code
+
+ // Ensure the port is positioned on its parent borders and not in the middle.
+ // Modify position if needed.
+ // if((realLocation.y != yMin) && (realLocation.y != yMax)) {
+ // if((realLocation.x != xMin) && (realLocation.x != xMax)) {
+ //
+ // if(realLocation.x <= (xMin + (parentRec.width / 2))) {
+ // realLocation.x = xMin;
+ // } else {
+ // realLocation.x = xMax;
+ // }
+ // }
+ // }
+
+ // this code replaces the previous commented lines
+ final Rectangle maxRect = parentRec.getCopy();
+ maxRect.shrink(-borderItemOffset, -borderItemOffset);
+ while (maxRect.contains(realLocation.getLocation())) {
+ maxRect.shrink(1, 1);
+ }
+ int pos = maxRect.getPosition(realLocation.getLocation());
+ switch (pos) {
+ case PositionConstants.NORTH:
+ realLocation.y = yMin;
+ break;
+ case PositionConstants.SOUTH:
+ realLocation.y = yMax;
+ break;
+ case PositionConstants.EAST:
+ realLocation.x = xMax;
+ break;
+ case PositionConstants.WEST:
+ realLocation.x = xMin;
+ break;
+ case PositionConstants.NORTH_EAST:
+ realLocation.x = xMax;
+ realLocation.y = yMin;
+ break;
+ case PositionConstants.NORTH_WEST:
+ realLocation.x = xMin;
+ realLocation.y = yMin;
+ break;
+ case PositionConstants.SOUTH_EAST:
+ realLocation.x = xMax;
+ realLocation.y = yMax;
+ break;
+ case PositionConstants.SOUTH_WEST:
+ realLocation.x = xMin;
+ realLocation.y = yMax;
+ break;
+ }
+
+ // Return constrained location
+ return realLocation;
+ }
+
+ /**
+ * Due to the new algorithm of calculating port position, this method need to be recalculated.
+ * @see org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator#getCurrentSideOfParent()
+ *
+ * @return
+ */
+ public int getCurrentSideOfParent() {
+ int position = PositionConstants.NONE;
+ Rectangle thisRec = portEditPart.getFigure().getBounds().getCopy();
+
+ int x = constraint.x;
+ int y = constraint.y;
+// int h = thisRec.height;
+// int w = thisRec.width;
+
+ Rectangle p = parentFigure.getBounds();
+
+ int xMin = p.x - thisRec.width/2;
+// int xMax = parentRec.x - borderItemOffset + parentRec.width;
+ int xMax = p.x + p.width - thisRec.width/2;
+
+// int yMin = parentRec.y - thisRec.height + borderItemOffset;
+ int yMin = p.y - thisRec.height/2;
+// int yMax = parentRec.y - borderItemOffset + parentRec.height;
+ int yMax = p.y + p.height - thisRec.height/2;
+
+ if(x == xMin && y == yMin)
+ position = PositionConstants.NORTH_WEST;
+ else if(x == xMin && y == yMax)
+ position = PositionConstants.SOUTH_WEST;
+ else if (x == xMax && y == yMin)
+ position = PositionConstants.NORTH_EAST;
+ else if(x == xMax && y == yMax)
+ position = PositionConstants.SOUTH_EAST;
+ else if(y == yMin)
+ position = PositionConstants.NORTH;
+ else if(y == yMax)
+ position = PositionConstants.SOUTH;
+ else if(x == xMin)
+ position = PositionConstants.WEST;
+ else
+ position = PositionConstants.EAST;
+
+
+// //NORTH EAST
+// if(y == borderItemOffset -h && x == p.width - borderItemOffset)
+// position = PositionConstants.NORTH_EAST;
+//
+// //NORTH WEST
+// else if(x == -(w - borderItemOffset) && y == -(h - borderItemOffset))
+// position = PositionConstants.NORTH_WEST;
+//
+// //SOUTH WEST
+// else if(x == -(w - borderItemOffset) && y == p.height - borderItemOffset)
+// position = PositionConstants.SOUTH_WEST;
+//
+// //SOUTH EAST
+// else if(x == p.width - borderItemOffset && y == p.height - borderItemOffset)
+// position = PositionConstants.SOUTH_EAST;
+//
+// //EAST
+// else if(x >= p.width - borderItemOffset )
+// position = PositionConstants.EAST;
+//
+// //WEST
+// else if(x <= -(w - borderItemOffset))
+// position = PositionConstants.WEST;
+//
+// //NORTH
+// else if(y <= -(h-borderItemOffset))
+// position = PositionConstants.NORTH;
+// //SOUTH
+// else if(y >= p.height - borderItemOffset)
+// position = PositionConstants.SOUTH;
+ return position;
+ }
+
+}

Back to the top