01: package com.opensymphony.workflow.designer;
02:
03: import java.util.Iterator;
04: import java.util.List;
05:
06: import com.opensymphony.workflow.loader.ActionDescriptor;
07: import com.opensymphony.workflow.loader.ConditionalResultDescriptor;
08: import com.opensymphony.workflow.loader.ResultDescriptor;
09: import com.opensymphony.workflow.loader.StepDescriptor;
10: import org.jgraph.graph.GraphConstants;
11:
12: public class StepCell extends WorkflowCell implements ResultAware {
13: private StepDescriptor descriptor;
14:
15: // Construct Cell for Userobject
16: public StepCell(StepDescriptor userObject) {
17: super (userObject);
18: setAttributes(new WorkflowAttributeMap(getAttributes()));
19: GraphConstants.setEditable(attributes, true);
20: descriptor = userObject;
21: id = descriptor.getId();
22: name = descriptor.getName();
23: }
24:
25: public String toString() {
26: return descriptor.getName();
27: }
28:
29: public String getName() {
30: return descriptor.getName();
31: }
32:
33: public StepDescriptor getDescriptor() {
34: return descriptor;
35: }
36:
37: public boolean removeResult(ResultDescriptor result) {
38: Iterator iter = descriptor.getActions().iterator();
39: boolean removed = false;
40: while (iter.hasNext()) {
41: ActionDescriptor action = (ActionDescriptor) iter.next();
42: if (result instanceof ConditionalResultDescriptor) {
43: List list = action.getConditionalResults();
44: if (list != null) {
45: for (int i = 0; i < list.size(); i++) {
46: if (list.get(i) == result) {
47: list.remove(i);
48: if (action.getUnconditionalResult() == null) {
49: iter.remove();
50: }
51: removed = true;
52: }
53: }
54: }
55: } else {
56: if (action.getUnconditionalResult() == result) {
57: action.setUnconditionalResult(null);
58: if (action.getConditionalResults().size() == 0) {
59: iter.remove();
60: }
61: removed = true;
62: }
63: }
64: }
65: if (descriptor.getActions().size() == 0
66: && descriptor.getCommonActions().size() == 0) {
67: descriptor.removeActions();
68: }
69: return removed;
70: }
71: }
|