summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2014-01-29 07:53:32 (EST)
committerJuergen Haug2014-02-02 11:39:32 (EST)
commit4ce072b06cd7d0d2d7aaae5b6f644a67b2a32084 (patch)
tree0c404185ecb9acb5668e852b9ea049d931ec76c9
parent3fa09676322bbfafb7404e1b128b2dc5cf4f2f6f (diff)
downloadorg.eclipse.etrice-4ce072b06cd7d0d2d7aaae5b6f644a67b2a32084.zip
org.eclipse.etrice-4ce072b06cd7d0d2d7aaae5b6f644a67b2a32084.tar.gz
org.eclipse.etrice-4ce072b06cd7d0d2d7aaae5b6f644a67b2a32084.tar.bz2
[ui.structure] Bug 417823, fixed user and initial position of ifitemrefs/changes/52/21252/2
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/InterfaceItemSupport.java147
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/DefaultPositionProvider.java11
2 files changed, 64 insertions, 94 deletions
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/InterfaceItemSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/InterfaceItemSupport.java
index 1459fdd..0212b27 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/InterfaceItemSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/InterfaceItemSupport.java
@@ -147,59 +147,17 @@ public class InterfaceItemSupport {
IPeCreateService peCreateService = Graphiti.getPeCreateService();
ContainerShape containerShape =
peCreateService.createContainerShape(acShape, true);
-
+
Graphiti.getPeService().setPropertyValue(containerShape, Constants.TYPE_KEY, Constants.PORT_TYPE);
String kind = getItemKind(port);
Graphiti.getPeService().setPropertyValue(containerShape, PROP_KIND, kind);
// the context point is the midpoint relative to the invisible rectangle
- int x = context.getX();
- int y = context.getY();
int width = acShape.getGraphicsAlgorithm().getWidth();
int height = acShape.getGraphicsAlgorithm().getHeight();
- if (internal) {
- if (x<2*margin)
- x = 2*margin;
- else if (x>width-2*margin)
- x = width-2*margin;
- if (y<2*margin)
- y = 2*margin;
- else if (y>height-2*margin)
- y = height-2*margin;
- }
- else {
- // TODOHRR: remove duplicate code
- int dx = (x<=width/2)? x:width-x;
- int dy = (y<=height/2)? y:height-y;
- if (dx>dy) {
- // keep x, project y
- if (y<=height/2)
- y = margin;
- else
- y = height-margin;
-
- if (x<margin)
- x = margin;
- else if (x>width-margin)
- x = width-margin;
- }
- else {
- // keep y, project x
- if (x<=width/2)
- x = margin;
- else
- x = width-margin;
-
- if (y<margin)
- y = margin;
- else if (y>height-margin)
- y = height-margin;
- }
- }
- // finally we subtract the midpoint to get coordinates of the upper left corner
- x -= margin;
- y -= margin;
+ int[] pos = layoutInterfaceItem(context.getX(), context.getY(), internal, margin, width, height);
+ int x = pos[0], y = pos[1];
Color dark = manageColor(inherited? INHERITED_COLOR:DARK_COLOR);
IGaService gaService = Graphiti.getGaService();
@@ -512,58 +470,17 @@ public class InterfaceItemSupport {
Shape shape = (Shape) context.getPictogramElement();
InterfaceItem item = (InterfaceItem) getBusinessObjectForPictogramElement(shape);
int margin = isRefItem(shape)?MARGIN_SMALL:MARGIN;
- int x = shape.getGraphicsAlgorithm().getX();
- int y = shape.getGraphicsAlgorithm().getY();
+ int midX = shape.getGraphicsAlgorithm().getX() + margin;
+ int midY = shape.getGraphicsAlgorithm().getY() + margin;
ContainerShape container = shape.getContainer();
int width = container.getGraphicsAlgorithm().getWidth();
int height = container.getGraphicsAlgorithm().getHeight();
- if (isInternal(item)) {
- if (x<2*margin)
- x = 2*margin;
- else if (x>width-2*margin)
- x = width-2*margin;
- if (y<2*margin)
- y = 2*margin;
- else if (y>height-2*margin)
- y = height-2*margin;
- }
- else {
- // TODOHRR: remove duplicate code
- int dx = (x<=width/2)? x:width-x;
- int dy = (y<=height/2)? y:height-y;
- if (dx>dy) {
- // keep x, project y
- if (y<=height/2)
- y = margin;
- else
- y = height-margin;
-
- if (x<margin)
- x = margin;
- else if (x>width-margin)
- x = width-margin;
- }
- else {
- // keep y, project x
- if (x<=width/2)
- x = margin;
- else
- x = width-margin;
-
- if (y<margin)
- y = margin;
- else if (y>height-margin)
- y = height-margin;
- }
- }
- // finally we subtract the midpoint to get coordinates of the upper left corner
- x -= margin;
- y -= margin;
+ int[] pos = layoutInterfaceItem(midX, midY, isInternal(item), margin, width, height);
+ int x = pos[0], y = pos[1];
Graphiti.getGaLayoutService().setLocation(shape.getGraphicsAlgorithm(), x, y);
-
return true;
}
@@ -674,6 +591,56 @@ public class InterfaceItemSupport {
return inStripe;
}
+ /**
+ * width, height from parent inv rectangle
+ */
+ protected static int[] layoutInterfaceItem(int midX, int midY, boolean internal, int margin, int width, int height){
+ int x = midX, y = midY;
+ if (internal) {
+ if (x<2*margin)
+ x = 2*margin;
+ else if (x>width-2*margin)
+ x = width-2*margin;
+ if (y<2*margin)
+ y = 2*margin;
+ else if (y>height-2*margin)
+ y = height-2*margin;
+ }
+ else {
+ int dx = (x<=width/2)? x:width-x;
+ int dy = (y<=height/2)? y:height-y;
+ if (dx>dy) {
+ // keep x, project y
+ if (y<=height/2)
+ y = margin;
+ else
+ y = height-margin;
+
+ if (x<margin)
+ x = margin;
+ else if (x>width-margin)
+ x = width-margin;
+ }
+ else {
+ // keep y, project x
+ if (x<=width/2)
+ x = margin;
+ else
+ x = width-margin;
+
+ if (y<margin)
+ y = margin;
+ else if (y>height-margin)
+ y = height-margin;
+ }
+ }
+ // finally we subtract the midpoint to get coordinates of the upper left corner
+ x -= margin;
+ y -= margin;
+
+ return new int[]{x,y};
+ }
+
@Override
public IMoveShapeFeature getMoveShapeFeature(IMoveShapeContext context) {
return new MoveShapeFeature(fp);
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/DefaultPositionProvider.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/DefaultPositionProvider.java
index b1f11a3..1b5eb26 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/DefaultPositionProvider.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/DefaultPositionProvider.java
@@ -25,6 +25,7 @@ import org.eclipse.etrice.core.room.ActorContainerClass;
import org.eclipse.etrice.core.room.ActorContainerRef;
import org.eclipse.etrice.core.room.ActorRef;
import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.Port;
import org.eclipse.etrice.core.room.RoomClass;
import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.core.room.SubSystemRef;
@@ -103,11 +104,13 @@ public class DefaultPositionProvider implements IPositionProvider {
for(EObject obj : toLayout){
if(obj instanceof ActorContainerRef)
refs.add((ActorContainerRef) obj);
- else if(obj instanceof InterfaceItem)
- if(obj.eContainer() == sc)
- intPorts.add((InterfaceItem) obj);
+ else if(obj instanceof InterfaceItem){
+ InterfaceItem item = (InterfaceItem)obj;
+ if(item instanceof Port && RoomHelpers.isInternal((Port)item))
+ intPorts.add(item);
else
- ifItems.add((InterfaceItem) obj);
+ ifItems.add(item);
+ }
}
layoutInterfaceItems(ifItems, width, height, -InterfaceItemSupport.MARGIN);