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.JaWEManager;
010: import org.enhydra.jawe.base.tooltip.TooltipGenerator;
011: import org.enhydra.shark.xpdl.XMLComplexElement;
012: import org.enhydra.shark.xpdl.elements.Activity;
013:
014: /**
015: * Used to define Activity object in graph and to modify it's
016: * properties.
017: *
018: * @author Sasa Bojanic
019: */
020: public class DefaultGraphActivity extends GraphActivityInterface {
021:
022: /**
023: * Creates activity with given userObject. Also creates default port
024: * for holding activity transitions.
025: */
026: public DefaultGraphActivity(Activity act) {
027: setUserObject(act);
028: addPort();
029: }
030:
031: protected void addPort() {
032: // Create Port
033: // Floating Center Port (Child 0 is Default)
034: GraphPortInterface port = GraphUtilities.getGraphController()
035: .getGraphObjectFactory().createPort("Center",
036: GraphEAConstants.PORT_TYPE_DEFAULT);
037: add(port);
038: }
039:
040: public String getType() {
041: return JaWEManager.getInstance().getJaWEController()
042: .getTypeResolver().getJaWEType((Activity) userObject)
043: .getTypeId();
044: }
045:
046: /**
047: * Gets the port associate with this activity.
048: */
049: public GraphPortInterface getPort() {
050: for (Enumeration e = children(); e.hasMoreElements();) {
051: Object child = e.nextElement();
052: if (child instanceof GraphPortInterface) {
053: return (GraphPortInterface) child;
054: }
055: }
056: return null;
057: }
058:
059: /**
060: * Returns <code>true</code> if Activity is a valid source for transition.
061: * This depends of activitie's type property, it can accept to be a
062: * source for transition if it is a normal or starting.
063: */
064: public boolean acceptsSource() {
065: return true;
066: }
067:
068: /**
069: * Returns <code>true</code> if Activity is a valid target for transition.
070: * This depends of activitie's type property, it can accept to be a
071: * target for for transition if it is a normal or ending.
072: */
073: public boolean acceptsTarget() {
074: return true;
075: }
076:
077: public XMLComplexElement getPropertyObject() {
078: if (userObject instanceof XMLComplexElement) {//Harald Meister: fixes a rare bug
079: return (XMLComplexElement) userObject;
080: }
081: return null;//Harald Meister
082: }
083:
084: /**
085: * Gets a tooltip text for activity.
086: */
087: public String getTooltip() {
088: TooltipGenerator ttg = JaWEManager.getInstance()
089: .getTooltipGenerator();
090: if (userObject != null && ttg != null) {
091: return ttg.getTooltip(getPropertyObject());
092: }
093: return "";
094: }
095:
096: /**
097: * Gets an activity "display name" property.
098: */
099: public String toString() {
100: String name = null;
101: if (userObject != null) {
102: name = getPropertyObject().get("Name").toValue();
103: if (name.equals("")) {
104: name = getPropertyObject().get("Id").toValue();
105: }
106: }
107: return name;
108: }
109:
110: /**
111: * Create a clone of the cell. The cloning of the
112: * user object is deferred to the cloneUserObject()
113: * method.
114: * NOTE: this original method of DefaultGraphCell is
115: * modified to retain synchronization of userObject and
116: * value attribute from attribute map when model
117: * is attribute store
118: *
119: * @return Object a clone of this object.
120: */
121: public Object clone() {
122: DefaultGraphActivity c = (DefaultGraphActivity) super .clone();
123: c.setUserObject(c.userObject);
124: return c;
125: }
126:
127: /**
128: * Create a clone of the ActivityProperties object.
129: * @return Object a clone of this activity property object.
130: */
131: protected Object cloneUserObject() {
132: return ((Activity) userObject).clone();
133: }
134:
135: /**
136: * Gets all activities that reference this one.
137: */
138: public Set getReferencingActivities() {
139: Set referencingActivities = new HashSet();
140: for (Iterator i = getPort().edges(); i.hasNext();) {
141: GraphTransitionInterface l = (GraphTransitionInterface) i
142: .next();
143: GraphActivityInterface target = ((GraphPortInterface) l
144: .getTarget()).getActivity();
145: if (this == target) {
146: referencingActivities.add(((GraphPortInterface) l
147: .getSource()).getActivity());
148: }
149: }
150: return referencingActivities;
151: }
152:
153: /**
154: * Gets all activities that this activity references.
155: */
156: public Set getReferencedActivities() {
157: Set referencedActivities = new HashSet();
158: for (Iterator i = getPort().edges(); i.hasNext();) {
159: GraphTransitionInterface l = (GraphTransitionInterface) i
160: .next();
161: GraphActivityInterface source = ((GraphPortInterface) l
162: .getSource()).getActivity();
163: if (this == source) {
164: referencedActivities.add(((GraphPortInterface) l
165: .getTarget()).getActivity());
166: }
167: }
168: return referencedActivities;
169: }
170:
171: public Point getOffset() {
172: return GraphUtilities.getOffsetPoint((Activity) userObject);
173: }
174:
175: }
|