1 package hero.client.grapheditor; 2 3 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 ; 18 import java.awt.image.BufferedImage ; 19 import java.util.Enumeration ; 20 import java.util.Hashtable ; 21 import java.util.Vector ; 22 23 import javax.jms.Message ; 24 import javax.jms.MessageListener ; 25 import javax.swing.JFrame ; 26 import javax.swing.JOptionPane ; 27 import javax.swing.ImageIcon ; 28 29 30 public class WFManager { 31 32 static java.util.ResourceBundle resource = java.util.ResourceBundle.getBundle("resources.Traduction"); 33 34 Frame frame; 35 WFGraph wfGraph; 36 WFWindowManager windowManager; 37 WFPersistence wfPersistence; 38 boolean automatic=true; 39 Vector clipboardEdges; 40 int clipboardNodes; 41 String activeProject=null; 42 String activeUser; 43 Listener ml; 44 public final static String imageBase = "images/"; 45 public final static ImageIcon icon = new ImageIcon (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 55 { 56 private JMSServicesClient jms; 57 58 public Listener(){} 59 60 public void subscription(String subs) throws Exception 61 { 62 jms = JMSServicesClient.getInstance(); 63 jms.createSubscription(this,subs); 64 } 65 66 public void onMessage(Message message) 67 { 68 Object key; 69 Object value = Color.lightGray; 70 71 synchronized(this){ 72 73 try{ 74 Hashtable evt = JMSServicesClient.getEvt(message); 75 76 if (((String )evt.get(EventConstants.PROJECTNAME)).equals(activeProject)) 77 { 78 String event = (String )evt.get(EventConstants.EVENT); 79 80 if (event.equals(EventConstants.SETNODESTATE)) 81 { 82 String nodeState = null; 83 String node = (String )evt.get(EventConstants.NODENAME); 84 int state = (new Integer ((String )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 node = (String )evt.get(EventConstants.NODENAME); 91 String user = (String )evt.get(EventConstants.USERNAME); 92 String state = (String )evt.get(EventConstants.NODESTATE); 93 int type = new Integer (((String )evt.get(EventConstants.NODETYPE))).intValue(); 94 wfGraph.addNewNode(node, (new Integer (state)).intValue(), type); 95 wfPersistence.setProjectNodes(); 96 } 97 if (event.equals(EventConstants.ADDEDGE)) 98 { 99 String edge = (String )evt.get(EventConstants.EDGENAME); 100 String user = (String )evt.get(EventConstants.USERNAME); 101 102 String nodeIn = (String )evt.get(EventConstants.NODEIN); 103 String nodeOut = (String )evt.get(EventConstants.NODEOUT); 104 wfGraph.restoreEdge(edge,nodeIn,nodeOut); 105 106 } 107 if (event.equals(EventConstants.DELETENODE)) 108 { 109 String node = (String )evt.get(EventConstants.NODENAME); 110 String user = (String )evt.get(EventConstants.USERNAME); 111 wfGraph.deleteNode(node); 112 wfPersistence.setProjectNodes(); 113 } 114 if (event.equals(EventConstants.DELETEEDGE)) 115 { 116 String edge = (String )evt.get(EventConstants.EDGENAME); 117 String user = (String )evt.get(EventConstants.USERNAME); 118 wfGraph.deleteEdge(edge); 119 } 120 } 121 122 }catch(Exception e1){e1.printStackTrace();} 123 124 } 125 126 } 127 } 128 129 public void makeJMSConnection(String name) 130 { 131 try { 132 ml.subscription("projectName = '"+name+"'"); 133 }catch (Exception 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 (); 143 activeUser = wfPersistence.getUser(); 144 ml = new Listener (); 145 } catch (Exception 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 edgeName) { 159 try { 160 String condition = windowManager.setEdgeCondition(edgeName); 161 wfPersistence.setEdgeCondition(edgeName, condition); 162 } catch (Exception e1) { 163 JOptionPane.showMessageDialog(null, resource.getString("wfmanager.edgeerror")); 164 } 165 } 166 167 public void addNodeProperty(String nodeName) { 168 windowManager.addNodePropertyWindow(nodeName); 169 } 170 171 public void addProjectProperty() { 172 windowManager.addProjectPropertyWindow(); 173 } 174 175 public void iterate(String nodeName) { 176 windowManager.iterate(nodeName); 177 } 178 179 public void setNodeHook(String nodeName) { 180 try { 181 Vector hook = windowManager.addInterHook(); 182 if (hook.size()!=0) 183 { 184 wfPersistence.addNodeInterHook(nodeName, (String ) hook.get(0), (String ) hook.get(1), (String ) hook.get(2)); 185 String value = windowManager.setInterHookValue((String ) hook.get(2)); 186 wfPersistence.setNodeInterHookValue(nodeName, (String ) hook.get(0), value); 187 } 188 } catch (Exception e1) { 189 JOptionPane.showMessageDialog(null, resource.getString("wfmanager.hookerror")); 190 } 191 } 192 193 public void setProjectHook() { 194 try { 195 Vector hook = windowManager.addInterHook(); 196 if (hook.size()!=0) 197 { 198 wfPersistence.addProjectInterHook((String ) hook.get(0), (String ) hook.get(1), (String ) hook.get(2)); 199 String value = windowManager.setInterHookValue((String ) hook.get(2)); 200 wfPersistence.setProjectInterHookValue((String ) hook.get(0), value); 201 } 202 } catch (Exception e1) { 203 JOptionPane.showMessageDialog(null, resource.getString("wfmanager.hookerror")); 204 } 205 } 206 207 public void editNode(String nodeName) { 208 try { 209 windowManager.editNode(nodeName); 210 } catch (Exception e1) { 211 JOptionPane.showMessageDialog(null, resource.getString("wfmanager.errordesc")); 212 } 213 } 214 215 public void addPerformerAssigment(String nodeName) { 216 windowManager.addPerformerAssigment(nodeName); 217 } 218 219 public void addNode() { 220 try { 221 wfGraph.setAddEdgeState(false); 222 Vector addNode = windowManager.addNode(); 223 String name = (String ) addNode.elementAt(0); 224 if (!name.equalsIgnoreCase("")) { 225 wfPersistence.addNode(name, (String ) addNode.elementAt(1)); 226 } 227 updateStatus(); 228 } catch (Exception addNode) {} 229 } 230 231 public void addNodeSubProcess() { 232 try { 233 wfGraph.setAddEdgeState(false); 234 Vector addNode = windowManager.addNodeSubProcess(); 235 String name = (String ) addNode.elementAt(0); 236 wfPersistence.addNodeSubProcess(name, (String ) addNode.elementAt(1)); 237 updateStatus(); 238 } catch (Exception 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 [] nodes = wfGraph.getSelectionNodes(); 259 Object [] 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 )nodes[i]); 264 JOptionPane.showMessageDialog(null,resource.getString("wfmanager.removesucc"),resource.getString("wfmanager.deletesel"),JOptionPane.INFORMATION_MESSAGE, icon); 265 } 266 } catch (Exception e1) { 267 JOptionPane.showMessageDialog(null,e1.getMessage(),resource.getString("wfmanager.delproj"),JOptionPane.INFORMATION_MESSAGE,icon); 268 } 270 271 } 272 273 public void copySelection(){ 274 clipboardEdges=new Vector (); 275 clipboardNodes=((Object [])wfGraph.getSelectionNodes()).length; 276 Object [] 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 [] edge = wfGraph.getEdgesBetween(nodes[i],nodes[j]); 281 if(edge.length>0){ 282 Object 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 [] nodes = new Object [clipboardNodes]; 300 for (int i = 0; i < clipboardNodes; i++) { 301 Vector node = windowManager.addNode(); 302 nodes[i] = (String ) (node.elementAt(0)); 303 if (!((String ) nodes[i]).equals("")) 304 wfPersistence.addNode((String ) nodes[i], (String ) (node.elementAt(1))); 305 else 306 return; 307 308 } 310 311 for (Enumeration e = clipboardEdges.elements(); e.hasMoreElements();) { 312 Edge edge = (Edge) e.nextElement(); 313 wfPersistence.addEdge((String ) nodes[edge.source], (String ) nodes[edge.target]); 314 } 316 } catch (Exception e1) { 317 JOptionPane.showMessageDialog(null, resource.getString("wfmanager.pasteerror")); 318 } 319 320 } 321 322 public void newProject(){ 323 String temp; 324 if((temp=windowManager.newProjectWindow())!=null){ 325 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 project) throws Exception { 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 e1) { 359 JOptionPane.showMessageDialog(null, resource.getString("jprojectlist.modify")); 360 throw new Exception (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 info){ 384 frame.setStatusBar(info); 385 } 386 387 public Color getGraphBackground(){ 388 return wfGraph.getBackground(); 389 } 390 391 public void setGraphBackground(Color 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 getGraphImage(){ 410 return WFGraph.toImage(wfGraph); 411 } 412 413 public String getGraphVRML(){ 414 return WFGraph.vrmlView(wfGraph); 415 } 416 417 public WFGraph getGraph(){ 418 return wfGraph; 419 } 420 421 public JFrame getFrame(){ 422 return frame; 423 } 424 public void setTitle(String 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 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 s = " "; 455 String state; 456 457 if (wfGraph.getSelectionNodes().length == 1 && wfGraph.getRoots().length > 0) { 458 Object [] cell = wfGraph.getSelectionNodes(); 459 StrutsNodeValue nl = wfPersistence.getProjectNode((String ) cell[0]); 460 String name = (String ) 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 e1) { 472 JOptionPane.showMessageDialog(null, resource.getString("wfmanager.updateerror")); 473 } 474 475 } 476 477 } | Popular Tags |