Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGéry Deloge2016-05-11 03:38:27 -0400
committerPatrick Tessier2016-07-01 07:22:01 -0400
commit098878d3d56893f5d767b45d7a5d10ad0444094d (patch)
tree05ac9fd63bde9dab3b9f2ec23cc9d344a602c986
parent184eae77538997610368faae86cd00d5628deca7 (diff)
downloadorg.eclipse.papyrus-098878d3d56893f5d767b45d7a5d10ad0444094d.tar.gz
org.eclipse.papyrus-098878d3d56893f5d767b45d7a5d10ad0444094d.tar.xz
org.eclipse.papyrus-098878d3d56893f5d767b45d7a5d10ad0444094d.zip
Bug 459888: [Activity Diagram] The bottom and right margins of
Activities are too big change margins to 10px Change-Id: I2a13b68123356cc6022a5de6370edb67a037c98e Signed-off-by: Géry Deloge <gery.deloge@cea.fr>
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/figures/ActivityFigure.java37
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/canonical/TestActivityMargin.java165
2 files changed, 194 insertions, 8 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/figures/ActivityFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/figures/ActivityFigure.java
index 6fcf49ed5b7..ffe3fd9bc69 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/figures/ActivityFigure.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/figures/ActivityFigure.java
@@ -43,6 +43,18 @@ public class ActivityFigure extends RoundedCompartmentFigure {
*/
protected class ActivityLayoutManager extends AbstractLayout {
+
+ /** right and bottom margin of diagram. Set to 10 to be consistent with left and top margin */
+ private int rightAndBottomMargin = 10;
+
+ public int getRightAndBottomMargin() {
+ return rightAndBottomMargin;
+ }
+
+ public void setRightAndBottomMargin(int rightAndBottomMargin) {
+ this.rightAndBottomMargin = rightAndBottomMargin;
+ }
+
/**
* ---------------------------------------------------| |sterotypeLabel|
* precondition | |--------------| | |QualifiedName
@@ -57,28 +69,29 @@ public class ActivityFigure extends RoundedCompartmentFigure {
*/
@Override
protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
- int minimumWith = 0;
+ int minimumWidth = 0;
int minimumHeight = 0;
+
// take in account the content of the figure activity
if ((getContentFigure().getChildren().size() > 0)) {
IFigure content = (IFigure) getContentFigure().getChildren().get(0);
- minimumWith = content.getPreferredSize().width + 50;
- minimumHeight = content.getPreferredSize().height + 50;
+ minimumWidth = content.getPreferredSize().width + rightAndBottomMargin;
+ minimumHeight = content.getPreferredSize().height + rightAndBottomMargin;
}
// display name
if (getNameLabel() != null) {
- if (getNameLabel().getPreferredSize().width > minimumWith) {
- minimumWith = getNameLabel().getPreferredSize().width;
+ if (getNameLabel().getPreferredSize().width > minimumWidth) {
+ minimumWidth = getNameLabel().getPreferredSize().width;
}
minimumHeight += getNameLabel().getPreferredSize().height;
}
if (getHeaderSingleExecution() != null) {
- if (getHeaderSingleExecution().getBounds().getTopRight().x > minimumWith) {
- minimumWith = getHeaderSingleExecution().getBounds().getTopRight().x;
+ if (getHeaderSingleExecution().getBounds().getTopRight().x > minimumWidth) {
+ minimumWidth = getHeaderSingleExecution().getBounds().getTopRight().x;
}
}
- return new Dimension(minimumWith, minimumHeight);
+ return new Dimension(minimumWidth, minimumHeight);
}
/**
@@ -430,4 +443,12 @@ public class ActivityFigure extends RoundedCompartmentFigure {
public RectangleFigure getCompartmentFigure() {
return fCompartmentFigure;
}
+
+ public void setRightAndBottomMargin(int rightAndBottomMargin){
+ ActivityLayoutManager lm = (ActivityLayoutManager) getLayoutManager();
+
+ if(lm != null){
+ lm.setRightAndBottomMargin(rightAndBottomMargin);
+ }
+ }
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/canonical/TestActivityMargin.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/canonical/TestActivityMargin.java
new file mode 100644
index 00000000000..6fa97a9793b
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/canonical/TestActivityMargin.java
@@ -0,0 +1,165 @@
+/*****************************************************************************
+ * 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.activity.tests.canonical;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Logger;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.papyrus.infra.gmfdiag.common.updater.DiagramUpdater;
+import org.eclipse.papyrus.uml.diagram.activity.figures.ActivityFigure;
+import org.eclipse.papyrus.uml.diagram.activity.part.UMLDiagramUpdater;
+import org.eclipse.papyrus.uml.diagram.activity.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.activity.tests.IActivityDiagramTestsConstants;
+import org.eclipse.swt.widgets.Display;
+import org.junit.Assert;
+import org.junit.Test;
+
+
+public class TestActivityMargin extends AbstractTestActivityChildNode {
+
+ private final static Logger log = Logger.getAnonymousLogger();
+
+ @Override
+ protected String getProjectName() {
+ return IActivityDiagramTestsConstants.PROJECT_NAME;
+ }
+
+ @Override
+ protected String getFileName() {
+ return IActivityDiagramTestsConstants.FILE_NAME;
+ }
+
+ public DiagramUpdater getDiagramUpdater() {
+ return UMLDiagramUpdater.INSTANCE;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected CreateViewRequest createViewRequestShapeContainer() {
+ // no container, it should be created on the main activity, not the diagram edit part
+ return null;
+ }
+
+
+ @Test
+ public void testDefaultMargin() {
+ final int DEFAULT_MARGIN = 10;
+
+ IFigure selectableBorderedNodeFigure = (IFigure) getDiagramEditPart().getFigure().getChildren().get(0);
+ IFigure linkSVGNodePlateFigure = (IFigure) selectableBorderedNodeFigure.getChildren().get(0);
+ ActivityFigure activityFigure = (ActivityFigure) linkSVGNodePlateFigure.getChildren().get(0);
+
+ IElementType type = UMLElementTypes.OpaqueAction_Shape;
+ int expectedGraphicalChildren = 0;
+ int expectedSemanticChildren = 0;
+ int addedGraphicalChildren = 1;
+ int addedSemanticChildren = 1;
+
+ createElement(type);
+ testToCreateANode(UMLElementTypes.OpaqueAction_Shape, 1, 1, 1, 1, false, null, 0);
+ testDestroy(type, expectedGraphicalChildren + 2 * addedGraphicalChildren, 2, 1, 1);
+ /*
+ * testToCreateANode(UMLElementTypes.OpaqueAction_Shape, 0, 0, 1, 1, false, null, 0);
+ * testToCreateANode(UMLElementTypes.OpaqueAction_Shape, 1, 1, 1, 1, false, null, 0);
+ * testDestroy(type, expectedGraphicalChildren+2*addedGraphicalChildren, 2, 1, 1);
+ * // destroy the second one
+ * testDestroy(type, expectedGraphicalChildren+addedGraphicalChildren, 1, 1, 1);
+ */
+ if ((activityFigure.getContentFigure().getChildren().size() > 0)) {
+
+ Dimension activityDim = activityFigure.getPreferredSize();
+ IFigure activityChild = (IFigure) activityFigure.getContentFigure().getChildren().get(0);
+ Dimension activityChildDim = activityChild.getPreferredSize();
+ activityDim = activityFigure.getPreferredSize();
+ Dimension nameLabel =activityFigure.getNameLabel().getPreferredSize();
+ Assert.assertEquals(DEFAULT_MARGIN, activityDim.width - activityChildDim.width);
+ Assert.assertEquals(DEFAULT_MARGIN, activityDim.height - activityChildDim.height-nameLabel.height);
+ }
+ }
+
+ @Test
+ public void testCustomMargin() {
+ final int margin = 70;
+
+ IFigure selectableBorderedNodeFigure = (IFigure) getDiagramEditPart().getFigure().getChildren().get(0);
+ IFigure linkSVGNodePlateFigure = (IFigure) selectableBorderedNodeFigure.getChildren().get(0);
+ ActivityFigure activityFigure = (ActivityFigure) linkSVGNodePlateFigure.getChildren().get(0);
+ activityFigure.setRightAndBottomMargin(margin);
+
+ testToCreateANode(UMLElementTypes.OpaqueAction_Shape, 0, 0, 1, 1, false, null, 0);
+
+ if ((activityFigure.getContentFigure().getChildren().size() > 0)) {
+
+ Dimension activityDim = activityFigure.getPreferredSize();
+ IFigure activityChild = (IFigure) activityFigure.getContentFigure().getChildren().get(0);
+ Dimension activityChildDim = activityChild.getPreferredSize();
+
+ Dimension nameLabel =activityFigure.getNameLabel().getPreferredSize();
+ Assert.assertEquals(margin, activityDim.width - activityChildDim.width);
+ Assert.assertEquals(margin, activityDim.height - activityChildDim.height-nameLabel.height);
+ }
+
+ }
+
+ protected void createElement(IElementType type) {
+
+ final CreateViewRequest requestcreation = CreateViewRequestFactory.getCreateShapeRequest(type, getContainerEditPart().getDiagramPreferencesHint());
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ command = getContainerEditPart().getCommand(requestcreation);
+ }
+ });
+ executeOnUIThread(command);
+ assertEquals(CREATION + INITIALIZATION_TEST, 1, getRootView().getChildren().size());
+
+
+ GraphicalEditPart containerEditPart = (GraphicalEditPart) getContainerEditPart().getChildren().get(0);
+ ChangeBoundsRequest changeBoundsRequest = new ChangeBoundsRequest(RequestConstants.REQ_ADD);
+ changeBoundsRequest.setEditParts(containerEditPart);
+ changeBoundsRequest.setLocation(new Point(100, 100));
+/*
+ ShapeCompartmentEditPart compartment = null;
+ int index = 0;
+ while (compartment == null && index < containerEditPart.getChildren().size()) {
+ if ((containerEditPart.getChildren().get(index)) instanceof ShapeCompartmentEditPart) {
+ compartment = (ShapeCompartmentEditPart) (containerEditPart.getChildren().get(index));
+ }
+ index++;
+ }
+ assertTrue("Container not found", compartment != null);
+
+
+ command = getContainerEditPart().getCommand(changeBoundsRequest);
+ assertNotNull(CHANGE_CONTAINER, command);
+ assertTrue(CHANGE_CONTAINER + TEST_IF_THE_COMMAND_IS_CREATED, command != UnexecutableCommand.INSTANCE);
+ assertTrue(CHANGE_CONTAINER + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute());
+
+ // execute change container
+ executeOnUIThread(command);
+*/
+ }
+}

Back to the top