001: package org.enhydra.jawe.components.graph;
002:
003: import java.awt.Point;
004: import java.util.Enumeration;
005: import java.util.HashSet;
006: import java.util.Iterator;
007: import java.util.Set;
008:
009: import org.enhydra.jawe.ResourceManager;
010: import org.enhydra.shark.xpdl.XMLComplexElement;
011: import org.enhydra.shark.xpdl.elements.ExtendedAttribute;
012:
013: /**
014: * Used to define End object.
015: * @author Sasa Bojanic
016: */
017: public class DefaultGraphBubbleActivity extends
018: GraphBubbleActivityInterface {
019:
020: protected boolean isStart;
021: protected String type;
022:
023: /**
024: * Creates End with given userObject.
025: */
026: public DefaultGraphBubbleActivity(ExtendedAttribute ea) {
027: setUserObject(ea);
028: StartEndDescription sed = getStartEndDescription();
029: isStart = sed.isStart();
030: type = sed.getType();
031: addPort();
032: }
033:
034: protected void addPort() {
035: // Create Port
036: // Floating Center Port (Child 0 is Default)
037: GraphPortInterface port = GraphUtilities.getGraphController()
038: .getGraphObjectFactory().createPort("Center",
039: GraphEAConstants.PORT_TYPE_DEFAULT);
040: add(port);
041: }
042:
043: public String getType() {
044: return type;
045: }
046:
047: public boolean isStart() {
048: return isStart;
049: }
050:
051: public StartEndDescription getStartEndDescription() {
052: return new StartEndDescription((ExtendedAttribute) userObject);
053: }
054:
055: /**
056: * Gets the port associate with this activity.
057: */
058: public GraphPortInterface getPort() {
059: for (Enumeration e = children(); e.hasMoreElements();) {
060: Object child = e.nextElement();
061: if (child instanceof GraphPortInterface) {
062: return (GraphPortInterface) child;
063: }
064: }
065: return null;
066: }
067:
068: public XMLComplexElement getPropertyObject() {
069: if (userObject instanceof XMLComplexElement) {//Harald Meister: fixes a rare bug
070: return (XMLComplexElement) userObject;
071: }
072: return null;//Harald Meister
073: }
074:
075: /**
076: * Gets a tooltip text for activity.
077: */
078: public String getTooltip() {
079: return "";
080: }
081:
082: /**
083: * Returns <code>true</code> if End is a valid target for transition.
084: * This depends if there is any transition already connected to it.
085: */
086: public boolean acceptsTarget() {
087: if (isStart()) {
088: return false;
089: }
090: if (getReferencingActivities().size() < 1) {
091: return true;
092: }
093: return false;
094: }
095:
096: public boolean acceptsSource() {
097: if (isStart()) {
098: if (getReferencedActivities().size() < 1) {
099: return true;
100: }
101: return false;
102: }
103: return false;
104: }
105:
106: /**
107: *
108: */
109: public String toString() {
110: String toRet = ResourceManager
111: .getLanguageDependentString("EndKey");
112: if (isStart()) {
113: toRet = ResourceManager
114: .getLanguageDependentString("StartKey");
115: }
116: if (toRet != null) {
117: return toRet;
118: }
119: return "";
120: }
121:
122: /**
123: * Create a clone of the cell. The cloning of the
124: * user object is deferred to the cloneUserObject()
125: * method.
126: * NOTE: this original method of DefaultGraphCell is
127: * modified to retain synchronization of userObject and
128: * value attribute from attribute map when model
129: * is attribute store
130: *
131: * @return Object a clone of this object.
132: */
133: public Object clone() {
134: DefaultGraphBubbleActivity c = (DefaultGraphBubbleActivity) super
135: .clone();
136: c.setUserObject(c.userObject);
137: return c;
138: }
139:
140: /**
141: * Create a clone of the ActivityProperties object.
142: * @return Object a clone of this activity property object.
143: */
144: protected Object cloneUserObject() {
145: return ((ExtendedAttribute) userObject).clone();
146: }
147:
148: /**
149: * Gets all activities that reference this one.
150: */
151: public Set getReferencingActivities() {
152: Set referencingActivities = new HashSet();
153: for (Iterator i = getPort().edges(); i.hasNext();) {
154: GraphTransitionInterface l = (GraphTransitionInterface) i
155: .next();
156: Object target = ((GraphPortInterface) (l.getTarget()))
157: .getParent();
158: if (this == target) {
159: referencingActivities.add(((GraphPortInterface) (l
160: .getSource())).getParent());
161: }
162: }
163: return referencingActivities;
164: }
165:
166: /**
167: * Gets all activities that this activity references.
168: */
169: public Set getReferencedActivities() {
170: Set referencedActivities = new HashSet();
171: for (Iterator i = getPort().edges(); i.hasNext();) {
172: GraphTransitionInterface l = (GraphTransitionInterface) i
173: .next();
174: Object source = ((GraphPortInterface) (l.getSource()))
175: .getParent();
176: if (this == source) {
177: referencedActivities.add(((GraphPortInterface) (l
178: .getTarget())).getParent());
179: }
180: }
181: return referencedActivities;
182: }
183:
184: public Point getOffset() {
185: return getStartEndDescription().getOffset();
186: }
187:
188: }
|