summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2013-04-30 05:29:08 (EDT)
committerJuergen Haug2013-05-05 16:47:08 (EDT)
commit61ee475b185ae90769e73d4628d8b7653f36fd34 (patch)
tree725224b7b30c3cc3f57545a199a3c9b4562e516b
parent9eab08530e398cf70bc9e3dccc3c6607fae7e5f1 (diff)
downloadorg.eclipse.etrice-61ee475b185ae90769e73d4628d8b7653f36fd34.zip
org.eclipse.etrice-61ee475b185ae90769e73d4628d8b7653f36fd34.tar.gz
org.eclipse.etrice-61ee475b185ae90769e73d4628d8b7653f36fd34.tar.bz2
[draft][ui.structure] new update behaviorrefs/changes/20/12520/1
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/room/util/RoomHelpers.java17
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java11
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ProviderDispatcher.java6
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/PopulateDiagramCommand.java118
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateDiagramCommand.java60
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/DiagramRefreshBehavior.java54
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java19
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java165
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/BindingSupport.java83
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DiagramUpdateFeature.java213
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DiagramUtil.java63
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/InterfaceItemSupport.java339
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/LayerConnectionSupport.java106
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SPPSupport.java2
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java256
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassUpdate.java192
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SupportUtil.java3
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/ConnectionUpdateContext.java32
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/DeleteContext.java25
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/InitialAddConnectionContext.java30
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/InitialAddShapeContext.java29
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/PositionUpdateContext.java33
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/CommonUpdateFeature.java113
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/ConnectionUpdateFeature.java80
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/ShapeUpdateFeature.java88
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/ConnectionProvider.java79
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/DecorationProvider.java (renamed from plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DecorationProvider.java)2
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/DefaultPositionProvider.java283
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/IPositionProvider.java74
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/SuperDiagramPositionProvider.java270
31 files changed, 2172 insertions, 675 deletions
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/room/util/RoomHelpers.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/room/util/RoomHelpers.java
index 7fb0360..96925f2 100644
--- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/room/util/RoomHelpers.java
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/room/util/RoomHelpers.java
@@ -1408,6 +1408,23 @@ public class RoomHelpers {
return result;
}
+ public static List<ActorContainerRef> getAllActorContainerRefs(StructureClass sc) {
+ List<ActorContainerRef> refs = new ArrayList<ActorContainerRef>();
+
+ if(sc instanceof LogicalSystem)
+ refs.addAll(((LogicalSystem)sc).getSubSystems());
+ else if(sc instanceof ActorContainerClass) {
+ refs.addAll(((ActorContainerClass)sc).getActorRefs());
+ if(sc instanceof ActorClass){
+ ActorClass base = (ActorClass)sc;
+ while((base = base.getBase()) != null)
+ refs.addAll(base.getActorRefs());
+ }
+ }
+
+ return refs;
+ }
+
/**
* Returns the parent {@link ActorClass} of a {@link StateGraphItem}.
*
diff --git a/plugins/org.eclipse.etrice.ui.structure/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.ui.structure/META-INF/MANIFEST.MF
index e9cba26..51e5836 100644
--- a/plugins/org.eclipse.etrice.ui.structure/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.ui.structure/META-INF/MANIFEST.MF
@@ -7,7 +7,6 @@ Bundle-Activator: org.eclipse.etrice.ui.structure.Activator
Bundle-Vendor: Eclipse eTrice (Incubation)
Require-Bundle: org.eclipse.etrice.core.room.ui;bundle-version="0.3.0",
org.eclipse.etrice.ui.common;bundle-version="0.3.0",
- org.eclipse.etrice.ui.behavior;bundle-version="0.3.0",
org.eclipse.graphiti;bundle-version="0.8.0",
org.eclipse.graphiti.ui;bundle-version="0.8.0",
org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.100",
@@ -23,3 +22,4 @@ Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.etrice.ui.structure,
org.eclipse.etrice.ui.structure.editor,
org.eclipse.etrice.ui.structure.support
+Import-Package: org.eclipse.etrice.ui.behavior
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java
index c1e2307..5e39a6b 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java
@@ -16,9 +16,7 @@ package org.eclipse.etrice.ui.structure;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.etrice.ui.common.DiagramAccessBase;
-import org.eclipse.etrice.ui.common.commands.UpdateCommand;
-import org.eclipse.etrice.ui.common.support.AutoUpdateFeature;
-import org.eclipse.etrice.ui.structure.commands.PopulateDiagramCommand;
+import org.eclipse.etrice.ui.structure.commands.UpdateDiagramCommand;
import org.eclipse.etrice.ui.structure.editor.StructureEditor;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IFeatureProvider;
@@ -46,7 +44,9 @@ public class DiagramAccess extends DiagramAccessBase {
}
protected Command getInitialCommand(StructureClass ac, Diagram diagram, TransactionalEditingDomain editingDomain) {
- return new PopulateDiagramCommand(diagram, ac, editingDomain);
+ IDiagramTypeProvider dtp = GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram, DiagramTypeProvider.PROVIDER_ID); //$NON-NLS-1$
+ IFeatureProvider featureProvider = dtp.getFeatureProvider();
+ return new UpdateDiagramCommand(ac, diagram, editingDomain, featureProvider);
}
/* (non-Javadoc)
@@ -56,7 +56,8 @@ public class DiagramAccess extends DiagramAccessBase {
protected Command getUpdateCommand(Diagram diagram, TransactionalEditingDomain editingDomain) {
IDiagramTypeProvider dtp = GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram, DiagramTypeProvider.PROVIDER_ID); //$NON-NLS-1$
IFeatureProvider featureProvider = dtp.getFeatureProvider();
- UpdateCommand cmd = new UpdateCommand(diagram, editingDomain, new AutoUpdateFeature(featureProvider));
+ StructureClass sc = (StructureClass) featureProvider.getBusinessObjectForPictogramElement(diagram);
+ UpdateDiagramCommand cmd = new UpdateDiagramCommand(sc, diagram, editingDomain, featureProvider);
if (cmd.updateNeeded())
return cmd;
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ProviderDispatcher.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ProviderDispatcher.java
index ad1e803..f488200 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ProviderDispatcher.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ProviderDispatcher.java
@@ -24,15 +24,15 @@ import org.eclipse.etrice.core.room.Port;
import org.eclipse.etrice.core.room.SPPRef;
import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.core.room.util.RoomSwitch;
-import org.eclipse.etrice.ui.common.support.AutoUpdateFeature;
import org.eclipse.etrice.ui.common.support.RemoveBendpointsFeature;
import org.eclipse.etrice.ui.structure.support.ActorContainerRefSupport;
import org.eclipse.etrice.ui.structure.support.BindingSupport;
-import org.eclipse.etrice.ui.structure.support.DecorationProvider;
+import org.eclipse.etrice.ui.structure.support.DiagramUpdateFeature;
import org.eclipse.etrice.ui.structure.support.LayerConnectionSupport;
import org.eclipse.etrice.ui.structure.support.PortSupport;
import org.eclipse.etrice.ui.structure.support.SPPSupport;
import org.eclipse.etrice.ui.structure.support.StructureClassSupport;
+import org.eclipse.etrice.ui.structure.support.provider.DecorationProvider;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.ICreateConnectionFeature;
@@ -266,7 +266,7 @@ public class ProviderDispatcher {
@Override
public IUpdateFeature getUpdateFeature(IUpdateContext context) {
if (context.getPictogramElement() instanceof Diagram)
- return new AutoUpdateFeature(this);
+ return new DiagramUpdateFeature(this);
IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
if (fp!=null)
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/PopulateDiagramCommand.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/PopulateDiagramCommand.java
deleted file mode 100644
index 0e80b87..0000000
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/PopulateDiagramCommand.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * 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:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.commands;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.ActorContainerClass;
-import org.eclipse.etrice.core.room.Binding;
-import org.eclipse.etrice.core.room.InterfaceItem;
-import org.eclipse.etrice.core.room.LayerConnection;
-import org.eclipse.etrice.core.room.LogicalSystem;
-import org.eclipse.etrice.core.room.StructureClass;
-import org.eclipse.etrice.core.room.SubSystemClass;
-import org.eclipse.etrice.ui.structure.DiagramTypeProvider;
-import org.eclipse.etrice.ui.structure.support.StructureClassSupport;
-import org.eclipse.etrice.ui.structure.support.SupportUtil;
-import org.eclipse.graphiti.dt.IDiagramTypeProvider;
-import org.eclipse.graphiti.features.IAddFeature;
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.context.impl.AddContext;
-import org.eclipse.graphiti.mm.pictograms.Anchor;
-import org.eclipse.graphiti.mm.pictograms.ContainerShape;
-import org.eclipse.graphiti.mm.pictograms.Diagram;
-import org.eclipse.graphiti.ui.services.GraphitiUi;
-
-public class PopulateDiagramCommand extends RecordingCommand {
-
- private StructureClass sc;
- private Diagram diagram;
-
- public PopulateDiagramCommand(Diagram diag, StructureClass sc, TransactionalEditingDomain domain) {
- super(domain);
- this.diagram = diag;
- this.sc = sc;
- }
-
- @Override
- protected void doExecute() {
- IDiagramTypeProvider dtp = GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram, DiagramTypeProvider.PROVIDER_ID); //$NON-NLS-1$
- IFeatureProvider featureProvider = dtp.getFeatureProvider();
-
- AddContext addContext = new AddContext();
- addContext.setNewObject(sc);
- addContext.setTargetContainer(diagram);
- addContext.setX(StructureClassSupport.MARGIN);
- addContext.setY(StructureClassSupport.MARGIN);
-
- HashMap<String, Anchor> ifitem2anchor = new HashMap<String, Anchor>();
-
- IAddFeature addFeature = featureProvider.getAddFeature(addContext);
- if (addFeature!=null && addFeature.canAdd(addContext)) {
- ContainerShape acShape = (ContainerShape) addFeature.add(addContext);
-
- int width = acShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getWidth();
-
- if (sc instanceof ActorClass) {
- List<InterfaceItem> items = new ArrayList<InterfaceItem>();
- items.addAll(((ActorClass) sc).getIfPorts());
- items.addAll(((ActorClass) sc).getIfSPPs());
- SupportUtil.addInterfaceItems(items, 0, acShape, width, featureProvider, ifitem2anchor);
-
- SupportUtil.addInterfaceItems(((ActorClass)sc).getIntPorts(), 3*StructureClassSupport.MARGIN, acShape, width, featureProvider, ifitem2anchor);
- }
- else if (sc instanceof SubSystemClass) {
- List<InterfaceItem> items = new ArrayList<InterfaceItem>();
- items.addAll(((SubSystemClass) sc).getRelayPorts());
- items.addAll(((SubSystemClass) sc).getIfSPPs());
- SupportUtil.addInterfaceItems(items, 0, acShape, width, featureProvider, ifitem2anchor);
- }
-
- // actor container references
- if (sc instanceof ActorContainerClass) {
- ActorContainerClass acc = (ActorContainerClass) sc;
- SupportUtil.addRefItems(acc.getActorRefs(), acShape, width, featureProvider, ifitem2anchor);
- }
- else if (sc instanceof LogicalSystem) {
- LogicalSystem sys = (LogicalSystem) sc;
- SupportUtil.addRefItems(sys.getSubSystems(), acShape, width, featureProvider, ifitem2anchor);
- }
-
- // base class items
- if (sc instanceof ActorClass) {
- ActorClass base = ((ActorClass) sc).getBase();
-
- // add inherited ports and refs and bindings (and preserve layout)
- if (base!=null)
- StructureClassSupport.addInheritedItems(base, acShape, ifitem2anchor, featureProvider);
- }
-
- // layer connections
- for (LayerConnection lc : sc.getConnections()) {
- SupportUtil.addLayerConnection(lc, featureProvider, ifitem2anchor);
- }
-
- // bindings
- for (Binding bind : sc.getBindings()) {
- SupportUtil.addBinding(bind, featureProvider, ifitem2anchor);
- }
- }
-
- }
-
-}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateDiagramCommand.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateDiagramCommand.java
new file mode 100644
index 0000000..1dd5f02
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateDiagramCommand.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.commands;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.ui.structure.support.DiagramUtil;
+import org.eclipse.etrice.ui.structure.support.context.PositionUpdateContext;
+import org.eclipse.etrice.ui.structure.support.provider.DefaultPositionProvider;
+import org.eclipse.etrice.ui.structure.support.provider.SuperDiagramPositionProvider;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.context.impl.UpdateContext;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+
+public class UpdateDiagramCommand extends RecordingCommand {
+
+ private Diagram diagram;
+ private IFeatureProvider featureProvider;
+ private StructureClass sc;
+
+ public UpdateDiagramCommand(StructureClass sc, Diagram diagram, TransactionalEditingDomain domain, IFeatureProvider featureProvider) {
+ super(domain);
+ this.sc = sc;
+ this.diagram = diagram;
+ this.featureProvider = featureProvider;
+ }
+
+ @Override
+ protected void doExecute() {
+ if(diagram.getLink() == null)
+ featureProvider.link(diagram, sc);
+
+ IUpdateContext context;
+ if(sc instanceof ActorClass && ((ActorClass)sc).getBase() != null)
+ context = new PositionUpdateContext(diagram, new SuperDiagramPositionProvider(sc));
+ else if(DiagramUtil.findScShape(diagram) == null)
+ context = new PositionUpdateContext(diagram, new DefaultPositionProvider(sc));
+ else
+ context = new UpdateContext(diagram);
+
+ featureProvider.updateIfPossible(context);
+ }
+
+ public boolean updateNeeded() {
+ return featureProvider.updateNeeded(new UpdateContext(diagram)).toBoolean();
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/DiagramRefreshBehavior.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/DiagramRefreshBehavior.java
new file mode 100644
index 0000000..66e582a
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/DiagramRefreshBehavior.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.editor;
+
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.ui.structure.support.context.PositionUpdateContext;
+import org.eclipse.etrice.ui.structure.support.provider.SuperDiagramPositionProvider;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.context.impl.UpdateContext;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.ui.editor.DefaultRefreshBehavior;
+
+public class DiagramRefreshBehavior extends DefaultRefreshBehavior {
+
+ public DiagramRefreshBehavior(StructureEditor diagramEditor) {
+ super(diagramEditor);
+ }
+
+ @Override
+ protected void handleAutoUpdateAtStartup() {
+ IDiagramTypeProvider diagramTypeProvider = diagramEditor.getDiagramTypeProvider();
+ if (diagramTypeProvider.isAutoUpdateAtStartup()) {
+ StructureEditor editor = (StructureEditor)diagramEditor;
+ StructureClass sc = editor.getStructureClass();
+ Diagram diagram = diagramTypeProvider.getDiagram();
+ if(sc instanceof ActorClass && ((ActorClass)sc).getBase() != null)
+ autoUpdate(new PositionUpdateContext(diagram, new SuperDiagramPositionProvider(sc)));
+ else
+ autoUpdate(new UpdateContext(diagram));
+
+ }
+ }
+
+ public void autoUpdate(IUpdateContext updateCtx) {
+ IDiagramTypeProvider diagramTypeProvider = diagramEditor.getDiagramTypeProvider();
+ IFeatureProvider featureProvider = diagramTypeProvider.getFeatureProvider();
+ featureProvider.updateIfPossible(updateCtx);
+ refresh();
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java
index 22d232f..10b4cc1 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java
@@ -16,8 +16,14 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.ui.common.editor.RoomDiagramEditor;
import org.eclipse.etrice.ui.structure.Activator;
+import org.eclipse.etrice.ui.structure.support.context.PositionUpdateContext;
+import org.eclipse.etrice.ui.structure.support.provider.SuperDiagramPositionProvider;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.ui.editor.DefaultRefreshBehavior;
import org.eclipse.swt.graphics.Image;
@@ -49,8 +55,17 @@ public class StructureEditor extends RoomDiagramEditor {
@Override
protected void superClassChanged() {
- // TODO Auto-generated method stub
-
+ IDiagramTypeProvider diagramTypeProvider = getDiagramTypeProvider();
+ Diagram diagram = diagramTypeProvider.getDiagram();
+ IFeatureProvider featureProvider = diagramTypeProvider.getFeatureProvider();
+ IUpdateContext updateCtx = new PositionUpdateContext(diagram, new SuperDiagramPositionProvider(getStructureClass()));
+ featureProvider.updateIfPossible(updateCtx);
+ refresh();
+ }
+
+ @Override
+ protected DefaultRefreshBehavior createRefreshBehavior() {
+ return new DiagramRefreshBehavior(this);
}
}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java
index b155dd2..7ceb6ce 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java
@@ -12,7 +12,10 @@
package org.eclipse.etrice.ui.structure.support;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.emf.common.util.EList;
@@ -38,6 +41,13 @@ import org.eclipse.etrice.ui.structure.DiagramAccess;
import org.eclipse.etrice.ui.structure.DiagramTypeProvider;
import org.eclipse.etrice.ui.structure.ImageProvider;
import org.eclipse.etrice.ui.structure.dialogs.ActorContainerRefPropertyDialog;
+import org.eclipse.etrice.ui.structure.support.context.InitialAddShapeContext;
+import org.eclipse.etrice.ui.structure.support.context.PositionUpdateContext;
+import org.eclipse.etrice.ui.structure.support.feature.ShapeUpdateFeature;
+import org.eclipse.etrice.ui.structure.support.provider.DefaultPositionProvider;
+import org.eclipse.etrice.ui.structure.support.provider.IPositionProvider;
+import org.eclipse.etrice.ui.structure.support.provider.SuperDiagramPositionProvider;
+import org.eclipse.etrice.ui.structure.support.provider.IPositionProvider.PosAndSize;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.ICreateConnectionFeature;
@@ -62,13 +72,11 @@ import org.eclipse.graphiti.features.context.IRemoveContext;
import org.eclipse.graphiti.features.context.IResizeShapeContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.context.impl.CreateConnectionContext;
-import org.eclipse.graphiti.features.context.impl.RemoveContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
import org.eclipse.graphiti.features.custom.ICustomFeature;
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
-import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
import org.eclipse.graphiti.features.impl.DefaultMoveShapeFeature;
import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature;
@@ -245,18 +253,15 @@ public class ActorContainerRefSupport {
context.getX()-(width/2+MARGIN), context.getY()-(height/2+MARGIN), width + 2*MARGIN, height + 2*MARGIN);
createRefFigure(ar, getDiagram(), containerShape, invisibleRectangle, lineColor, manageColor(BACKGROUND));
- }
+ }
- // create link and wire it
- link(containerShape, ar);
+ // create link and wire it
+ link(containerShape, ar);
- // other child shapes may follow
- if (inherited) {
- InterfaceItemSupport.createInheritedRefItems(ar, containerShape, fp);
- }
- else {
- InterfaceItemSupport.createRefItems(ar, containerShape, fp);
- }
+ // do not update in first place, because there are no positions
+ // therefore default positions for children interface items are needed -> expensive
+ if(!(context instanceof InitialAddShapeContext))
+ updatePictogramElement(containerShape);
// call the layout feature
layoutPictogramElement(containerShape);
@@ -524,27 +529,19 @@ public class ActorContainerRefSupport {
}
}
- private class UpdateFeature extends AbstractUpdateFeature {
+ private class UpdateFeature extends ShapeUpdateFeature {
public UpdateFeature(IFeatureProvider fp) {
super(fp);
}
@Override
- public boolean canUpdate(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy())
- return true;
-
+ protected boolean canUpdate(EObject bo, PictogramElement pe) {
return bo instanceof ActorContainerRef;
}
-
+
@Override
- public IReason updateNeeded(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- return Reason.createTrueReason("Ref deleted from model");
- }
+ protected IReason updateNeeded(EObject bo, IUpdateContext context) {
ActorContainerRef acr = (ActorContainerRef) bo;
ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
GraphicsAlgorithm invisibleRect = containerShape.getGraphicsAlgorithm();
@@ -568,9 +565,9 @@ public class ActorContainerRefSupport {
}
// check if ref still owned/inherited anymore
- bo = getBusinessObjectForPictogramElement(containerShape);
- if (bo instanceof ActorClass) {
- ActorClass ac = (ActorClass) bo;
+ Object containerBo = getBusinessObjectForPictogramElement(containerShape);
+ if (containerBo instanceof ActorClass) {
+ ActorClass ac = (ActorClass) containerBo;
boolean found = false;
do {
if (ac==acr.eContainer())
@@ -642,24 +639,15 @@ public class ActorContainerRefSupport {
}
@Override
- public boolean update(IUpdateContext context) {
- ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
- Object bo = getBusinessObjectForPictogramElement(containerShape);
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- IRemoveContext rc = new RemoveContext(containerShape);
- IFeatureProvider featureProvider = getFeatureProvider();
- IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
- if (removeFeature != null) {
- removeFeature.remove(rc);
- }
- EcoreUtil.delete((EObject) bo);
- return true;
- }
-
+ protected boolean update(EObject bo, IUpdateContext context) {
+ ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
GraphicsAlgorithm invisibleRect = containerShape.getGraphicsAlgorithm();
ActorContainerRef acr = (ActorContainerRef) bo;
int borderRectId = 0;
+ if(context instanceof PositionUpdateContext)
+ setPosition(acr, containerShape, (PositionUpdateContext) context);
+
// check replicated
if(acr instanceof ActorRef){
if(((ActorRef)acr).getSize()>1){
@@ -668,8 +656,7 @@ public class ActorContainerRefSupport {
IGaService gaService = Graphiti.getGaService();
int width = invisibleRect.getWidth()-2*MARGIN;
int height = invisibleRect.getHeight()-2*MARGIN;
- EObject parent = (EObject) getBusinessObjectForPictogramElement(containerShape.getContainer());
- Color lineColor = manageColor(isInherited(acr, parent)?INHERITED_COLOR:LINE_COLOR);
+ Color lineColor = manageColor(isInherited(acr, acr.eContainer())?INHERITED_COLOR:LINE_COLOR);
Rectangle replRect = gaService.createRectangle(invisibleRect);
replRect.setForeground(lineColor);
@@ -713,10 +700,46 @@ public class ActorContainerRefSupport {
updateLabel(acr, context.getPictogramElement());
- InterfaceItemSupport.createRefItems(acr, containerShape, fp);
+ GraphicsAlgorithm innerRect = containerShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(borderRectId);
+ IPositionProvider positionProvider = null;
+ if(context instanceof PositionUpdateContext){
+ positionProvider = ((PositionUpdateContext)context).getPositionProvider();
+ positionProvider = positionProvider.setNewParent(acr, DiagramUtil.getPosAndSize(invisibleRect), DiagramUtil.getPosAndSize(innerRect));
+ }
- return true;
+ Map<EObject, Shape> present = getChildrenShapesForBoClass(containerShape, RoomPackage.Literals.INTERFACE_ITEM);
+ ActorContainerClass acc = (acr instanceof ActorRef)?((ActorRef)acr).getType():((SubSystemRef)acr).getType();
+ List<InterfaceItem> expected = new ArrayList<InterfaceItem>(RoomHelpers.getInterfaceItems(acc, true));
+
+ expected.removeAll(present.keySet());
+ Map<EObject, Shape> newShapes = addShapesInitial(expected, containerShape);
+
+ if(positionProvider != null)
+ updatePictogramElements(newShapes.values(), positionProvider);
+ // handle new shapes without position
+ Map<EObject, Shape> withoutPosition = new HashMap<EObject, Shape>();
+ if(positionProvider != null){
+ for(EObject obj : newShapes.keySet())
+ if(!positionProvider.contains(obj))
+ withoutPosition.put(obj, newShapes.get(obj));
+ } else if(!newShapes.isEmpty())
+ withoutPosition.putAll(newShapes);
+
+ if(!withoutPosition.isEmpty()){
+ IPositionProvider defaultPP = new DefaultPositionProvider(acr);
+ defaultPP = defaultPP.setNewParent(acr, DiagramUtil.getPosAndSize(invisibleRect), DiagramUtil.getPosAndSize(innerRect));
+ updatePictogramElements(newShapes.values(), defaultPP);
+ }
+
+ // only update positions if inherited
+ if(positionProvider instanceof SuperDiagramPositionProvider)
+ updatePictogramElements(present.values(), positionProvider);
+ else
+ updatePictogramElements(present.values());
+
+ return true;
}
+
}
private class RemoveFeature extends DefaultRemoveFeature {
@@ -816,26 +839,48 @@ public class ActorContainerRefSupport {
@Override
public void resizeShape(IResizeShapeContext context) {
- Shape shape = context.getShape();
+ ContainerShape containerShape = (ContainerShape) context.getShape();
+ GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm();
+ Object bo = getBusinessObjectForPictogramElement(containerShape);
- if (shape.getGraphicsAlgorithm()!=null) {
- GraphicsAlgorithm containerGa = shape.getGraphicsAlgorithm();
- double sx = (context.getWidth()-2*MARGIN)/(double)(containerGa.getWidth()-2*MARGIN);
- double sy = (context.getHeight()-2*MARGIN)/(double)(containerGa.getHeight()-2*MARGIN);
-
- GraphicsAlgorithm ga;
- for (Shape childShape : ((ContainerShape)context.getShape()).getChildren()) {
- Object childBo = getBusinessObjectForPictogramElement(childShape);
- if (childBo instanceof InterfaceItem) {
- ga = childShape.getGraphicsAlgorithm();
- ga.setX((int) (ga.getX()*sx));
- ga.setY((int) (ga.getY()*sy));
- }
+ if(bo instanceof ActorRef && ((ActorRef)bo).getSize() > 1)
+ resizeChildrenInterfaceItems(context, containerGa.getGraphicsAlgorithmChildren().get(1));
+ else
+ resizeChildrenInterfaceItems(context, containerGa.getGraphicsAlgorithmChildren().get(0));
+
+ super.resizeShape(context);
+ }
+
+ private void resizeChildrenInterfaceItems(IResizeShapeContext context, GraphicsAlgorithm innerRect){
+ PosAndSize innerRectPos = DiagramUtil.getPosAndSize(innerRect);
+
+ double sx = (double)(context.getWidth() - 2*innerRectPos.getX()) / innerRectPos.getW();
+ double sy = (double)(context.getHeight() - 2*innerRectPos.getY()) / innerRectPos.getH();
+
+ for (Shape childShape : ((ContainerShape)context.getPictogramElement()).getChildren()) {
+ Object childBo = getBusinessObjectForPictogramElement(childShape);
+ if (childBo instanceof InterfaceItem) {
+ GraphicsAlgorithm childGa = childShape.getGraphicsAlgorithm();
+ PosAndSize childPos = DiagramUtil.getPosAndSize(childGa);
+ // calc mid point & align to inner rect
+ int midX = childPos.getX() + childPos.getW()/2 - innerRectPos.getX();
+ int midY = childPos.getY() + childPos.getH()/2 - innerRectPos.getY();
+ // scale
+ midX = (int) (sx*midX);
+ midY = (int) (sy*midY);
+ // first step reverse
+ midX = midX - childPos.getW()/2 + innerRectPos.getX();
+ midY = midY - childPos.getH()/2 + innerRectPos.getY();
+
+ Graphiti.getGaService().setLocation(childGa, midX, midY);
+ updatePictogramElement(childShape);
}
+
}
- super.resizeShape(context);
+
}
+
}
private IFeatureProvider fp;
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/BindingSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/BindingSupport.java
index 96d4d52..6f890e0 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/BindingSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/BindingSupport.java
@@ -13,7 +13,6 @@
package org.eclipse.etrice.ui.structure.support;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.etrice.core.naming.RoomNameProvider;
import org.eclipse.etrice.core.room.ActorContainerClass;
import org.eclipse.etrice.core.room.ActorContainerRef;
@@ -28,12 +27,16 @@ import org.eclipse.etrice.core.validation.ValidationUtil;
import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
import org.eclipse.etrice.ui.structure.ImageProvider;
import org.eclipse.etrice.ui.structure.dialogs.SubProtocolSelectionDialog;
+import org.eclipse.etrice.ui.structure.support.context.ConnectionUpdateContext;
+import org.eclipse.etrice.ui.structure.support.context.InitialAddConnectionContext;
+import org.eclipse.etrice.ui.structure.support.feature.ConnectionUpdateFeature;
+import org.eclipse.etrice.ui.structure.support.provider.ConnectionProvider;
+import org.eclipse.etrice.ui.structure.support.provider.DecorationProvider;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.ICreateConnectionFeature;
import org.eclipse.graphiti.features.IDeleteFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.IReason;
import org.eclipse.graphiti.features.IReconnectionFeature;
import org.eclipse.graphiti.features.IRemoveFeature;
import org.eclipse.graphiti.features.IUpdateFeature;
@@ -48,15 +51,12 @@ import org.eclipse.graphiti.features.context.IRemoveContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.features.context.impl.ReconnectionContext;
-import org.eclipse.graphiti.features.context.impl.RemoveContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
import org.eclipse.graphiti.features.custom.ICustomFeature;
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature;
-import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
import org.eclipse.graphiti.features.impl.DefaultReconnectionFeature;
import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
-import org.eclipse.graphiti.features.impl.Reason;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
import org.eclipse.graphiti.mm.algorithms.Polyline;
import org.eclipse.graphiti.mm.pictograms.Anchor;
@@ -253,15 +253,14 @@ public class BindingSupport {
@Override
public boolean canAdd(IAddContext context) {
- if (context instanceof IAddConnectionContext && context.getNewObject() instanceof Binding) {
+ if(context.getNewObject() instanceof Binding)
return true;
- }
+
return false;
}
@Override
public PictogramElement add(IAddContext context) {
- IAddConnectionContext addConContext = (IAddConnectionContext) context;
Binding bind = (Binding) context.getNewObject();
boolean inherited = isInherited(getDiagram(), bind);
@@ -269,9 +268,18 @@ public class BindingSupport {
IPeCreateService peCreateService = Graphiti.getPeCreateService();
// CONNECTION WITH POLYLINE
Connection connection = peCreateService.createFreeFormConnection(getDiagram());
- connection.setStart(addConContext.getSourceAnchor());
- connection.setEnd(addConContext.getTargetAnchor());
-
+ if(context instanceof InitialAddConnectionContext){
+ ConnectionProvider cp = ((InitialAddConnectionContext)context).getConnectionProvider();
+ Anchor a1 = cp.getAnchor(bind.getEndpoint1());
+ Anchor a2 = cp.getAnchor(bind.getEndpoint2());
+ assert(a1 != null && a2 != null) : "start and end anchor must be present";
+ connection.setStart(a1);
+ connection.setEnd(a2);
+ } else {
+ IAddConnectionContext addConContext = (IAddConnectionContext) context;
+ connection.setStart(addConContext.getSourceAnchor());
+ connection.setEnd(addConContext.getTargetAnchor());
+ }
Graphiti.getPeService().setPropertyValue(connection, Constants.TYPE_KEY, Constants.BIND_TYPE);
IGaService gaService = Graphiti.getGaService();
@@ -280,6 +288,9 @@ public class BindingSupport {
// create link and wire it
link(connection, bind);
+
+ // call update
+ updatePictogramElement(connection);
return connection;
}
@@ -376,45 +387,35 @@ public class BindingSupport {
}
}
- private class UpdateFeature extends AbstractUpdateFeature {
+ private class UpdateFeature extends ConnectionUpdateFeature {
public UpdateFeature(IFeatureProvider fp) {
super(fp);
}
@Override
- public boolean canUpdate(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy())
- return true;
-
- return false;
+ protected boolean canUpdate(EObject bo, PictogramElement pe) {
+ return bo instanceof Binding;
}
-
- @Override
- public IReason updateNeeded(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- return Reason.createTrueReason("Binding deleted from model");
- }
- return Reason.createFalseReason();
- }
-
+
@Override
- public boolean update(IUpdateContext context) {
- PictogramElement pe = context.getPictogramElement();
- Object bo = getBusinessObjectForPictogramElement(pe);
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- IRemoveContext rc = new RemoveContext(pe);
- IFeatureProvider featureProvider = getFeatureProvider();
- IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
- if (removeFeature != null) {
- removeFeature.remove(rc);
- }
- EcoreUtil.delete((EObject) bo);
- return true;
+ protected boolean update(EObject bo, IUpdateContext context) {
+ boolean success = super.update(bo, context);
+
+ Connection conn = (Connection) context.getPictogramElement();
+ if(context instanceof ConnectionUpdateContext){
+ ConnectionProvider cp = ((ConnectionUpdateContext) context).getConnectionProvider();
+ Binding bind = (Binding)bo;
+ Anchor newStart = cp.getAnchor(bind.getEndpoint1());
+ Anchor newEnd = cp.getAnchor(bind.getEndpoint2());
+ assert(newStart != null && newEnd != null) : "start and end anchor must be not null";
+ if(newStart != conn.getStart())
+ conn.setStart(newEnd);
+ if(newEnd != conn.getEnd())
+ conn.setEnd(newEnd);
}
- return false;
+
+ return success;
}
}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DiagramUpdateFeature.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DiagramUpdateFeature.java
new file mode 100644
index 0000000..4a3dc4f
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DiagramUpdateFeature.java
@@ -0,0 +1,213 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support;
+
+import java.util.ArrayList;
+
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.ui.structure.support.context.DeleteContext;
+import org.eclipse.etrice.ui.structure.support.context.PositionUpdateContext;
+import org.eclipse.etrice.ui.structure.support.provider.IPositionProvider;
+import org.eclipse.etrice.ui.structure.support.provider.IPositionProvider.PosAndSize;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.IReason;
+import org.eclipse.graphiti.features.IUpdateFeature;
+import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.context.impl.AddContext;
+import org.eclipse.graphiti.features.context.impl.UpdateContext;
+import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
+import org.eclipse.graphiti.features.impl.Reason;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+
+public class DiagramUpdateFeature extends AbstractUpdateFeature {
+
+ public DiagramUpdateFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canUpdate(IUpdateContext context) {
+ return true;
+ }
+
+ @Override
+ public IReason updateNeeded(IUpdateContext context) {
+ StructureClass sc = (StructureClass) getBusinessObjectForPictogramElement(getDiagram());
+
+ if(sc instanceof ActorClass && ((ActorClass)sc).getBase() != null)
+ return new Reason(true);
+ if(updateConnectionsNeeded(getDiagram()))
+ return new Reason(true);
+ if(updateNeeded(getDiagram()))
+ return new Reason(true);
+
+ return new Reason(false);
+ }
+
+ /**
+ * This just removes dangling connections (bindings and layer connections).
+ * New ones are added by the structure class support.
+ *
+ * @param diagram
+ * @return
+ */
+ private boolean updateConnectionsNeeded(Diagram diagram) {
+ boolean needed = false;
+
+ for (Connection conn : new ArrayList<Connection>(diagram.getConnections())) {
+ UpdateContext context = new UpdateContext(conn);
+ IUpdateFeature updateFeature = getFeatureProvider().getUpdateFeature(context);
+ if (updateFeature!=null && updateFeature.canUpdate(context))
+ if (updateFeature.updateNeeded(context).toBoolean())
+ needed = true;
+ }
+ return needed;
+ }
+
+ /**
+ * @param diagram
+ * @return
+ */
+ private boolean updateNeeded(ContainerShape container) {
+ boolean needed = false;
+
+ for (Shape child : new ArrayList<Shape>(container.getChildren())) {
+ if (child instanceof ContainerShape)
+ if (updateNeeded((ContainerShape) child))
+ needed = true;
+ }
+
+ // avoid infinite recursion by not entering with diagram again
+ if (!(container instanceof Diagram)) {
+ UpdateContext context = new UpdateContext(container);
+ IUpdateFeature updateFeature = getFeatureProvider().getUpdateFeature(context);
+ if (updateFeature!=null && updateFeature.canUpdate(context))
+ if (updateFeature.updateNeeded(context).toBoolean())
+ needed = true;
+ }
+
+ return needed;
+ }
+
+ @Override
+ public boolean update(IUpdateContext context) {
+ StructureClass sc = (StructureClass) getBusinessObjectForPictogramElement(getDiagram());
+ ContainerShape scShape = DiagramUtil.findScShape(getDiagram());
+ IPositionProvider positionProvider = null;
+ if(context instanceof PositionUpdateContext)
+ positionProvider = ((PositionUpdateContext) context).getPositionProvider();
+
+ if(scShape == null)
+ scShape = createStructureClass(sc, positionProvider);
+
+ boolean doneChanges = updateConnections(getDiagram());
+
+ if (updateIfNeeded(getDiagram()))
+ doneChanges = true;
+
+ // structure class update
+ if(scShape != null){
+ IUpdateContext ctx;
+ if(positionProvider != null)
+ ctx = new PositionUpdateContext(scShape, positionProvider);
+ else
+ ctx = new UpdateContext(scShape);
+
+ doneChanges |= getFeatureProvider().updateIfPossible(ctx).toBoolean();
+ }
+
+ return doneChanges;
+ }
+
+ /**
+ * This just removes dangling connections (bindings and layer connections).
+ * New ones are added by the structure class support.
+ *
+ * @param diagram
+ * @return
+ */
+ private boolean updateConnections(Diagram diagram) {
+ boolean doneChanges = false;
+
+ ArrayList<Connection> connections = new ArrayList<Connection>(diagram.getConnections());
+ for (Connection conn : connections) {
+ UpdateContext context = new DeleteContext(conn);
+ IUpdateFeature updateFeature = getFeatureProvider().getUpdateFeature(context);
+ if (updateFeature!=null && updateFeature.canUpdate(context))
+ if (updateFeature.updateNeeded(context).toBoolean())
+ if (updateFeature.update(context))
+ doneChanges = true;
+ }
+ return doneChanges;
+ }
+
+ /**
+ * @param diagram
+ * @return
+ */
+ private boolean updateIfNeeded(ContainerShape container) {
+ boolean doneChanges = false;
+
+ // first recursion because ref ports might be needed for bindings
+ // we need to make a copy since children might be removed
+ ArrayList<Shape> children = new ArrayList<Shape>(container.getChildren());
+ for (Shape child : children) {
+ if (child instanceof ContainerShape)
+ if (updateIfNeeded((ContainerShape) child))
+ doneChanges = true;
+ }
+
+ // avoid infinite recursion by not entering with diagram again
+ if (!(container instanceof Diagram)) {
+ UpdateContext context = new DeleteContext(container);
+ IUpdateFeature updateFeature = getFeatureProvider().getUpdateFeature(context);
+ if (updateFeature!=null && updateFeature.canUpdate(context))
+ if (updateFeature.updateNeeded(context).toBoolean())
+ if (updateFeature.update(context))
+ doneChanges = true;
+ }
+
+ return doneChanges;
+ }
+
+ private ContainerShape createStructureClass(StructureClass sc, IPositionProvider positionProvider){
+ AddContext addContext = new AddContext();
+ addContext.setNewObject(sc);
+ addContext.setTargetContainer(getDiagram());
+ addContext.setX(StructureClassSupport.MARGIN);
+ addContext.setY(StructureClassSupport.MARGIN);
+
+ ContainerShape scShape = (ContainerShape) getFeatureProvider().addIfPossible(addContext);
+
+ if(positionProvider != null){
+ PosAndSize pos = positionProvider.getDiagramPosition();
+ GraphicsAlgorithm ga = scShape.getGraphicsAlgorithm();
+ if(pos != null){
+ ga.setX(pos.getX());
+ ga.setY(pos.getY());
+ if(pos.getW() > 0)
+ ga.setWidth(pos.getW());
+ if(pos.getH() > 0)
+ ga.setHeight(pos.getH());
+ }
+ }
+
+ return scShape;
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DiagramUtil.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DiagramUtil.java
new file mode 100644
index 0000000..f89145b
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DiagramUtil.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.ActorContainerRef;
+import org.eclipse.etrice.core.room.Binding;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.LayerConnection;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.ui.structure.support.provider.IPositionProvider.PosAndSize;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.ILinkService;
+
+public class DiagramUtil {
+
+ public static boolean isSupported(Object obj){
+ return obj instanceof StructureClass
+ || obj instanceof ActorContainerRef
+ || obj instanceof InterfaceItem
+ || obj instanceof Binding
+ || obj instanceof LayerConnection;
+ }
+
+ public static boolean isConnection(EObject bo){
+ return bo instanceof Binding
+ || bo instanceof LayerConnection;
+ }
+
+ public static String getResourcePath(EObject bo){
+ assert(isSupported(bo)) : "unexpected type";
+ return bo.eResource().getURI().toString()+bo.eResource().getURIFragment(bo);
+ }
+
+ public static ContainerShape findScShape(Diagram diagram){
+ ILinkService linkService = Graphiti.getLinkService();
+ for(Shape child : diagram.getChildren()){
+ Object bo = linkService.getBusinessObjectForLinkedPictogramElement(child);
+ if(bo instanceof StructureClass)
+ return (ContainerShape) child;
+ }
+
+ return null;
+ }
+
+ public static PosAndSize getPosAndSize(GraphicsAlgorithm ga){
+ return new PosAndSize(ga.getX(), ga.getY(), ga.getWidth(), ga.getHeight());
+ }
+}
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 e1a2f54..a81e444 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
@@ -12,11 +12,7 @@
package org.eclipse.etrice.ui.structure.support;
-import java.util.List;
-
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.ActorContainerClass;
import org.eclipse.etrice.core.room.ActorContainerRef;
@@ -28,10 +24,12 @@ import org.eclipse.etrice.core.room.SubSystemRef;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
import org.eclipse.etrice.ui.common.support.NoResizeFeature;
-import org.eclipse.etrice.ui.structure.DiagramAccess;
+import org.eclipse.etrice.ui.structure.support.context.PositionUpdateContext;
+import org.eclipse.etrice.ui.structure.support.feature.ShapeUpdateFeature;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IDeleteFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.ILayoutFeature;
import org.eclipse.graphiti.features.IMoveShapeFeature;
import org.eclipse.graphiti.features.IReason;
import org.eclipse.graphiti.features.IRemoveFeature;
@@ -40,17 +38,17 @@ import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.context.ICreateContext;
import org.eclipse.graphiti.features.context.ICustomContext;
import org.eclipse.graphiti.features.context.IDeleteContext;
+import org.eclipse.graphiti.features.context.ILayoutContext;
import org.eclipse.graphiti.features.context.ILocationContext;
import org.eclipse.graphiti.features.context.IMoveShapeContext;
import org.eclipse.graphiti.features.context.IRemoveContext;
import org.eclipse.graphiti.features.context.IResizeShapeContext;
import org.eclipse.graphiti.features.context.ITargetContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
-import org.eclipse.graphiti.features.context.impl.RemoveContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
-import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
+import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
import org.eclipse.graphiti.features.impl.DefaultMoveShapeFeature;
import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
import org.eclipse.graphiti.features.impl.Reason;
@@ -60,7 +58,6 @@ import org.eclipse.graphiti.mm.algorithms.Text;
import org.eclipse.graphiti.mm.algorithms.styles.Color;
import org.eclipse.graphiti.mm.algorithms.styles.Orientation;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
-import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
@@ -240,9 +237,12 @@ public class InterfaceItemSupport {
adjustLabel(label, x, y, width, margin, size);
}
+ // call update
+ updatePictogramElement(containerShape);
+
// call the layout feature
layoutPictogramElement(containerShape);
-
+
return containerShape;
}
@@ -357,36 +357,28 @@ public class InterfaceItemSupport {
}
}
- protected abstract class UpdateFeature extends AbstractUpdateFeature {
+ protected abstract class UpdateFeature extends ShapeUpdateFeature {
public UpdateFeature(IFeatureProvider fp) {
super(fp);
}
@Override
- public boolean canUpdate(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy())
- return true;
-
+ protected boolean canUpdate(EObject bo, PictogramElement pe) {
return bo instanceof InterfaceItem;
}
@Override
- public IReason updateNeeded(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- return Reason.createTrueReason("InterfaceItem deleted from model");
- }
+ protected IReason updateNeeded(EObject bo, IUpdateContext context) {
InterfaceItem port = (InterfaceItem) bo;
String reason = "";
// check if port still owned/inherited
ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
- bo = getBusinessObjectForPictogramElement(containerShape);
- if (bo instanceof ActorClass) {
- ActorClass ac = (ActorClass) bo;
+ Object containerBo = getBusinessObjectForPictogramElement(containerShape);
+ if (containerBo instanceof ActorClass) {
+ ActorClass ac = (ActorClass) containerBo;
boolean found = false;
do {
if (ac==port.eContainer())
@@ -415,28 +407,22 @@ public class InterfaceItemSupport {
return Reason.createFalseReason();
}
+
@Override
- public boolean update(IUpdateContext context) {
+ protected boolean update(EObject bo, IUpdateContext context) {
ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
- Object bo = getBusinessObjectForPictogramElement(containerShape);
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- IRemoveContext rc = new RemoveContext(containerShape);
- IFeatureProvider featureProvider = getFeatureProvider();
- IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
- if (removeFeature != null) {
- removeFeature.remove(rc);
- }
- EcoreUtil.delete((EObject) bo);
- return true;
- }
InterfaceItem port = (InterfaceItem) bo;
- boolean inherited = isInherited(port, bo, containerShape);
+ boolean inherited = isInherited(port, getBusinessObjectForPictogramElement(containerShape.getContainer()), containerShape);
Color dark = manageColor(inherited? INHERITED_COLOR:DARK_COLOR);
updateFigure(port, containerShape, dark, manageColor(BRIGHT_COLOR));
String kind = getItemKind(port);
Graphiti.getPeService().setPropertyValue(containerShape, PROP_KIND, kind);
+
+ if(context instanceof PositionUpdateContext)
+ setPosition(port, containerShape, (PositionUpdateContext) context);
+
return true;
}
@@ -514,6 +500,80 @@ public class InterfaceItemSupport {
}
}
+ protected static class LayoutFeature extends AbstractLayoutFeature{
+
+ public LayoutFeature(IFeatureProvider fp) {
+ super(fp);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public boolean canLayout(ILayoutContext context) {
+ return true;
+ }
+
+ @Override
+ public boolean layout(ILayoutContext context) {
+ 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();
+
+ 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;
+
+ Graphiti.getGaLayoutService().setLocation(shape.getGraphicsAlgorithm(), x, y);
+
+
+ return true;
+ }
+
+ }
+
protected IFeatureProvider fp;
protected FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
@@ -639,6 +699,11 @@ public class InterfaceItemSupport {
return new DeleteFeature(fp);
}
+ @Override
+ public ILayoutFeature getLayoutFeature(ILayoutContext context) {
+ return new LayoutFeature(fp);
+ }
+
protected static void adjustLabel(Text label, int x, int y, int width, int margin, int size) {
Orientation align = Orientation.ALIGNMENT_CENTER;
label.setHorizontalAlignment(align);
@@ -712,105 +777,105 @@ public class InterfaceItemSupport {
}
}
- public static void createRefItems(ActorContainerRef acr, ContainerShape refShape, IFeatureProvider featureProvider) {
-
- ActorContainerClass refClass = (acr instanceof ActorRef)?((ActorRef)acr).getType():((SubSystemRef)acr).getType();
- List<InterfaceItem> refItems = RoomHelpers.getInterfaceItems(refClass, true);
-
- if (refShape!=null && refClass!=null &&!refItems.isEmpty()) {
-
- // the diagram will be created and initialized if not present
- // TODOHRR: how to proceed if diagram not up to date?
- Diagram refDiag = new DiagramAccess().getDiagram(refClass);
-
- ResourceSet rs = acr.eResource().getResourceSet();
-
- if (!refDiag.getChildren().isEmpty()) {
- ContainerShape refAcShape = (ContainerShape) refDiag.getChildren().get(0);
- Object bo = featureProvider.getBusinessObjectForPictogramElement(refAcShape);
- if (bo instanceof ActorContainerClass) {
- ActorContainerClass extRefClass = (ActorContainerClass) bo;
- assert(extRefClass.getName().equals(refClass.getName())): "structure class names must match";
-
- List<InterfaceItem> extRefItems = RoomHelpers.getInterfaceItems(extRefClass, true);
- List<InterfaceItem> intRefItems = SupportUtil.getInterfaceItems(refShape, featureProvider);
-
- // relate visible rectangle sizes to each other and compute scale factors
- double scaleX = (refAcShape.getGraphicsAlgorithm().getWidth()-2*StructureClassSupport.MARGIN)
- /(double)(refShape.getGraphicsAlgorithm().getWidth()-2*ActorContainerRefSupport.MARGIN);
- double scaleY = (refAcShape.getGraphicsAlgorithm().getHeight()-2*StructureClassSupport.MARGIN)
- /(double)(refShape.getGraphicsAlgorithm().getHeight()-2*ActorContainerRefSupport.MARGIN);
-
- for (Shape childShape : refAcShape.getChildren()) {
- bo = featureProvider.getBusinessObjectForPictogramElement(childShape);
- if (bo instanceof InterfaceItem) {
- if (extRefItems.contains(bo)) {
- // this is an interface item, insert it
-
- EObject ownObject = SupportUtil.getOwnObject((InterfaceItem)bo, rs);
- if (!intRefItems.contains(ownObject)) {
- // original mid points relative to visible rectangle
- int origMidX = childShape.getGraphicsAlgorithm().getX();
- int origMidY = childShape.getGraphicsAlgorithm().getY();
- int x = (int) (origMidX/scaleX);
- int y = (int) (origMidY/scaleY);
-
- // translate to get mid points relative to invisible rectangle
- x += ActorContainerRefSupport.MARGIN;
- y += ActorContainerRefSupport.MARGIN;
-
- SupportUtil.addItem(ownObject, x, y, refShape, featureProvider);
- }
- }
- }
- }
- }
- }
- else {
- assert(false): "empty referenced structure class diagram";
- }
- }
- }
-
- protected static void createInheritedRefItems(ActorContainerRef acr, ContainerShape arShape, IFeatureProvider fp) {
-
- ActorClass ac = (ActorClass) acr.eContainer();
- ResourceSet rs = ac.eResource().getResourceSet();
- List<InterfaceItem> presentObjects = SupportUtil.getInterfaceItems(arShape, fp);
-
- Diagram refDiag = new DiagramAccess().getDiagram(ac);
- if (!refDiag.getChildren().isEmpty()) {
- ContainerShape refAcShape = (ContainerShape) refDiag.getChildren().get(0);
- Object bo = fp.getBusinessObjectForPictogramElement(refAcShape);
- if (bo instanceof ActorClass) {
- ActorClass extRefClass = (ActorClass) bo;
- assert(extRefClass.getName().equals(ac.getName())): "actor class names must match";
-
- for (Shape childShape : refAcShape.getChildren()) {
- bo = fp.getBusinessObjectForPictogramElement(childShape);
- if (bo instanceof ActorRef) {
- EObject ownObject = SupportUtil.getOwnObject((ActorRef)bo, rs);
- if (ownObject==acr) {
- int subScaleX = arShape.getGraphicsAlgorithm().getWidth()/ActorContainerRefSupport.DEFAULT_SIZE_X;
- int subScaleY = arShape.getGraphicsAlgorithm().getHeight()/ActorContainerRefSupport.DEFAULT_SIZE_Y;
-
- // add items of actor ref
- for (Shape grandChildShape : ((ContainerShape)childShape).getChildren()) {
- bo = fp.getBusinessObjectForPictogramElement(grandChildShape);
- if (bo instanceof InterfaceItem) {
- ownObject = SupportUtil.getOwnObject((Port)bo, rs);
- if (!presentObjects.contains(ownObject)) {
- int x = ITEM_SIZE_SMALL/2 + grandChildShape.getGraphicsAlgorithm().getX()/subScaleX;
- int y = ITEM_SIZE_SMALL/2 + grandChildShape.getGraphicsAlgorithm().getY()/subScaleY;
- SupportUtil.addItem(ownObject, x, y, arShape, fp);
- }
- }
- }
- break;
- }
- }
- }
- }
- }
- }
+// public static void createRefItems(ActorContainerRef acr, ContainerShape refShape, IFeatureProvider featureProvider) {
+//
+// ActorContainerClass refClass = (acr instanceof ActorRef)?((ActorRef)acr).getType():((SubSystemRef)acr).getType();
+// List<InterfaceItem> refItems = RoomHelpers.getInterfaceItems(refClass, true);
+//
+// if (refShape!=null && refClass!=null &&!refItems.isEmpty()) {
+//
+// // the diagram will be created and initialized if not present
+// // TODOHRR: how to proceed if diagram not up to date?
+// Diagram refDiag = new DiagramAccess().getDiagram(refClass);
+//
+// ResourceSet rs = acr.eResource().getResourceSet();
+//
+// if (!refDiag.getChildren().isEmpty()) {
+// ContainerShape refAcShape = (ContainerShape) refDiag.getChildren().get(0);
+// Object bo = featureProvider.getBusinessObjectForPictogramElement(refAcShape);
+// if (bo instanceof ActorContainerClass) {
+// ActorContainerClass extRefClass = (ActorContainerClass) bo;
+// assert(extRefClass.getName().equals(refClass.getName())): "structure class names must match";
+//
+// List<InterfaceItem> extRefItems = RoomHelpers.getInterfaceItems(extRefClass, true);
+// List<InterfaceItem> intRefItems = SupportUtil.getInterfaceItems(refShape, featureProvider);
+//
+// // relate visible rectangle sizes to each other and compute scale factors
+// double scaleX = (refAcShape.getGraphicsAlgorithm().getWidth()-2*StructureClassSupport.MARGIN)
+// /(double)(refShape.getGraphicsAlgorithm().getWidth()-2*ActorContainerRefSupport.MARGIN);
+// double scaleY = (refAcShape.getGraphicsAlgorithm().getHeight()-2*StructureClassSupport.MARGIN)
+// /(double)(refShape.getGraphicsAlgorithm().getHeight()-2*ActorContainerRefSupport.MARGIN);
+//
+// for (Shape childShape : refAcShape.getChildren()) {
+// bo = featureProvider.getBusinessObjectForPictogramElement(childShape);
+// if (bo instanceof InterfaceItem) {
+// if (extRefItems.contains(bo)) {
+// // this is an interface item, insert it
+//
+// EObject ownObject = SupportUtil.getOwnObject((InterfaceItem)bo, rs);
+// if (!intRefItems.contains(ownObject)) {
+// // original mid points relative to visible rectangle
+// int origMidX = childShape.getGraphicsAlgorithm().getX();
+// int origMidY = childShape.getGraphicsAlgorithm().getY();
+// int x = (int) (origMidX/scaleX);
+// int y = (int) (origMidY/scaleY);
+//
+// // translate to get mid points relative to invisible rectangle
+// x += ActorContainerRefSupport.MARGIN;
+// y += ActorContainerRefSupport.MARGIN;
+//
+// SupportUtil.addItem(ownObject, x, y, refShape, featureProvider);
+// }
+// }
+// }
+// }
+// }
+// }
+// else {
+// assert(false): "empty referenced structure class diagram";
+// }
+// }
+// }
+//
+// protected static void createInheritedRefItems(ActorContainerRef acr, ContainerShape arShape, IFeatureProvider fp) {
+//
+// ActorClass ac = (ActorClass) acr.eContainer();
+// ResourceSet rs = ac.eResource().getResourceSet();
+// List<InterfaceItem> presentObjects = SupportUtil.getInterfaceItems(arShape, fp);
+//
+// Diagram refDiag = new DiagramAccess().getDiagram(ac);
+// if (!refDiag.getChildren().isEmpty()) {
+// ContainerShape refAcShape = (ContainerShape) refDiag.getChildren().get(0);
+// Object bo = fp.getBusinessObjectForPictogramElement(refAcShape);
+// if (bo instanceof ActorClass) {
+// ActorClass extRefClass = (ActorClass) bo;
+// assert(extRefClass.getName().equals(ac.getName())): "actor class names must match";
+//
+// for (Shape childShape : refAcShape.getChildren()) {
+// bo = fp.getBusinessObjectForPictogramElement(childShape);
+// if (bo instanceof ActorRef) {
+// EObject ownObject = SupportUtil.getOwnObject((ActorRef)bo, rs);
+// if (ownObject==acr) {
+// int subScaleX = arShape.getGraphicsAlgorithm().getWidth()/ActorContainerRefSupport.DEFAULT_SIZE_X;
+// int subScaleY = arShape.getGraphicsAlgorithm().getHeight()/ActorContainerRefSupport.DEFAULT_SIZE_Y;
+//
+// // add items of actor ref
+// for (Shape grandChildShape : ((ContainerShape)childShape).getChildren()) {
+// bo = fp.getBusinessObjectForPictogramElement(grandChildShape);
+// if (bo instanceof InterfaceItem) {
+// ownObject = SupportUtil.getOwnObject((Port)bo, rs);
+// if (!presentObjects.contains(ownObject)) {
+// int x = ITEM_SIZE_SMALL/2 + grandChildShape.getGraphicsAlgorithm().getX()/subScaleX;
+// int y = ITEM_SIZE_SMALL/2 + grandChildShape.getGraphicsAlgorithm().getY()/subScaleY;
+// SupportUtil.addItem(ownObject, x, y, arShape, fp);
+// }
+// }
+// }
+// break;
+// }
+// }
+// }
+// }
+// }
+// }
}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/LayerConnectionSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/LayerConnectionSupport.java
index d2e061b..b454c2d 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/LayerConnectionSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/LayerConnectionSupport.java
@@ -13,7 +13,6 @@
package org.eclipse.etrice.ui.structure.support;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.etrice.core.room.ActorContainerClass;
import org.eclipse.etrice.core.room.ActorContainerRef;
import org.eclipse.etrice.core.room.LayerConnection;
@@ -27,12 +26,15 @@ import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.core.validation.ValidationUtil;
import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
import org.eclipse.etrice.ui.structure.ImageProvider;
+import org.eclipse.etrice.ui.structure.support.context.ConnectionUpdateContext;
+import org.eclipse.etrice.ui.structure.support.context.InitialAddConnectionContext;
+import org.eclipse.etrice.ui.structure.support.feature.ConnectionUpdateFeature;
+import org.eclipse.etrice.ui.structure.support.provider.ConnectionProvider;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.ICreateConnectionFeature;
import org.eclipse.graphiti.features.IDeleteFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.IReason;
import org.eclipse.graphiti.features.IReconnectionFeature;
import org.eclipse.graphiti.features.IRemoveFeature;
import org.eclipse.graphiti.features.IUpdateFeature;
@@ -45,13 +47,10 @@ import org.eclipse.graphiti.features.context.IRemoveContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.features.context.impl.ReconnectionContext;
-import org.eclipse.graphiti.features.context.impl.RemoveContext;
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature;
-import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
import org.eclipse.graphiti.features.impl.DefaultReconnectionFeature;
import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
-import org.eclipse.graphiti.features.impl.Reason;
import org.eclipse.graphiti.mm.GraphicsAlgorithmContainer;
import org.eclipse.graphiti.mm.algorithms.Polyline;
import org.eclipse.graphiti.mm.pictograms.Anchor;
@@ -150,22 +149,31 @@ public class LayerConnectionSupport {
@Override
public boolean canAdd(IAddContext context) {
- if (context instanceof IAddConnectionContext && context.getNewObject() instanceof LayerConnection) {
+ if(context.getNewObject() instanceof LayerConnection)
return true;
- }
+
return false;
}
@Override
public PictogramElement add(IAddContext context) {
- IAddConnectionContext addConContext = (IAddConnectionContext) context;
LayerConnection lc = (LayerConnection) context.getNewObject();
IPeCreateService peCreateService = Graphiti.getPeCreateService();
Connection connection = createConnection();
- connection.setStart(addConContext.getSourceAnchor());
- connection.setEnd(addConContext.getTargetAnchor());
+ if(context instanceof InitialAddConnectionContext){
+ ConnectionProvider cp = ((InitialAddConnectionContext)context).getConnectionProvider();
+ Anchor a1 = cp.getAnchor(lc.getFrom());
+ Anchor a2 = cp.getAnchor(lc.getTo());
+ assert(a1 != null && a2 != null) : "start and end anchor must be present";
+ connection.setStart(a1);
+ connection.setEnd(a2);
+ } else {
+ IAddConnectionContext addConContext = (IAddConnectionContext) context;
+ connection.setStart(addConContext.getSourceAnchor());
+ connection.setEnd(addConContext.getTargetAnchor());
+ }
Graphiti.getPeService().setPropertyValue(connection, Constants.TYPE_KEY, Constants.CONN_TYPE);
@@ -181,6 +189,9 @@ public class LayerConnectionSupport {
// create link and wire it
link(connection, lc);
+ // call update
+ updatePictogramElement(connection);
+
return connection;
}
@@ -241,6 +252,39 @@ public class LayerConnectionSupport {
}
}
+ private class UpdateFeature extends ConnectionUpdateFeature {
+
+ public UpdateFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ protected boolean canUpdate(EObject bo, PictogramElement pe) {
+ return bo instanceof LayerConnection;
+ }
+
+ @Override
+ protected boolean update(EObject bo, IUpdateContext context) {
+ boolean success = super.update(bo, context);
+
+ Connection conn = (Connection) context.getPictogramElement();
+ if(context instanceof ConnectionUpdateContext){
+ ConnectionProvider cp = ((ConnectionUpdateContext) context).getConnectionProvider();
+ LayerConnection lc = (LayerConnection)bo;
+ Anchor newStart = cp.getAnchor(lc.getFrom());
+ Anchor newEnd = cp.getAnchor(lc.getTo());
+ assert(newStart != null && newEnd != null) : "start and end anchor must be not null";
+ if(newStart != conn.getStart())
+ conn.setStart(newEnd);
+ if(newEnd != conn.getEnd())
+ conn.setEnd(newEnd);
+ }
+
+ return success;
+ }
+
+ }
+
private class ReconnectionFeature extends DefaultReconnectionFeature {
private boolean doneChanges = false;
@@ -311,48 +355,6 @@ public class LayerConnectionSupport {
}
}
- private class UpdateFeature extends AbstractUpdateFeature {
-
- public UpdateFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canUpdate(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy())
- return true;
-
- return false;
- }
-
- @Override
- public IReason updateNeeded(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- return Reason.createTrueReason("LayerConnection deleted from model");
- }
- return Reason.createFalseReason();
- }
-
- @Override
- public boolean update(IUpdateContext context) {
- PictogramElement pe = context.getPictogramElement();
- Object bo = getBusinessObjectForPictogramElement(pe);
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- IRemoveContext rc = new RemoveContext(pe);
- IFeatureProvider featureProvider = getFeatureProvider();
- IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
- if (removeFeature != null) {
- removeFeature.remove(rc);
- }
- EcoreUtil.delete((EObject) bo);
- return true;
- }
- return false;
- }
- }
-
private IFeatureProvider fp;
public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SPPSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SPPSupport.java
index f95d69f..e20ec5c 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SPPSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SPPSupport.java
@@ -402,7 +402,7 @@ public class SPPSupport extends InterfaceItemSupport {
GraphicsAlgorithm invisibleRect = pe.getGraphicsAlgorithm();
invisibleRect.getGraphicsAlgorithmChildren().clear();
- createSPPFigure(spp, false, container, invisibleRect, dark, bright);
+ createSPPFigure(spp, isRefItem(pe), container, invisibleRect, dark, bright);
GraphicsAlgorithm ga = container.getChildren().get(0).getGraphicsAlgorithm();
if (ga instanceof Text) {
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java
index e360cb0..74ca7e5 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java
@@ -12,31 +12,18 @@
package org.eclipse.etrice.ui.structure.support;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.ActorContainerRef;
-import org.eclipse.etrice.core.room.Binding;
import org.eclipse.etrice.core.room.InterfaceItem;
-import org.eclipse.etrice.core.room.LayerConnection;
import org.eclipse.etrice.core.room.Port;
import org.eclipse.etrice.core.room.StructureClass;
-import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
-import org.eclipse.etrice.ui.structure.DiagramAccess;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.IDeleteFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.ILayoutFeature;
-import org.eclipse.graphiti.features.IReason;
import org.eclipse.graphiti.features.IRemoveFeature;
import org.eclipse.graphiti.features.IResizeShapeFeature;
import org.eclipse.graphiti.features.IUpdateFeature;
@@ -47,19 +34,14 @@ import org.eclipse.graphiti.features.context.ILayoutContext;
import org.eclipse.graphiti.features.context.IRemoveContext;
import org.eclipse.graphiti.features.context.IResizeShapeContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
-import org.eclipse.graphiti.features.context.impl.RemoveContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
import org.eclipse.graphiti.features.custom.ICustomFeature;
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
-import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature;
-import org.eclipse.graphiti.features.impl.Reason;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
import org.eclipse.graphiti.mm.algorithms.Rectangle;
-import org.eclipse.graphiti.mm.pictograms.Anchor;
-import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
@@ -217,118 +199,6 @@ public class StructureClassSupport {
}
- private class UpdateFeature extends AbstractUpdateFeature {
-
- public UpdateFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canUpdate(IUpdateContext context) {
- if (context.getPictogramElement() instanceof Diagram)
- return false;
-
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy())
- return true;
-
- return bo instanceof StructureClass;
- }
-
- @Override
- public IReason updateNeeded(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- return Reason.createTrueReason("Structure class deleted from model");
- }
-
- StructureClass sc = (StructureClass) bo;
- ContainerShape shape = (ContainerShape) context.getPictogramElement();
-
- String reason = "";
- int missing = 0;
-
- // check for interface items added in model not present in diagram (including inherited)
- {
- List<InterfaceItem> expectedItems = RoomHelpers.getInterfaceItems(sc, true);
- List<InterfaceItem> presentItems = SupportUtil.getInterfaceItems(shape, fp);
- for (InterfaceItem interfaceItem : expectedItems) {
- if (!presentItems.contains(interfaceItem))
- ++missing;
- }
- if (missing>0)
- reason += missing+" missing interface items\n";
- }
-
- // check for refs added in model not present in diagram (including inherited)
- {
- missing = 0;
- List<ActorContainerRef> expectedRefs = RoomHelpers.getRefs(sc, true);
- List<ActorContainerRef> presentRefs = SupportUtil.getRefs(shape, fp);
- for (ActorContainerRef actorContainerRef : expectedRefs) {
- if (!presentRefs.contains(actorContainerRef))
- ++missing;
- }
- if (missing>0)
- reason += missing+" missing refs\n";
- }
-
- // check for bindings added in model not present in diagram (including inherited)
- {
- missing = 0;
- List<Binding> expectedBindings = RoomHelpers.getBindings(sc, true);
- List<Binding> presentBindings = SupportUtil.getBindings(getDiagram(), fp);
- for (Binding binding : expectedBindings) {
- if (!presentBindings.contains(binding))
- ++missing;
- }
- if (missing>0)
- reason += missing+" missing bindings\n";
- }
-
- // check for layer connections added in model not present in diagram (including inherited)
- {
- missing = 0;
- List<LayerConnection> expectedBindings = RoomHelpers.getConnections(sc, true);
- List<LayerConnection> presentBindings = SupportUtil.getConnections(getDiagram(), fp);
- for (LayerConnection binding : expectedBindings) {
- if (!presentBindings.contains(binding))
- ++missing;
- }
- if (missing>0)
- reason += missing+" missing layer connections\n";
- }
-
- if (!reason.isEmpty())
- return Reason.createTrueReason(reason.substring(0, reason.length()-1));
-
- return Reason.createFalseReason();
- }
-
- @Override
- public boolean update(IUpdateContext context) {
- ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
- if (containerShape instanceof Diagram)
- containerShape = (ContainerShape) containerShape.getChildren().get(0);
- Object bo = getBusinessObjectForPictogramElement(containerShape);
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- IRemoveContext rc = new RemoveContext(containerShape);
- IFeatureProvider featureProvider = getFeatureProvider();
- IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
- if (removeFeature != null) {
- removeFeature.remove(rc);
- }
- EcoreUtil.delete((EObject) bo);
- return true;
- }
-
- StructureClass sc = (StructureClass) bo;
- addMissingItems(sc, containerShape, fp);
-
- return true;
- }
- }
-
private class OpenBehaviorDiagram extends AbstractCustomFeature {
public OpenBehaviorDiagram(IFeatureProvider fp) {
@@ -373,7 +243,7 @@ public class StructureClassSupport {
}
}
- private class ResizeFeature extends DefaultResizeShapeFeature {
+ private class ResizeFeature extends DefaultResizeShapeFeature{
public ResizeFeature(IFeatureProvider fp) {
super(fp);
@@ -498,7 +368,7 @@ public class StructureClassSupport {
@Override
public IUpdateFeature getUpdateFeature(IUpdateContext context) {
- return new UpdateFeature(fp);
+ return new StructureClassUpdate(fp);
}
@Override
@@ -564,126 +434,4 @@ public class StructureClassSupport {
return tbp;
}
- public static void addInheritedItems(ActorClass ac, ContainerShape acShape, Map<String,Anchor> ifitem2anchor, IFeatureProvider fp) {
-
- // we don't have to recurse since the base class diagram already contains all inherited items
- Diagram diag = (Diagram) acShape.eContainer();
- ResourceSet rs = ac.eResource().getResourceSet();
- List<InterfaceItem> presentIfItems = SupportUtil.getInterfaceItems(acShape, fp, ifitem2anchor);
- List<ActorContainerRef> presentRefs = SupportUtil.getRefs(acShape, fp, ifitem2anchor);
- List<Binding> presentBindings = SupportUtil.getBindings(diag, fp);
- List<LayerConnection> presentConnections = SupportUtil.getConnections(diag, fp);
-
- Diagram refDiag = new DiagramAccess().getDiagram(ac);
- if (!refDiag.getChildren().isEmpty()) {
- ContainerShape refAcShape = (ContainerShape) refDiag.getChildren().get(0);
- Object bo = fp.getBusinessObjectForPictogramElement(refAcShape);
- if (bo instanceof StructureClass) {
- StructureClass extRefClass = (StructureClass) bo;
- assert(extRefClass.getName().equals(ac.getName())): "actor class names must match";
-
- int scaleX = refAcShape.getGraphicsAlgorithm().getWidth()/acShape.getGraphicsAlgorithm().getWidth();
- int scaleY = refAcShape.getGraphicsAlgorithm().getHeight()/acShape.getGraphicsAlgorithm().getHeight();
-
- for (Shape childShape : refAcShape.getChildren()) {
- bo = fp.getBusinessObjectForPictogramElement(childShape);
- GraphicsAlgorithm ga = childShape.getGraphicsAlgorithm();
- if (bo instanceof InterfaceItem || bo instanceof ActorContainerRef) {
- EObject ownObject = SupportUtil.getOwnObject((EObject)bo, rs);
- if (!presentIfItems.contains(ownObject) && !presentRefs.contains(ownObject)) {
- int x = (ga.getX()+ga.getWidth()/2)/scaleX;
- int y = (ga.getY()+ga.getHeight()/2)/scaleY;
- SupportUtil.addItem(ownObject, x, y, acShape, ifitem2anchor, fp);
- }
- }
- }
- for (Connection conn : refDiag.getConnections()) {
- bo = fp.getBusinessObjectForPictogramElement(conn);
- if (bo instanceof Binding) {
- Binding bind = (Binding) SupportUtil.getOwnObject((Binding)bo, rs);
- if (!presentBindings.contains(bind))
- SupportUtil.addBinding(bind, fp, ifitem2anchor);
- }
- else if (bo instanceof LayerConnection) {
- LayerConnection lc = (LayerConnection) SupportUtil.getOwnObject((LayerConnection)bo, rs);
- if (!presentConnections.contains(lc))
- SupportUtil.addLayerConnection(lc, fp, ifitem2anchor);
- }
- }
- }
- }
- }
-
- private static void addMissingItems(StructureClass sc, ContainerShape acShape, IFeatureProvider fp) {
-
- int width = acShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getWidth();
-
- HashMap<String, Anchor> ifitem2anchor = new HashMap<String, Anchor>();
-
- // interface items
- {
- List<InterfaceItem> present = SupportUtil.getInterfaceItems(acShape, fp, ifitem2anchor);
- {
- List<InterfaceItem> expected = RoomHelpers.getInterfaceItems(sc, false);
- List<InterfaceItem> items = new ArrayList<InterfaceItem>();
- for (InterfaceItem item : expected) {
- if (!present.contains(item))
- items.add(item);
- }
- SupportUtil.addInterfaceItems(items, 0, acShape, width, fp, ifitem2anchor);
- }
- if (sc instanceof ActorClass) {
-
- List<InterfaceItem> ports = new ArrayList<InterfaceItem>();
- for (Port port : ((ActorClass) sc).getIntPorts()) {
- if (!present.contains(port))
- ports.add(port);
- }
- SupportUtil.addInterfaceItems(ports, 3*StructureClassSupport.MARGIN, acShape, width, fp, ifitem2anchor);
- }
- }
-
- // actor container references
- {
- List<ActorContainerRef> present = SupportUtil.getRefs(acShape, fp, ifitem2anchor);
- List<ActorContainerRef> expected = RoomHelpers.getRefs(sc, false);
- List<ActorContainerRef> items = new ArrayList<ActorContainerRef>();
- for (ActorContainerRef item : expected) {
- if (!present.contains(item))
- items.add(item);
- }
- SupportUtil.addRefItems(items, acShape, width, fp, ifitem2anchor);
- }
-
- // base class items
- if (sc instanceof ActorClass) {
- ActorClass base = ((ActorClass) sc).getBase();
-
- // add inherited ports and refs and bindings (and preserve layout)
- if (base!=null)
- StructureClassSupport.addInheritedItems(base, acShape, ifitem2anchor, fp);
- }
-
- Diagram diag = (Diagram) acShape.eContainer();
-
- // bindings
- {
- List<Binding> present = SupportUtil.getBindings(diag, fp);
- List<Binding> expected = RoomHelpers.getBindings(sc, false);
- for (Binding bind : expected) {
- if (!present.contains(bind))
- SupportUtil.addBinding(bind, fp, ifitem2anchor);
- }
- }
-
- // layer connections
- {
- List<LayerConnection> present = SupportUtil.getConnections(diag, fp);
- List<LayerConnection> expected = RoomHelpers.getConnections(sc, false);
- for (LayerConnection lc : expected) {
- if (!present.contains(lc))
- SupportUtil.addLayerConnection(lc, fp, ifitem2anchor);
- }
- }
- }
}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassUpdate.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassUpdate.java
new file mode 100644
index 0000000..3057aba
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassUpdate.java
@@ -0,0 +1,192 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ActorContainerRef;
+import org.eclipse.etrice.core.room.Binding;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.LayerConnection;
+import org.eclipse.etrice.core.room.RoomPackage;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.ui.structure.support.context.ConnectionUpdateContext;
+import org.eclipse.etrice.ui.structure.support.context.InitialAddConnectionContext;
+import org.eclipse.etrice.ui.structure.support.context.PositionUpdateContext;
+import org.eclipse.etrice.ui.structure.support.feature.ShapeUpdateFeature;
+import org.eclipse.etrice.ui.structure.support.provider.ConnectionProvider;
+import org.eclipse.etrice.ui.structure.support.provider.DefaultPositionProvider;
+import org.eclipse.etrice.ui.structure.support.provider.IPositionProvider;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.IReason;
+import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.impl.Reason;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+
+public class StructureClassUpdate extends ShapeUpdateFeature {
+
+ public StructureClassUpdate(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ protected boolean canUpdate(EObject bo, PictogramElement pe) {
+ return bo instanceof StructureClass && !(pe instanceof Diagram);
+ }
+
+ @Override
+ protected boolean update(EObject bo, IUpdateContext context) {
+ StructureClass sc = (StructureClass)bo;
+ ContainerShape containerShape = (ContainerShape) context.getPictogramElement();
+ Map<EObject, PictogramElement> newPes = new HashMap<EObject, PictogramElement>();
+
+ IPositionProvider positionProvider = null;
+ if(context instanceof PositionUpdateContext){
+ positionProvider = ((PositionUpdateContext)context).getPositionProvider();
+ GraphicsAlgorithm invRect = containerShape.getGraphicsAlgorithm();
+ GraphicsAlgorithm innerRect = containerShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0);
+ positionProvider = positionProvider.setNewParent(sc, DiagramUtil.getPosAndSize(invRect), DiagramUtil.getPosAndSize(innerRect));
+ }
+ ConnectionProvider connectionProvider = new ConnectionProvider(getFeatureProvider());
+
+ // ACTOR_CONTAINER_REF
+ {
+ Map<EObject, Shape> present = getChildrenShapesForBoClass(containerShape, RoomPackage.Literals.ACTOR_CONTAINER_REF);
+ List<ActorContainerRef> toAdd = RoomHelpers.getAllActorContainerRefs(sc);
+ toAdd.removeAll(present.keySet());
+
+ Map<EObject, Shape> newShapes = addShapesInitial(toAdd, containerShape);
+ // initial add on actorRef does not create anchors of its interface items
+ updateShapes(newShapes.values(), positionProvider);
+ connectionProvider.insertAnchors(newShapes.values());
+ newPes.putAll(newShapes);
+
+ updateShapes(present.values(), positionProvider);
+ connectionProvider.insertAnchors(present.values());
+ }
+ // INTERFACE_ITEM
+ {
+ Map<EObject, Shape> present = getChildrenShapesForBoClass(containerShape, RoomPackage.Literals.INTERFACE_ITEM);
+ List<InterfaceItem> toAdd = RoomHelpers.getInterfaceItems(sc, true);
+ if(sc instanceof ActorClass){
+ ActorClass base = (ActorClass)sc;
+ while(base != null){
+ toAdd.addAll(base.getIntPorts());
+ base = base.getBase();
+ }
+ }
+ toAdd.removeAll(present.keySet());
+
+ Map<EObject, Shape> newShapes = addShapesInitial(toAdd, containerShape);
+ connectionProvider.insertAnchors(newShapes.values());
+ newPes.putAll(newShapes);
+
+ updateShapes(present.values(), positionProvider);
+ connectionProvider.insertAnchors(present.values());
+ }
+ // LAYER_CONNECTION
+ {
+ Map<EObject, Connection> present = getAllConnectionsForBoClass(getDiagram(), RoomPackage.Literals.LAYER_CONNECTION);
+ List<LayerConnection> toAdd = RoomHelpers.getConnections(sc, true);
+ toAdd.removeAll(present.keySet());
+
+ Map<EObject, Connection> newConns = addConnectionsInitial(toAdd, connectionProvider);
+ updateConnections(newConns.values(), null, positionProvider);
+ updateConnections(present.values(), connectionProvider, positionProvider);
+ }
+ // BINDING
+ {
+ Map<EObject, Connection> present = getAllConnectionsForBoClass(getDiagram(), RoomPackage.Literals.BINDING);
+ List<Binding> toAdd = RoomHelpers.getBindings(sc, true);
+ toAdd.removeAll(present.keySet());
+
+ Map<EObject, Connection> newConns = addConnectionsInitial(toAdd, connectionProvider);
+ updateConnections(newConns.values(), null, positionProvider);
+ updateConnections(present.values(), connectionProvider, positionProvider);
+ }
+
+ // set position of new elements (actorRef, interface items)
+
+ Map<EObject, PictogramElement> withPosition = new HashMap<EObject, PictogramElement>();
+ Map<EObject, PictogramElement> withoutPosition = new HashMap<EObject, PictogramElement>();
+ if(positionProvider == null)
+ withoutPosition = newPes;
+ else {
+ for(EObject obj : newPes.keySet())
+ if(positionProvider.contains(obj))
+ withPosition.put(obj, newPes.get(obj));
+ else
+ withoutPosition.put(obj, newPes.get(obj));
+ }
+
+ updatePictogramElements(withPosition.values(), positionProvider);
+ if(!withoutPosition.isEmpty()){
+ IPositionProvider autoPositionsProvider = new DefaultPositionProvider(sc, containerShape, withoutPosition.keySet());
+ updatePictogramElements(withoutPosition.values(), autoPositionsProvider);
+ }
+
+ return true;
+ }
+
+ private void updateShapes(Collection<Shape> toUpdate, IPositionProvider pp) {
+ if(pp != null)
+ updatePictogramElements(toUpdate, pp);
+ else
+ updatePictogramElements(toUpdate);
+ }
+
+ private void updateConnections(Collection<Connection> toUpdate, ConnectionProvider cp, IPositionProvider pp) {
+ if(cp != null){
+ for(PictogramElement pe : toUpdate){
+ IUpdateContext context = new ConnectionUpdateContext(pe, cp);
+ getFeatureProvider().updateIfPossibleAndNeeded(context);
+ }
+ }
+ if(pp != null)
+ updatePictogramElements(toUpdate, pp);
+ if(cp == null && pp == null)
+ updatePictogramElements(toUpdate);
+
+ }
+
+ @Override
+ protected IReason updateNeeded(EObject bo, IUpdateContext context) {
+ return Reason.createTrueReason();
+ }
+
+ private Map<EObject,Connection> addConnectionsInitial(List<? extends EObject> toAdd, ConnectionProvider cp){
+ Map<EObject,Connection> created = new HashMap<EObject, Connection>();
+
+ for(EObject bo : toAdd){
+ PictogramElement pe = getFeatureProvider().addIfPossible(new InitialAddConnectionContext(bo, cp));
+ if(pe != null){
+ assert(pe instanceof Connection) : "unexpected type";
+ created.put(bo, (Connection) pe);
+ }
+ }
+
+ return created;
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SupportUtil.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SupportUtil.java
index 3d5d468..1210b00 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SupportUtil.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SupportUtil.java
@@ -279,6 +279,9 @@ public class SupportUtil {
}
public static StructureClass getParent(ContainerShape shape, IFeatureProvider fp) {
+ if(shape == null)
+ return null;
+
Object bo = fp.getBusinessObjectForPictogramElement(shape);
if (bo instanceof StructureClass)
return (StructureClass) bo;
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/ConnectionUpdateContext.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/ConnectionUpdateContext.java
new file mode 100644
index 0000000..ad8aeac
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/ConnectionUpdateContext.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support.context;
+
+import org.eclipse.etrice.ui.structure.support.provider.ConnectionProvider;
+import org.eclipse.graphiti.features.context.impl.UpdateContext;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+
+public class ConnectionUpdateContext extends UpdateContext{
+
+ private ConnectionProvider connectionProvider;
+
+ public ConnectionUpdateContext(PictogramElement pictogramElement, ConnectionProvider connectionProvider) {
+ super(pictogramElement);
+ this.connectionProvider = connectionProvider;
+ }
+
+ public ConnectionProvider getConnectionProvider(){
+ return connectionProvider;
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/DeleteContext.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/DeleteContext.java
new file mode 100644
index 0000000..204663e
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/DeleteContext.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support.context;
+
+import org.eclipse.graphiti.features.context.impl.UpdateContext;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+
+public class DeleteContext extends UpdateContext {
+
+ public DeleteContext(PictogramElement pictogramElement) {
+ super(pictogramElement);
+ // TODO Auto-generated constructor stub
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/InitialAddConnectionContext.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/InitialAddConnectionContext.java
new file mode 100644
index 0000000..9e905c8
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/InitialAddConnectionContext.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support.context;
+
+import org.eclipse.etrice.ui.structure.support.provider.ConnectionProvider;
+import org.eclipse.graphiti.features.context.impl.AddContext;
+
+public class InitialAddConnectionContext extends AddContext {
+
+ private ConnectionProvider connectionProvider;
+
+ public InitialAddConnectionContext(Object newObject, ConnectionProvider connectionProvider) {
+ setNewObject(newObject);
+ this.connectionProvider = connectionProvider;
+ }
+
+ public ConnectionProvider getConnectionProvider() {
+ return connectionProvider;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/InitialAddShapeContext.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/InitialAddShapeContext.java
new file mode 100644
index 0000000..6d0e818
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/InitialAddShapeContext.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support.context;
+
+import org.eclipse.graphiti.features.context.impl.AddContext;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+
+public class InitialAddShapeContext extends AddContext {
+
+ public InitialAddShapeContext(Object newObject, ContainerShape targetContainer){
+ setNewObject(newObject);
+ setTargetContainer(targetContainer);
+
+ setX(0);
+ setY(0);
+ setWidth(0);
+ setHeight(0);
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/PositionUpdateContext.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/PositionUpdateContext.java
new file mode 100644
index 0000000..9dfc24c
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/context/PositionUpdateContext.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support.context;
+
+import org.eclipse.etrice.ui.structure.support.provider.IPositionProvider;
+import org.eclipse.graphiti.features.context.impl.UpdateContext;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+
+public class PositionUpdateContext extends UpdateContext {
+
+ IPositionProvider positionProvider;
+
+
+ public PositionUpdateContext(PictogramElement pictogramElement, IPositionProvider positionProvider) {
+ super(pictogramElement);
+ this.positionProvider = positionProvider;
+ }
+
+ public IPositionProvider getPositionProvider() {
+ return positionProvider;
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/CommonUpdateFeature.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/CommonUpdateFeature.java
new file mode 100644
index 0000000..ec6ad7d
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/CommonUpdateFeature.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support.feature;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.ui.structure.support.context.DeleteContext;
+import org.eclipse.etrice.ui.structure.support.context.PositionUpdateContext;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.IReason;
+import org.eclipse.graphiti.features.IRemoveFeature;
+import org.eclipse.graphiti.features.context.IRemoveContext;
+import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.context.impl.RemoveContext;
+import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
+import org.eclipse.graphiti.features.impl.Reason;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+
+public abstract class CommonUpdateFeature extends AbstractUpdateFeature {
+
+ public CommonUpdateFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public final boolean canUpdate(IUpdateContext context) {
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
+ if (bo instanceof EObject){
+ EObject eBo = (EObject)bo;
+ if(eBo.eIsProxy())
+ return true;
+
+ return canUpdate(eBo, context.getPictogramElement());
+ }
+
+ return false;
+ }
+
+ protected abstract boolean canUpdate(EObject bo, PictogramElement pe);
+
+ @Override
+ public final IReason updateNeeded(IUpdateContext context) {
+ PictogramElement pe = context.getPictogramElement();
+ Object bo = getBusinessObjectForPictogramElement(pe);
+ if(bo instanceof EObject){
+ EObject eBo = (EObject)bo;
+ if (eBo.eIsProxy())
+ return Reason.createTrueReason("Deleted from model");
+ if(context instanceof PositionUpdateContext)
+ return new Reason(true);
+
+ return updateNeeded(eBo, context);
+ }
+
+ return new Reason(false);
+ }
+
+ protected abstract IReason updateNeeded(EObject bo, IUpdateContext context);
+
+ @Override
+ public final boolean update(IUpdateContext context) {
+ PictogramElement pe = context.getPictogramElement();
+ Object bo = getBusinessObjectForPictogramElement(pe);
+ if (bo instanceof EObject){
+ EObject eBo = (EObject)bo;
+ if(eBo.eIsProxy()) {
+ IRemoveContext rc = new RemoveContext(pe);
+ IFeatureProvider featureProvider = getFeatureProvider();
+ IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
+ if (removeFeature != null)
+ removeFeature.remove(rc);
+ EcoreUtil.delete((EObject) bo);
+ return true;
+ }
+
+ if(!(context instanceof DeleteContext))
+ return update(eBo, context);
+ }
+
+ return false;
+ }
+
+ protected abstract boolean update(EObject bo, IUpdateContext context);
+
+ protected Map<EObject, Connection> getAllConnectionsForBoClass(Diagram diagram,
+ EClass boEClass) {
+ Map<EObject, Connection> connections = new HashMap<EObject, Connection>();
+ for(Connection conn : diagram.getConnections()){
+ Object bo = getBusinessObjectForPictogramElement(conn);
+ if(boEClass.isInstance(bo))
+ connections.put((EObject)bo, conn);
+ }
+
+ return connections;
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/ConnectionUpdateFeature.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/ConnectionUpdateFeature.java
new file mode 100644
index 0000000..b0901fd
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/ConnectionUpdateFeature.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support.feature;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.ui.structure.support.context.ConnectionUpdateContext;
+import org.eclipse.etrice.ui.structure.support.context.PositionUpdateContext;
+import org.eclipse.etrice.ui.structure.support.provider.IPositionProvider;
+import org.eclipse.etrice.ui.structure.support.provider.IPositionProvider.Pos;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.IReason;
+import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.impl.Reason;
+import org.eclipse.graphiti.mm.algorithms.styles.Point;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
+import org.eclipse.graphiti.services.Graphiti;
+
+public abstract class ConnectionUpdateFeature extends CommonUpdateFeature {
+
+ public ConnectionUpdateFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ protected final IReason updateNeeded(EObject bo, IUpdateContext context) {
+ if(context instanceof PositionUpdateContext || context instanceof ConnectionUpdateContext)
+ return new Reason(true);
+
+ return new Reason(false);
+ }
+
+ @Override
+ protected boolean update(EObject bo, IUpdateContext context) {
+ Connection conn = (Connection)context.getPictogramElement();
+
+ if(context instanceof PositionUpdateContext){
+ PositionUpdateContext pc = (PositionUpdateContext)context;
+ IPositionProvider pp = pc.getPositionProvider();
+
+ updateBendpoints(bo, conn, pp);
+ updateText(bo, conn, pp);
+ }
+
+ return true;
+ }
+
+ private void updateText(EObject bo, Connection conn, IPositionProvider pp) {
+ // TODO Auto-generated method stub
+ }
+
+ private void updateBendpoints(EObject bo, Connection conn, IPositionProvider pp) {
+ if(conn instanceof FreeFormConnection){
+ FreeFormConnection ffc = (FreeFormConnection) conn;
+ List<Pos> positions = pp.getConnectionBendpoints(bo);
+ if(!positions.isEmpty()){
+ Iterator<Pos> iter = positions.iterator();
+ ffc.getBendpoints().clear();
+ while(iter.hasNext()){
+ Pos pos = iter.next();
+ Point pt = Graphiti.getGaService().createPoint(pos.getX(), pos.getY());
+ ffc.getBendpoints().add(pt);
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/ShapeUpdateFeature.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/ShapeUpdateFeature.java
new file mode 100644
index 0000000..8f2589b
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/ShapeUpdateFeature.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support.feature;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.ui.structure.support.context.InitialAddShapeContext;
+import org.eclipse.etrice.ui.structure.support.context.PositionUpdateContext;
+import org.eclipse.etrice.ui.structure.support.provider.IPositionProvider;
+import org.eclipse.etrice.ui.structure.support.provider.IPositionProvider.PosAndSize;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.impl.UpdateContext;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+
+public abstract class ShapeUpdateFeature extends CommonUpdateFeature {
+
+ public ShapeUpdateFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ protected void setPosition(EObject bo, Shape shape, PositionUpdateContext context){
+ PosAndSize pos = context.getPositionProvider().getPosition(bo);
+ if(pos != null){
+ GraphicsAlgorithm ga = shape.getGraphicsAlgorithm();
+ ga.setX(pos.getX());
+ ga.setY(pos.getY());
+ if(pos.getW() > 0)
+ ga.setWidth(pos.getW());
+ if(pos.getH() > 0)
+ ga.setHeight(pos.getH());
+ }
+ }
+
+ protected Map<EObject, Shape> getChildrenShapesForBoClass(ContainerShape containerShape, EClass boEClass){
+ Map<EObject, Shape> items = new HashMap<EObject ,Shape>();
+
+ for(Shape shape : containerShape.getChildren()){
+ Object bo = getBusinessObjectForPictogramElement(shape);
+ if(boEClass.isInstance(bo))
+ items.put((EObject)bo, shape);
+ }
+
+ return items;
+ }
+
+ protected Map<EObject, Shape> addShapesInitial(List<? extends EObject> toAdd, ContainerShape containerShape) {
+ Map<EObject, Shape> shapes = new HashMap<EObject, Shape>();
+ for(EObject bo : toAdd){
+ PictogramElement pe = getFeatureProvider().addIfPossible(new InitialAddShapeContext(bo, containerShape));
+ if(pe != null){
+ assert(pe instanceof Shape) : "unexpected type";
+ Shape shape = (Shape)pe;
+ shapes.put(bo, shape);
+ }
+ }
+
+ return shapes;
+ }
+
+ protected void updatePictogramElements(Collection<? extends PictogramElement> toUpdate, IPositionProvider pp) {
+ for(PictogramElement pe : toUpdate)
+ getFeatureProvider().updateIfPossibleAndNeeded(new PositionUpdateContext(pe, pp));
+ }
+
+ protected void updatePictogramElements(Collection<? extends PictogramElement> toUpdate) {
+ for(PictogramElement pe : toUpdate)
+ getFeatureProvider().updateIfPossibleAndNeeded(new UpdateContext(pe));
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/ConnectionProvider.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/ConnectionProvider.java
new file mode 100644
index 0000000..126564d
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/ConnectionProvider.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support.provider;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.ActorContainerRef;
+import org.eclipse.etrice.core.room.BindingEndPoint;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.RelaySAPoint;
+import org.eclipse.etrice.core.room.SAPoint;
+import org.eclipse.etrice.core.room.SPPoint;
+import org.eclipse.etrice.ui.structure.support.DiagramUtil;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+
+public class ConnectionProvider {
+
+ private Map<String, Anchor> connectionMap;
+ private IFeatureProvider fp;
+
+ public ConnectionProvider(IFeatureProvider featureProvider){
+ connectionMap = new HashMap<String, Anchor>();
+ fp = featureProvider;
+ }
+
+ public void insertAnchors(Collection<Shape> collection){
+ for(Shape shape : collection){
+ if(!shape.getAnchors().isEmpty()){
+ EObject bo = (EObject) fp.getBusinessObjectForPictogramElement(shape);
+ Object parentBo = fp.getBusinessObjectForPictogramElement(shape.getContainer());
+ if(bo instanceof InterfaceItem){
+ if(parentBo instanceof ActorContainerRef)
+ connectionMap.put(getKey(bo, (ActorContainerRef)parentBo), shape.getAnchors().get(0));
+ else
+ connectionMap.put(getKey(bo, null), shape.getAnchors().get(0));
+ }
+ }
+ if(shape instanceof ContainerShape)
+ insertAnchors(((ContainerShape)shape).getChildren());
+ }
+ }
+
+ public Anchor getAnchor(BindingEndPoint endPoint){
+ return connectionMap.get(getKey(endPoint.getPort(), endPoint.getActorRef()));
+ }
+
+ public Anchor getAnchor(SAPoint point){
+ if(point instanceof RelaySAPoint)
+ return connectionMap.get(getKey(((RelaySAPoint) point).getRelay(), null));
+ assert(false) : "unexpected type";
+ return null;
+ }
+
+ public Anchor getAnchor(SPPoint point){
+ return connectionMap.get(getKey(point.getService(), point.getRef()));
+ }
+
+ private String getKey(EObject item, ActorContainerRef acr){
+ if(acr != null)
+ return DiagramUtil.getResourcePath(acr)+DiagramUtil.getResourcePath(item);
+ return DiagramUtil.getResourcePath(item);
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DecorationProvider.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/DecorationProvider.java
index 1cb852c..e9bae5a 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DecorationProvider.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/DecorationProvider.java
@@ -9,7 +9,7 @@
* Henrik Rentz-Reichert (initial contribution)
*
*******************************************************************************/
-package org.eclipse.etrice.ui.structure.support;
+package org.eclipse.etrice.ui.structure.support.provider;
import java.util.ArrayList;
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
new file mode 100644
index 0000000..e178d36
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/DefaultPositionProvider.java
@@ -0,0 +1,283 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support.provider;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.ActorClass;
+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.RoomClass;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.room.SubSystemRef;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.ui.structure.DiagramAccess;
+import org.eclipse.etrice.ui.structure.support.ActorContainerRefSupport;
+import org.eclipse.etrice.ui.structure.support.DiagramUtil;
+import org.eclipse.etrice.ui.structure.support.InterfaceItemSupport;
+import org.eclipse.etrice.ui.structure.support.StructureClassSupport;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.ILinkService;
+
+
+public class DefaultPositionProvider implements IPositionProvider {
+
+ private class Position {
+
+ public Position(double x, double y){
+ this.x = x;
+ this.y = y;
+ }
+
+ double x;
+ double y;
+ }
+
+ private class Parent {
+ EObject bo;
+ PosAndSize inner;
+ }
+
+ private Map<String, Position> obj2pos;
+ private Map<String, Position> obj2text;
+ private Set<RoomClass> mappedClasses;
+ private Parent parent;
+
+ private DefaultPositionProvider(){
+ obj2pos = new HashMap<String, Position>();
+ obj2text = new HashMap<String, Position>();
+ mappedClasses = new HashSet<RoomClass>();
+
+ parent = new Parent();
+ parent.bo = null;
+ parent.inner = new PosAndSize(StructureClassSupport.MARGIN, StructureClassSupport.MARGIN,
+ StructureClassSupport.DEFAULT_SIZE_X, StructureClassSupport.DEFAULT_SIZE_Y);
+ }
+
+ public DefaultPositionProvider(ActorContainerRef acr) {
+ this();
+
+ parent.bo = acr;
+ parent.inner = new PosAndSize(ActorContainerRefSupport.MARGIN, ActorContainerRefSupport.MARGIN,
+ ActorContainerRefSupport.DEFAULT_SIZE_X, ActorContainerRefSupport.DEFAULT_SIZE_Y);
+
+ mapChildrenInterfaceItems(acr);
+ }
+
+ public DefaultPositionProvider(StructureClass sc, ContainerShape scShape,
+ Set<EObject> toLayout) {
+ this();
+ parent.bo = sc;
+ parent.inner = DiagramUtil.getPosAndSize(scShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0));
+
+ int width = parent.inner.getW();
+ int height = parent.inner.getH();
+ int y = ActorContainerRefSupport.DEFAULT_SIZE_Y*5/2;
+
+ List<ActorContainerRef> refs = new ArrayList<ActorContainerRef>();
+ List<InterfaceItem> ifItems = new ArrayList<InterfaceItem>();
+ List<InterfaceItem> intPorts = new ArrayList<InterfaceItem>();
+
+ 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
+ ifItems.add((InterfaceItem) obj);
+ }
+
+ layoutInterfaceItems(ifItems, width, height, -InterfaceItemSupport.MARGIN);
+
+ layoutActorRefs(refs, width, height, y);
+ y += ActorContainerRefSupport.DEFAULT_SIZE_Y*5/2;
+
+ layoutInterfaceItems(intPorts, width, height, y);
+ }
+
+ public DefaultPositionProvider(StructureClass sc) {
+ this();
+ parent.bo = sc;
+
+ int width = StructureClassSupport.DEFAULT_SIZE_X;
+ int height = StructureClassSupport.DEFAULT_SIZE_Y;
+ int y = ActorContainerRefSupport.DEFAULT_SIZE_Y*5/2;
+
+ layoutInterfaceItems(RoomHelpers.getInterfaceItems(sc, true), width, height, -InterfaceItemSupport.MARGIN);
+
+ layoutActorRefs(RoomHelpers.getAllActorContainerRefs(sc), width, height, y);
+ y += ActorContainerRefSupport.DEFAULT_SIZE_Y*5/2;
+
+ List<InterfaceItem> intPorts = new ArrayList<InterfaceItem>();
+ if(sc instanceof ActorClass){
+ ActorClass base = (ActorClass)sc;
+ while(base != null){
+ intPorts.addAll(base.getIntPorts());
+ base = base.getBase();
+ }
+ }
+ layoutInterfaceItems(intPorts, width, height, y);
+
+ }
+
+ @Override
+ public IPositionProvider setNewParent(EObject parent,
+ PosAndSize invisibleRect, PosAndSize innerRect) {
+ DefaultPositionProvider pp = new DefaultPositionProvider();
+ pp.mappedClasses = this.mappedClasses;
+ pp.obj2pos = this.obj2pos;
+ pp.obj2text = this.obj2text;
+
+ pp.parent.bo = parent;
+ pp.parent.inner = innerRect;
+
+ return pp;
+ }
+
+ @Override
+ public PosAndSize getPosition(EObject bo) {
+ Position pos = obj2pos.get(getKey(bo));
+
+ int width = 0, height = 0;
+ // interface items of actore refs are mid points
+ if(bo instanceof InterfaceItem && parent.bo instanceof ActorContainerRef)
+ width = height = 2*InterfaceItemSupport.MARGIN_SMALL;
+
+ if(pos != null){
+ return new PosAndSize(
+ (int) (pos.x*parent.inner.getW()) + parent.inner.getX() - width/2,
+ (int) (pos.y*parent.inner.getH()) + parent.inner.getY() - height/2,
+ -1, -1);
+ }
+
+ return null;
+ }
+
+ @Override
+ public boolean contains(EObject obj) {
+ String key = getKey(obj);
+ return obj2pos.containsKey(key) || obj2text.containsKey(key);
+ }
+
+ private void mapChildrenInterfaceItems(ActorContainerRef acr) {
+ ActorContainerClass acc = null;
+ if(acr instanceof ActorRef)
+ acc = ((ActorRef) acr).getType();
+ else if(acr instanceof SubSystemRef)
+ acc = ((SubSystemRef) acr).getType();
+
+ if(acc == null || mappedClasses.contains(acc))
+ return;
+
+ Diagram diagram = new DiagramAccess().getDiagram(acc);
+ if (diagram == null)
+ return;
+
+ ContainerShape scShape = DiagramUtil.findScShape(diagram);
+ if(scShape == null)
+ return;
+
+ ILinkService linkService = Graphiti.getLinkService();
+ EObject acc2 = linkService.getBusinessObjectForLinkedPictogramElement(scShape);
+ if(!acc2.eResource().getURI().equals(acc.eResource().getURI()))
+ return;
+
+ if(scShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().isEmpty())
+ return;
+
+ GraphicsAlgorithm borderRect = scShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0);
+
+ for(Shape child : scShape.getChildren()){
+ Object bo = linkService.getBusinessObjectForLinkedPictogramElement(child);
+ if(bo instanceof InterfaceItem){
+ GraphicsAlgorithm ga = child.getGraphicsAlgorithm();
+ Position pos = new Position(
+ (double)(ga.getX()-borderRect.getX()+ga.getWidth()/2)/borderRect.getWidth(),
+ (double)(ga.getY()-borderRect.getY()+ga.getHeight()/2)/borderRect.getHeight());
+ obj2pos.put(getKey((EObject) bo), pos);
+ }
+ }
+
+ mappedClasses.add(acc);
+ }
+
+ private void layoutActorRefs(List<? extends ActorContainerRef> actorRefs, int width, int height, int y0){
+ int ncols = width/ActorContainerRefSupport.DEFAULT_SIZE_X;
+ int nrows = actorRefs.size()/ncols;
+ int gap = (width-(ncols*ActorContainerRefSupport.DEFAULT_SIZE_X))/(ncols+1);
+ int delta = gap+ActorContainerRefSupport.DEFAULT_SIZE_X;
+ int x0 = gap+ActorContainerRefSupport.DEFAULT_SIZE_X/2;
+ int i = 0;
+ for (ActorContainerRef ar : actorRefs) {
+ int row = i/ncols;
+ int col = i%ncols;
+ if (row>=nrows) {
+ int nc = actorRefs.size()%ncols;
+ gap = (width-(nc*ActorContainerRefSupport.DEFAULT_SIZE_X))/(nc+1);
+ delta = gap+ActorContainerRefSupport.DEFAULT_SIZE_X;
+ x0 = gap+ActorContainerRefSupport.DEFAULT_SIZE_X/2;
+ }
+ int x = x0+delta*col;
+ int y = y0+(ActorContainerRefSupport.MARGIN+ActorContainerRefSupport.DEFAULT_SIZE_Y)*row;
+ obj2pos.put(getKey(ar), new Position((double)x/width, (double)y/height));
+ ++i;
+ }
+ }
+
+ private void layoutInterfaceItems(List<? extends InterfaceItem> items, int width, int height, int y0){
+ int n = items.size();
+ int delta = width/(n+1);
+ int pos = delta;
+ for (InterfaceItem item : items) {
+ obj2pos.put(getKey(item), new Position((double)pos/width, (double)y0/height));
+ pos += delta;
+ }
+ }
+
+ private String getKey(EObject obj){
+ return DiagramUtil.getResourcePath(obj);
+ }
+
+
+ @Override
+ public List<Pos> getConnectionBendpoints(EObject obj) {
+ return new ArrayList<Pos>();
+ }
+
+ @Override
+ public PosAndSize getDiagramPosition() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ @Override
+ public Pos getConnectionText(EObject obj) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/IPositionProvider.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/IPositionProvider.java
new file mode 100644
index 0000000..908f863
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/IPositionProvider.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support.provider;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+
+public interface IPositionProvider {
+ public static class Pos {
+
+ private int x, y;
+
+ public Pos(int x, int y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ public int getX() {
+ return x;
+ }
+
+ public int getY() {
+ return y;
+ }
+ }
+
+ public static class PosAndSize extends Pos {
+
+ private int w, h;
+
+ public PosAndSize(int x, int y, int w, int h) {
+ super(x, y);
+ this.w = w;
+ this.h = h;
+ }
+
+ public int getW() {
+ return w;
+ }
+
+ public int getH() {
+ return h;
+ }
+
+ }
+
+ /**
+ * Returns a new position provider.
+ * parent determines align and scaling
+ *
+ * @param parent
+ * @param invisibleRect
+ * @param innerRect
+ * @return
+ */
+ public IPositionProvider setNewParent(EObject parent, PosAndSize invisibleRect, PosAndSize innerRect);
+
+ public boolean contains(EObject obj);
+ public PosAndSize getDiagramPosition();
+ public PosAndSize getPosition(EObject bo);
+ public Pos getConnectionText(EObject bo);
+ public List<Pos> getConnectionBendpoints(EObject bo);
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/SuperDiagramPositionProvider.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/SuperDiagramPositionProvider.java
new file mode 100644
index 0000000..1654978
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/provider/SuperDiagramPositionProvider.java
@@ -0,0 +1,270 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support.provider;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ActorContainerRef;
+import org.eclipse.etrice.core.room.Binding;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.LayerConnection;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.ui.structure.DiagramAccess;
+import org.eclipse.etrice.ui.structure.support.ActorContainerRefSupport;
+import org.eclipse.etrice.ui.structure.support.DiagramUtil;
+import org.eclipse.etrice.ui.structure.support.InterfaceItemSupport;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.algorithms.Text;
+import org.eclipse.graphiti.mm.algorithms.styles.Point;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.ILinkService;
+
+public class SuperDiagramPositionProvider implements IPositionProvider {
+
+ private class Position {
+ double x;
+ double y;
+ double sx = -1;
+ double sy = -1;
+ }
+
+ private class Parent {
+ EObject bo;
+ String key;
+ PosAndSize inv, inner;
+ }
+
+ private PosAndSize superDiagramPosition;
+ private HashMap<String, Position> obj2pos;
+ private HashMap<String, Position> obj2text;
+ private HashMap<String, ArrayList<Position>> obj2bendpoints;
+ private Parent parent;
+
+ private SuperDiagramPositionProvider(){ }
+
+ public SuperDiagramPositionProvider(StructureClass sc) {
+ obj2pos = new HashMap<String, Position>();
+ obj2text = new HashMap<String, Position>();
+ obj2bendpoints = new HashMap<String, ArrayList<Position>>();
+
+ // defaults
+ parent = new Parent();
+ parent.bo = sc;
+ parent.key = getKey(sc);
+ // parent.inv & parent.inner at mapPositions()
+
+ if (sc instanceof ActorClass) {
+ ActorClass base = ((ActorClass) sc).getBase();
+ if (base != null)
+ mapPositions(base);
+ }
+ }
+
+ @Override
+ public SuperDiagramPositionProvider setNewParent(EObject parent, PosAndSize invisibleRect, PosAndSize innerRect) {
+ SuperDiagramPositionProvider pp = new SuperDiagramPositionProvider();
+ pp.obj2pos = this.obj2pos;
+ pp.obj2text = this.obj2text;
+ pp.obj2bendpoints = this.obj2bendpoints;
+ pp.superDiagramPosition = this.superDiagramPosition;
+
+ Parent newParent = new Parent();
+ newParent.bo = parent;
+ newParent.key = getKey(parent);
+ newParent.inv = invisibleRect;
+ newParent.inner = innerRect;
+
+ pp.parent = newParent;
+
+ return pp;
+ }
+
+ @Override
+ public boolean contains(EObject obj) {
+ String key = getKey(obj);
+ return obj2pos.containsKey(key) || obj2text.containsKey(key) || obj2bendpoints.containsKey(key);
+ }
+
+ @Override
+ public PosAndSize getDiagramPosition() {
+ return superDiagramPosition;
+ }
+
+ @Override
+ public PosAndSize getPosition(EObject bo) {
+ Position pos = obj2pos.get(getKey(bo));
+ if (pos==null)
+ return null;
+
+ boolean fixedSize = false;
+ int width = 0, height = 0;
+ if(bo instanceof InterfaceItem){
+ if(parent.bo instanceof ActorContainerRef)
+ width = height = 2*InterfaceItemSupport.MARGIN_SMALL;
+ else
+ width = height = 2*InterfaceItemSupport.MARGIN;
+ fixedSize = true;
+ } else if(bo instanceof ActorContainerRef){
+ int margin = ActorContainerRefSupport.MARGIN;
+ width = (int) (pos.sx * parent.inner.getW()) + 2*margin;
+ height = (int) (pos.sy * parent.inner.getH()) + 2*margin;
+ }
+
+ return new PosAndSize(
+ (int) (pos.x * parent.inner.getW()) - width/2 + parent.inner.getX(),
+ (int) (pos.y * parent.inner.getH()) - height/2 + parent.inner.getY(),
+ (fixedSize)?-1:width,
+ (fixedSize)?-1:height);
+ }
+
+ @Override
+ public Pos getConnectionText(EObject obj) {
+ Position pos = obj2text.get(getKey(obj));
+ if(pos == null)
+ return null;
+
+ return new Pos(
+ (int) (pos.x * parent.inner.getW()) + parent.inner.getX() + parent.inv.getX(),
+ (int) (pos.y * parent.inner.getH()) + parent.inner.getY() + parent.inv.getY());
+ }
+
+ @Override
+ public List<Pos> getConnectionBendpoints(EObject obj) {
+ ArrayList<Pos> result = new ArrayList<Pos>();
+
+ ArrayList<Position> list = obj2bendpoints.get(getKey(obj));
+ if(list == null)
+ return result;
+
+ for (Position p : list) {
+ Pos pos = new Pos(
+ (int) (p.x * parent.inner.getW()) + parent.inner.getX() + parent.inv.getX(),
+ (int) (p.y * parent.inner.getH()) + parent.inner.getY() + parent.inv.getY());
+ result.add(pos);
+ }
+
+ return result;
+ }
+
+ private void mapPositions(ActorClass ac) {
+ Diagram diagram = new DiagramAccess().getDiagram(ac);
+ if (diagram == null)
+ return;
+
+ ContainerShape acShape = DiagramUtil.findScShape(diagram);
+ if(acShape == null)
+ return;
+
+ ILinkService linkService = Graphiti.getLinkService();
+ EObject sc = linkService.getBusinessObjectForLinkedPictogramElement(acShape);
+ if(!sc.eResource().getURI().equals(ac.eResource().getURI()))
+ return;
+
+ PosAndSize acInv = DiagramUtil.getPosAndSize(acShape.getGraphicsAlgorithm());
+ PosAndSize acInner = DiagramUtil.getPosAndSize(acShape.getGraphicsAlgorithm()
+ .getGraphicsAlgorithmChildren().get(0));
+
+ superDiagramPosition = acInv;
+ // default
+ parent.inv = acInv;
+ parent.inner = acInner;
+
+ // refs & interface items
+ for (Shape shape : ((ContainerShape) acShape).getChildren()) {
+ EObject obj = linkService.getBusinessObjectForLinkedPictogramElement(shape);
+
+ // positions
+ if (obj instanceof ActorContainerRef || obj instanceof InterfaceItem) {
+
+ PosAndSize objInv = DiagramUtil.getPosAndSize(shape.getGraphicsAlgorithm());
+ PosAndSize objInner = DiagramUtil.getPosAndSize(shape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0));
+
+ Position pos = new Position();
+ pos.x = (double)(objInv.getX() - acInner.getX() + objInv.getW()/2) / acInner.getW();
+ pos.y = (double)(objInv.getY() - acInner.getY() + objInv.getH()/2) / acInner.getH();
+ pos.sx = (double)(objInner.getW()) / acInner.getW();
+ pos.sy = (double)(objInner.getH()) / acInner.getH();
+ obj2pos.put(getKey(obj), pos);
+
+ // refs interface items
+ if (obj instanceof ActorContainerRef){
+ for(Shape child : ((ContainerShape)shape).getChildren()){
+ EObject childBo = linkService.getBusinessObjectForLinkedPictogramElement(child);
+
+ if(!(childBo instanceof InterfaceItem))
+ continue;
+ PosAndSize ifInv = DiagramUtil.getPosAndSize(child.getGraphicsAlgorithm());
+
+ Position p = new Position();
+ p.x = (double)(ifInv.getX() - objInner.getX() + ifInv.getW()/2) / objInner.getW();
+ p.y = (double)(ifInv.getY() - objInner.getY() + ifInv.getH()/2) / objInner.getH();
+ obj2pos.put(getKey(obj)+getKey(childBo), p);
+
+ }
+ }
+ }
+ }
+
+ // bindings & layer connections
+ for (Connection conn : diagram.getConnections()) {
+ EObject obj = linkService.getBusinessObjectForLinkedPictogramElement(conn);
+
+ if (obj instanceof Binding || obj instanceof LayerConnection) {
+
+ // label position
+ if (conn.getConnectionDecorators().size() > 1) {
+ ConnectionDecorator cd = conn.getConnectionDecorators().get(1);
+ if (cd.getGraphicsAlgorithm() instanceof Text) {
+ GraphicsAlgorithm ga = cd.getGraphicsAlgorithm();
+ Position pos = new Position();
+ pos.x = (double)(ga.getX() - acInv.getX() - acInner.getX()) / acInner.getW();
+ pos.y = (double)(ga.getY() - acInv.getY() - acInner.getY()) / acInner.getH();
+ obj2text.put(getKey(obj), pos);
+ }
+ }
+
+ // bend points
+ if (conn instanceof FreeFormConnection) {
+ ArrayList<Position> points = new ArrayList<Position>();
+ for (Point bp : ((FreeFormConnection) conn).getBendpoints()) {
+ Position pos = new Position();
+ pos.x = (double)(bp.getX() - acInv.getX() - acInner.getX()) / acInner.getW();
+ pos.y = (double)(bp.getY() - acInv.getY() - acInner.getY()) / acInner.getH();
+ points.add(pos);
+ }
+ if(!points.isEmpty())
+ obj2bendpoints.put(getKey(obj), points);
+ }
+ }
+ }
+
+ }
+
+ private String getKey(EObject bo){
+ // short path
+ if(bo instanceof StructureClass)
+ return "";
+
+ return parent.key+DiagramUtil.getResourcePath(bo);
+ }
+}