KickJava   Java API By Example, From Geeks To Geeks.

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


1 package hero.client.grapheditor;
2
3 /**
4  * WFManager.java
5  *
6  *
7  * Created: Fri Aug 09 16:35:03 2002
8  *
9  * @version 1.0
10  */

11
12 import hero.net.ProjectSession.StrutsNodeValue;
13
14 import hero.util.EventConstants;
15 import hero.client.events.JMSServicesClient;
16
17 import java.awt.Color JavaDoc;
18 import java.awt.image.BufferedImage JavaDoc;
19 import java.util.Enumeration JavaDoc;
20 import java.util.Hashtable JavaDoc;
21 import java.util.Vector JavaDoc;
22
23 import javax.jms.Message JavaDoc;
24 import javax.jms.MessageListener JavaDoc;
25 import javax.swing.JFrame JavaDoc;
26 import javax.swing.JOptionPane JavaDoc;
27 import javax.swing.ImageIcon JavaDoc;
28
29
30 public class WFManager {
31
32 static java.util.ResourceBundle JavaDoc resource = java.util.ResourceBundle.getBundle("resources.Traduction")/*#BundleType=List*/;
33
34     Frame frame;
35     WFGraph wfGraph;
36     WFWindowManager windowManager;
37     WFPersistence wfPersistence;
38     boolean automatic=true;
39     Vector JavaDoc clipboardEdges;
40     int clipboardNodes;
41     String JavaDoc activeProject=null;
42     String JavaDoc activeUser;
43     Listener JavaDoc ml;
44     public final static String JavaDoc imageBase = "images/";
45     public final static ImageIcon JavaDoc icon = new ImageIcon JavaDoc(Thread.currentThread().getContextClassLoader().getResource(imageBase + "icon.png"));
46
47     class Edge{
48     public int source;
49     public int target;
50     public Edge(){}
51     }
52
53
54     public class Listener implements MessageListener JavaDoc
55     {
56     private JMSServicesClient jms;
57     
58     public Listener(){}
59     
60     public void subscription(String JavaDoc subs) throws Exception JavaDoc
61     {
62         jms = JMSServicesClient.getInstance();
63         jms.createSubscription(this,subs);
64     }
65
66     public void onMessage(Message JavaDoc message)
67     {
68         Object JavaDoc key;
69         Object JavaDoc value = Color.lightGray;
70
71         synchronized(this){
72
73         try{
74         Hashtable JavaDoc evt = JMSServicesClient.getEvt(message);
75
76         if (((String JavaDoc)evt.get(EventConstants.PROJECTNAME)).equals(activeProject))
77         {
78             String JavaDoc event = (String JavaDoc)evt.get(EventConstants.EVENT);
79         
80         if (event.equals(EventConstants.SETNODESTATE))
81             {
82             String JavaDoc nodeState = null;
83             String JavaDoc node = (String JavaDoc)evt.get(EventConstants.NODENAME);
84             int state = (new Integer JavaDoc ((String JavaDoc)evt.get(EventConstants.NODESTATE))).intValue();
85             wfGraph.changeNodeState(node,state);
86             wfPersistence.setProjectNodeState(node,state);
87             }
88         if (event.equals(EventConstants.ADDNODE))
89             {
90             String JavaDoc node = (String JavaDoc)evt.get(EventConstants.NODENAME);
91             String JavaDoc user = (String JavaDoc)evt.get(EventConstants.USERNAME);
92             String JavaDoc state = (String JavaDoc)evt.get(EventConstants.NODESTATE);
93             int type = new Integer JavaDoc(((String JavaDoc)evt.get(EventConstants.NODETYPE))).intValue();
94             wfGraph.addNewNode(node, (new Integer JavaDoc(state)).intValue(), type);
95             wfPersistence.setProjectNodes();
96             }
97         if (event.equals(EventConstants.ADDEDGE))
98             {
99             String JavaDoc edge = (String JavaDoc)evt.get(EventConstants.EDGENAME);
100             String JavaDoc user = (String JavaDoc)evt.get(EventConstants.USERNAME);
101
102             String JavaDoc nodeIn = (String JavaDoc)evt.get(EventConstants.NODEIN);
103             String JavaDoc nodeOut = (String JavaDoc)evt.get(EventConstants.NODEOUT);
104             wfGraph.restoreEdge(edge,nodeIn,nodeOut);
105
106             }
107         if (event.equals(EventConstants.DELETENODE))
108             {
109             String JavaDoc node = (String JavaDoc)evt.get(EventConstants.NODENAME);
110             String JavaDoc user = (String JavaDoc)evt.get(EventConstants.USERNAME);
111             wfGraph.deleteNode(node);
112             wfPersistence.setProjectNodes();
113             }
114         if (event.equals(EventConstants.DELETEEDGE))
115             {
116             String JavaDoc edge = (String JavaDoc)evt.get(EventConstants.EDGENAME);
117             String JavaDoc user = (String JavaDoc)evt.get(EventConstants.USERNAME);
118             wfGraph.deleteEdge(edge);
119             }
120         }
121         
122         }catch(Exception JavaDoc e1){e1.printStackTrace();}
123
124         }
125
126     }
127     }
128     
129     public void makeJMSConnection(String JavaDoc name)
130     {
131     try {
132         ml.subscription("projectName = '"+name+"'");
133     }catch (Exception JavaDoc e) {e.printStackTrace();}
134     }
135
136     public WFManager(Frame frame, WFPersistence persist) {
137         try {
138             this.frame = frame;
139             wfPersistence = persist;
140             windowManager = new WFWindowManager(this, wfPersistence);
141             clipboardNodes = 0;
142             clipboardEdges = new Vector JavaDoc();
143             activeUser = wfPersistence.getUser();
144             ml = new Listener JavaDoc();
145         } catch (Exception JavaDoc e1) {
146             e1.printStackTrace();
147         }
148     }
149
150     public void setWFGraph(WFGraph wfGraph){
151     this.wfGraph=wfGraph;
152     }
153
154     public void addEdge(){
155     wfGraph.setAddEdgeState(true);
156     }
157     
158     public void setEdgeCondition(String JavaDoc edgeName) {
159         try {
160             String JavaDoc condition = windowManager.setEdgeCondition(edgeName);
161             wfPersistence.setEdgeCondition(edgeName, condition);
162         } catch (Exception JavaDoc e1) {
163             JOptionPane.showMessageDialog(null, resource.getString("wfmanager.edgeerror"));
164         }
165     }
166
167     public void addNodeProperty(String JavaDoc nodeName) {
168         windowManager.addNodePropertyWindow(nodeName);
169     }
170     
171     public void addProjectProperty() {
172         windowManager.addProjectPropertyWindow();
173     }
174     
175     public void iterate(String JavaDoc nodeName) {
176         windowManager.iterate(nodeName);
177     }
178     
179     public void setNodeHook(String JavaDoc nodeName) {
180         try {
181             Vector JavaDoc hook = windowManager.addInterHook();
182             if (hook.size()!=0)
183             {
184               wfPersistence.addNodeInterHook(nodeName, (String JavaDoc) hook.get(0), (String JavaDoc) hook.get(1), (String JavaDoc) hook.get(2));
185               String JavaDoc value = windowManager.setInterHookValue((String JavaDoc) hook.get(2));
186               wfPersistence.setNodeInterHookValue(nodeName, (String JavaDoc) hook.get(0), value);
187             }
188         } catch (Exception JavaDoc e1) {
189             JOptionPane.showMessageDialog(null, resource.getString("wfmanager.hookerror"));
190         }
191     }
192     
193     public void setProjectHook() {
194         try {
195             Vector JavaDoc hook = windowManager.addInterHook();
196             if (hook.size()!=0)
197             {
198               wfPersistence.addProjectInterHook((String JavaDoc) hook.get(0), (String JavaDoc) hook.get(1), (String JavaDoc) hook.get(2));
199               String JavaDoc value = windowManager.setInterHookValue((String JavaDoc) hook.get(2));
200               wfPersistence.setProjectInterHookValue((String JavaDoc) hook.get(0), value);
201             }
202         } catch (Exception JavaDoc e1) {
203             JOptionPane.showMessageDialog(null, resource.getString("wfmanager.hookerror"));
204         }
205     }
206     
207     public void editNode(String JavaDoc nodeName) {
208                 try {
209                      windowManager.editNode(nodeName);
210                 } catch (Exception JavaDoc e1) {
211                     JOptionPane.showMessageDialog(null, resource.getString("wfmanager.errordesc"));
212                 }
213             }
214
215     public void addPerformerAssigment(String JavaDoc nodeName) {
216          windowManager.addPerformerAssigment(nodeName);
217     }
218
219     public void addNode() {
220             try {
221                 wfGraph.setAddEdgeState(false);
222                 Vector JavaDoc addNode = windowManager.addNode();
223                 String JavaDoc name = (String JavaDoc) addNode.elementAt(0);
224                 if (!name.equalsIgnoreCase("")) {
225                     wfPersistence.addNode(name, (String JavaDoc) addNode.elementAt(1));
226                 }
227                 updateStatus();
228             } catch (Exception JavaDoc addNode) {}
229         }
230
231     public void addNodeSubProcess() {
232         try {
233             wfGraph.setAddEdgeState(false);
234             Vector JavaDoc addNode = windowManager.addNodeSubProcess();
235             String JavaDoc name = (String JavaDoc) addNode.elementAt(0);
236             wfPersistence.addNodeSubProcess(name, (String JavaDoc) addNode.elementAt(1));
237             updateStatus();
238         } catch (Exception JavaDoc addNodeSubProcess) {}
239     }
240     
241     
242     public void clearSelection(){
243     wfGraph.clearSelection();
244     }
245     public void selectAll(){
246     wfGraph.selectAll();
247     }
248     
249     public void exit(){
250         frame.setPropertyChange();
251         frame.dispose();
252     }
253
254     public void deleteSelection() {
255     try {
256         int option = JOptionPane.showConfirmDialog(null,resource.getString("wfmanager.willdelete"),resource.getString("wfmanager.deletesel"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon);
257         if (option == JOptionPane.OK_OPTION) {
258           Object JavaDoc[] nodes = wfGraph.getSelectionNodes();
259           Object JavaDoc[] edges = wfGraph.getSelectionEdges();
260           if (edges.length > 0)
261              wfPersistence.deleteEdges(edges);
262           for (int i = 0; i < nodes.length; i++)
263             wfPersistence.deleteNode((String JavaDoc)nodes[i]);
264           JOptionPane.showMessageDialog(null,resource.getString("wfmanager.removesucc"),resource.getString("wfmanager.deletesel"),JOptionPane.INFORMATION_MESSAGE, icon);
265         }
266     } catch (Exception JavaDoc e1) {
267         JOptionPane.showMessageDialog(null,e1.getMessage(),resource.getString("wfmanager.delproj"),JOptionPane.INFORMATION_MESSAGE,icon);
268         //JOptionPane.showMessageDialog(null, "You can not delete this selection","Delete Selection",JOptionPane.INFORMATION_MESSAGE, icon);
269
}
270
271 }
272     
273     public void copySelection(){
274     clipboardEdges=new Vector JavaDoc();
275     clipboardNodes=((Object JavaDoc[])wfGraph.getSelectionNodes()).length;
276         Object JavaDoc[] nodes=wfGraph.getVertices(wfGraph.getSelectionCells());
277     if(nodes.length>1){
278         for(int i=0;i<nodes.length;i++){
279         for(int j=0;j<nodes.length;j++){
280             Object JavaDoc[] edge = wfGraph.getEdgesBetween(nodes[i],nodes[j]);
281             if(edge.length>0){
282             Object JavaDoc target=wfGraph.getSourceVertex(edge[0]);
283             if(nodes[i].equals(target)){
284                 Edge e= new Edge();
285                 e.target=i;
286                 e.source=j;
287                 clipboardEdges.add(e);
288             }
289             }
290         }
291         }
292     }
293
294     
295     }
296
297 public void pasteSelection() {
298     try {
299         Object JavaDoc[] nodes = new Object JavaDoc[clipboardNodes];
300         for (int i = 0; i < clipboardNodes; i++) {
301             Vector JavaDoc node = windowManager.addNode();
302             nodes[i] = (String JavaDoc) (node.elementAt(0));
303             if (!((String JavaDoc) nodes[i]).equals(""))
304                 wfPersistence.addNode((String JavaDoc) nodes[i], (String JavaDoc) (node.elementAt(1)));
305             else
306                 return;
307
308             // wfGraph.addNewNode((String)nodes[i]);
309
}
310
311         for (Enumeration JavaDoc e = clipboardEdges.elements(); e.hasMoreElements();) {
312             Edge edge = (Edge) e.nextElement();
313             wfPersistence.addEdge((String JavaDoc) nodes[edge.source], (String JavaDoc) nodes[edge.target]);
314             // wfGraph.restoreEdges();
315
}
316     } catch (Exception JavaDoc e1) {
317         JOptionPane.showMessageDialog(null, resource.getString("wfmanager.pasteerror"));
318     }
319
320 }
321
322      public void newProject(){
323         String JavaDoc temp;
324     if((temp=windowManager.newProjectWindow())!=null){
325         /*if(activeProject!=null){
326         JMSEvents jmse = new JMSEvents();
327         jmse.sendProjectEvent(PROJECTCLOSE, activeProject);
328         }*/

329         activeProject=temp;
330         wfGraph.newGraph();
331         makeJMSConnection(activeProject);
332     }
333     updateStatus();
334     }
335     
336     public void cloneProject(){
337     windowManager.cloneProjectWindow();
338     }
339
340     public void openProject(){
341     windowManager.openProject();
342     updateStatus();
343     }
344     
345     public void Info(){
346         Info.showInfo();
347     }
348
349 public void openProject(String JavaDoc project) throws Exception JavaDoc {
350     try {
351         wfPersistence.openProject(project);
352         wfGraph.openGraph(project);
353         makeJMSConnection(project);
354         activeProject = project;
355         setTitle(project);
356         setLayout1();
357         updateStatus();
358     } catch (Exception JavaDoc e1) {
359         JOptionPane.showMessageDialog(null, resource.getString("jprojectlist.modify"));
360         throw new Exception JavaDoc(resource.getString("wfmanager.openerror"));
361     }
362
363 }
364
365
366     public void setLayout1(){
367     wfGraph.setLayout1();
368     }
369     public void setLayout2(){
370     wfGraph.setExpand();
371     }
372    
373     public void automaticLayout(){
374     if(automatic){
375         automatic=false;
376         wfGraph.setAutomaticLayout(false);
377     }else{
378         automatic=true;
379         wfGraph.setAutomaticLayout(true);
380     }
381     }
382    
383     public void setStatusBar(String JavaDoc info){
384     frame.setStatusBar(info);
385     }
386     
387     public Color JavaDoc getGraphBackground(){
388     return wfGraph.getBackground();
389     }
390
391     public void setGraphBackground(Color JavaDoc color){
392     wfGraph.setBackground(color);
393     }
394
395     public void zoom(int value){
396     wfGraph.setZoom(value);
397     }
398
399     public void zoomIn(){
400     wfGraph.zoomIn();
401     }
402     public void zoomOut(){
403     wfGraph.zoomOut();
404     }
405     public void fitWindow(){
406     wfGraph.fitWindow(frame.getScrollPane());
407     }
408
409     public BufferedImage JavaDoc getGraphImage(){
410     return WFGraph.toImage(wfGraph);
411     }
412
413     public String JavaDoc getGraphVRML(){
414     return WFGraph.vrmlView(wfGraph);
415     }
416
417     public WFGraph getGraph(){
418     return wfGraph;
419     }
420
421     public JFrame JavaDoc getFrame(){
422     return frame;
423     }
424     public void setTitle(String JavaDoc title){
425     frame.setTitle(resource.getString("wfmanager.title")+title+resource.getString("wfmanager.user")+activeUser);
426     }
427
428     public WFPersistence getPersistence(){
429     return wfPersistence;
430     }
431
432     public void changeRole (String JavaDoc nodeName){
433     windowManager.changeRoleWindow(nodeName);
434     }
435
436     public void newUser (){
437     windowManager.newUser();
438     }
439     public void newRole (){
440     windowManager.newRole();
441     }
442     public void addUserToRole (){
443     windowManager.addUserToRole();
444     }
445     public void addMapperToRole (){
446     windowManager.addMapperToRole();
447     }
448     public void usersInProject (){
449     windowManager.usersInProject();
450     }
451
452     public void updateStatus() {
453     try {
454         String JavaDoc s = " ";
455         String JavaDoc state;
456
457         if (wfGraph.getSelectionNodes().length == 1 && wfGraph.getRoots().length > 0) {
458             Object JavaDoc[] cell = wfGraph.getSelectionNodes();
459             StrutsNodeValue nl = wfPersistence.getProjectNode((String JavaDoc) cell[0]);
460             String JavaDoc name = (String JavaDoc) cell[0];
461             if (wfPersistence.isActive(name))
462                 s = name + resource.getString("wfmanager.is") + nl.getState() + resource.getString("wfmanager.byuser") + nl.getRole();
463             else
464                 s = name + " is " + nl.getState();
465
466         } else {
467             s = wfGraph.getVertices(wfGraph.getRoots()).length + resource.getString("wfmanager.cell");
468         }
469         frame.setStatusBar(s);
470         
471     } catch (Exception JavaDoc e1) {
472         JOptionPane.showMessageDialog(null, resource.getString("wfmanager.updateerror"));
473     }
474
475 }
476
477 }// WFManager
478
Popular Tags