From 157c33f899e16f0745df0689730aa4c1c250ef6e Mon Sep 17 00:00:00 2001 From: Jayant Gupta Date: Mon, 30 Jul 2012 08:30:56 +0530 Subject: Done Corrections and Added some Layout Option Infrastructure. 1. Added ETrice Semantic Layout Configurator. 2. Added two new Diagram Types for eTrice. 3. Done a few corrections and commenting. Change-Id: I24c39aad2c13db4da05963281908ec38a094d94f --- plugins/org.eclipse.etrice.ui.layout/plugin.xml | 40 +++- .../ui/layout/BehaviorDiagramLayoutManager.java | 43 +++-- .../etrice/ui/layout/BehaviorLayoutCommand.java | 16 ++ .../ui/layout/ETriceDiagramLayoutManager.java | 116 ++++-------- .../etrice/ui/layout/ETriceLayoutCommand.java | 7 +- .../ui/layout/ETriceSemanticLayoutConfig.java | 96 ++++++++++ .../ui/layout/StructureDiagramLayoutManager.java | 202 +++++++++++++++++++++ .../ui/layout/StructureDiagramLayoutmanager.java | 201 -------------------- .../etrice/ui/layout/StructureLayoutCommand.java | 21 ++- 9 files changed, 426 insertions(+), 316 deletions(-) create mode 100644 plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceSemanticLayoutConfig.java create mode 100644 plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureDiagramLayoutManager.java delete mode 100644 plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureDiagramLayoutmanager.java (limited to 'plugins/org.eclipse.etrice.ui.layout') diff --git a/plugins/org.eclipse.etrice.ui.layout/plugin.xml b/plugins/org.eclipse.etrice.ui.layout/plugin.xml index 8528c918b..8df4cb91b 100644 --- a/plugins/org.eclipse.etrice.ui.layout/plugin.xml +++ b/plugins/org.eclipse.etrice.ui.layout/plugin.xml @@ -8,29 +8,55 @@ priority="1"> + + + + + + - diff --git a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorDiagramLayoutManager.java b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorDiagramLayoutManager.java index 1bb0d2958..b110fd9ba 100644 --- a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorDiagramLayoutManager.java +++ b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorDiagramLayoutManager.java @@ -11,6 +11,7 @@ package org.eclipse.etrice.ui.layout; +import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.emf.ecore.EObject; import org.eclipse.etrice.core.room.StateGraph; import org.eclipse.etrice.core.room.TrPoint; @@ -77,32 +78,32 @@ public class BehaviorDiagramLayoutManager extends ETriceDiagramLayoutManager { } @Override - protected Size getDefaultSize(Shape shape) { - Size defaultSize = new Size(); - - // This code sets same minimal default size for both State Graph and + protected Dimension getDefaultSize(Shape shape) { + Dimension defaultSize = new Dimension(); + + // This code sets the same minimal default size for both State Graph and // State - defaultSize.setHeight(StateSupport.MIN_SIZE_Y); - defaultSize.setWidth(StateSupport.MIN_SIZE_X); - + defaultSize.setSize(StateSupport.MIN_SIZE_X, StateSupport.MIN_SIZE_Y); + /* - * This code sets default size differently for Actor Class and Actor Container - * Refs. This keeps the top-level container quite large on layout, which - * might not seem so pleasant, but is more closer to the model. + * This code sets default size differently for State Graphs and States. + * This keeps the top-level container quite large on layout (according + * to the default size in StateGraphSupport), which might not seem so + * pleasant. */ - /* + /* EObject modelObject = shape.getLink().getBusinessObjects().get(0); if (modelObject instanceof StateGraph) { - defaultSize.setHeight(StateGraphSupport.DEFAULT_SIZE_Y); - defaultSize.setWidth(StateGraphSupport.DEFAULT_SIZE_X); + defaultSize.setSize(StateGraphSupport.DEFAULT_SIZE_X, + StateGraphSupport.DEFAULT_SIZE_Y); } else if (modelObject instanceof State) { - defaultSize.setHeight(StateSupport.MIN_SIZE_Y); - defaultSize.setWidth(StateSupport.MIN_SIZE_X); + defaultSize.setSize(StateSupport.MIN_SIZE_X, + StateSupport.MIN_SIZE_Y); + } else { - defaultSize.setHeight(MIN_HEIGHT); - defaultSize.setWidth(MIN_WIDHT); + defaultSize.setSize(20, 20); }*/ - + return defaultSize; } @@ -146,7 +147,6 @@ public class BehaviorDiagramLayoutManager extends ETriceDiagramLayoutManager { return false; } - /** * {@inheritDoc} * @@ -154,10 +154,10 @@ public class BehaviorDiagramLayoutManager extends ETriceDiagramLayoutManager { */ @Override public boolean isInternalPort(Shape shape) { - //No shape is an internal port (i.e. All ports are external only) + // No shape is an internal port (i.e. All ports are external only) return false; } - + /** * {@inheritDoc} * @@ -172,5 +172,4 @@ public class BehaviorDiagramLayoutManager extends ETriceDiagramLayoutManager { return false; } - } diff --git a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorLayoutCommand.java b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorLayoutCommand.java index 26ee58162..a107f13b0 100644 --- a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorLayoutCommand.java +++ b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorLayoutCommand.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * 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: + * Jayant Gupta (initial contribution) + * + *******************************************************************************/ package org.eclipse.etrice.ui.layout; import org.eclipse.emf.ecore.EObject; @@ -18,6 +28,12 @@ import org.eclipse.graphiti.services.IGaService; import de.cau.cs.kieler.core.kgraph.KNode; import de.cau.cs.kieler.core.kgraph.KPort; +/** + * A command for applying the result of automatic layout to diagram elements in + * eTrice Behavior Editor. + * + * @author jayant + */ public class BehaviorLayoutCommand extends ETriceLayoutCommand { public BehaviorLayoutCommand(TransactionalEditingDomain domain, diff --git a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceDiagramLayoutManager.java b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceDiagramLayoutManager.java index 9cf2a5f91..09f22f298 100644 --- a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceDiagramLayoutManager.java +++ b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceDiagramLayoutManager.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Map.Entry; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor; @@ -32,11 +33,7 @@ import org.eclipse.graphiti.mm.pictograms.PictogramElement; import org.eclipse.graphiti.mm.pictograms.Shape; import org.eclipse.graphiti.ui.editor.DiagramEditor; import org.eclipse.graphiti.ui.internal.parts.IPictogramElementEditPart; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.MessageBox; -import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PlatformUI; import de.cau.cs.kieler.core.kgraph.KGraphElement; import de.cau.cs.kieler.core.kgraph.KLabeledGraphElement; @@ -58,7 +55,7 @@ import de.cau.cs.kieler.kiml.util.KimlUtil; /** * The abstract class to support the creation of eTrice * {@link BehaviorDiagramLayoutManager } and - * {@link StructureDiagramLayoutmanager} + * {@link StructureDiagramLayoutManager} * * @author jayant */ @@ -233,6 +230,14 @@ public abstract class ETriceDiagramLayoutManager extends shapeLayout.setSize(ga.getWidth(), ga.getHeight()); mapping.getGraphMap().put(diagramNode, element); + VolatileLayoutConfig staticConfig = mapping + .getProperty(KimlGraphitiUtil.STATIC_CONFIG); + + if (workbenchPart instanceof BehaviorEditor) + staticConfig.setValue(LayoutOptions.DIAGRAM_TYPE, diagramNode, + LayoutContext.GRAPH_ELEM, + ETriceSemanticLayoutConfig.BEHAVIOR_DAGRAM_TYPE); + // Node creation for currently visible top-level Container // Shape(Bounding Box) in // eTrice Diagrams @@ -265,32 +270,20 @@ public abstract class ETriceDiagramLayoutManager extends mapping.setLayoutGraph((KNode) internalKGraphElement); } else { - // The selected Element is a Port(Boundary or Internal) or an Edge Label. - - // Giving the user a SWT dialog indicating that this Shape - // cannot be lay-outed. - Shell shell = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow().getShell(); - MessageBox dialog = new MessageBox(shell, SWT.ICON_ERROR - | SWT.OK | SWT.CANCEL); - dialog.setText("Invalid Layout Call"); - dialog.setMessage("This shape connot be layouted saparately."); - System.out.println(dialog.open()); + // The selected Element is a Port(Boundary or Internal) or + // an Edge Label. + // It is an illegal argument for layout + throw new IllegalArgumentException( + "The seleted element cannot be lay-outed separately"); } } } else if (element instanceof FreeFormConnection) { - // This gives the user a SWT dialog indicating this is a connection - // and - // cannot be lay-outed. - Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() - .getShell(); - MessageBox dialog = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK - | SWT.CANCEL); - dialog.setText("Invalid Layout Call"); - dialog.setMessage("A connection connot be layouted saparately"); - System.out.println(dialog.open()); + // The selected element is an edge. + // It is an illegal argument for layout + throw new IllegalArgumentException( + "A connection cannot be layouted separately"); } for (Connection entry : mapping @@ -313,8 +306,13 @@ public abstract class ETriceDiagramLayoutManager extends * @param mapping * the mapping of pictogram elements to graph elements * @param diagram + * The Diagram Containing the Bounding Box * @param diagramNode + * The Node for the diagram * @param onlyVisible + * If true, only the visible bounding box will be lay-outed. + * Otherwise, all bounding boxes in current Diagram are + * lay-outed. * * @author jayant */ @@ -491,7 +489,7 @@ public abstract class ETriceDiagramLayoutManager extends * This is fairly general for both the eTrice editors and same for Nodes and * Ports */ - public static void setCurrentPositionAndSize( + protected void setCurrentPositionAndSize( final LayoutMapping mapping, final KNode parentNode, final KGraphElement kelem, final Shape shape) { @@ -545,7 +543,7 @@ public abstract class ETriceDiagramLayoutManager extends * @param node * the node for which layout options need to be set * @param shape - * TODO + * the corresponding shape * @author jayant */ /* This is fairly general for both the eTrice editors */ @@ -567,56 +565,11 @@ public abstract class ETriceDiagramLayoutManager extends VolatileLayoutConfig staticConfig = mapping .getProperty(KimlGraphitiUtil.STATIC_CONFIG); - Size defaultSize = getDefaultSize(shape); + Dimension defaultSize = getDefaultSize(shape); staticConfig.setValue(LayoutOptions.MIN_WIDTH, node, - LayoutContext.GRAPH_ELEM, defaultSize.getWidth() + labelWidth); - staticConfig - .setValue(LayoutOptions.MIN_HEIGHT, node, - LayoutContext.GRAPH_ELEM, defaultSize.getHeight() - + labelHeight); - } - - public static class Size { - private float width = 0; - private float height = 0; - - /** - * Getter for width - * - * @return the width - */ - public float getWidth() { - return width; - } - - /** - * Setter for width - * - * @param width - * the width to set - */ - public void setWidth(float width) { - this.width = width; - } - - /** - * Getter for height - * - * @return the height - */ - public float getHeight() { - return height; - } - - /** - * Setter for height - * - * @param height - * the height to set - */ - public void setHeight(float height) { - this.height = height; - } + LayoutContext.GRAPH_ELEM, defaultSize.width() + labelWidth); + staticConfig.setValue(LayoutOptions.MIN_HEIGHT, node, + LayoutContext.GRAPH_ELEM, defaultSize.height() + labelHeight); } /** @@ -646,6 +599,7 @@ public abstract class ETriceDiagramLayoutManager extends * * @param shape * the shape to be investigated + * * @return true if the {@code shape} is the Top Level Bounding Box * * @author jayant @@ -653,15 +607,15 @@ public abstract class ETriceDiagramLayoutManager extends public abstract boolean isTopLevelBoundingBox(Shape shape); /** - * Gets the Default Minimal Width for a node + * Gets the Default Minimal Size for a node * * @param shape - * TODO + * The shape attached to the node * - * @return the defaults minimal width a node + * @return the defaults minimal size for a node * * @author jayant */ - protected abstract Size getDefaultSize(Shape shape); + protected abstract Dimension getDefaultSize(Shape shape); } diff --git a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceLayoutCommand.java b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceLayoutCommand.java index 5d33d8a2c..dcd58138d 100644 --- a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceLayoutCommand.java +++ b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceLayoutCommand.java @@ -34,8 +34,9 @@ import de.cau.cs.kieler.kiml.klayoutdata.KInsets; import de.cau.cs.kieler.kiml.klayoutdata.KShapeLayout; /** - * A command for applying the result of automatic layout to an eTrice - * editor(Graphiti) diagram. + * An abstract class to support creation of commands for applying the result of + * automatic layout to eTrice diagrams. Help create the + * {@link BehaviorLayoutCommand} and the {@link StructureLayoutCommand}. * * @author jayant */ @@ -114,7 +115,7 @@ public abstract class ETriceLayoutCommand extends GraphitiLayoutCommand { * * @author jayant */ - public static void setCalculatedPositionAndSize(final KGraphElement kelem, + protected void setCalculatedPositionAndSize(final KGraphElement kelem, KNode parentNode, final ContainerShape shape) { KShapeLayout shapeLayout = kelem.getData(KShapeLayout.class); diff --git a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceSemanticLayoutConfig.java b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceSemanticLayoutConfig.java new file mode 100644 index 000000000..d9e21ee44 --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceSemanticLayoutConfig.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * 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: + * Jayant Gupta (initial contribution) + * + *******************************************************************************/ +package org.eclipse.etrice.ui.layout; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.etrice.core.room.ActorContainerClass; +import org.eclipse.etrice.core.room.StateGraph; + +import de.cau.cs.kieler.core.properties.IProperty; +import de.cau.cs.kieler.kiml.LayoutOptionData; +import de.cau.cs.kieler.kiml.config.SemanticLayoutConfig; +import de.cau.cs.kieler.kiml.options.LayoutOptions; + +/** + * @author jayant + * + */ +public class ETriceSemanticLayoutConfig extends SemanticLayoutConfig { + + /** + * The diagram type for the top-level bounding box containers in eTrice + * Behavior Diagram. + */ + public static final String BEHAVIOR_DAGRAM_TYPE = "org.eclipse.etrice.ui.layout.eTriceBehaviorDiagram"; + + /** + * The diagram type for the top-level bounding box containers in eTrice + * Structure Diagram. + */ + public static final String STRUCTURE_DAGRAM_TYPE = "org.eclipse.etrice.ui.layout.eTriceStructureDiagram"; + + /** the priority for eTrice Semantic layout configurations. */ + public static final int PRIORITY = 20; + + /** + * {@inheritDoc} + */ + @Override + public int getPriority() { + return PRIORITY; + } + + /** + * {@inheritDoc} + * + * @author jayant + */ + @Override + protected IProperty[] getAffectedOptions(EObject semanticElem) { + if (semanticElem instanceof ActorContainerClass + || semanticElem instanceof StateGraph) + return new IProperty[] { LayoutOptions.DIAGRAM_TYPE }; + + return null; + } + + /** + * {@inheritDoc} + * + * @author jayant + */ + @Override + protected Object getSemanticValue(EObject semanticElem, + LayoutOptionData layoutOption) { + if (layoutOption.getId().equals(LayoutOptions.DIAGRAM_TYPE.getId())) { + if (semanticElem instanceof ActorContainerClass) + return STRUCTURE_DAGRAM_TYPE; + else if (semanticElem instanceof StateGraph) + return BEHAVIOR_DAGRAM_TYPE; + else + return "de.cau.cs.kieler.layout.diagrams.general"; + } + + return null; + } + + /** + * {@inheritDoc} + * + * @author jayant + */ + @Override + protected void setSemanticValue(EObject semanticElem, + LayoutOptionData layoutOption, Object value) { + // not supported by this layout configuration + } + +} diff --git a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureDiagramLayoutManager.java b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureDiagramLayoutManager.java new file mode 100644 index 000000000..47121beae --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureDiagramLayoutManager.java @@ -0,0 +1,202 @@ +/******************************************************************************* + * 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: + * Jayant Gupta (initial contribution) + * + *******************************************************************************/ +package org.eclipse.etrice.ui.layout; + +import org.eclipse.draw2d.geometry.Dimension; +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.InterfaceItem; +import org.eclipse.etrice.core.room.Port; +import org.eclipse.etrice.core.room.SAPoint; +import org.eclipse.etrice.core.room.SPPRef; +import org.eclipse.etrice.core.room.SPPoint; +import org.eclipse.etrice.ui.structure.editor.StructureEditor; +import org.eclipse.etrice.ui.structure.support.ActorContainerRefSupport; +import org.eclipse.graphiti.mm.pictograms.Anchor; +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.ui.internal.parts.IPictogramElementEditPart; + +import de.cau.cs.kieler.core.kgraph.KNode; +import de.cau.cs.kieler.kiml.graphiti.KimlGraphitiUtil; +import de.cau.cs.kieler.kiml.ui.diagram.LayoutMapping; +import de.cau.cs.kieler.kiml.util.KimlUtil; + +/** + * Layout Manager implementation for eTrice Structure Editor. + * + * @author jayant + */ +@SuppressWarnings("restriction") +public class StructureDiagramLayoutManager extends ETriceDiagramLayoutManager { + + /** + * {@inheritDoc} + * + * @author jayant + */ + @Override + public boolean supports(final Object object) { + + return object instanceof StructureEditor + || object instanceof IPictogramElementEditPart + || object instanceof PictogramElement; + + } + + /** + * {@inheritDoc} + * + * @author jayant + */ + @Override + protected void buildLayoutGraphForBoundingBox( + LayoutMapping mapping, Diagram diagram, + KNode diagramNode, boolean onlyVisible) { + + for (Shape boundingBox : ((Diagram) diagram).getChildren()) { + if (boundingBox.isVisible()) { + buildAllLevels(mapping, boundingBox, diagramNode); + break; + } + } + } + + @Override + protected Dimension getDefaultSize(Shape shape) { + + Dimension defaultSize = new Dimension(); + + // This code sets the same minimal default size for both Actor Class and + // Actor Container Refs + defaultSize.setSize(ActorContainerRefSupport.MIN_SIZE_X, + ActorContainerRefSupport.MIN_SIZE_Y); + + /* + * This code sets default size differently for Actor Class and Actor + * Container Refs. This keeps the top-level container quite large on + * layout(according to the default size in StructureSupport), which + * might not seem so pleasant. + */ + /* + EObject modelObject = shape.getLink().getBusinessObjects().get(0); + if (modelObject instanceof ActorClass) { + defaultSize.setSize(StructureClassSupport.DEFAULT_SIZE_X, + StructureClassSupport.DEFAULT_SIZE_Y); + } else if (modelObject instanceof ActorContainerRef) { + defaultSize.setSize(ActorContainerRefSupport.MIN_SIZE_X, + ActorContainerRefSupport.MIN_SIZE_Y); + } else { + defaultSize.setSize(20, 20); + }*/ + + return defaultSize; + } + + /** + * {@inheritDoc} + * + * @author jayant + */ + @Override + protected KNode createNode(final LayoutMapping mapping, + final KNode parentNode, final Shape shape) { + KNode node = KimlUtil.createInitializedNode(); + node.setParent(parentNode); + + setCurrentPositionAndSize(mapping, parentNode, node, shape); + + mapping.getGraphMap().put(node, shape); + + // gather all connections connected to Internal ports in the diagram. + // It is of no use to ActorRefs as they do-not possess direct + // connection(They have all connections via port). + for (Anchor anchor : shape.getAnchors()) { + mapping.getProperty(KimlGraphitiUtil.CONNECTIONS).addAll( + anchor.getOutgoingConnections()); + } + + return node; + } + + /** + * {@inheritDoc} + * + * @author jayant + */ + @Override + public boolean isBoundaryPort(Shape shape) { + EObject modelObject = shape.getLink().getBusinessObjects().get(0); + if ((modelObject instanceof InterfaceItem && !isInternal((InterfaceItem) modelObject)) + || modelObject instanceof SPPoint + || modelObject instanceof SAPoint) + return true; + + return false; + } + + /** + * {@inheritDoc} + * + * @author jayant + */ + @Override + public boolean isInternalPort(Shape shape) { + EObject modelObject = shape.getLink().getBusinessObjects().get(0); + + if ((modelObject instanceof InterfaceItem && isInternal((InterfaceItem) modelObject))) + return true; + + return false; + } + + /* + * This method has been derived from + * org.eclipse.eTrice.ui.structure.InterfaceItem.FeatureProvider + */ + private static boolean isInternal(InterfaceItem item) { + if (item instanceof Port) { + Port port = (Port) item; + + // NB: the port's container might be a base class of the depicted + // actor class + ActorContainerClass acc = (ActorContainerClass) port.eContainer(); + if (acc instanceof ActorClass) { + ActorClass ac = (ActorClass) acc; + if (ac.getIntPorts().contains(port)) + return true; + } + } else if (item instanceof SPPRef) { + return false; + } else { + assert (false) : "unexpected sub type"; + } + + return false; + } + + /** + * {@inheritDoc} + * + * @author jayant + */ + @Override + public boolean isTopLevelBoundingBox(Shape shape) { + EObject modelObject = shape.getLink().getBusinessObjects().get(0); + if (modelObject instanceof ActorClass) + return true; + + return false; + } + +} diff --git a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureDiagramLayoutmanager.java b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureDiagramLayoutmanager.java deleted file mode 100644 index 63a1976bf..000000000 --- a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureDiagramLayoutmanager.java +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - * 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: - * Jayant Gupta (initial contribution) - * - *******************************************************************************/ -package org.eclipse.etrice.ui.layout; - -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.InterfaceItem; -import org.eclipse.etrice.core.room.Port; -import org.eclipse.etrice.core.room.SAPoint; -import org.eclipse.etrice.core.room.SPPRef; -import org.eclipse.etrice.core.room.SPPoint; -import org.eclipse.etrice.ui.structure.editor.StructureEditor; -import org.eclipse.etrice.ui.structure.support.ActorContainerRefSupport; -import org.eclipse.graphiti.mm.pictograms.Anchor; -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.ui.internal.parts.IPictogramElementEditPart; - -import de.cau.cs.kieler.core.kgraph.KNode; -import de.cau.cs.kieler.kiml.graphiti.KimlGraphitiUtil; -import de.cau.cs.kieler.kiml.ui.diagram.LayoutMapping; -import de.cau.cs.kieler.kiml.util.KimlUtil; - -/** - * Layout Manager implementation for eTrice Structure Editor. - * - * @author jayant - */ -@SuppressWarnings("restriction") -public class StructureDiagramLayoutmanager extends ETriceDiagramLayoutManager { - - /** - * {@inheritDoc} - * - * @author jayant - */ - @Override - public boolean supports(final Object object) { - - return object instanceof StructureEditor - || object instanceof IPictogramElementEditPart - || object instanceof PictogramElement; - - } - - /** - * {@inheritDoc} - * - * @author jayant - */ - @Override - protected void buildLayoutGraphForBoundingBox( - LayoutMapping mapping, Diagram diagram, - KNode diagramNode, boolean onlyVisible) { - - for (Shape boundingBox : ((Diagram) diagram).getChildren()) { - if (boundingBox.isVisible()) { - buildAllLevels(mapping, boundingBox, diagramNode); - break; - } - } - } - - @Override - protected Size getDefaultSize(Shape shape) { - Size defaultSize = new Size(); - - // This code sets same minimal default size for both Actor Class and - // Actor Container Ref - defaultSize.setHeight(ActorContainerRefSupport.MIN_SIZE_Y); - defaultSize.setWidth(ActorContainerRefSupport.MIN_SIZE_X); - - - /* - * This code sets default size differently for Actor Class and Actor Container - * Refs. This keeps the top-level container quite large on layout, which - * might not seem so pleasant, but is more closer to the model. - */ - /* - EObject modelObject = shape.getLink().getBusinessObjects().get(0); - if (modelObject instanceof ActorClass) { - defaultSize.setHeight(StructureClassSupport.DEFAULT_SIZE_Y); - defaultSize.setWidth(StructureClassSupport.DEFAULT_SIZE_X); - } else if (modelObject instanceof ActorContainerRef) { - defaultSize.setHeight(ActorContainerRefSupport.MIN_SIZE_Y); - defaultSize.setWidth(ActorContainerRefSupport.MIN_SIZE_X); - } else { - defaultSize.setHeight(MIN_HEIGHT); - defaultSize.setWidth(MIN_WIDHT); - }*/ - - return defaultSize; - } - - /** - * {@inheritDoc} - * - * @author jayant - */ - @Override - protected KNode createNode(final LayoutMapping mapping, - final KNode parentNode, final Shape shape) { - KNode node = KimlUtil.createInitializedNode(); - node.setParent(parentNode); - - setCurrentPositionAndSize(mapping, parentNode, node, shape); - - mapping.getGraphMap().put(node, shape); - - // gather all connections connected to Internal ports in the diagram. - // It is of no use to ActorRefs as they do-not possess direct - // connection(They have all connections via port). - for (Anchor anchor : shape.getAnchors()) { - mapping.getProperty(KimlGraphitiUtil.CONNECTIONS).addAll( - anchor.getOutgoingConnections()); - } - - return node; - } - - /** - * {@inheritDoc} - * - * @author jayant - */ - @Override - public boolean isBoundaryPort(Shape shape) { - EObject modelObject = shape.getLink().getBusinessObjects().get(0); - if ((modelObject instanceof InterfaceItem && !isInternal((InterfaceItem) modelObject)) - || modelObject instanceof SPPoint - || modelObject instanceof SAPoint) - return true; - - return false; - } - - /** - * {@inheritDoc} - * - * @author jayant - */ - @Override - public boolean isInternalPort(Shape shape) { - EObject modelObject = shape.getLink().getBusinessObjects().get(0); - - if ((modelObject instanceof InterfaceItem && isInternal((InterfaceItem) modelObject))) - return true; - - return false; - } - - /* - * This method has been derived from - * org.eclipse.eTrice.ui.structure.InterfaceItem.FeatureProvider - */ - private static boolean isInternal(InterfaceItem item) { - if (item instanceof Port) { - Port port = (Port) item; - - // NB: the port's container might be a base class of the depicted - // actor class - ActorContainerClass acc = (ActorContainerClass) port.eContainer(); - if (acc instanceof ActorClass) { - ActorClass ac = (ActorClass) acc; - if (ac.getIntPorts().contains(port)) - return true; - } - } else if (item instanceof SPPRef) { - return false; - } else { - assert (false) : "unexpected sub type"; - } - - return false; - } - - /** - * {@inheritDoc} - * - * @author jayant - */ - @Override - public boolean isTopLevelBoundingBox(Shape shape) { - EObject modelObject = shape.getLink().getBusinessObjects().get(0); - if (modelObject instanceof ActorClass) - return true; - - return false; - } - -} diff --git a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureLayoutCommand.java b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureLayoutCommand.java index f3f4dde40..9955e58f1 100644 --- a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureLayoutCommand.java +++ b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureLayoutCommand.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * 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: + * Jayant Gupta (initial contribution) + * + *******************************************************************************/ package org.eclipse.etrice.ui.layout; import org.eclipse.emf.ecore.EObject; @@ -19,6 +29,12 @@ import org.eclipse.graphiti.services.IGaService; import de.cau.cs.kieler.core.kgraph.KNode; import de.cau.cs.kieler.core.kgraph.KPort; +/** + * A command for applying the result of automatic layout to diagram elements in + * eTrice Structure Editor. + * + * @author jayant + */ public class StructureLayoutCommand extends ETriceLayoutCommand { public StructureLayoutCommand(TransactionalEditingDomain domain, @@ -79,11 +95,12 @@ public class StructureLayoutCommand extends ETriceLayoutCommand { */ private static void adjustLabelForPort(ContainerShape shape) { GraphicsAlgorithm ga = shape.getGraphicsAlgorithm(); - EObject boContainer = shape.getContainer().getLink().getBusinessObjects().get(0); + EObject boContainer = shape.getContainer().getLink() + .getBusinessObjects().get(0); // First make sure that the shape corresponds to a Port EObject bo = shape.getLink().getBusinessObjects().get(0); - if ( bo instanceof InterfaceItem) { + if (bo instanceof InterfaceItem) { // margin and size for bounding box (ActorClass ) int margin = InterfaceItemSupport.MARGIN; int size = InterfaceItemSupport.ITEM_SIZE; -- cgit v1.2.3