From 1c6214fc5ed257ea123814bae0c6e7cf7442da79 Mon Sep 17 00:00:00 2001 From: maroni Date: Sun, 4 Dec 2011 17:02:14 -0200 Subject: [PATCH] --- .gitignore | 3 +- .../org/ufcspa/simdecs/diagram/DiagramManager.java | 53 ++++++++++++++----- .../org/ufcspa/simdecs/diagram/elements/Empty.java | 56 ++++++++++++++++++++ .../org/ufcspa/simdecs/diagram/elements/Node.java | 14 +++++- .../ufcspa/simdecs/diagram/elements/SwimLane.java | 4 +- .../org/ufcspa/simdecs/diagram/mb/EditNode.java | 3 +- web/editDiagram.xhtml | 4 +- 7 files changed, 118 insertions(+), 19 deletions(-) create mode 100644 src/java/org/ufcspa/simdecs/diagram/elements/Empty.java diff --git a/.gitignore b/.gitignore index 3197301..abc3c57 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /build/ -/nbproject/private/ \ No newline at end of file +/nbproject/private/ +/dist/ \ No newline at end of file diff --git a/src/java/org/ufcspa/simdecs/diagram/DiagramManager.java b/src/java/org/ufcspa/simdecs/diagram/DiagramManager.java index ff3eb27..592956f 100755 --- a/src/java/org/ufcspa/simdecs/diagram/DiagramManager.java +++ b/src/java/org/ufcspa/simdecs/diagram/DiagramManager.java @@ -4,10 +4,9 @@ */ package org.ufcspa.simdecs.diagram; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.TreeMap; +import java.util.LinkedList; +import org.ufcspa.simdecs.diagram.elements.Empty; +import org.ufcspa.simdecs.diagram.elements.Node; import org.ufcspa.simdecs.diagram.elements.SwimLane; /** @@ -17,19 +16,25 @@ import org.ufcspa.simdecs.diagram.elements.SwimLane; public class DiagramManager { private String diagramName; - private Map swimLanes; - + private LinkedList swimLanes; + public DiagramManager(String diagramName) { this.diagramName = diagramName; - swimLanes = new TreeMap(); + swimLanes = new LinkedList(); } public void addSwimLane(SwimLane swimLane) { - swimLanes.put(swimLane.getId(), swimLane); + if (!swimLanes.isEmpty()) { + while(swimLane.getNodes().size() < swimLanes.getFirst().getNodes().size()) { + swimLane.addNode(new Empty(swimLane.getMessageBundle(), swimLane.getLocale())); + } + } + + swimLanes.add(swimLane); } public final void clear() { - swimLanes = new HashMap(); + swimLanes = new LinkedList(); } public String getDiagramName() { @@ -40,15 +45,37 @@ public class DiagramManager { this.diagramName = diagramName; } - public ArrayList getSwimLanes() { - return new ArrayList(swimLanes.values()); + public LinkedList getSwimLanes() { + return swimLanes; } public SwimLane getSwimLane(String id) { - return swimLanes.get(id); + for(SwimLane swimLane : swimLanes) { + if (swimLane.getId().equals(id)) + return swimLane; + } + + return null; } public void removeSwimLane(String id) { - swimLanes.remove(id); + for(SwimLane swimLane : swimLanes) { + if (swimLane.getId().equals(id)) + swimLanes.remove(swimLane); + } } + + public void addNode(SwimLane swimLane, Node node) { + swimLane.addNode(node); + for(SwimLane sl : swimLanes) { + if (!sl.equals(swimLane)) { + if (sl.getNodes().size() < swimLane.getNodes().size()) { + while(sl.getNodes().size() < swimLane.getNodes().size()) { + sl.addNode(new Empty(swimLane.getMessageBundle(), swimLane.getLocale())); + } + } + } + } + } + } diff --git a/src/java/org/ufcspa/simdecs/diagram/elements/Empty.java b/src/java/org/ufcspa/simdecs/diagram/elements/Empty.java new file mode 100644 index 0000000..d3303e2 --- /dev/null +++ b/src/java/org/ufcspa/simdecs/diagram/elements/Empty.java @@ -0,0 +1,56 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.ufcspa.simdecs.diagram.elements; + +import java.util.List; +import java.util.Locale; + +/** + * + * @author maroni + */ +public class Empty extends Node { + + public Empty(String messageBundle, Locale locale) { + super(messageBundle, locale); + } + + @Override + public List getGrantedPrevious() { + return null; + } + + @Override + public List getGrantedSwimLanes() { + return null; + } + + @Override + public String getImage() { + return null; + } + + @Override + public String getImageWithLink() { + return null; + } + + @Override + public String getName() { + return ""; + } + + @Override + public boolean isFirst() { + return false; + } + + @Override + public boolean isInternal() { + return true; + } + + +} diff --git a/src/java/org/ufcspa/simdecs/diagram/elements/Node.java b/src/java/org/ufcspa/simdecs/diagram/elements/Node.java index 5b410e8..8c6798b 100755 --- a/src/java/org/ufcspa/simdecs/diagram/elements/Node.java +++ b/src/java/org/ufcspa/simdecs/diagram/elements/Node.java @@ -2,16 +2,20 @@ package org.ufcspa.simdecs.diagram.elements; import java.util.List; import java.util.Locale; -import javax.print.attribute.Size2DSyntax; public abstract class Node extends Element { private String currentImage; + private int position; public Node(String messageBundle, Locale locale) { super(messageBundle, locale); } + public boolean isInternal() { + return false; + } + public abstract String getImage(); public abstract String getImageWithLink(); public abstract List getGrantedPrevious(); @@ -44,5 +48,13 @@ public abstract class Node extends Element { public void setCurrentImage(String currentImage) { this.currentImage = currentImage; } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } } diff --git a/src/java/org/ufcspa/simdecs/diagram/elements/SwimLane.java b/src/java/org/ufcspa/simdecs/diagram/elements/SwimLane.java index af6b347..c6097c7 100755 --- a/src/java/org/ufcspa/simdecs/diagram/elements/SwimLane.java +++ b/src/java/org/ufcspa/simdecs/diagram/elements/SwimLane.java @@ -85,8 +85,10 @@ public abstract class SwimLane extends Element { } public void addNode(Node node) { - if (!nodes.contains(node)) + if (!nodes.contains(node)) { + node.setPosition(nodes.size()+1); nodes.addLast(node); + } updateImages(); } diff --git a/src/java/org/ufcspa/simdecs/diagram/mb/EditNode.java b/src/java/org/ufcspa/simdecs/diagram/mb/EditNode.java index 505cd9e..ce68b79 100644 --- a/src/java/org/ufcspa/simdecs/diagram/mb/EditNode.java +++ b/src/java/org/ufcspa/simdecs/diagram/mb/EditNode.java @@ -20,6 +20,7 @@ import org.primefaces.component.menu.Menu; import org.primefaces.component.menuitem.MenuItem; import org.primefaces.model.DefaultMenuModel; import org.primefaces.model.MenuModel; +import org.ufcspa.simdecs.diagram.DiagramManager; import org.ufcspa.simdecs.diagram.elements.Node; import org.ufcspa.simdecs.diagram.elements.NodeElement; import org.ufcspa.simdecs.diagram.elements.NodeTextProperty; @@ -137,7 +138,7 @@ public class EditNode extends DefaultManagedBean { acessor.invoke(node, property.getValue()); } - currentSwimLane.addNode(node); + getEditDiagram().getDiagramManager().addNode(currentSwimLane, node); } diff --git a/web/editDiagram.xhtml b/web/editDiagram.xhtml index 9a95440..2f5c456 100755 --- a/web/editDiagram.xhtml +++ b/web/editDiagram.xhtml @@ -53,8 +53,8 @@ - - + + -- 1.7.6.4