001: package hero.client.grapheditor;
002:
003: /**
004: * WFManager.java
005: *
006: *
007: * Created: Fri Aug 09 16:35:03 2002
008: *
009: * @version 1.0
010: */
011:
012: import hero.net.ProjectSession.StrutsNodeValue;
013:
014: import hero.util.EventConstants;
015: import hero.client.events.JMSServicesClient;
016:
017: import java.awt.Color;
018: import java.awt.image.BufferedImage;
019: import java.util.Enumeration;
020: import java.util.Hashtable;
021: import java.util.Vector;
022:
023: import javax.jms.Message;
024: import javax.jms.MessageListener;
025: import javax.swing.JFrame;
026: import javax.swing.JOptionPane;
027: import javax.swing.ImageIcon;
028:
029: import javax.jms.MessageListener;
030:
031: public class WFManager {
032:
033: static java.util.ResourceBundle resource = java.util.ResourceBundle
034: .getBundle("resources.Traduction")/*#BundleType=List*/;
035:
036: Frame frame;
037: WFGraph wfGraph;
038: WFWindowManager windowManager;
039: WFPersistence wfPersistence;
040: boolean automatic = true;
041: Vector clipboardEdges;
042: int clipboardNodes;
043: String activeProject = null;
044: String activeUser;
045: Listener ml;
046: private JMSServicesClient jms;
047: public final static String imageBase = "images/";
048: public final static ImageIcon icon = new ImageIcon(Thread
049: .currentThread().getContextClassLoader().getResource(
050: imageBase + "icon.png"));
051:
052: class Edge {
053: public int source;
054: public int target;
055:
056: public Edge() {
057: }
058: }
059:
060: public class Listener implements MessageListener {
061:
062: public Listener() {
063: }
064:
065: public void subscription(String subs) throws Exception {
066: //jms = JMSServicesClient.getInstance();
067: jms.createSubscription(this , subs);
068: }
069:
070: public void onMessage(Message message) {
071: Object key;
072: Object value = Color.lightGray;
073:
074: synchronized (this ) {
075:
076: try {
077: Hashtable evt = JMSServicesClient.getEvt(message);
078:
079: if (((String) evt.get(EventConstants.PROJECTNAME))
080: .equals(activeProject)) {
081: String event = (String) evt
082: .get(EventConstants.EVENT);
083:
084: if (event.equals(EventConstants.SETNODESTATE)) {
085: String nodeState = null;
086: String node = (String) evt
087: .get(EventConstants.NODENAME);
088: int state = (new Integer((String) evt
089: .get(EventConstants.NODESTATE)))
090: .intValue();
091: wfGraph.changeNodeState(node, state);
092: wfPersistence.setProjectNodeState(node,
093: state);
094: }
095: if (event.equals(EventConstants.ADDNODE)) {
096: String node = (String) evt
097: .get(EventConstants.NODENAME);
098: String user = (String) evt
099: .get(EventConstants.USERNAME);
100: String state = (String) evt
101: .get(EventConstants.NODESTATE);
102: int type = new Integer(((String) evt
103: .get(EventConstants.NODETYPE)))
104: .intValue();
105: wfGraph.addNewNode(node,
106: (new Integer(state)).intValue(),
107: type);
108: wfPersistence.setProjectNodes();
109: }
110: if (event.equals(EventConstants.ADDEDGE)) {
111: String edge = (String) evt
112: .get(EventConstants.EDGENAME);
113: String user = (String) evt
114: .get(EventConstants.USERNAME);
115:
116: String nodeIn = (String) evt
117: .get(EventConstants.NODEIN);
118: String nodeOut = (String) evt
119: .get(EventConstants.NODEOUT);
120: wfGraph.restoreEdge(edge, nodeIn, nodeOut);
121:
122: }
123: if (event.equals(EventConstants.DELETENODE)) {
124: String node = (String) evt
125: .get(EventConstants.NODENAME);
126: String user = (String) evt
127: .get(EventConstants.USERNAME);
128: wfGraph.deleteNode(node);
129: wfPersistence.setProjectNodes();
130: }
131: if (event.equals(EventConstants.DELETEEDGE)) {
132: String edge = (String) evt
133: .get(EventConstants.EDGENAME);
134: String user = (String) evt
135: .get(EventConstants.USERNAME);
136: wfGraph.deleteEdge(edge);
137: }
138: }
139:
140: } catch (Exception e1) {
141: e1.printStackTrace();
142: }
143:
144: }
145:
146: }
147: }
148:
149: public void makeJMSConnection(String name) {
150: try {
151: ml.subscription("projectName = '" + name + "'");
152: } catch (Exception e) {
153: e.printStackTrace();
154: }
155: }
156:
157: public WFManager(Frame frame, WFPersistence persist) {
158: try {
159: this .frame = frame;
160: wfPersistence = persist;
161: windowManager = new WFWindowManager(this , wfPersistence);
162: clipboardNodes = 0;
163: clipboardEdges = new Vector();
164: activeUser = wfPersistence.getUser();
165: ml = new Listener();
166: jms = new JMSServicesClient();
167: } catch (Exception e1) {
168: e1.printStackTrace();
169: }
170: }
171:
172: public void setWFGraph(WFGraph wfGraph) {
173: this .wfGraph = wfGraph;
174: }
175:
176: public void addEdge() {
177: wfGraph.setAddEdgeState(true);
178: }
179:
180: public void setEdgeCondition(String edgeName) {
181: try {
182: String condition = windowManager.setEdgeCondition(edgeName);
183: wfPersistence.setEdgeCondition(edgeName, condition);
184: } catch (Exception e1) {
185: JOptionPane.showMessageDialog(null, resource
186: .getString("wfmanager.edgeerror"));
187: }
188: }
189:
190: public void addNodeProperty(String nodeName) {
191: windowManager.addNodePropertyWindow(nodeName);
192: }
193:
194: public void addProjectProperty() {
195: windowManager.addProjectPropertyWindow();
196: }
197:
198: public void iterate(String nodeName) {
199: windowManager.iterate(nodeName);
200: }
201:
202: public void setNodeHook(String nodeName) {
203: try {
204: Vector hook = windowManager.addInterHook();
205: if (hook.size() != 0) {
206: wfPersistence.addNodeInterHook(nodeName, (String) hook
207: .get(0), (String) hook.get(1), (String) hook
208: .get(2));
209: String value = windowManager
210: .setInterHookValue((String) hook.get(2));
211: wfPersistence.setNodeInterHookValue(nodeName,
212: (String) hook.get(0), value);
213: }
214: } catch (Exception e1) {
215: JOptionPane.showMessageDialog(null, resource
216: .getString("wfmanager.hookerror"));
217: }
218: }
219:
220: public void setProjectHook() {
221: try {
222: Vector hook = windowManager.addInterHook();
223: if (hook.size() != 0) {
224: wfPersistence.addProjectInterHook((String) hook.get(0),
225: (String) hook.get(1), (String) hook.get(2));
226: String value = windowManager
227: .setInterHookValue((String) hook.get(2));
228: wfPersistence.setProjectInterHookValue((String) hook
229: .get(0), value);
230: }
231: } catch (Exception e1) {
232: JOptionPane.showMessageDialog(null, resource
233: .getString("wfmanager.hookerror"));
234: }
235: }
236:
237: public void editNode(String nodeName) {
238: try {
239: windowManager.editNode(nodeName);
240: } catch (Exception e1) {
241: JOptionPane.showMessageDialog(null, resource
242: .getString("wfmanager.errordesc"));
243: }
244: }
245:
246: public void addPerformerAssigment(String nodeName) {
247: windowManager.addPerformerAssigment(nodeName);
248: }
249:
250: public void addNode() {
251: try {
252: wfGraph.setAddEdgeState(false);
253: Vector addNode = windowManager.addNode();
254: String name = (String) addNode.elementAt(0);
255: if (!name.equalsIgnoreCase("")) {
256: wfPersistence.addNode(name, (String) addNode
257: .elementAt(1));
258: }
259: updateStatus();
260: } catch (Exception addNode) {
261: }
262: }
263:
264: public void addNodeSubProcess() {
265: try {
266: wfGraph.setAddEdgeState(false);
267: Vector addNode = windowManager.addNodeSubProcess();
268: String name = (String) addNode.elementAt(0);
269: wfPersistence.addNodeSubProcess(name, (String) addNode
270: .elementAt(1));
271: updateStatus();
272: } catch (Exception addNodeSubProcess) {
273: }
274: }
275:
276: public void clearSelection() {
277: wfGraph.clearSelection();
278: }
279:
280: public void selectAll() {
281: wfGraph.selectAll();
282: }
283:
284: public void exit() {
285: frame.setPropertyChange();
286: frame.dispose();
287: }
288:
289: public void deleteSelection() {
290: try {
291: int option = JOptionPane.showConfirmDialog(null, resource
292: .getString("wfmanager.willdelete"), resource
293: .getString("wfmanager.deletesel"),
294: JOptionPane.OK_CANCEL_OPTION,
295: JOptionPane.QUESTION_MESSAGE, icon);
296: if (option == JOptionPane.OK_OPTION) {
297: Object[] nodes = wfGraph.getSelectionNodes();
298: Object[] edges = wfGraph.getSelectionEdges();
299: if (edges.length > 0)
300: wfPersistence.deleteEdges(edges);
301: for (int i = 0; i < nodes.length; i++)
302: wfPersistence.deleteNode((String) nodes[i]);
303: JOptionPane.showMessageDialog(null, resource
304: .getString("wfmanager.removesucc"), resource
305: .getString("wfmanager.deletesel"),
306: JOptionPane.INFORMATION_MESSAGE, icon);
307: }
308: } catch (Exception e1) {
309: JOptionPane.showMessageDialog(null, e1.getMessage(),
310: resource.getString("wfmanager.delproj"),
311: JOptionPane.INFORMATION_MESSAGE, icon);
312: //JOptionPane.showMessageDialog(null, "You can not delete this selection","Delete Selection",JOptionPane.INFORMATION_MESSAGE, icon);
313: }
314:
315: }
316:
317: public void copySelection() {
318: clipboardEdges = new Vector();
319: clipboardNodes = ((Object[]) wfGraph.getSelectionNodes()).length;
320: Object[] nodes = wfGraph.getVertices(wfGraph
321: .getSelectionCells());
322: if (nodes.length > 1) {
323: for (int i = 0; i < nodes.length; i++) {
324: for (int j = 0; j < nodes.length; j++) {
325: Object[] edge = wfGraph.getEdgesBetween(nodes[i],
326: nodes[j]);
327: if (edge.length > 0) {
328: Object target = wfGraph
329: .getSourceVertex(edge[0]);
330: if (nodes[i].equals(target)) {
331: Edge e = new Edge();
332: e.target = i;
333: e.source = j;
334: clipboardEdges.add(e);
335: }
336: }
337: }
338: }
339: }
340:
341: }
342:
343: public void pasteSelection() {
344: try {
345: Object[] nodes = new Object[clipboardNodes];
346: for (int i = 0; i < clipboardNodes; i++) {
347: Vector node = windowManager.addNode();
348: nodes[i] = (String) (node.elementAt(0));
349: if (!((String) nodes[i]).equals(""))
350: wfPersistence.addNode((String) nodes[i],
351: (String) (node.elementAt(1)));
352: else
353: return;
354:
355: // wfGraph.addNewNode((String)nodes[i]);
356: }
357:
358: for (Enumeration e = clipboardEdges.elements(); e
359: .hasMoreElements();) {
360: Edge edge = (Edge) e.nextElement();
361: wfPersistence.addEdge((String) nodes[edge.source],
362: (String) nodes[edge.target]);
363: // wfGraph.restoreEdges();
364: }
365: } catch (Exception e1) {
366: JOptionPane.showMessageDialog(null, resource
367: .getString("wfmanager.pasteerror"));
368: }
369:
370: }
371:
372: public void newProject() {
373: String temp;
374: if ((temp = windowManager.newProjectWindow()) != null) {
375: /*if(activeProject!=null){
376: JMSEvents jmse = new JMSEvents();
377: jmse.sendProjectEvent(PROJECTCLOSE, activeProject);
378: }*/
379: activeProject = temp;
380: wfGraph.newGraph();
381: makeJMSConnection(activeProject);
382: }
383: updateStatus();
384: }
385:
386: public void cloneProject() {
387: windowManager.cloneProjectWindow();
388: }
389:
390: public void openProject() {
391: windowManager.openProject();
392: updateStatus();
393: }
394:
395: public void Info() {
396: Info.showInfo();
397: }
398:
399: public void openProject(String project) throws Exception {
400: try {
401: wfPersistence.openProject(project);
402: wfGraph.openGraph(project);
403: makeJMSConnection(project);
404: activeProject = project;
405: setTitle(project);
406: setLayout1();
407: updateStatus();
408: } catch (Exception e1) {
409: JOptionPane.showMessageDialog(null, resource
410: .getString("jprojectlist.modify"));
411: throw new Exception(resource
412: .getString("wfmanager.openerror"));
413: }
414:
415: }
416:
417: public void setLayout1() {
418: wfGraph.setLayout1();
419: }
420:
421: public void setLayout2() {
422: wfGraph.setExpand();
423: }
424:
425: public void automaticLayout() {
426: if (automatic) {
427: automatic = false;
428: wfGraph.setAutomaticLayout(false);
429: } else {
430: automatic = true;
431: wfGraph.setAutomaticLayout(true);
432: }
433: }
434:
435: public void setStatusBar(String info) {
436: frame.setStatusBar(info);
437: }
438:
439: public Color getGraphBackground() {
440: return wfGraph.getBackground();
441: }
442:
443: public void setGraphBackground(Color color) {
444: wfGraph.setBackground(color);
445: }
446:
447: public void zoom(int value) {
448: wfGraph.setZoom(value);
449: }
450:
451: public void zoomIn() {
452: wfGraph.zoomIn();
453: }
454:
455: public void zoomOut() {
456: wfGraph.zoomOut();
457: }
458:
459: public void fitWindow() {
460: wfGraph.fitWindow(frame.getScrollPane());
461: }
462:
463: public BufferedImage getGraphImage() {
464: return WFGraph.toImage(wfGraph);
465: }
466:
467: public String getGraphVRML() {
468: return WFGraph.vrmlView(wfGraph);
469: }
470:
471: public WFGraph getGraph() {
472: return wfGraph;
473: }
474:
475: public JFrame getFrame() {
476: return frame;
477: }
478:
479: public void setTitle(String title) {
480: frame.setTitle(resource.getString("wfmanager.title") + title
481: + resource.getString("wfmanager.user") + activeUser);
482: }
483:
484: public WFPersistence getPersistence() {
485: return wfPersistence;
486: }
487:
488: public void changeRole(String nodeName) {
489: windowManager.changeRoleWindow(nodeName);
490: }
491:
492: public void newUser() {
493: windowManager.newUser();
494: }
495:
496: public void newRole() {
497: windowManager.newRole();
498: }
499:
500: public void addUserToRole() {
501: windowManager.addUserToRole();
502: }
503:
504: public void addMapperToRole() {
505: windowManager.addMapperToRole();
506: }
507:
508: public void usersInProject() {
509: windowManager.usersInProject();
510: }
511:
512: public void updateStatus() {
513: try {
514: String s = " ";
515: String state;
516:
517: if (wfGraph.getSelectionNodes().length == 1
518: && wfGraph.getRoots().length > 0) {
519: Object[] cell = wfGraph.getSelectionNodes();
520: StrutsNodeValue nl = wfPersistence
521: .getProjectNode((String) cell[0]);
522: String name = (String) cell[0];
523: if (wfPersistence.isActive(name))
524: s = name + resource.getString("wfmanager.is")
525: + nl.getState()
526: + resource.getString("wfmanager.byuser")
527: + nl.getRole();
528: else
529: s = name + " is " + nl.getState();
530:
531: } else {
532: s = wfGraph.getVertices(wfGraph.getRoots()).length
533: + resource.getString("wfmanager.cell");
534: }
535: frame.setStatusBar(s);
536:
537: } catch (Exception e1) {
538: JOptionPane.showMessageDialog(null, resource
539: .getString("wfmanager.updateerror"));
540: }
541:
542: }
543:
544: }// WFManager
|