KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > client > grapheditor > WFWindowManager


1 package hero.client.grapheditor;
2
3 /**
4  * WFWindowManager.java
5  *
6  *
7  * Created: Mon Aug 12 12:02:44 2002
8  *
9  * @version 1.0
10  */

11
12 import java.awt.*;
13 import java.util.*;
14
15 import hero.net.ProjectSession.StrutsNodeValue;
16 import hero.interfaces.Constants;
17 import javax.swing.JComboBox JavaDoc;
18 import javax.swing.JFrame JavaDoc;
19 import javax.swing.JLabel JavaDoc;
20 import javax.swing.JOptionPane JavaDoc;
21 import javax.swing.JPanel JavaDoc;
22 import javax.swing.JScrollPane JavaDoc;
23 import javax.swing.JTextField JavaDoc;
24 import javax.swing.JTextArea JavaDoc;
25 import javax.swing.SwingConstants JavaDoc;
26 import java.text.SimpleDateFormat JavaDoc;
27 import javax.swing.JCheckBox JavaDoc;
28 import javax.swing.ImageIcon JavaDoc;
29
30 public class WFWindowManager implements Constants{
31
32 static java.util.ResourceBundle JavaDoc resource = java.util.ResourceBundle.getBundle("resources.Traduction")/*#BundleType=List*/;
33
34     WFManager manager;
35     WFPersistence persistence;
36     public final static String JavaDoc imageBase = "images/";
37         public final static ImageIcon JavaDoc icon = new ImageIcon JavaDoc(Thread.currentThread().getContextClassLoader().getResource(imageBase + "icon.png"));
38
39     public String JavaDoc newProjectWindow() {
40         try {
41             JPanel JavaDoc jp = new JPanel JavaDoc();
42             ArrayList types = new ArrayList();
43             types.add("Model");
44             types.add("Cooperative");
45             JComboBox JavaDoc processTypes = new JComboBox JavaDoc(types.toArray());
46             processTypes.setSelectedItem("Model");
47             
48             JTextField JavaDoc projectName = new JTextField JavaDoc();
49             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.newproj"), SwingConstants.LEFT));
50             jp.add(projectName);
51                         
52             jp.setLayout(new GridLayout(0, 2));
53             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.choosetype"), SwingConstants.LEFT));
54             jp.add(processTypes);
55                         
56             int cloneOption =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newproj"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
57             if (cloneOption != JOptionPane.CANCEL_OPTION) {
58                 while ((projectName.getText()).equals("")
59                     && cloneOption != JOptionPane.CANCEL_OPTION) {
60                     JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.enterproj"),resource.getString("wfwindowsmanager.newproj"),JOptionPane.INFORMATION_MESSAGE, icon);
61                     cloneOption =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newproj"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
62                 }
63                 if (cloneOption != JOptionPane.CANCEL_OPTION) {
64                     boolean ok = false;
65                     if (processTypes.getSelectedItem().equals("Model"))
66                         ok =persistence.createModel(projectName.getText());
67                     else
68                         ok = persistence.createProject(projectName.getText());
69                     if (!ok) {
70                         JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.existproj"),resource.getString("wfwindowsmanager.newproj"),JOptionPane.INFORMATION_MESSAGE, icon);
71
72                     } else {
73                         manager.setTitle(projectName.getText());
74                         return projectName.getText();
75                     }
76                 }
77             }
78         } catch (Exception JavaDoc e1) {
79             JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.createerror"),resource.getString("wfwindowsmanager.newproj"),JOptionPane.INFORMATION_MESSAGE, icon);
80         }
81         return null;
82     }
83
84     public WFWindowManager(WFManager manager, WFPersistence persistence) {
85         this.manager = manager;
86         this.persistence = persistence;
87     }
88
89     public boolean cloneProjectWindow() {
90         try {
91             JPanel JavaDoc jp = new JPanel JavaDoc();
92             Object JavaDoc[] possibleValues = persistence.getProjects();
93             JComboBox JavaDoc projectNames = new JComboBox JavaDoc(possibleValues);
94             jp.setLayout(new GridLayout(0, 2));
95             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.chooseproj"), SwingConstants.LEFT));
96             jp.add(projectNames);
97
98             JTextField JavaDoc newProject = new JTextField JavaDoc("", 0);
99             jp.setLayout(new GridLayout(0, 2));
100             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.projname"), SwingConstants.LEFT));
101             jp.add(newProject);
102             
103             int cloneOption =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.cloneproj"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
104             if (cloneOption != JOptionPane.CANCEL_OPTION) {
105                 while ((newProject.getText()).equals("")
106                     && cloneOption != JOptionPane.CANCEL_OPTION) {
107                     JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.enterproj"),resource.getString("wfwindowsmanager.cloneproj"),JOptionPane.INFORMATION_MESSAGE, icon);
108                     cloneOption =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.cloneproj"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
109                 }
110                 if (cloneOption != JOptionPane.CANCEL_OPTION) {
111                     boolean ok =persistence.cloneProject((String JavaDoc) projectNames.getSelectedItem(),newProject.getText());
112                     if (!ok) {
113                         JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.existproj"),resource.getString("wfwindowsmanager.cloneproj"),JOptionPane.INFORMATION_MESSAGE, icon);
114                     } else {
115                         manager.openProject(newProject.getText());
116                         return true;
117                     }
118                 }
119             }
120         } catch (Exception JavaDoc e1) {
121             JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.cloneerror"),resource.getString("wfwindowsmanager.cloneproj"),JOptionPane.INFORMATION_MESSAGE, icon);
122         }
123         return false;
124     }
125
126     public void openProject() {
127         try {
128             Object JavaDoc[] values = persistence.getProjects();
129             Object JavaDoc selectedValue = JOptionPane.showInputDialog(null,resource.getString("wfwindowsmanager.graphedit"),resource.getString("wfwindowsmanager.openproj"),JOptionPane.INFORMATION_MESSAGE,icon,values,values[0]);
130             if (selectedValue != null) {
131                 manager.openProject((String JavaDoc) selectedValue);
132             }
133         } catch (Exception JavaDoc e1) {
134             JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.openerror"),resource.getString("wfwindowsmanager.openproj"),JOptionPane.INFORMATION_MESSAGE, icon);
135         }
136     }
137     
138     public void editNode(String JavaDoc nodeName) {
139
140         String JavaDoc result = null;
141         JPanel JavaDoc jp = new JPanel JavaDoc();
142         try {
143             persistence.setProjectNodes();
144             StrutsNodeValue nl = persistence.getProjectNode(nodeName);
145             GridBagLayout gridbag = new GridBagLayout();
146             GridBagConstraints c = new GridBagConstraints();
147             jp.setLayout(gridbag);
148
149             c.fill = GridBagConstraints.BOTH;
150             c.weightx = 1.0;
151
152             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.deadline")));
153             DateComboBox dcb = new DateComboBox();
154             SimpleDateFormat JavaDoc df = new SimpleDateFormat JavaDoc("yyyy-MM-dd");
155             SimpleDateFormat JavaDoc dateFormat = new SimpleDateFormat JavaDoc("MMM dd,yyyy");
156             if (persistence.getDeadline(nodeName) != null)
157                 dcb.setSelectedItem(dateFormat.format(df.parse(nl.getDeadline().toString())));
158
159             dcb.setEditable(true);
160             jp.add(dcb);
161             gridbag.setConstraints(dcb, c);
162             c.gridwidth = GridBagConstraints.REMAINDER;
163
164             c.weightx = 1.0;
165             Object JavaDoc[] possibleRoles = persistence.getRoles();
166             JComboBox JavaDoc roles = new JComboBox JavaDoc(possibleRoles);
167             roles.setSelectedItem(persistence.getRole(nodeName));
168             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.selectrole"), SwingConstants.LEFT));
169             jp.add(roles);
170             gridbag.setConstraints(roles, c);
171
172             c.gridwidth = GridBagConstraints.REMAINDER;
173             c.weightx = 0.0;
174
175             JTextArea JavaDoc description = new JTextArea JavaDoc(nl.getDescription());
176             JScrollPane JavaDoc areaScrollPane = new JScrollPane JavaDoc(description);
177             areaScrollPane.setVerticalScrollBarPolicy(
178             JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
179             areaScrollPane.setPreferredSize(new Dimension(200, 100));
180
181             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.description"), SwingConstants.LEFT));
182             jp.add(areaScrollPane);
183             gridbag.setConstraints(areaScrollPane, c);
184             
185             JCheckBox JavaDoc anti = new JCheckBox JavaDoc(resource.getString("wfwindowsmanager.anticipable"));
186             if (persistence.getNodeAnticipable(nodeName) == true)
187                 anti.setSelected(true);
188             else
189                 anti.setSelected(false);
190             jp.add(anti);
191             gridbag.setConstraints(anti, c);
192
193             int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.editact"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
194
195             if (option != JOptionPane.CANCEL_OPTION) {
196                 if (dcb.getSelectedItem() != null) {
197                     java.util.Date JavaDoc deadline =
198                         dateFormat.parse((String JavaDoc) dcb.getSelectedItem());
199
200                     while (deadline.getTime() <= System.currentTimeMillis()
201                         && option != JOptionPane.CANCEL_OPTION) {
202                         JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.datedeadline"),resource.getString("wfwindowsmanager.editact"),JOptionPane.INFORMATION_MESSAGE, icon);
203                         option =JOptionPane.showConfirmDialog(null,jp,"Edit Activity",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
204                         deadline =dateFormat.parse((String JavaDoc) dcb.getSelectedItem());
205                     }
206                     persistence.setEditNode(nodeName,(String JavaDoc) roles.getSelectedItem(),description.getText(),deadline);
207                 } else {
208                     persistence.setNodeDescription(nodeName,description.getText());
209                     persistence.setNodeRole(nodeName,(String JavaDoc) roles.getSelectedItem());
210                     if (!anti.isSelected())
211                         persistence.setNodeTraditional(nodeName);
212                     else
213                         persistence.setNodeAnticipable(nodeName);
214                 }
215             }
216         } catch (Exception JavaDoc e) {
217             JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.editerror") + e.getMessage(),resource.getString("wfwindowsmanager.editact"),JOptionPane.INFORMATION_MESSAGE, icon);
218         }
219     }
220
221     public Vector addInterHook() {
222         Vector result = new Vector();
223         Vector hookTypes = new Vector();
224         hookTypes.add(hero.interfaces.Constants.Nd.AFTERSTART);
225         hookTypes.add(hero.interfaces.Constants.Nd.BEFORESTART);
226         hookTypes.add(hero.interfaces.Constants.Nd.AFTERTERMINATE);
227         hookTypes.add(hero.interfaces.Constants.Nd.BEFORETERMINATE);
228         hookTypes.add(hero.interfaces.Constants.Nd.ANTICIPATE);
229         hookTypes.add(hero.interfaces.Constants.Nd.ONCANCEL);
230         hookTypes.add(hero.interfaces.Constants.Nd.ONDEADLINE);
231         hookTypes.add(hero.interfaces.Constants.Nd.ONREADY);
232
233         JPanel JavaDoc jp = new JPanel JavaDoc();
234         JTextField JavaDoc hook = new JTextField JavaDoc("", 10);
235         jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.namehook"), SwingConstants.LEFT));
236         jp.add(hook);
237
238         JComboBox JavaDoc types = new JComboBox JavaDoc(hookTypes);
239         jp.setLayout(new GridLayout(0, 2));
240         jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.choosetype"), SwingConstants.LEFT));
241         jp.add(types);
242
243         int option = JOptionPane.showConfirmDialog( null,jp,resource.getString("wfwindowsmanager.newhook"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
244
245         if (option != JOptionPane.CANCEL_OPTION) {
246             while ((hook.getText()).equals("")
247                 && option != JOptionPane.CANCEL_OPTION) {
248                 JOptionPane.showMessageDialog(null,hook.getText()+ resource.getString("wfwindowsmanager.nullhook"),resource.getString("wfwindowsmanager.newhook"),JOptionPane.INFORMATION_MESSAGE, icon);
249                 option = JOptionPane.showConfirmDialog( null,jp,resource.getString("wfwindowsmanager.newhook"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
250             }
251             if (option != JOptionPane.CANCEL_OPTION) {
252                 result.add(hook.getText());
253                 result.add((String JavaDoc) types.getSelectedItem());
254                 String JavaDoc value = null;
255                 switch (types.getSelectedIndex()) {
256                     case 0 :
257                         value = hero.interfaces.Constants.AFTERSTART;
258                         break;
259                     case 1 :
260                         value = hero.interfaces.Constants.BEFORESTART;
261                         break;
262                     case 2 :
263                         value = hero.interfaces.Constants.AFTERTERMINATE;
264                         break;
265                     case 3 :
266                         value = hero.interfaces.Constants.BEFORETERMINATE;
267                         break;
268                     case 4 :
269                         value = hero.interfaces.Constants.ANTICIPATE;
270                         break;
271                     case 5 :
272                         value = hero.interfaces.Constants.ONCANCEL;
273                         break;
274                     case 6 :
275                         value = hero.interfaces.Constants.ONDEADLINE;
276                         break;
277                     case 7 :
278                         value = hero.interfaces.Constants.ONREADY;
279                         break;
280                 }
281                 result.add(value);
282                 return (result);
283             }
284         }
285         return (result);
286     }
287
288     public String JavaDoc setInterHookValue(String JavaDoc value) {
289
290         String JavaDoc result = null;
291         JPanel JavaDoc jp = new JPanel JavaDoc();
292         JTextArea JavaDoc hook = new JTextArea JavaDoc(value);
293         JScrollPane JavaDoc areaScrollPane = new JScrollPane JavaDoc(hook);
294         areaScrollPane.setVerticalScrollBarPolicy(
295         JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
296         areaScrollPane.setPreferredSize(new Dimension(350, 250));
297
298         jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.hookaction"), SwingConstants.LEFT));
299         jp.add(areaScrollPane);
300
301         int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.hookscript"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
302
303         if (option != JOptionPane.CANCEL_OPTION) {
304             while ((hook.getText()).equals("")
305                 && option != JOptionPane.CANCEL_OPTION) {
306                 JOptionPane.showMessageDialog(null,hook.getText()+ resource.getString("wfwindowsmanager.nullhook"),resource.getString("wfwindowsmanager.hookscript"),JOptionPane.INFORMATION_MESSAGE, icon);
307                 option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.hookscript"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
308             }
309             if (option != JOptionPane.CANCEL_OPTION)
310                 result = hook.getText();
311         }
312         return (result);
313     }
314
315     public void addNodePropertyWindow(String JavaDoc node) {
316         JPanel JavaDoc jp = new JPanel JavaDoc();
317
318         JTextField JavaDoc key = new JTextField JavaDoc("", 0);
319         jp.setLayout(new GridLayout(0, 2));
320         jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.keyprop"), SwingConstants.LEFT));
321         jp.add(key);
322
323         JTextField JavaDoc value = new JTextField JavaDoc("", 0);
324         jp.setLayout(new GridLayout(0, 2));
325         jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.valprop"), SwingConstants.LEFT));
326         jp.add(value);
327
328         JCheckBox JavaDoc prop = new JCheckBox JavaDoc(resource.getString("wfwindowsmanager.propagate"));
329         prop.setSelected(true);
330         jp.add(prop);
331
332         int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newnodeprop"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
333
334         if (option != JOptionPane.CANCEL_OPTION) {
335             while ((key.getText()).equals("")
336                 && option != JOptionPane.CANCEL_OPTION) {
337                 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.enterprop"),resource.getString("wfwindowsmanager.newnodeprop"),JOptionPane.INFORMATION_MESSAGE, icon);
338                 option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newprop"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
339             }
340             if (option != JOptionPane.CANCEL_OPTION && !prop.isSelected()) {
341                 try {
342                     persistence.addNodeProperty(node,key.getText(),value.getText(), false);
343                 } catch (Exception JavaDoc e) {
344                     JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.existprop"),resource.getString("wfwindowsmanager.newnodeproperty"),JOptionPane.INFORMATION_MESSAGE, icon);
345                 }
346             } else if (
347                 option != JOptionPane.CANCEL_OPTION && prop.isSelected()) {
348                 try {
349                     persistence.addNodeProperty(node,key.getText(),value.getText(),true);
350                 } catch (Exception JavaDoc e) {
351                     JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.adderrorprop"),resource.getString("wfwindowsmanager.newnodeprop"),JOptionPane.INFORMATION_MESSAGE, icon);
352                 }
353             }
354         }
355     }
356     
357     public void addProjectPropertyWindow() {
358             JPanel JavaDoc jp = new JPanel JavaDoc();
359
360             JTextField JavaDoc key = new JTextField JavaDoc("", 0);
361             jp.setLayout(new GridLayout(0, 2));
362             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.keyprop"), SwingConstants.LEFT));
363             jp.add(key);
364
365             JTextField JavaDoc value = new JTextField JavaDoc("", 0);
366             jp.setLayout(new GridLayout(0, 2));
367             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.valprop"), SwingConstants.LEFT));
368             jp.add(value);
369
370             int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newpropproj"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
371
372             if (option != JOptionPane.CANCEL_OPTION) {
373                 while ((key.getText()).equals("")
374                     && option != JOptionPane.CANCEL_OPTION) {
375                     JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.enterprop"),resource.getString("wfwindowsmanager.newpropproj"),JOptionPane.INFORMATION_MESSAGE, icon);
376                     option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newprop"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
377                 }
378                 if (option != JOptionPane.CANCEL_OPTION) {
379                     try {
380                         persistence.addProjectProperty(key.getText(),value.getText());
381                     } catch (Exception JavaDoc e) {
382                         JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.adderrorprop"),resource.getString("wfwindowsmanager.newpropproj"),JOptionPane.INFORMATION_MESSAGE, icon);
383                     }
384                 }
385             }
386         }
387
388     public void iterate(String JavaDoc node) {
389             JPanel JavaDoc jp = new JPanel JavaDoc();
390
391             JTextField JavaDoc from = new JTextField JavaDoc(node, 0);
392             from.setEditable(false);
393             jp.setLayout(new GridLayout(0, 2));
394             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.fromnode"), SwingConstants.LEFT));
395             jp.add(from);
396             
397             JTextField JavaDoc to = new JTextField JavaDoc("", 0);
398             jp.setLayout(new GridLayout(0, 2));
399             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.tonode"), SwingConstants.LEFT));
400             jp.add(to);
401             
402             JTextField JavaDoc condition = new JTextField JavaDoc("", 30);
403             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.itecond"), SwingConstants.LEFT));
404             jp.add(condition);
405
406             int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.iterate"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
407
408             if (option != JOptionPane.CANCEL_OPTION) {
409                 while ((from.getText()).equals("") && (condition.getText()).equals("")
410                     && option != JOptionPane.CANCEL_OPTION) {
411                     JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.enternode"),resource.getString("wfwindowsmanager.iterate"),JOptionPane.INFORMATION_MESSAGE, icon);
412                     option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.iterate"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
413                 }
414                 if (option != JOptionPane.CANCEL_OPTION) {
415                     try {
416                         persistence.addIteration(node,to.getText(), condition.getText());
417                         manager.wfGraph.updateIterationNodes(node,to.getText());
418                     } catch (Exception JavaDoc e) {
419                         JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.iterno"),resource.getString("wfwindowsmanager.iterate"),JOptionPane.INFORMATION_MESSAGE, icon);
420                     }
421                 }
422             }
423         }
424
425
426
427     public Vector addNode() {
428         Vector result = new Vector();
429         try {
430             JPanel JavaDoc jp = new JPanel JavaDoc();
431             Vector nodeTypes = new Vector();
432             nodeTypes.add("AND JOIN");
433             nodeTypes.add("OR JOIN");
434             nodeTypes.add("AND JOIN AUTO");
435             nodeTypes.add("OR JOIN AUTO");
436
437             JTextField JavaDoc nodeName = new JTextField JavaDoc("", 10);
438             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.namenode"), SwingConstants.LEFT));
439             jp.add(nodeName);
440
441             JComboBox JavaDoc types = new JComboBox JavaDoc(nodeTypes);
442             jp.setLayout(new GridLayout(0, 2));
443             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.choosetype"), SwingConstants.LEFT));
444             jp.add(types);
445             int option = JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newnode"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
446             if (option != JOptionPane.CANCEL_OPTION) {
447                 while ((persistence.containsNode(nodeName.getText())
448                     || (nodeName.getText()).equals(""))
449                     && option != JOptionPane.CANCEL_OPTION) {
450                     JOptionPane.showMessageDialog(null,nodeName.getText()+ resource.getString("wfwindowsmanager.existnode"),resource.getString("wfwindowsmanager.newnode"),JOptionPane.INFORMATION_MESSAGE, icon);
451                     option =JOptionPane.showConfirmDialog(null,jp,"New Activity",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
452                 }
453                 if (option != JOptionPane.CANCEL_OPTION) {
454                     result.add(nodeName.getText());
455                     result.add((String JavaDoc) types.getSelectedItem());
456                     return (result);
457
458                 }
459             }
460         } catch (Exception JavaDoc e1) {
461             JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.errornode"),resource.getString("wfwindowsmanager.newnode"),JOptionPane.INFORMATION_MESSAGE, icon);
462         }
463         return (result);
464     }
465     
466     public Vector addNodeSubProcess() {
467         Vector result = new Vector();
468         try {
469             JPanel JavaDoc jp = new JPanel JavaDoc();
470
471             Object JavaDoc[] possibleValues = persistence.getProjects();
472             JComboBox JavaDoc projectNames = new JComboBox JavaDoc(possibleValues);
473             jp.setLayout(new GridLayout(0, 2));
474             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.choosesub"), SwingConstants.LEFT));
475             jp.add(projectNames);
476             
477             JTextField JavaDoc nodeName = new JTextField JavaDoc("", 10);
478             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.namenode"), SwingConstants.LEFT));
479             jp.add(nodeName);
480
481             int option = JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newsub"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
482             if (option != JOptionPane.CANCEL_OPTION) {
483                 while ((persistence.containsNode(nodeName.getText()) || (nodeName.getText()).equals(""))
484                                     && option != JOptionPane.CANCEL_OPTION) {
485                     JOptionPane.showMessageDialog(null,(String JavaDoc) projectNames.getSelectedItem()+ resource.getString("wfwindowsmanager.existnodesub"),resource.getString("wfwindowsmanager.newsub"),JOptionPane.INFORMATION_MESSAGE, icon);
486                     option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newsub"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
487                 }
488                 while (persistence.containsProject(nodeName.getText()) && option != JOptionPane.CANCEL_OPTION) {
489                     JOptionPane.showMessageDialog(null,(String JavaDoc) projectNames.getSelectedItem()+ resource.getString("wfwindowsmanager.existsub"),resource.getString("wfwindowsmanager.newsub"),JOptionPane.INFORMATION_MESSAGE, icon);
490                     option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newsub"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
491                 }
492                 if (option != JOptionPane.CANCEL_OPTION) {
493                     result.add(nodeName.getText());
494                     result.add((String JavaDoc) projectNames.getSelectedItem());
495                     return (result);
496                 }
497             }
498         } catch (Exception JavaDoc e1) {
499             JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.errorsystem"),resource.getString("wfwindowsmanager.newsub"),JOptionPane.INFORMATION_MESSAGE, icon);
500         }
501         return (result);
502     }
503
504     public String JavaDoc setEdgeCondition(String JavaDoc edgeName) {
505         String JavaDoc result = null;
506         try {
507           JPanel JavaDoc jp = new JPanel JavaDoc();
508           JTextField JavaDoc condition = new JTextField JavaDoc("", 30);
509           jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.edgecond"), SwingConstants.LEFT));
510           jp.add(condition);
511           result = persistence.getEdgeCondition(edgeName);
512           condition.setText(result);
513
514           int option = JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.setedge"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
515
516           if (option != JOptionPane.CANCEL_OPTION) {
517             while ((condition.getText()).equals("")
518                 && option != JOptionPane.CANCEL_OPTION) {
519                 JOptionPane.showMessageDialog(null,condition.getText()+ resource.getString("wfwindowsmanager.entercond"),resource.getString("wfwindowsmanager.setedge"),JOptionPane.INFORMATION_MESSAGE, icon);
520                 option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.setedge"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
521             }
522             if (option != JOptionPane.CANCEL_OPTION) {
523                 result = condition.getText();
524                 return (result);
525
526             }
527           }
528           } catch (Exception JavaDoc ec) {
529             JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.erroredge"),resource.getString("wfwindowsmanager.setedge"),JOptionPane.INFORMATION_MESSAGE, icon);
530           }
531         return (result);
532       }
533
534     public void changeRoleWindow(String JavaDoc node) {
535         try {
536             Object JavaDoc[] possibleRoles = persistence.getRoles();
537
538             JPanel JavaDoc jp = new JPanel JavaDoc();
539
540             JComboBox JavaDoc roles = new JComboBox JavaDoc(possibleRoles);
541             jp.setLayout(new GridLayout(0, 2));
542             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.selectrole"), SwingConstants.LEFT));
543             jp.add(roles);
544
545             int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.changerole"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
546             if (option != JOptionPane.CANCEL_OPTION) {
547                 persistence.setNodeRole(node, (String JavaDoc) roles.getSelectedItem());
548             }
549
550         } catch (Exception JavaDoc e) {
551             JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.errorchangerole"),resource.getString("wfwindowsmanager.changerole"),JOptionPane.INFORMATION_MESSAGE, icon);
552         }
553     }
554     
555     
556 /* Open a dialog and return the filename. Returns null if cancelled. */
557 protected String JavaDoc dialog(String JavaDoc message, int mode) {
558     FileDialog f = new FileDialog(manager.getFrame(), message, mode);
559     f.show();
560     if (f.getFile() != null)
561         return f.getDirectory() + f.getFile();
562     else
563         return null;
564 }
565
566     private boolean contains(Object JavaDoc[] data, String JavaDoc elem) {
567         for (int i = 0; i < data.length; i++) {
568             if (((String JavaDoc) data[i]).equalsIgnoreCase(elem))
569                 return true;
570         }
571         return false;
572     }
573
574     public void newUser() {
575         try {
576             Object JavaDoc[] usersIn = persistence.getUsersInProject();
577             Object JavaDoc[] allUsers = persistence.getAllUsers();
578             int size = allUsers.length - usersIn.length;
579
580             if (size == 0)
581                 JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.nomoreuser"));
582             else {
583                 Object JavaDoc[] possibleUsers = new Object JavaDoc[size];
584                 int j = 0;
585                 for (int i = 0; i < allUsers.length; i++) {
586                     if (!contains(usersIn, (String JavaDoc) allUsers[i])) {
587                         possibleUsers[j] = allUsers[i];
588                         j++;
589                     }
590                 }
591
592                 JPanel JavaDoc jp = new JPanel JavaDoc();
593
594                 JComboBox JavaDoc users = new JComboBox JavaDoc(possibleUsers);
595                 jp.setLayout(new GridLayout(0, 2));
596                 jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.selectuser"), SwingConstants.LEFT));
597                 jp.add(users);
598
599                 int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newuser"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
600
601                 if (option != JOptionPane.CANCEL_OPTION) {
602                     persistence.addUser((String JavaDoc) users.getSelectedItem());
603                 }
604             }
605         } catch (Exception JavaDoc e) {e.printStackTrace();}
606     }
607
608     public void newRole() {
609         JPanel JavaDoc jp = new JPanel JavaDoc();
610
611         JTextField JavaDoc roleName = new JTextField JavaDoc("", 0);
612         jp.setLayout(new GridLayout(0, 2));
613         jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.namerole"), SwingConstants.LEFT));
614         jp.add(roleName);
615
616         JTextField JavaDoc description = new JTextField JavaDoc("", 0);
617         jp.setLayout(new GridLayout(0, 2));
618         jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.description"), SwingConstants.LEFT));
619         jp.add(description);
620
621         int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newrole"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
622
623         if (option != JOptionPane.CANCEL_OPTION) {
624             while ((roleName.getText()).equals("")
625                 && option != JOptionPane.CANCEL_OPTION) {
626                 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.enterrolename"),resource.getString("wfwindowsmanager.newrole"),JOptionPane.INFORMATION_MESSAGE, icon);
627                 option =JOptionPane.showConfirmDialog(null,jp,"New Role",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
628             }
629             if (option != JOptionPane.CANCEL_OPTION) {
630                 try {
631                     persistence.addRole(roleName.getText(),description.getText());
632                 } catch (Exception JavaDoc e) {
633                     JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.existrole"),resource.getString("wfwindowsmanager.newrole"),JOptionPane.INFORMATION_MESSAGE, icon);
634                 }
635             }
636         }
637     }
638
639     public void addUserToRole() {
640         try {
641             JPanel JavaDoc jp = new JPanel JavaDoc();
642
643             Object JavaDoc[] possibleUsers = persistence.getUsersInProject();
644
645             JComboBox JavaDoc users = new JComboBox JavaDoc(possibleUsers);
646             jp.setLayout(new GridLayout(0, 2));
647             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.selectuser"), SwingConstants.LEFT));
648             jp.add(users);
649
650             Object JavaDoc[] possibleRoles = persistence.getRoles();
651
652             JComboBox JavaDoc roles = new JComboBox JavaDoc(possibleRoles);
653             jp.setLayout(new GridLayout(0, 2));
654             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.selectrole"), SwingConstants.LEFT));
655             jp.add(roles);
656             int option =JOptionPane.showConfirmDialog(null, jp,resource.getString("wfwindowsmanager.adduserrole"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
657
658             if (option != JOptionPane.CANCEL_OPTION) {
659                 try {
660                     persistence.setUserRole((String JavaDoc) users.getSelectedItem(),(String JavaDoc) roles.getSelectedItem());
661                 } catch (Exception JavaDoc exx) {
662                     JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.existuserrole"),resource.getString("wfwindowsmanager.adduserrole"),JOptionPane.INFORMATION_MESSAGE, icon);
663                 }
664             }
665         } catch (Exception JavaDoc ex) {
666             JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.exerole"),resource.getString("wfwindowsmanager.adduserrole"),JOptionPane.INFORMATION_MESSAGE, icon);
667         }
668     }
669     
670     public void addMapperToRole() {
671         try {
672             JPanel JavaDoc jp = new JPanel JavaDoc();
673             
674             Vector mapperTypes = new Vector();
675             mapperTypes.add(Constants.Mapper.LDAPMAPPER);
676             mapperTypes.add(Constants.Mapper.PROPERTIESMAPPER);
677             mapperTypes.add(Constants.Mapper.CUSTOMMAPPER);
678
679             Object JavaDoc[] possibleRoles = persistence.getRoles();
680
681             JComboBox JavaDoc roles = new JComboBox JavaDoc(possibleRoles);
682             jp.setLayout(new GridLayout(0, 2));
683             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.selectrole"), SwingConstants.LEFT));
684             jp.add(roles);
685             
686             JTextField JavaDoc mapperName = new JTextField JavaDoc("", 0);
687             jp.setLayout(new GridLayout(0, 2));
688             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.mapper"), SwingConstants.LEFT));
689             jp.add(mapperName);
690             
691             JComboBox JavaDoc types = new JComboBox JavaDoc(mapperTypes);
692             jp.setLayout(new GridLayout(0, 2));
693             jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.mappertype"), SwingConstants.LEFT));
694             jp.add(types);
695             
696             int option =JOptionPane.showConfirmDialog(null, jp,resource.getString("wfwindowsmanager.addmapperrole"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
697
698             if (option != JOptionPane.CANCEL_OPTION) {
699                 try {
700                     persistence.addRoleMapper((String JavaDoc) roles.getSelectedItem(), mapperName.getText(),(String JavaDoc)types.getSelectedItem());
701                 } catch (Exception JavaDoc exx) {
702                     JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.existmapperrole"),resource.getString("wfwindowsmanager.addmapperrole"),JOptionPane.INFORMATION_MESSAGE, icon);
703                 }
704             }
705         } catch (Exception JavaDoc ex) {
706             ex.printStackTrace();
707             JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.exemapper"),resource.getString("wfwindowsmanager.addmapperrole"),JOptionPane.INFORMATION_MESSAGE, icon);
708         }
709     }
710     
711     public void addPerformerAssigment(String JavaDoc nodeName) {
712         JPanel JavaDoc jp = new JPanel JavaDoc();
713             
714         Vector performerTypes = new Vector();
715         performerTypes.add(Constants.PerformerAssigment.CALLBACKPA);
716         performerTypes.add(Constants.PerformerAssigment.PROPERTIESPA);
717             
718         JComboBox JavaDoc types = new JComboBox JavaDoc(performerTypes);
719         jp.setLayout(new GridLayout(0, 2));
720         jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.performertype"), SwingConstants.LEFT));
721         jp.add(types);
722             
723         JTextField JavaDoc performerName = new JTextField JavaDoc("", 0);
724         jp.setLayout(new GridLayout(0, 2));
725         jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.performername"), SwingConstants.LEFT));
726         jp.add(performerName);
727         
728         JTextField JavaDoc property = new JTextField JavaDoc("", 0);
729         jp.setLayout(new GridLayout(0, 2));
730         jp.add(new JLabel JavaDoc(resource.getString("wfwindowsmanager.performerprop"), SwingConstants.LEFT));
731         jp.add(property);
732             
733
734         int option =JOptionPane.showConfirmDialog(null, jp,resource.getString("wfwindowsmanager.addperformer"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
735         if (option != JOptionPane.CANCEL_OPTION) {
736             try {
737                 persistence.addPerformerAssigment(nodeName, performerName.getText(), (String JavaDoc) types.getSelectedItem(),(String JavaDoc)property.getText());
738             } catch (Exception JavaDoc exx) {
739                 JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.existperformer"),resource.getString("wfwindowsmanager.addperformer"),JOptionPane.INFORMATION_MESSAGE, icon);
740             }
741         }
742     }
743
744     public void usersInProject() {
745         try {
746             JPanel JavaDoc jp = new JPanel JavaDoc();
747
748             Object JavaDoc[] users = persistence.getUsersInProject();
749             String JavaDoc text = resource.getString("wfwindowsmanager.userhtml");
750             Object JavaDoc[] nameRoles = persistence.getRoles();
751             for (int i = 0; i < nameRoles.length; i++) {
752                 text = text + "<th>" + (String JavaDoc) nameRoles[i] + "</th>";
753             }
754
755             for (int j = 0; j < users.length; j++) {
756
757                 text =text+ "<tr bgcolor=white><td>"+ (String JavaDoc) users[j]+ "</td>";
758
759                 for (int i = 0; i < nameRoles.length; i++) {
760                     if (persistence.isInRole((String JavaDoc) users[j], (String JavaDoc) nameRoles[i])) {
761                         text = text + "<td align=center> X </td>";
762                     } else {
763                         text = text + "<td></td>";
764                     }
765                 }
766                 text = text + "</tr>";
767             }
768             text = text + "</table></html>";
769             JLabel JavaDoc jText = new JLabel JavaDoc(text);
770             jp.add(jText);
771             Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
772
773             JScrollPane JavaDoc scroll = new JScrollPane JavaDoc(jp);
774             scroll.setMaximumSize(new Dimension(screenSize.width / 2, screenSize.height / 2));
775             JFrame JavaDoc fr = new JFrame JavaDoc(resource.getString("wfwindowsmanager.userproj"));
776             fr.getContentPane().add(scroll, BorderLayout.CENTER);
777             fr.pack();
778
779             Dimension jpDim = scroll.getPreferredSize();
780             fr.setLocation(screenSize.width / 2 - (jpDim.width / 2),screenSize.height / 2 - (jpDim.height / 2));
781             fr.setResizable(true);
782             fr.setVisible(true);
783
784         } catch (Exception JavaDoc ex) {
785             JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.exeuserrole"),resource.getString("wfwindowsmanager.userole"),JOptionPane.INFORMATION_MESSAGE, icon);
786         }
787     }
788     
789
790 } // WFWindowManager
791
Popular Tags