KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > designer > editor > ConditionEditor


1 package com.opensymphony.workflow.designer.editor;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import com.opensymphony.workflow.designer.WorkflowCell;
7 import com.opensymphony.workflow.designer.WorkflowGraphModel;
8 import com.opensymphony.workflow.designer.spi.ConditionPlugin;
9 import com.opensymphony.workflow.designer.spi.DefaultConditionPlugin;
10 import com.opensymphony.workflow.loader.AbstractDescriptor;
11 import com.opensymphony.workflow.loader.ConditionDescriptor;
12 import com.opensymphony.workflow.loader.ConfigConditionDescriptor;
13
14 /**
15  * @author baab
16  */

17 public abstract class ConditionEditor
18 {
19   protected WorkflowCell cell;
20   protected WorkflowGraphModel model;
21
22   public ConditionEditor(WorkflowCell cell)
23   {
24     this.cell = cell;
25   }
26
27   public WorkflowGraphModel getModel()
28   {
29     return model;
30   }
31
32   public void setModel(WorkflowGraphModel model)
33   {
34     this.model = model;
35   }
36
37   public ConditionDescriptor add()
38   {
39     ConfigConditionDescriptor condition = getCondition();
40     if(condition == null)
41     {
42       return null;
43     }
44
45     condition = editCondition(condition);
46
47     if(condition != null)
48     {
49       ConditionDescriptor cond = new ConditionDescriptor();
50       // cond.setId(0);
51
// cond.setNegate(false);
52
cond.setParent(getParent());
53       cond.setType(condition.getType());
54       cond.setName(condition.getName());
55       cond.getArgs().putAll(condition.getArgs());
56
57       return cond;
58     }
59     else
60     {
61       return null;
62     }
63
64   }
65
66   public void modify(ConditionDescriptor cond)
67   {
68     ConfigConditionDescriptor condition;
69
70     if(cond.getName() != null)
71     {
72         condition = new ConfigConditionDescriptor(getConfigDescriptor(cond));
73     }
74     else
75     {
76       condition = new ConfigConditionDescriptor(getModel().getPalette());
77       condition.setType(cond.getType());
78     }
79
80     condition.getArgs().putAll(cond.getArgs());
81
82     condition = editCondition(condition);
83
84     if(condition != null)
85     {
86       cond.getArgs().putAll(condition.getArgs());
87     }
88   }
89
90     protected abstract ConfigConditionDescriptor getConfigDescriptor(ConditionDescriptor cond);
91
92     private ConfigConditionDescriptor editCondition(ConfigConditionDescriptor config)
93   {
94     // get plugin
95
String JavaDoc clazz = config.getPlugin();
96     if(clazz == null || clazz.length() == 0)
97     {
98       clazz = "com.opensymphony.workflow.designer.spi.DefaultConditionPlugin";
99     }
100     ConditionPlugin condImpl;
101     try
102     {
103       condImpl = (ConditionPlugin)Class.forName(clazz).newInstance();
104     }
105     catch(Exception JavaDoc e1)
106     {
107       e1.printStackTrace();
108       condImpl = new DefaultConditionPlugin();
109     }
110
111     condImpl.setCondition(config);
112
113     // put the parameter
114
Map JavaDoc args = new HashMap JavaDoc();
115     args.put("cell", cell);
116
117     if(!condImpl.editCondition(args))
118     {
119       // cancel
120
return null;
121     }
122     config = condImpl.getCondition();
123     return config;
124   }
125
126   abstract protected AbstractDescriptor getParent();
127
128   abstract protected ConfigConditionDescriptor getCondition();
129 }
130
Popular Tags