1 11 12 package org.enhydra.jawe; 13 14 import org.enhydra.jawe.actions.*; 15 import org.enhydra.jawe.graph.*; 16 17 import org.jgraph.JGraph; 18 import org.jgraph.graph.*; 19 20 import java.awt.*; 21 import java.awt.geom.Point2D ; 22 import java.awt.geom.Rectangle2D ; 23 import java.awt.event.*; 24 import java.util.*; 25 import javax.swing.*; 26 import javax.swing.event.*; 27 import javax.swing.border.*; 28 import org.enhydra.jawe.PackageEditor; 29 import org.enhydra.jawe.xml.elements.WorkflowProcess; 30 31 33 40 public class JaWEMarqueeHandler extends BasicMarqueeHandler { 42 43 private transient AbstractGraph graph=null; 44 45 private transient AbstractEditor ED=null; 46 47 private transient WorkflowManager workflowManager=null; 48 49 50 private boolean persistent=false; 51 52 53 private transient JToggleButton selectButton = new JToggleButton(); 54 55 private transient JToggleButton processButton = new JToggleButton(); 56 57 private transient JToggleButton participantButton = new JToggleButton(); 58 59 private transient JToggleButton subflowActivityButton = new JToggleButton(); 60 61 private transient JToggleButton blockActivityButton = new JToggleButton(); 62 63 private transient JToggleButton startButton = new JToggleButton(); 64 65 private transient JToggleButton endButton = new JToggleButton(); 66 67 private transient JToggleButton automaticStartEndButton = new JToggleButton(); 68 69 private transient JToggleButton genericActivityButton = new JToggleButton(); 70 71 private transient JToggleButton routeActivityButton = new JToggleButton(); 72 73 private transient JToggleButton transitionButton = new JToggleButton(); 74 75 private transient JToggleButton selfRoutedTransitionButton = new JToggleButton(); 76 77 private transient JToggleButton circularTransitionButton = new JToggleButton(); 78 79 81 private transient Cursor participantCursor; 82 83 private transient Cursor processCursor; 84 85 private transient Cursor subflowActivityCursor; 86 87 private transient Cursor blockActivityCursor; 88 89 private transient Cursor startCursor; 90 91 private transient Cursor endCursor; 92 93 private transient Cursor genericActivityCursor; 94 95 private transient Cursor routeActivityCursor; 96 97 private transient Cursor transitionCursor; 98 99 private transient Cursor selfRoutedTransitionCursor; 100 101 private transient Cursor circularTransitionCursor; 102 103 104 private transient ML ml=new ML(); 105 106 private transient ASEML aseml=new ASEML(); 107 108 private transient AL al=new AL(); 109 110 111 protected Point start; 112 113 protected Point current; 114 115 protected PortView port; 116 117 protected PortView firstPort; 118 119 protected PortView lastPort; 120 121 protected Point popupPoint; 122 123 124 125 class ML extends MouseAdapter { public void mousePressed(MouseEvent ev) { 127 if (ev.getClickCount()==2) persistent=true; 128 else persistent=false; 129 } 130 } 131 132 133 class ASEML extends MouseAdapter { public void mousePressed(MouseEvent ev) { 135 if (ED instanceof PackageEditor) { 136 Set activities=JaWEGraphModel.getAllActivitiesInModel(graph.getModel()); 137 if (activities!=null) { 138 Iterator it=activities.iterator(); 139 while(it.hasNext()) { 140 Activity act=(Activity)it.next(); 141 ProcessEditor pe=act.getImplementationEditor(); 142 if (pe!=null) { 143 ProcessGraph pg=(ProcessGraph)pe.getGraph(); 144 pg.getWorkflowManager().createGraphStarts((WorkflowProcess)pg.getPropertyObject(),true,true); 145 pg.getWorkflowManager().createGraphEnds((WorkflowProcess)pg.getPropertyObject(),true,true); 146 147 Set blockActs=pg.getWorkflowManager().getBlockActivities(true); 149 Iterator itBas=blockActs.iterator(); 150 while (itBas.hasNext()) { 151 BlockActivity ba=(BlockActivity)itBas.next(); 152 ProcessEditor bwe=ba.getImplementationEditor(); 153 if (bwe!=null) { 154 ProcessGraph bag=(ProcessGraph)bwe.getGraph(); 155 bag.getWorkflowManager().createGraphStarts((WorkflowProcess)pg.getPropertyObject(),true,true); 156 bag.getWorkflowManager().createGraphEnds((WorkflowProcess)pg.getPropertyObject(),true,true); 157 } 158 } 159 } 160 } 161 } 162 163 } else { 164 workflowManager.createGraphStarts((WorkflowProcess)graph.getPropertyObject(),true,true); 165 workflowManager.createGraphEnds((WorkflowProcess)graph.getPropertyObject(),true,true); 166 } 167 ED.getStatusBar().updateMessage(); 168 } 169 } 170 171 172 class AL implements ActionListener { public void actionPerformed (ActionEvent ev) { 174 JToggleButton source=(JToggleButton)ev.getSource(); 175 setProperCursor(source); 176 } 177 } 178 179 180 183 public JaWEMarqueeHandler (AbstractGraph graph) { 184 this.graph=graph; 186 ED=graph.getEditor(); 188 workflowManager=graph.getWorkflowManager(); 190 191 ImageIcon curIc; 193 Point hotSpot; 195 Image curIm; 197 198 try { 200 curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.PARTICIPANT_TOOL+JaWEConstants.IMAGE_SUFFIX)); 201 hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2); 202 curIm = curIc.getImage(); 203 participantCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot, 204 "participant20x20"); 205 } catch (Exception e) { 206 System.err.println("Missing participant cursor in property file !"); 207 } 208 209 try { 210 curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.PROCESS_ACTIVITY_TOOL+JaWEConstants.IMAGE_SUFFIX)); 211 hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2); 212 curIm = curIc.getImage(); 213 processCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot, 214 "process20x20"); 215 } catch (Exception e) { 216 System.err.println("Missing process cursor in property file !"); 217 } 218 219 try { 220 curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.SUBFLOW_ACTIVITY_TOOL+JaWEConstants.IMAGE_SUFFIX)); 221 hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2); 222 curIm = curIc.getImage(); 223 subflowActivityCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot, 224 "subflowActivity20x20"); 225 } catch (Exception e) { 226 System.err.println("Missing subflow activity cursor in property file !"); 227 } 228 229 try { 230 curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.BLOCK_ACTIVITY_TOOL+JaWEConstants.IMAGE_SUFFIX)); 231 hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2); 232 curIm = curIc.getImage(); 233 blockActivityCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot, 234 "blockActivity20x20"); 235 } catch (Exception e) { 236 System.err.println("Missing block activity cursor in property file !"); 237 } 238 239 try { 240 curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.START_TOOL+JaWEConstants.IMAGE_SUFFIX)); 241 hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2); 242 curIm = curIc.getImage(); 243 startCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot, 244 "start20x20"); 245 } catch (Exception e) { 246 System.err.println("Missing start cursor in property file !"); 247 } 248 249 try { 250 curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.END_TOOL+JaWEConstants.IMAGE_SUFFIX)); 251 hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2); 252 curIm = curIc.getImage(); 253 endCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,"end20x20"); 254 } catch (Exception e) { 255 System.err.println("Missing end cursor in property file !"); 256 } 257 258 try { 259 curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.GENERIC_ACTIVITY_TOOL+JaWEConstants.IMAGE_SUFFIX)); 260 hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2); 261 curIm = curIc.getImage(); 262 genericActivityCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot, 263 "genericActivity20x20"); 264 } catch (Exception e) { 265 System.err.println("Missing generic activity cursor in property file !"); 266 } 267 268 try { 269 curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.ROUTE_ACTIVITY_TOOL+JaWEConstants.IMAGE_SUFFIX)); 270 hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2); 271 curIm = curIc.getImage(); 272 routeActivityCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,"routeActivity20x20"); 273 } catch (Exception e) { 274 System.err.println("Missing route activity cursor in property file !"); 275 } 276 277 try { 278 curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.TRANSITION_TOOL+JaWEConstants.IMAGE_SUFFIX)); 279 hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2); 280 curIm = curIc.getImage(); 281 transitionCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,"transition20x20"); 282 } catch (Exception e) { 283 System.err.println("Missing transition cursor in property file !"); 284 } 285 286 try { 287 curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.SELF_ROUTED_TRANSITION_TOOL+JaWEConstants.IMAGE_SUFFIX)); 288 hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2); 289 curIm = curIc.getImage(); 290 selfRoutedTransitionCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,"selfRoutedTransition20x20"); 291 } catch (Exception e) { 292 System.err.println("Missing self routed transition cursor in property file !"); 293 } 294 295 try { 296 curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.CIRCULAR_TRANSITION_TOOL+JaWEConstants.IMAGE_SUFFIX)); 297 hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2); 298 curIm = curIc.getImage(); 299 circularTransitionCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,"circularTransition20x20"); 300 } catch (Exception e) { 301 System.err.println("Missing circular transition cursor in property file !"); 302 } 303 304 selectButton.addMouseListener(ml); 306 participantButton.addMouseListener(ml); 307 processButton.addMouseListener(ml); 308 subflowActivityButton.addMouseListener(ml); 309 blockActivityButton.addMouseListener(ml); 310 startButton.addMouseListener(ml); 311 endButton.addMouseListener(ml); 312 automaticStartEndButton.addMouseListener(aseml); 313 genericActivityButton.addMouseListener(ml); 314 routeActivityButton.addMouseListener(ml); 315 transitionButton.addMouseListener(ml); 316 selfRoutedTransitionButton.addMouseListener(ml); 317 circularTransitionButton.addMouseListener(ml); 318 319 selectButton.addActionListener(al); 321 participantButton.addActionListener(al); 322 processButton.addActionListener(al); 323 subflowActivityButton.addActionListener(al); 324 blockActivityButton.addActionListener(al); 325 startButton.addActionListener(al); 326 endButton.addActionListener(al); 327 automaticStartEndButton.addActionListener(al); 328 genericActivityButton.addActionListener(al); 329 routeActivityButton.addActionListener(al); 330 transitionButton.addActionListener(al); 331 selfRoutedTransitionButton.addActionListener(al); 332 circularTransitionButton.addActionListener(al); 333 334 ButtonGroup group = new ButtonGroup(); 335 if (ED instanceof ProcessEditor) { 336 group.add(selectButton); 337 group.add(participantButton); 338 group.add(subflowActivityButton); 339 group.add(blockActivityButton); 340 group.add(startButton); 341 group.add(endButton); 342 group.add(automaticStartEndButton); 343 group.add(genericActivityButton); 344 group.add(routeActivityButton); 345 group.add(transitionButton); 346 group.add(selfRoutedTransitionButton); 347 group.add(circularTransitionButton); 348 } else { 349 group.add(selectButton); 350 group.add(processButton); 351 group.add(automaticStartEndButton); 352 } 353 if (!JaWEConfig.getInstance().getUseBubblesStatus()) { 354 enableBubblesButtons(false); 355 } 356 357 } 358 359 360 public boolean isForceMarqueeEvent(MouseEvent e) { 361 return ((selectButton.isSelected() && SwingUtilities.isRightMouseButton(e)) || 362 !selectButton.isSelected() || 363 super.isForceMarqueeEvent(e)); 364 } 365 366 public void mousePressed(MouseEvent ev) { 367 if (SwingUtilities.isRightMouseButton(ev)) { 369 Object cell = graph.getFirstCellForLocation(ev.getX(),ev.getY()); 371 popupPoint = (Point)graph.fromScreen(new Point(ev.getPoint())); JPopupMenu menu = createPopupMenu(cell); 374 menu.show(graph,ev.getX(),ev.getY()); 376 } else if (!ev.isConsumed() && !selectButton.isSelected()) { 377 378 start = (Point)graph.snap(ev.getPoint()); firstPort = port; 380 381 if ((transitionButton.isSelected() || selfRoutedTransitionButton.isSelected()) && firstPort!=null) { 383 double scale=graph.getScale(); 384 start=firstPort.getBounds().getBounds().getLocation(); start.x+=JaWEPortView.getPortSize()/2;start.y+=JaWEPortView.getPortSize()/2; 386 start=new Point((int)(start.getX() * scale), 387 (int)(start.getY() * scale)); 388 if (acceptsSourceOrTarget(firstPort,true,null,false)) { 390 ev.consume(); 391 } else { 392 firstPort=null; 393 port = null; 394 start = null; 395 current = null; 396 } 397 return; 398 } 399 400 if (circularTransitionButton.isSelected() && firstPort!=null) { 402 boolean as=acceptsSourceOrTarget(firstPort,true,null,true); 403 boolean at=acceptsSourceOrTarget(firstPort,false,firstPort,true); 404 if (as && at) { 405 workflowManager.insertTransition(start,start,firstPort,firstPort, 408 false,true); 409 } 410 411 } 412 413 if (participantButton.isSelected()) { 415 workflowManager.insertParticipantAndArrangeParticipants(start,null); 416 } 417 418 if (processButton.isSelected()) { 420 org.enhydra.jawe.graph.Process pr=workflowManager.insertProcess (((PackageGraph)graph).getNextInsertionPoint(),true); 421 ((PackageEditor)ED).putProcessObjectMapping((WorkflowProcess)pr.getUserObject(),pr); 422 } 423 424 if (subflowActivityButton.isSelected()) { 426 workflowManager.insertSubflowAndArrangeParticipants(start); 427 } 428 429 if (blockActivityButton.isSelected()) { 431 workflowManager.insertBlockActivityAndArrangeParticipants(start); 432 } 433 434 if (startButton.isSelected()) { 436 workflowManager.insertStartAndArrangeParticipants(start); 437 } 438 439 if (endButton.isSelected()) { 441 workflowManager.insertEndAndArrangeParticipants(start); 442 } 443 444 if (genericActivityButton.isSelected()) { 446 workflowManager.insertActivityAndArrangeParticipants(start); 447 } 448 449 if (routeActivityButton.isSelected()) { 451 workflowManager.insertRouteAndArrangeParticipants(start); 452 } 453 454 ev.consume(); 455 if (!persistent) selectButton.doClick(); 456 firstPort=null; 457 port = null; 458 start = null; 459 current = null; 460 461 } 462 463 if(!SwingUtilities.isRightMouseButton(ev)) { 464 super.mousePressed(ev); 465 } 466 467 setProperCursor(); 468 } 469 470 public void mouseDragged(MouseEvent ev) { 471 if (!ev.isConsumed() && (transitionButton.isSelected() || selfRoutedTransitionButton.isSelected()) && (firstPort != null) && 472 !SwingUtilities.isRightMouseButton(ev)) { 473 Graphics g = graph.getGraphics(); 474 Color bg = graph.getBackground(); 475 Color fg = Utils.getColor(JaWEConfig.getInstance().getTransitionColor()); 476 g.setColor(fg); 477 g.setXORMode(bg); 478 overlay(g); 479 current = (Point)graph.snap(ev.getPoint()); 484 double scale=graph.getScale(); 485 port=graph.getPortViewAt((int)(ev.getX() / scale), 486 (int)(ev.getY() / scale)); 487 if (port!=null) { 488 current = port.getBounds().getBounds().getLocation(); current=new Point((int)(current.x * scale), 491 (int)(current.y * scale)); 492 current.x+=JaWEPortView.getPortSize()/2;current.y+=JaWEPortView.getPortSize()/2; 493 494 } 495 g.setColor(bg); 496 g.setXORMode(fg); 497 overlay(g); 498 ev.consume(); 499 } 500 super.mouseDragged(ev); 502 504 } 505 506 public void mouseReleased(MouseEvent ev) { 507 if (ev != null && !ev.isConsumed() && (transitionButton.isSelected() || selfRoutedTransitionButton.isSelected()) 508 && !SwingUtilities.isRightMouseButton(ev)) { 509 if (acceptsSourceOrTarget(port,false,firstPort,false) && port!=firstPort) { 512 workflowManager.insertTransition(start,current,firstPort,port, 513 selfRoutedTransitionButton.isSelected(),true); 514 } 515 else { 516 Graphics g = graph.getGraphics(); 517 Color bg = graph.getBackground(); 518 Color fg = Utils.getColor(JaWEConfig.getInstance().getTransitionColor()); 519 g.setColor(fg); 520 g.setXORMode(bg); 521 port = firstPort; 522 overlay(g); 523 } 524 ev.consume(); 525 } 526 if (!persistent) selectButton.doClick(); 527 firstPort = null; 528 port = null; 529 start = null; 530 current = null; 531 try { 533 if (ev != null && !ev.isConsumed() && marqueeBounds != null 534 && !SwingUtilities.isRightMouseButton(ev)) { 535 Rectangle2D bounds = graph.fromScreen(marqueeBounds); CellView[] rootViews = graph.getGraphLayoutCache().getRoots(bounds); 537 538 CellView[] views = AbstractCellView.getDescendantViews(rootViews); 540 ArrayList wholeList = new ArrayList(); 541 ArrayList participantList = new ArrayList(); 542 ArrayList otherList = new ArrayList(); 543 for (int i = 0; i < views.length; i++) { 544 if (bounds.contains(views[i].getBounds())) { 545 if (!(views[i] instanceof ParticipantView)) { 546 otherList.add(views[i].getCell()); 547 } 548 else { 549 participantList.add(views[i].getCell()); 550 } 551 wholeList.add(views[i].getCell()); 553 } 555 } 556 557 563 Object [] cells = wholeList.toArray(); 564 565 graph.getUI().selectCellsForEvent(graph, cells, ev); 566 Rectangle dirty = marqueeBounds.getBounds(); dirty.width++; dirty.height++; graph.repaint(dirty); 571 ev.consume(); 572 } 573 } finally { 574 currentPoint = null; 575 startPoint = null; 576 marqueeBounds = null; 577 } 578 setProperCursor(); 579 } 580 581 public void mouseMoved(MouseEvent ev) { 582 if (!ev.isConsumed() && !selectButton.isSelected()) { 583 ev.consume(); 584 if (transitionButton.isSelected() || selfRoutedTransitionButton.isSelected() || 585 circularTransitionButton.isSelected()) { 586 PortView oldPort = port; 587 double scale=graph.getScale(); 588 PortView newPort=graph.getPortViewAt((int)(ev.getX() / scale), 589 (int)(ev.getY() / scale)); 590 if (oldPort != newPort) { 592 Graphics g = graph.getGraphics(); 593 Color bg = graph.getBackground(); 594 Color fg = graph.getMarqueeColor(); 595 g.setColor(fg); 596 g.setXORMode(bg); 597 overlay(g); 598 port = newPort; 599 g.setColor(bg); 600 g.setXORMode(fg); 601 overlay(g); 602 } 603 } 604 } 605 super.mouseMoved(ev); 606 } 607 608 public void overlay(Graphics g) { 609 super.overlay(g); 610 paintPort(graph.getGraphics()); 611 if (start != null) { 612 if ((transitionButton.isSelected() || selfRoutedTransitionButton.isSelected()) && current != null) { 613 g.drawLine(start.x, start.y, current.x, current.y); 614 } 615 } 616 } 617 618 protected void paintPort(Graphics g) { 619 if (port != null) { 620 boolean offset = (GraphConstants.getOffset(port.getAttributes()) != null); 621 Rectangle r = (offset) ? port.getBounds().getBounds() : port.getParentView().getBounds().getBounds(); r = (Rectangle)graph.toScreen(new Rectangle(r)); int s = 3; 625 r.translate(-s, -s); 626 r.setSize(r.width+2*s, r.height+2*s); 627 JaWEGraphUI ui = (JaWEGraphUI)graph.getUI(); 628 ui.paintCell(g, port, r, true); 629 } 630 } 631 632 639 protected JPopupMenu createPopupMenu(final Object cell) { 640 JPopupMenu menu = new JPopupMenu(); 641 BarFactory jbf=new BarFactory(ED); 642 643 JMenuItem mi; 644 645 if (((cell==null) || ( 646 !(cell instanceof Participant) && 647 !(cell instanceof org.enhydra.jawe.graph.Process) && 648 !(cell instanceof BlockActivity) && 649 !(cell instanceof Transition) && 650 !(cell instanceof Start) && 651 !(cell instanceof End))) && (graph instanceof ProcessGraph)) { 652 menu.add(jbf.createMenuItem( 654 Utils.getUnqualifiedClassName(Cut.class),false)); 655 menu.add(jbf.createMenuItem( 657 Utils.getUnqualifiedClassName(Copy.class),false)); 658 659 menu.add(jbf.createMenuItem( 661 Utils.getUnqualifiedClassName(PasteAt.class),false)); 662 if (!graph.isSelectionEmpty() && cell != null) { 663 menu.addSeparator(); 664 } 665 } 666 if (!graph.isSelectionEmpty() && cell!=null) { 668 669 menu.add(jbf.createMenuItem( 670 Utils.getUnqualifiedClassName(Delete.class),false)); 671 menu.addSeparator(); 672 } 673 if ((cell != null) && 675 !(cell instanceof Start) && 676 !(cell instanceof End)) { 677 678 if (cell instanceof Transition && graph instanceof ProcessGraph) { 679 Transition t=(Transition)cell; 680 boolean isCircular=Utils.isCircularTransition(t.getAttributes()); 681 if (!isCircular) { 682 boolean isRouting=Utils.isRoutingTransition(t.getAttributes()); 683 684 if (t.getSourceActivity() instanceof Start || 685 t.getTargetActivity() instanceof End) { 686 if (!isRouting) { 687 menu.add(jbf.createMenuItem( 688 Utils.getUnqualifiedClassName(SetSelfRouting.class),false)); 689 } else { 690 menu.add(jbf.createMenuItem( 691 Utils.getUnqualifiedClassName(SetNoRouting.class),false)); 692 } 693 } else { 694 menu.add(jbf.createMenuItem( 695 Utils.getUnqualifiedClassName(EditProperties.class),false)); 696 if (!isRouting) { 697 menu.add(jbf.createMenuItem( 698 Utils.getUnqualifiedClassName(AddPoint.class),false)); 699 menu.add(jbf.createMenuItem( 700 Utils.getUnqualifiedClassName(RemovePoint.class),false)); 701 menu.add(jbf.createMenuItem( 702 Utils.getUnqualifiedClassName(SetSelfRouting.class),false)); 703 } else { 704 menu.add(jbf.createMenuItem( 705 Utils.getUnqualifiedClassName(SetNoRouting.class),false)); 706 } 707 } 708 } else { 709 menu.add(jbf.createMenuItem( 710 Utils.getUnqualifiedClassName(EditProperties.class),false)); 711 } 712 } else { 713 menu.add(jbf.createMenuItem( 714 Utils.getUnqualifiedClassName(EditProperties.class),false)); 715 } 716 717 if (cell instanceof org.enhydra.jawe.graph.Process || 719 cell instanceof Subflow || 720 cell instanceof BlockActivity) { 721 boolean toAdd=true; 722 if (cell instanceof Subflow) { 723 Subflow sbflw=(Subflow)cell; 724 WorkflowProcess wp=sbflw.getReferencedWorkflowProcess(graph.getXMLPackage()); 725 if (wp==null) { 726 toAdd=false; 727 } 728 } 729 if (toAdd) { 730 menu.add(jbf.createMenuItem( 731 Utils.getUnqualifiedClassName(EditCell.class),false)); 732 } 733 } 734 735 if (cell instanceof org.enhydra.jawe.graph.Process) { 736 menu.add(jbf.createMenuItem( 737 Utils.getUnqualifiedClassName(MakeCopyOfProcess.class),false)); 738 } 739 740 } 741 742 if (cell instanceof Activity && !(cell instanceof org.enhydra.jawe.graph.Process) && 743 !(cell instanceof Start) && !(cell instanceof End)) { 744 menu.add(jbf.createMenuItem(JaWEConstants.REFERRED_DOCUMENT,false)); 745 } 746 747 if (cell instanceof Participant) { 749 menu.addSeparator(); 750 menu.add(jbf.createMenuItem( 751 Utils.getUnqualifiedClassName(MoveUpParticipant.class),false)); 752 menu.add(jbf.createMenuItem( 753 Utils.getUnqualifiedClassName(MoveDownParticipant.class),false)); 754 } 755 757 return menu; 758 } 759 760 763 public Point getPopupPoint () { 764 return popupPoint; 765 } 766 767 771 public boolean acceptsSourceOrTarget (PortView port, 772 boolean source, 773 PortView firstPort, 774 boolean circularTransition) { 775 if (port!=null && port.getCell()!=null 777 && (port.getCell() instanceof DefaultPort)) { 779 Object p=((DefaultPort)port.getCell()).getParent(); 782 if ((p instanceof Linkable)) { 783 boolean usingBubbles=JaWEConfig.getInstance().getUseBubblesStatus(); 784 if (source) { 785 if (!((Linkable)p).acceptsSource()) return false; 786 if (usingBubbles) { 789 if (p instanceof Activity) { 790 Activity act=(Activity)p; 791 if (Utils.hasConnectedEndBubble(act) && !circularTransition) { 792 JOptionPane.showMessageDialog(ED.getWindow(), 793 ResourceManager.getLanguageDependentString( 794 "ErrorLastActivityCannotHaveOutgoingTransitions"), 795 JaWE.getAppTitle(),JOptionPane.ERROR_MESSAGE); 796 return false; 797 798 } 799 } 800 } 801 return true; 802 } else { 803 if (!((Linkable)p).acceptsTarget()) return false; 804 Object srcCell=((DefaultPort)firstPort.getCell()).getParent(); 805 if (usingBubbles && (p instanceof End) && (srcCell instanceof Start)) { 807 JOptionPane.showMessageDialog(ED.getWindow(), 808 ResourceManager.getLanguageDependentString("ErrorCannotConnectStartAndEnd"), 809 JaWE.getAppTitle(),JOptionPane.ERROR_MESSAGE); 810 return false; 811 } 812 if (p instanceof Activity) { 813 Activity act=(Activity)p; 814 Set trns=act.getIncomingTransitions(); 815 if (usingBubbles) { 818 if (trns.size()==1 || trns.size()==2) { 819 Object [] trnsArr=trns.toArray(); 820 if((((Transition)trnsArr[0]).getSourceActivity() instanceof Start) || 821 (trns.size()==2 && ((Transition)trnsArr[1]).getSourceActivity() instanceof Start)) { 822 if (!circularTransition) { 823 JOptionPane.showMessageDialog(ED.getWindow(), 824 ResourceManager.getLanguageDependentString( 825 "ErrorFirstActivityCannotHaveIncomingTransitions"), 826 JaWE.getAppTitle(),JOptionPane.ERROR_MESSAGE); 827 return false; 828 } 829 } 830 } 831 if ((trns.size()>0) && (srcCell instanceof Start)) { 832 if (trns.size()>1 || (trns.size()==1 && !Utils.hasCircularTransitions(trns))) { 833 JOptionPane.showMessageDialog(ED.getWindow(), 834 ResourceManager.getLanguageDependentString( 835 "ErrorFirstActivityCannotHaveIncomingTransitions"), 836 JaWE.getAppTitle(),JOptionPane.ERROR_MESSAGE); 837 return false; 838 } 839 } 840 if (act instanceof End) { 841 Set saNETrns=((Activity)srcCell).getNonExceptionalOutgoingTransitions(); 842 if (saNETrns.size()>1 || (saNETrns.size()==1 && !Utils.hasCircularTransitions(saNETrns))) { 843 JOptionPane.showMessageDialog(ED.getWindow(), 844 ResourceManager.getLanguageDependentString( 845 "ErrorLastActivityCannotHaveOutgoingTransitions"), 846 JaWE.getAppTitle(),JOptionPane.ERROR_MESSAGE); 847 return false; 848 } 849 } 850 } 851 if (trns.size()>0) { 854 Iterator it=trns.iterator(); 855 while (it.hasNext()) { 856 Object SRC=((Transition)it.next()).getSourceActivity(); 857 if (src.equals(srcCell)) { 858 JOptionPane.showMessageDialog(ED.getWindow(), 859 ResourceManager.getLanguageDependentString( 860 "ErrorActivityCannotHaveMoreThenOneIncomingOutgoingTransitionFromToTheSameActivity"), 861 JaWE.getAppTitle(),JOptionPane.ERROR_MESSAGE); 862 return false; 863 } 864 } 865 } 866 } 867 return true; 868 } 869 } 870 } 871 return false; 873 } 874 875 879 public Hashtable getSpecialButtons() { 880 Hashtable buttons = new Hashtable(); 881 ButtonGroup group = new ButtonGroup(); 882 if (ED instanceof ProcessEditor) { 884 buttons.put(JaWEConstants.SELECT_TOOL, selectButton); 885 buttons.put(JaWEConstants.PARTICIPANT_TOOL, participantButton); 886 buttons.put(JaWEConstants.SUBFLOW_ACTIVITY_TOOL, subflowActivityButton); 887 buttons.put(JaWEConstants.BLOCK_ACTIVITY_TOOL, blockActivityButton); 888 buttons.put(JaWEConstants.START_TOOL, startButton); 889 buttons.put(JaWEConstants.END_TOOL, endButton); 890 buttons.put(JaWEConstants.AUTOMATIC_START_END_TOOL, automaticStartEndButton); 891 buttons.put(JaWEConstants.GENERIC_ACTIVITY_TOOL, genericActivityButton); 892 buttons.put(JaWEConstants.ROUTE_ACTIVITY_TOOL, routeActivityButton); 893 buttons.put(JaWEConstants.TRANSITION_TOOL, transitionButton); 894 buttons.put(JaWEConstants.SELF_ROUTED_TRANSITION_TOOL, selfRoutedTransitionButton); 895 buttons.put(JaWEConstants.CIRCULAR_TRANSITION_TOOL, circularTransitionButton); 896 } else { 897 group.add(selectButton); buttons.put(JaWEConstants.SELECT_TOOL,selectButton); 898 group.add(processButton); buttons.put(JaWEConstants.PROCESS_ACTIVITY_TOOL,processButton); 899 group.add(automaticStartEndButton); buttons.put(JaWEConstants.AUTOMATIC_START_END_TOOL, automaticStartEndButton); 900 } 901 selectButton.doClick(); 902 return buttons; 903 } 904 905 public JToggleButton getSelectButton () { 906 return selectButton; 907 } 908 909 public JToggleButton getProcessButton () { 910 return processButton; 911 } 912 913 public JToggleButton getParticipantButton () { 914 return participantButton; 915 } 916 917 public JToggleButton getSubflowActivityButton () { 918 return subflowActivityButton; 919 } 920 921 public JToggleButton getBlockActivityButton () { 922 return blockActivityButton; 923 } 924 925 public JToggleButton getStartButton () { 926 return startButton; 927 } 928 929 public JToggleButton getEndButton () { 930 return endButton; 931 } 932 933 public JToggleButton getGenericActivityButton () { 934 return genericActivityButton; 935 } 936 937 public JToggleButton getRouteActivityButton () { 938 return routeActivityButton; 939 } 940 941 public JToggleButton getTransitionButton () { 942 return transitionButton; 943 } 944 945 public JToggleButton getSelfRoutedTransitionButton () { 946 return selfRoutedTransitionButton; 947 } 948 949 public JToggleButton getCircularTransitionButton () { 950 return circularTransitionButton; 951 } 952 953 public void enableBubblesButtons (boolean enable) { 954 startButton.setEnabled(enable); 955 endButton.setEnabled(enable); 956 automaticStartEndButton.setEnabled(enable); 957 } 958 959 private void setProperCursor () { 960 if (persistent) { 961 Iterator it=ED.getSpecialButtons().values().iterator(); 962 while (it.hasNext()) { 963 JToggleButton source=(JToggleButton)it.next(); 964 if (source.isSelected()) { 965 setProperCursor(source); 966 return; 967 } 968 } 969 } 970 } 971 972 private void setProperCursor(JToggleButton source) { 973 if (source.equals(participantButton)) { 974 graph.setCursor(participantCursor); 975 } else if (source.equals(processButton)) { 976 graph.setCursor(processCursor); 977 } else if (source.equals(subflowActivityButton)) { 978 graph.setCursor(subflowActivityCursor); 979 } else if (source.equals(blockActivityButton)) { 980 graph.setCursor(blockActivityCursor); 981 } else if (source.equals(startButton)) { 982 graph.setCursor(startCursor); 983 } else if (source.equals(endButton)) { 984 graph.setCursor(endCursor); 985 } else if (source.equals(automaticStartEndButton)) { 986 automaticStartEndButton.setSelected(false); 987 selectButton.setSelected(true); 988 } else if (source.equals(genericActivityButton)) { 989 graph.setCursor(genericActivityCursor); 990 } else if (source.equals(routeActivityButton)) { 991 graph.setCursor(routeActivityCursor); 992 } else if (source.equals(transitionButton)) { 993 graph.setCursor(transitionCursor); 994 } else if (source.equals(selfRoutedTransitionButton)) { 995 graph.setCursor(selfRoutedTransitionCursor); 996 } else if (source.equals(circularTransitionButton)) { 997 graph.setCursor(circularTransitionCursor); 998 } else { 999 graph.setCursor(Cursor.getDefaultCursor()); 1000 } 1001 } 1002 1003} 1004 | Popular Tags |