01: package org.drools.eclipse.editors.rete.model;
02:
03: import java.util.ArrayList;
04: import java.util.Iterator;
05: import java.util.List;
06:
07: import org.drools.reteoo.BaseVertex;
08:
09: /**
10: * Rete graph containing a set of vertices that form the graph itself.
11: */
12: public class ReteGraph extends ModelElement {
13:
14: /** Property ID to use when a child is added to this diagram. */
15: public static final String PROP_CHILD_ADDED = "ReteGraph.ChildAdded";
16:
17: /** Property ID to use when a child is removed from this diagram. */
18: public static final String PROP_CHILD_REMOVED = "ReteGraph.ChildRemoved";
19:
20: private List vertices = new ArrayList();
21:
22: /**
23: * Add new BaseVertex to the graph
24: *
25: * @param vertex
26: *
27: * @return true, if vertex was added, false otherwise
28: */
29: public boolean addChild(BaseVertex vertex) {
30: if (vertex != null && vertices.add(vertex)) {
31: firePropertyChange(PROP_CHILD_ADDED, null, vertex);
32: return true;
33: }
34: return false;
35: }
36:
37: /**
38: * Return all Vertices in this graph
39: */
40: public List getChildren() {
41: return vertices;
42: }
43:
44: /**
45: * Remove a vertex from this graph
46: *
47: * @param vertex vertex to be removed
48: * @return true, if the vertex removal succeeded, false otherwise
49: */
50: public boolean removeChild(BaseVertex vertex) {
51: if (vertex != null && vertices.remove(vertex)) {
52: firePropertyChange(PROP_CHILD_REMOVED, null, vertex);
53: return true;
54: }
55: return false;
56: }
57:
58: /**
59: * Removes all vertices from graph.
60: */
61: public void removeAll() {
62: while (vertices.size() > 0) {
63: removeChild(((BaseVertex) vertices.get(0)));
64: }
65: }
66:
67: public void addAll(List children) {
68: final Iterator iter = children.iterator();
69: while (iter.hasNext()) {
70: BaseVertex vertex = (BaseVertex) iter.next();
71: addChild(vertex);
72: }
73: }
74:
75: }
|