1 11 12 package org.enhydra.jawe; 13 14 import org.enhydra.jawe.PackageEditor; 15 import org.enhydra.jawe.graph.*; 16 import org.enhydra.jawe.xml.*; 17 import org.enhydra.jawe.xml.elements.Activities; 18 import org.enhydra.jawe.xml.elements.ActivitySet; 19 import org.enhydra.jawe.xml.elements.ActivitySets; 20 import org.enhydra.jawe.xml.elements.Join; 21 import org.enhydra.jawe.xml.elements.Package; 22 import org.enhydra.jawe.xml.elements.Participants; 23 import org.enhydra.jawe.xml.elements.Performer; 24 import org.enhydra.jawe.xml.elements.Split; 25 import org.enhydra.jawe.xml.elements.Transitions; 26 import org.enhydra.jawe.xml.elements.WorkflowProcess; 27 import org.enhydra.jawe.xml.elements.WorkflowProcesses; 28 29 import org.jgraph.graph.*; 30 import org.jgraph.*; 31 32 import java.util.*; 33 import java.awt.*; 34 import java.awt.geom.Point2D ; 35 import java.awt.geom.Rectangle2D ; 36 import javax.swing.*; 37 import javax.swing.tree.*; 38 39 import java.io.*; 40 41 58 public class WorkflowManager implements Serializable { 59 60 61 private transient AbstractGraph graph; 62 63 66 private int horizontalOffset=0; 67 68 70 private static final int defProcessWidth=JaWEConfig.getInstance().getProcessWidth(); 71 72 private static final int defProcessHeight=JaWEConfig.getInstance().getProcessHeight(); 73 74 private static final int minParWidth=JaWEConfig.getInstance().getMinParticipantWidth(); 75 76 private static final int minParHeight=JaWEConfig.getInstance().getMinParticipantHeight(); 77 78 private static final int defParNameWidth=JaWEConfig.getInstance().getParticipantNameWidth(); 79 80 private static final int defActivityWidth=JaWEConfig.getInstance().getActivityWidth(); 81 82 private static final int defActivityHeight=JaWEConfig.getInstance().getActivityHeight(); 83 84 private boolean creatingGraph=false; 85 86 90 public WorkflowManager (AbstractGraph g) { 91 this.graph=g; 92 } 93 94 95 public AbstractGraph getGraph () { 96 return graph; 97 } 98 99 103 public Package getXMLPackage () { 104 return graph.getXMLPackage(); 105 } 106 107 111 public JaWEGraphModel graphModel () { 112 return (JaWEGraphModel)graph.getModel(); 113 } 114 115 124 public void createWorkflowGraph (WorkflowProcess wp) { 125 creatingGraph=true; 126 boolean isMine=true; 128 if (!getXMLPackage().isMadeByJaWE()) { 129 isMine=false; 130 } 131 134 java.util.List entitiesToInsert=wp.getEntitiesToInsert(getVisualOwner()); 135 136 createGraphParticipants(wp,entitiesToInsert); 139 140 createGraphActivitiesAndBlockActivities(wp,entitiesToInsert,isMine); 142 143 createGraphTransitions(wp,entitiesToInsert,isMine); 145 146 if (JaWEConfig.getInstance().getUseBubblesStatus()) { 148 createGraphStarts(wp,isMine,false); 149 150 createGraphEnds(wp,isMine,false); 152 } 153 154 if (!isMine) { 157 layoutActivities(); 158 ProcessEditor pe=(ProcessEditor)graph.getEditor(); 159 Set startDescs=Utils.getStartDescriptions(pe); 160 Set endDescs=Utils.getEndDescriptions(pe); 161 XMLComplexElement vo=getVisualOwner(); 162 if (vo instanceof WorkflowProcess) { 163 ((WorkflowProcess)vo).setStartDescriptions(startDescs); 164 ((WorkflowProcess)vo).setEndDescriptions(endDescs); 165 } else { 166 ((org.enhydra.jawe.xml.elements.Activity)vo). 167 setStartDescriptions(startDescs); 168 ((org.enhydra.jawe.xml.elements.Activity)vo). 169 setEndDescriptions(endDescs); 170 } 171 } 172 creatingGraph=false; 173 try { 174 Dimension prefSize=new Dimension(getRootParticipantWidth(null,null)+50, 175 getNewRootParYPos(null,null)+50); 176 graph.setPreferredSize(prefSize); 177 } catch (Exception ex) {} 178 } 179 180 188 public XMLComplexElement getVisualOwner () { 189 if (graph instanceof BlockActivityGraph) { 190 return (org.enhydra.jawe.xml.elements.Activity) 191 ((BlockActivityGraph)graph).getMyBlockActivity().getUserObject(); 192 } else if (graph instanceof ProcessGraph) { 193 return (WorkflowProcess)graph.getPropertyObject(); 194 } else { 195 return (Package )graph.getPropertyObject(); 196 } 197 } 198 199 207 private Activities getActivitiesCollection () { 208 Activities acts; 209 XMLComplexElement myOwner=getVisualOwner(); 210 if (myOwner instanceof WorkflowProcess) { 211 acts=(Activities)myOwner.get("Activities"); 212 } else { 213 BlockActivity ba=((BlockActivityGraph)graph).getMyBlockActivity(); 214 ActivitySet as=getBlockActivitySet(ba); 215 acts=(Activities)as.get("Activities"); 216 } 217 return acts; 218 } 219 220 228 public Transitions getTransitionsCollection () { 229 Transitions trans; 230 XMLComplexElement myOwner=getVisualOwner(); 231 if (myOwner instanceof WorkflowProcess) { 232 trans=(Transitions)myOwner.get("Transitions"); 233 } else { 234 BlockActivity ba=((BlockActivityGraph)graph).getMyBlockActivity(); 235 ActivitySet as=getBlockActivitySet(ba); 236 trans=(Transitions)as.get("Transitions"); 237 } 238 return trans; 239 } 240 241 245 private ActivitySet getBlockActivitySet (BlockActivity ba) { 246 try { 247 String ID=ba.getBlockID(); 248 ActivitySet as=((ActivitySets)getWorkflowProcess(). 249 get("ActivitySets")).getActivitySet(ID); 250 return as; 251 } catch (Exception ex) { 252 return null; 253 } 254 } 255 256 264 private WorkflowProcess getWorkflowProcess () { 265 if (graph.getPropertyObject() instanceof WorkflowProcess) { 266 return (WorkflowProcess)graph.getPropertyObject(); 267 } else { 268 return null; 269 } 270 } 271 272 290 public org.enhydra.jawe.graph.Process insertProcess (Point p,boolean updateCollection) { 291 Point realP=(Point)graph.fromScreen(new Point(p)); int ulx=realP.x; 293 int uly=realP.y; 294 Rectangle bounds=new Rectangle(ulx,uly,defProcessWidth,defProcessHeight); 295 296 Map viewMap = new Hashtable(); 297 Map map = GraphConstants.createMap(); 298 299 org.enhydra.jawe.graph.Process pr = 300 new org.enhydra.jawe.graph.Process((PackageEditor)getGraph().getEditor()); 301 WorkflowProcess wp=new WorkflowProcess((WorkflowProcesses)getXMLPackage(). 302 get("WorkflowProcesses"),getXMLPackage()); 303 wp.get("Name").setValue(ResourceManager.getLanguageDependentString("ProcessKey")); 304 pr.setUserObject(wp); 305 306 GraphConstants.setBounds(map,bounds); 307 GraphConstants.setOpaque(map,true); 308 GraphConstants.setBorderColor(map,Color.darkGray); 309 GraphConstants.setFont(map,GraphConstants.defaultFont.deriveFont(JaWEConfig.getInstance().getFontSize())); 310 311 viewMap.put(pr,map); 312 Object [] insert = new Object []{pr}; 313 String actionName= 315 ResourceManager.getLanguageDependentString("MessageInsertingProcessIntoPackage"); 316 graphModel().insertAndEdit(insert,viewMap,null,null,null,actionName); 317 318 if (updateCollection) { 319 refreshCollections (insert,true); 320 } 321 322 return pr; 323 } 324 325 337 public void insertCellsAndArrangeParticipants (Object [] insert,Map viewMap, ConnectionSet cs) { 338 if(JaWEGraphModel.getRootParticipants(graphModel()) != null) { 339 updateModelAndArrangeParticipants(insert,null,null,viewMap, 340 ResourceManager.getLanguageDependentString("MessageDuplicatingObject"),true,cs); 341 } 342 else { 343 JOptionPane.showMessageDialog(graph.getEditor().getWindow(), 344 ResourceManager.getLanguageDependentString( 345 "WarningCannotInsertObjectsOutsideParticipant"), 346 JaWE.getAppTitle(),JOptionPane.WARNING_MESSAGE); 347 } 348 } 349 350 363 public void moveCellsAndArrangeParticipants (Map propertyMap) { 364 updateModelAndArrangeParticipants(null,propertyMap,null,null, 365 ResourceManager.getLanguageDependentString("MessageMovingObjects"),false,null); 366 } 367 368 380 public void insertSubflowAndArrangeParticipants (Point p) { 381 Set rootParticipants=JaWEGraphModel.getRootParticipants(graphModel()); 382 if(rootParticipants != null && rootParticipants.size()>0) { 383 Map viewMap = new Hashtable(); 384 Subflow sbf=createSubflow(p,viewMap); 385 updateModelAndArrangeParticipants(new Object [] {sbf},null,null,viewMap, 387 ResourceManager.getLanguageDependentString("MessageInsertingSubflowActivity"), 388 true,null); 389 } 390 else { 391 JOptionPane.showMessageDialog(graph.getEditor().getWindow(), 392 ResourceManager.getLanguageDependentString( 393 "WarningCannotInsertSubflowActivityOutsideParticipant"), 394 JaWE.getAppTitle(),JOptionPane.WARNING_MESSAGE); 395 } 396 } 397 398 410 public void insertBlockActivityAndArrangeParticipants (Point p) { 411 Set rootParticipants=JaWEGraphModel.getRootParticipants(graphModel()); 412 if(rootParticipants != null && rootParticipants.size()>0) { 413 Map viewMap = new Hashtable(); 414 BlockActivity bla=createBlockActivity(p,viewMap); 415 updateModelAndArrangeParticipants(new Object [] {bla},null,null,viewMap, 417 ResourceManager.getLanguageDependentString("MessageInsertingBlockActivity"), 418 true,null); 419 } 420 else { 421 JOptionPane.showMessageDialog(graph.getEditor().getWindow(), 422 ResourceManager.getLanguageDependentString( 423 "WarningCannotInsertBlockActivityOutsideParticipant"), 424 JaWE.getAppTitle(),JOptionPane.WARNING_MESSAGE); 425 } 426 } 427 428 440 public void insertStartAndArrangeParticipants (Point p) { 441 Set rootParticipants=JaWEGraphModel.getRootParticipants(graphModel()); 442 if(rootParticipants != null && rootParticipants.size()>0) { 443 Map viewMap = new Hashtable(); 444 Start s=createStart(p,viewMap); 445 updateModelAndArrangeParticipants(new Object [] {s},null,null,viewMap, 447 ResourceManager.getLanguageDependentString("MessageInsertingStart"), 448 true,null); 449 } 450 else { 451 String msg=ResourceManager.getLanguageDependentString( 452 "WarningCannotInsertStartOutsideParticipant"); 453 JOptionPane.showMessageDialog(graph.getEditor().getWindow(), 454 msg,JaWE.getAppTitle(),JOptionPane.WARNING_MESSAGE); 455 } 456 } 457 458 470 public void insertEndAndArrangeParticipants (Point p) { 471 Set rootParticipants=JaWEGraphModel.getRootParticipants(graphModel()); 472 if(rootParticipants != null && rootParticipants.size()>0) { 473 Map viewMap = new Hashtable(); 474 Activity e=createEnd(p,viewMap); 475 updateModelAndArrangeParticipants(new Object [] {e},null,null,viewMap, 477 ResourceManager.getLanguageDependentString("MessageInsertingEnd"), 478 true,null); 479 } 480 else { 481 JOptionPane.showMessageDialog(graph.getEditor().getWindow(), 482 ResourceManager.getLanguageDependentString( 483 "WarningCannotInsertEndOutsideParticipant"), 484 JaWE.getAppTitle(),JOptionPane.WARNING_MESSAGE); 485 } 486 } 487 488 500 public void insertActivityAndArrangeParticipants (Point p) { 501 Set rootParticipants=JaWEGraphModel.getRootParticipants(graphModel()); 502 if(rootParticipants != null && rootParticipants.size()>0) { 503 Map viewMap = new Hashtable(); 504 Activity act=createActivity(p,viewMap); 505 updateModelAndArrangeParticipants(new Object [] {act},null,null,viewMap, 507 ResourceManager.getLanguageDependentString("MessageInsertingGenericActivity"), 508 true,null); 509 } 510 else { 511 JOptionPane.showMessageDialog(graph.getEditor().getWindow(), 512 ResourceManager.getLanguageDependentString( 513 "WarningCannotInsertGenericActivityOutsideParticipant"), 514 JaWE.getAppTitle(),JOptionPane.WARNING_MESSAGE); 515 } 516 } 517 518 530 public void insertRouteAndArrangeParticipants (Point p) { 531 Set rootParticipants=JaWEGraphModel.getRootParticipants(graphModel()); 532 if(rootParticipants != null && rootParticipants.size()>0) { 533 Map viewMap = new Hashtable(); 534 Route r=createRoute(p,viewMap); 535 updateModelAndArrangeParticipants(new Object [] {r},null,null,viewMap, 537 ResourceManager.getLanguageDependentString("MessageInsertingRouteActivity"), 538 true,null); 539 } 540 else { 541 JOptionPane.showMessageDialog(graph.getEditor().getWindow(), 542 ResourceManager.getLanguageDependentString( 543 "WarningCannotInsertRouteActivityOutsideParticipant"), 544 JaWE.getAppTitle(),JOptionPane.WARNING_MESSAGE); 545 } 546 } 547 548 566 public Participant insertParticipantAndArrangeParticipants (Point p, 567 org.enhydra.jawe.xml.elements.Participant parUO) { 568 569 ToolTipManager.sharedInstance().setEnabled(false); 570 571 Participant par=null; 572 573 Map viewMap=new HashMap(); 574 ParentMap parentMap=null; 575 Map propertyMap=null; 576 577 Object cell=((ProcessGraph)graph). 580 getFirstParticipantForLocation(p.x,p.y); 581 582 if (cell==null) { 585 par=createParticipant( 586 new Rectangle(horizontalOffset,getNewRootParYPos(null,null), 587 getRootParticipantWidth(null,null),minParHeight), 588 viewMap); 589 propertyMap=new HashMap(viewMap); 590 } else { 593 JOptionPane.showMessageDialog(graph.getEditor().getWindow(), 594 ResourceManager.getLanguageDependentString( 595 "WarningParticipantCannotHaveParticipants"), 596 JaWE.getAppTitle(),JOptionPane.WARNING_MESSAGE); 597 return null; 598 } 599 600 Participants wfp =(Participants)getWorkflowProcess().get("Participants"); 601 if (parUO!=null) { 603 Object [] insert = new Object []{par}; 604 graphModel().insertAndEdit(insert,propertyMap,null,parentMap,null, 606 ResourceManager.getLanguageDependentString("MessageInsertingParticipant")); 607 par.setUserObject(parUO); 608 if (!getXMLPackage().isReadOnly()) { 613 parUO.graphReferenceAdded(); 614 } 615 } else { 618 parUO=(org.enhydra.jawe.xml.elements.Participant) 619 wfp.generateNewElement(); 620 Window w=graph.getEditor().getWindow(); 622 XMLElementDialog de=new XMLElementDialog((JDialog)w, 623 ResourceManager.getLanguageDependentString("DialogNewParticipant")); 624 625 de.editXMLElement(parUO.getPanel(),true,false); 626 if (!de.isCanceled()) { 628 Object [] insert = new Object []{par}; 629 graphModel().insertAndEdit(insert,propertyMap,null,parentMap,null, 631 ResourceManager.getLanguageDependentString("MessageInsertingParticipant")); 632 par.setUserObject(parUO); 633 if (!getXMLPackage().isReadOnly()) { 638 parUO.graphReferenceAdded(); 639 } 640 wfp.add(parUO); 642 } 643 } 644 645 if (JaWEConfig.getInstance().getTooltipStatus()) { 646 ToolTipManager.sharedInstance().setEnabled(true); 647 } 648 649 if (!creatingGraph) { 650 try { 651 Dimension prefSize=new Dimension(getRootParticipantWidth(propertyMap,parentMap)+50, 652 getNewRootParYPos(propertyMap,parentMap)+50); 653 graph.setPreferredSize(prefSize); 654 } catch (Exception ex) {} 655 } 656 657 return par; 658 } 659 660 667 public boolean showNode (org.enhydra.jawe.xml.elements.Participant parUO) { 668 if (parUO==null) return false; 669 670 Point ofInsert = new Point(10,Integer.MAX_VALUE); 671 Object graphObj = getGraphObjectForXMLParticipant(parUO); 672 if (null != graphObj) { 674 return true; 675 } 676 677 Object ins=insertParticipantAndArrangeParticipants(ofInsert,parUO); 678 679 if (ins==null) { 680 return false; 681 } else { 682 return true; 683 } 684 } 685 686 692 public void hideNode(org.enhydra.jawe.xml.elements.Participant parUO) { 693 Participant p=getGraphObjectForXMLParticipant(parUO); 694 if (p!=null && !p.hasAnyActivity()) { 695 removeCellsAndArrangeParticipants(new Object []{p}); 696 } 697 } 698 699 707 private Participant getGraphObjectForXMLParticipant( 708 org.enhydra.jawe.xml.elements.Participant source) { 709 710 Set graphParts=JaWEGraphModel.getAllParticipantsInModel(graphModel()); 711 if (graphParts!=null) { 712 Participant graphPart; 713 Iterator it=graphParts.iterator(); 714 while (it.hasNext()) { 715 graphPart=(Participant)it.next(); 716 if (graphPart.getUserObject()==source) { 717 return graphPart; 718 } 719 } 720 } 721 return null; 722 } 723 724 725 748 public Transition insertTransition (Point start,Point end,PortView source, 749 PortView target,boolean isRouting,boolean updateCollection) { 750 751 Point p = (Point)graph.fromScreen(new Point(start)); Point p2 = (Point)graph.fromScreen(new Point(end)); ArrayList list = new ArrayList(); 754 755 Map map = GraphConstants.createMap(); 757 if (source.equals(target)) { 758 GraphConstants.setLineStyle(map,GraphConstants.STYLE_BEZIER); 759 list.add(p); 760 if (updateCollection) { 761 list.add(new Point(p.x-50,p.y-75)); 762 list.add(new Point(p.x+50,p.y-75)); 763 } 764 list.add(p2); 765 } else { 766 list.add(p); 767 list.add(p2); 768 } 769 GraphConstants.setPoints(map,list); 770 if (isRouting) { 771 GraphConstants.setRouting(map, GraphConstants.ROUTING_SIMPLE); 772 } 773 GraphConstants.setLineEnd(map,GraphConstants.ARROW_TECHNICAL); 775 GraphConstants.setEndFill(map,true); 776 GraphConstants.setEndSize(map,10); 777 GraphConstants.setFont(map,GraphConstants.defaultFont.deriveFont(JaWEConfig.getInstance().getFontSize())); 778 779 Map viewMap = new Hashtable(); 780 Transition transition = new Transition(); 781 782 viewMap.put(transition,map); 783 784 Object [] insert = new Object []{transition}; 785 ConnectionSet cs = new ConnectionSet(); 786 787 cs.connect(transition,source.getCell(),target.getCell()); 788 789 org.enhydra.jawe.xml.elements.Transition uo=null; 790 Transitions ts=getTransitionsCollection(); 791 uo=new org.enhydra.jawe.xml.elements.Transition(ts); 792 transition.setUserObject(uo); 794 795 String undoMsg=ResourceManager.getLanguageDependentString("MessageInsertingTransition"); 798 graphModel().insertAndEdit(insert,viewMap,cs,null,null,undoMsg); 800 Activity s=null; 801 Activity t=null; 802 try { 803 s=transition.getSourceActivity(); 804 } catch (Exception ex) { 805 } 806 try { 807 t=transition.getTargetActivity(); 808 } catch (Exception ex) { 809 } 810 811 org.enhydra.jawe.xml.elements.Activity sourceAct=null; 813 if (s!=null && t!=null && !(s instanceof Start) && !(t instanceof End)) { 815 try { 816 sourceAct=(org.enhydra.jawe.xml.elements.Activity) 817 s.getPropertyObject(); 818 uo.setFrom(sourceAct); 819 } catch (Exception e) {} 820 try { 821 uo.setTo(t.getPropertyObject()); 822 } catch (Exception e) {} 823 } 824 825 if (updateCollection) { 827 refreshCollections (insert,true); 828 } 829 830 return transition; 831 } 832 833 846 public void removeCellsAndArrangeParticipants (Object [] cellsToDelete) { 847 Set participantsToArrange=new HashSet(); 848 Map propertyMap=new HashMap(); 849 ParentMap parentMap=new JaWEParentMap(); 850 851 Set ports=new HashSet(); 852 if (cellsToDelete != null && cellsToDelete.length>0) { 854 for (int i=0; i<cellsToDelete.length; i++) { 855 if (cellsToDelete[i] instanceof Participant) { 856 Participant par=(Participant)cellsToDelete[i]; 857 858 Rectangle2D r=getBounds(par,propertyMap); int yPos=r.getBounds().y+r.getBounds().height-1; 862 Participant ppar=(Participant)par.getParent(); 865 if (ppar != null) { 866 if (ppar.getChildCount()>1 || 870 getParticipantHeight(ppar,propertyMap)>minParHeight) { 871 Object [] allParents=ppar.getPath(); 873 int resizeValue=r.getBounds().height; int pHeight=getParticipantHeight(ppar,propertyMap); 876 if (pHeight-r.getBounds().height<minParHeight) { resizeValue=pHeight-minParHeight; 879 } 880 resize(allParents,propertyMap,0,-resizeValue); 881 translateVertically(propertyMap,null,yPos,-resizeValue); 883 } 884 } 885 else { 887 translateVertically(propertyMap,null,yPos,-r.getBounds().height); } 890 } else if (cellsToDelete[i] instanceof Port) { 892 ports.add(cellsToDelete[i]); 893 } 894 } 895 896 Set ctd=new HashSet(Arrays.asList(cellsToDelete)); 898 ctd.removeAll(ports); 899 if (ctd.size()==0) return; 900 cellsToDelete=ctd.toArray(); 901 902 907 Set cellsToDel = JaWEGraphModel.getDescendants(graphModel(),cellsToDelete); 909 Set edges=graphModel().getEdges(graphModel(),cellsToDel.toArray()); 911 912 cellsToDel.addAll(edges); 914 915 Set allEdgesToDelete=new HashSet(); 917 Set allCellsToDelete=new HashSet(); 918 Iterator it=cellsToDel.iterator(); 919 while (it.hasNext()) { 920 Object cell=it.next(); 921 if (cell instanceof Edge) { 922 allEdgesToDelete.add(cell); 923 } 924 else if (!(cell instanceof Port)){ 925 allCellsToDelete.add(cell); 926 } 927 } 928 929 cellsToDelete=allCellsToDelete.toArray(); 931 932 for (int i=0; i<cellsToDelete.length; i++) { 933 Object parent=((DefaultMutableTreeNode)cellsToDelete[i]).getParent(); 938 if ((parent != null) && (parent instanceof Participant)) { 939 if (cellsToDelete[i] instanceof Activity) { 940 participantsToArrange.add(parent); 941 } 942 } 943 parentMap.addEntry(cellsToDelete[i],null); 944 } 945 946 resizeAllParticipantsHorizontally(propertyMap,parentMap); 948 arrangeParticipantsVertically(participantsToArrange.toArray(),propertyMap,parentMap); 949 950 if (cellsToDelete!=null && cellsToDelete.length==1 && 952 (cellsToDelete[0] instanceof org.enhydra.jawe.graph.Process)) { 953 org.enhydra.jawe.graph.Process pr= 954 (org.enhydra.jawe.graph.Process)cellsToDelete[0]; 955 arrangeProcesses(propertyMap,GraphConstants.getBounds(pr.getAttributes()).getBounds()); } 957 958 graphModel().removeAndEdit(cellsToDel.toArray(),propertyMap, 959 ResourceManager.getLanguageDependentString("MessageRemovingObjects")); 960 961 refreshCollections(cellsToDel.toArray(),false); 963 } 964 965 try { 966 Dimension prefSize=new Dimension(getRootParticipantWidth(propertyMap,parentMap)+50, 967 getNewRootParYPos(propertyMap,parentMap)+50); 968 graph.setPreferredSize(prefSize); 969 } catch (Exception ex) {} 970 } 971 972 975 public int getHorizontalOffset () { 976 return horizontalOffset; 977 } 978 979 983 public String getParticipantID (Activity a) { 984 if (a!=null) { 985 Participant par=(Participant)a.getParent(); 986 if (par!=null) { 987 return par.get("Id").toString(); 988 } 989 } 990 return ""; 991 } 992 993 999 public Point getOffset (Activity a) { 1000 if (a!=null && a instanceof Activity) { 1001 Participant par=(Participant)((Activity)a).getParent(); 1002 if (par!=null) { 1003 Rectangle2D rpar=getBounds(par,null); Rectangle2D ract=getBounds(a,null); int yOff=ract.getBounds().y-rpar.getBounds().y; int xOff=ract.getBounds().x-rpar.getBounds().x; return new Point(xOff,yOff); 1008 } 1009 } 1010 return new Point(0,0); 1011 } 1012 1013 1020 public Set getBlockActivities(boolean recursivly) { 1021 Set allActs=JaWEGraphModel.getAllActivitiesInModel(graphModel()); 1022 Set bas=new HashSet(); 1023 if (allActs != null) { 1024 Iterator it=allActs.iterator(); 1025 Object act; 1026 while (it.hasNext()) { 1027 act=it.next(); 1028 if (act instanceof BlockActivity) { 1029 bas.add(act); 1030 if (!recursivly) continue; 1031 WorkflowManager wm=((BlockActivity)act).getWorkflowManager(); 1032 if (wm!=null) { 1033 bas.addAll(wm.getBlockActivities(true)); 1034 } 1035 } 1036 } 1037 } 1038 return bas; 1039 } 1040 1041 1044 protected Participant createParticipant(Rectangle bounds,Map viewMap) { 1045 1046 Map map; 1047 1048 Participant par = new Participant(); 1049 map = GraphConstants.createMap(); 1050 GraphConstants.setBounds(map,bounds); 1051 GraphConstants.setOpaque(map,false); 1052 GraphConstants.setBorderColor(map,Color.black); 1053 GraphConstants.setMoveable(map,false); 1054 GraphConstants.setFont(map,GraphConstants.defaultFont.deriveFont(JaWEConfig.getInstance().getFontSize())); 1055 1056 viewMap.put(par,map); 1057 1058 return par; 1059 } 1060 1061 1062 1066 protected Subflow createSubflow(Point p,Map viewMap) { 1067 Point realP=(Point)graph.fromScreen(new Point(p)); int ulx=realP.x; 1069 int uly=realP.y; 1070 Rectangle bounds=new Rectangle(ulx,uly,defActivityWidth,defActivityHeight); 1071 1072 Map map; 1073 1074 Subflow sbf = new Subflow(); 1075 1076 WorkflowProcess wp=getWorkflowProcess(); 1077 Activities acts=getActivitiesCollection(); 1078 1079 org.enhydra.jawe.xml.elements.Activity ap= 1080 new org.enhydra.jawe.xml.elements.Activity(acts,wp,3); 1081 ap.set("Name",ResourceManager.getLanguageDependentString("SubFlowKey")); 1082 sbf.setUserObject(ap); 1083 map = GraphConstants.createMap(); 1084 GraphConstants.setBounds(map, bounds); 1085 GraphConstants.setOpaque(map, true); 1086 GraphConstants.setBorderColor(map,new Color(15,0,115)); 1087 GraphConstants.setFont(map,GraphConstants.defaultFont.deriveFont(JaWEConfig.getInstance().getFontSize())); 1088 1089 viewMap.put(sbf,map); 1090 1091 return sbf; 1092 } 1093 1094 1098 protected BlockActivity createBlockActivity(Point p,Map viewMap) { 1099 Point realP=(Point)graph.fromScreen(new Point(p)); int ulx=realP.x; 1101 int uly=realP.y; 1102 Rectangle bounds=new Rectangle(ulx,uly,defActivityWidth,defActivityHeight); 1103 1104 Map map; 1105 1106 BlockActivity bla = new BlockActivity((ProcessEditor)getGraph().getEditor()); 1107 1108 org.enhydra.jawe.xml.elements.Activity ap= 1109 new org.enhydra.jawe.xml.elements.Activity( 1110 getActivitiesCollection(),getWorkflowProcess(),4); 1111 ap.getBlockActivity(). 1113 set("BlockId",((ActivitySets)getWorkflowProcess(). 1114 get("ActivitySets")).generateID()); 1115 ap.set("Name",ResourceManager.getLanguageDependentString("BlockActivityKey")); 1116 bla.setUserObject(ap); 1117 map = GraphConstants.createMap(); 1118 GraphConstants.setBounds(map, bounds); 1119 GraphConstants.setOpaque(map, true); 1120 GraphConstants.setBorderColor(map,new Color(15,0,115)); 1121 GraphConstants.setFont(map,GraphConstants.defaultFont.deriveFont(JaWEConfig.getInstance().getFontSize())); 1122 viewMap.put(bla,map); 1123 1124 return bla; 1125 } 1126 1127 1128 1131 protected Start createStart(Point p,Map viewMap) { 1132 Point realP=(Point)graph.fromScreen(new Point(p)); int ulx=realP.x; 1134 int uly=realP.y; 1135 Rectangle bounds=new Rectangle(ulx,uly,defActivityHeight,defActivityHeight); 1136 1137 Map map; 1138 1139 Start s = new Start(); 1140 map = GraphConstants.createMap(); 1141 GraphConstants.setBounds(map,bounds); 1142 GraphConstants.setOpaque(map,true); 1143 GraphConstants.setBorderColor(map,Color.darkGray); 1144 GraphConstants.setFont(map,GraphConstants.defaultFont.deriveFont(JaWEConfig.getInstance().getFontSize())); 1145 1146 viewMap.put(s,map); 1147 1148 return s; 1149 } 1150 1151 1154 protected End createEnd(Point p,Map viewMap) { 1155 Point realP=(Point)graph.fromScreen(new Point(p)); int ulx=realP.x; 1157 int uly=realP.y; 1158 Rectangle bounds=new Rectangle(ulx,uly,defActivityHeight,defActivityHeight); 1159 1160 Map map; 1161 1162 End e=new End(); 1163 map = GraphConstants.createMap(); 1164 GraphConstants.setBounds(map,bounds); 1165 GraphConstants.setOpaque(map,true); 1166 GraphConstants.setBorderColor(map,Color.darkGray); 1167 GraphConstants.setFont(map,GraphConstants.defaultFont.deriveFont(JaWEConfig.getInstance().getFontSize())); 1168 1169 viewMap.put(e,map); 1170 1171 return e; 1172 } 1173 1174 1178 protected Activity createActivity(Point p,Map viewMap) { 1179 Point realP=(Point)graph.fromScreen(new Point(p)); int ulx=realP.x; 1181 int uly=realP.y; 1182 1183 Rectangle bounds=new Rectangle(ulx,uly,defActivityWidth,defActivityHeight); 1184 1185 Map map; 1186 1187 Activity act = new Activity(); 1188 1189 WorkflowProcess wp=getWorkflowProcess(); 1190 Activities acts=getActivitiesCollection(); 1191 org.enhydra.jawe.xml.elements.Activity ap= 1192 new org.enhydra.jawe.xml.elements.Activity(acts,wp,2); 1193 ap.set("Name",ResourceManager.getLanguageDependentString("GenericKey")); 1194 act.setUserObject(ap); 1195 map = GraphConstants.createMap(); 1196 GraphConstants.setBounds(map,bounds); 1197 GraphConstants.setOpaque(map,true); 1198 GraphConstants.setBorderColor(map,Color.darkGray); 1199 GraphConstants.setFont(map,GraphConstants.defaultFont.deriveFont(JaWEConfig.getInstance().getFontSize())); 1200 viewMap.put(act,map); 1201 1202 return act; 1203 } 1204 1205 1209 protected Route createRoute(Point p,Map viewMap) { 1210 Point realP=(Point)graph.fromScreen(new Point(p)); int ulx=realP.x; 1212 int uly=realP.y; 1213 Rectangle bounds=new Rectangle(ulx,uly,defActivityWidth,defActivityHeight); 1214 1215 Map map; 1216 1217 Route r = new Route(); 1218 1219 WorkflowProcess wp=getWorkflowProcess(); 1220 Activities acts=getActivitiesCollection(); 1221 org.enhydra.jawe.xml.elements.Activity ap= 1222 new org.enhydra.jawe.xml.elements.Activity(acts,wp,0); 1223 ap.set("Name",ResourceManager.getLanguageDependentString("RouteKey")); 1224 r.setUserObject(ap); 1225 map = GraphConstants.createMap(); 1226 GraphConstants.setBounds(map,bounds); 1227 GraphConstants.setOpaque(map,true); 1228 GraphConstants.setBorderColor(map,Color.darkGray); 1229 GraphConstants.setFont(map,GraphConstants.defaultFont.deriveFont(JaWEConfig.getInstance().getFontSize())); 1230 viewMap.put(r,map); 1231 1232 return r; 1233 } 1234 1235 1246 protected void updateModelAndArrangeParticipants (Object [] insert, 1247 Map propertyMap,ParentMap parentMap,Map viewMap,String actionName, 1248 boolean updateCollection, ConnectionSet cs) { 1249 1250 if (propertyMap==null && viewMap==null) return; 1251 if (propertyMap==null) { 1252 propertyMap=new HashMap(viewMap); 1253 } 1254 if (parentMap==null) { 1255 parentMap=new JaWEParentMap(); 1256 } 1257 1258 arrangeParticipants(propertyMap,parentMap); 1259 1278 1279 if (insert != null && ((JaWEParentMap)parentMap).entryCount() != insert.length) { 1280 } 1282 1283 Dimension prefSize=null; 1284 if (!creatingGraph) { 1285 try{ 1286 prefSize=new Dimension(getRootParticipantWidth(propertyMap,parentMap)+50, 1287 getNewRootParYPos(propertyMap,parentMap)+50); 1288 } catch (Exception ex) {} 1289 } 1290 1291 graphModel().insertAndEdit(insert,propertyMap,cs,parentMap,null,actionName); 1294 1295 if (updateCollection) { 1296 refreshCollections(insert,true); 1297 } 1298 1299 if (!creatingGraph && prefSize!=null) { 1300 try{ 1301 graph.setPreferredSize(prefSize); 1302 } catch (Exception ex) {} 1303 } 1304 } 1305 1306 1309 protected void arrangeParticipants(Map propertyMap,ParentMap parentMap) { 1310 Set parsToArrangeVerticaly=new HashSet(); 1311 Object [] cellsToManage=propertyMap.keySet().toArray(); 1317 for (int i=0; i<cellsToManage.length; i++) { 1318 Object cell=cellsToManage[i]; 1319 if (cell instanceof Activity) { 1320 Set oldAndNewParentPar=updateActivityParent((Activity)cell, 1321 propertyMap,parentMap); 1322 parsToArrangeVerticaly.addAll(oldAndNewParentPar); 1323 } 1324 } 1325 arrangeParticipantsVertically(parsToArrangeVerticaly.toArray(),propertyMap,parentMap); 1327 resizeAllParticipantsHorizontally(propertyMap,parentMap); 1328 } 1329 1330 1335 protected Set updateActivityParent (Activity ac,Map propertyMap, 1336 ParentMap parentMap) { 1337 Set oldAndNewPar=new HashSet(); 1339 Participant oldPar=(Participant)ac.getParent(); 1341 1342 if (oldPar!=null) { 1344 oldAndNewPar.add(oldPar); 1345 } 1346 1347 Participant newPar=null; 1348 Rectangle2D acRect=getBounds(ac,propertyMap); Point acUpperLeft=acRect.getBounds().getLocation(); Point newAcUpperLeft=new Point(acUpperLeft); 1354 1355 newPar=findParentActivityParticipantForLocation(newAcUpperLeft,propertyMap,parentMap); 1356 1357 if (!newAcUpperLeft.equals(acUpperLeft)) { 1360 Rectangle r=new Rectangle(acRect.getBounds()); r.setLocation(newAcUpperLeft); 1362 changeBounds(ac,propertyMap,r); 1363 } 1364 1365 if (newPar != null) { 1366 oldAndNewPar.add(newPar); 1368 1369 if (!newPar.equals(oldPar)) { 1372 parentMap.addEntry(ac,newPar); 1373 } 1374 org.enhydra.jawe.xml.elements.Participant defaultP= 1375 org.enhydra.jawe.xml.elements.Participant.getFreeTextExpressionParticipant(); 1376 if (!(ac instanceof Route) && !(ac instanceof Start) && 1378 !(ac instanceof End) && !(ac instanceof Subflow) && 1379 !(ac instanceof BlockActivity) && 1380 newPar.getUserObject()!=defaultP) { 1381 ac.set("Performer",newPar.getUserObject()); 1382 } 1383 if (newPar!=oldPar && newPar.getUserObject()==defaultP) { 1384 ac.set("Performer",""); 1385 } 1386 1387 } 1388 1389 return oldAndNewPar; 1390 1391 } 1392 1393 1397 protected Participant findParentActivityParticipantForLocation (Point loc, 1398 Map propertyMap,ParentMap parentMap) { 1399 Participant newPar=null; 1400 if (loc.y <= 0) { 1402 loc.y=1; 1403 } 1404 if (loc.x <= 0) { 1405 loc.x=1; 1406 } 1407 1408 newPar=getLeafParticipantForYPos(loc.y,propertyMap,parentMap); 1410 1411 if (newPar == null) { 1414 newPar=getLeafParticipantForYPos(getNewRootParYPos(propertyMap,null)-10, 1415 propertyMap,parentMap); 1416 } 1417 1418 if (newPar!=null) { 1419 Rectangle newParRect=(Rectangle)getBounds(newPar,propertyMap); if (newParRect.x+defParNameWidth>=loc.x) { 1423 loc.x=newParRect.x+defParNameWidth+1; 1424 } 1425 } 1426 else { 1428 if (horizontalOffset>=loc.x) { 1430 loc.x=horizontalOffset; 1431 } 1432 } 1433 1434 return newPar; 1435 } 1436 1437 1438 1442 protected void arrangeParticipantsVertically(Object [] pars,Map propertyMap, 1443 ParentMap parentMap) { 1444 if ((pars == null) || (pars.length==0)) return; 1445 1446 for (int i=0; i<pars.length; i++) { 1447 arrangeParticipantVertically(pars[i],propertyMap,parentMap); 1449 } 1450 } 1451 1452 1461 protected void arrangeParticipantVertically(Object par,Map propertyMap, 1462 ParentMap parentMap) { 1463 if (par == null) return; 1467 if (!(par instanceof Participant)) return; 1468 Participant p=(Participant)par; 1469 if (hasAnyParticipant(p,parentMap)) return; 1470 ArrayList removedPars=((JaWEParentMap)parentMap).getRemovedNodes(); 1471 if (removedPars.contains(p)) return; 1472 int optHeight=optimalParticipantHeight(p,propertyMap,parentMap); 1474 int curHeight=getParticipantHeight(p,propertyMap); 1475 int dheight=optHeight-curHeight; 1477 1478 if (dheight != 0) { 1479 translateVertically(propertyMap, 1482 parentMap,getBounds(p,propertyMap).getBounds().y+curHeight-1,dheight); 1484 Object [] allParentsAndPar=p.getPath(); 1487 resize(allParentsAndPar,propertyMap,0,dheight); 1488 } 1489 1490 } 1491 1492 1499 protected void resizeAllParticipantsHorizontally (Map propertyMap, 1500 ParentMap parentMap) { 1501 Set participants=JaWEGraphModel.getAllParticipantsInModel(graphModel()); 1502 if (parentMap != null && participants != null) { 1504 participants.removeAll(((JaWEParentMap)parentMap).getRemovedNodes()); 1505 } 1506 int optimalRDW=optimalRootParticipantWidth(participants,propertyMap,parentMap); 1508 int rootParWidth=getRootParticipantWidth(propertyMap,parentMap); 1509 if (optimalRDW != rootParWidth) { 1510 int dw=optimalRDW-rootParWidth; 1512 if (participants != null) { 1513 resize(participants.toArray(),propertyMap,dw,0); 1514 } 1515 } 1516 } 1517 1518 1527 protected int optimalRootParticipantWidth (Set participants,Map propertyMap, 1528 ParentMap parentMap) { 1529 int minWidth=minParWidth; 1531 1532 if (participants==null) return minWidth; 1534 1535 Set leafParticipants=new HashSet(); 1537 1538 Iterator it=participants.iterator(); 1539 while (it.hasNext()) { 1540 Participant par=(Participant)it.next(); 1541 if (!hasAnyParticipant(par,parentMap)) { 1544 leafParticipants.add(par); 1545 } 1546 } 1547 1548 it=leafParticipants.iterator(); 1550 int maxRightEdgePosition=0; 1551 1552 while (it.hasNext()) { 1553 Participant lpar=(Participant)it.next(); 1554 int minREdge; 1555 int minParREdge; 1556 int minChildrenREdge=0; 1557 minParREdge=((Rectangle)getBounds(lpar,propertyMap)).x+minParWidth; Rectangle r=getBoundsOfParticipantFutureActivities(lpar,propertyMap,parentMap); 1562 if (r != null) { 1563 minChildrenREdge=r.x+r.width+defParNameWidth; 1564 } 1565 1566 minREdge=java.lang.Math.max(minParREdge,minChildrenREdge); 1567 if (maxRightEdgePosition==0) { 1569 maxRightEdgePosition=minREdge; 1570 } 1571 else if (minREdge>maxRightEdgePosition) { 1572 maxRightEdgePosition=minREdge; 1573 } 1574 } 1575 1576 int minW=maxRightEdgePosition-horizontalOffset; 1577 1578 if (minW>minParWidth) { 1580 minWidth=minW; 1581 } 1582 1583 return minWidth; 1584 1585 } 1586 1587 1595 protected int optimalParticipantHeight (Participant par,Map propertyMap, 1596 ParentMap parentMap) { 1597 int optHeight=minParHeight; 1599 1600 if (!hasAnyActivity(par,parentMap)) return optHeight; 1602 1603 Rectangle rCurrent=(Rectangle)getBounds(par,propertyMap); Rectangle rPreferred=getBoundsOfParticipantFutureActivities(par,propertyMap,parentMap);; 1607 1608 1611 if (rPreferred!=null) { 1613 int dBottom=(rPreferred.y+rPreferred.height)-(rCurrent.y+rCurrent.height); 1614 int optH=rCurrent.height+dBottom+10; 1615 1616 if (optH>optHeight) { 1618 optHeight=optH; 1619 } 1620 } else { 1621 } 1623 1624 return optHeight; 1625 1626 } 1627 1628 1632 protected void resize(Object [] cells,Map propertyMap,int dw,int dh) { 1633 if (cells!=null && cells.length>0) { 1634 Map map; 1635 Rectangle r; 1636 for (int i = 0; i < cells.length; i++) { 1637 r=new Rectangle(getBounds(cells[i],propertyMap).getBounds()); 1639 int newWidth=r.width+dw; 1640 int newHeight=r.height+dh; 1641 1642 if (newWidth<minParWidth || newHeight<minParHeight) { 1643 System.err.println("There was an error in calculating size of participant "+cells[i]+"!!!"); 1644 System.err.println("New width="+newWidth+", new height="+newHeight); 1645 } 1646 1647 r.setSize(newWidth,newHeight); 1648 changeBounds(cells[i],propertyMap,r); 1649 1650 } 1651 } 1652 } 1653 1654 1660 protected void translateVertically (Map propertyMap, 1661 ParentMap parentMap,int yPos,int dv) { 1662 Participant[] pars=getParticipantsForYPos(yPos,0,propertyMap,parentMap); 1663 translateParticipants(pars,propertyMap,parentMap,0,dv); 1664 } 1665 1666 1672 protected void translateParticipants (Participant[] cells,Map propertyMap, 1673 ParentMap parentMap,int dx,int dy) { 1674 if (cells!=null && cells.length>0) { 1675 for (int i=0; i<cells.length; i++) { 1676 translateParticipant(cells[i],propertyMap,parentMap,dx,dy); 1677 } 1678 } 1679 } 1680 1681 1687 protected void translateParticipant (Participant par,Map propertyMap, 1688 ParentMap parentMap,int dx,int dy) { 1689 Set participantAndItsFutureActivities = new HashSet(); 1690 participantAndItsFutureActivities.add(par); 1691 1692 Set futureActivities=getParticipantFutureActivities(par,parentMap); 1694 1695 participantAndItsFutureActivities.addAll(futureActivities); 1696 1697 Map map; 1699 Rectangle r; 1700 Iterator it=participantAndItsFutureActivities.iterator(); 1701 while (it.hasNext()) { 1702 Object cell=it.next(); 1703 r=new Rectangle(getBounds(cell,propertyMap).getBounds()); r.translate(dx,dy); 1705 changeBounds(cell,propertyMap,r); 1706 } 1707 } 1708 1709 1714 protected Rectangle getBoundsOfParticipantFutureActivities (Participant par, 1715 Map propertyMap,ParentMap parentMap) { 1716 Set futureActivities=getParticipantFutureActivities(par,parentMap); 1718 Set futureActivityBounds=new HashSet(); 1719 1720 Iterator it=futureActivities.iterator(); 1721 while (it.hasNext()) { 1722 Rectangle actBnd=(Rectangle)getBounds(it.next(),propertyMap); futureActivityBounds.add(actBnd); 1724 } 1725 1726 Rectangle[] fab=new Rectangle[futureActivityBounds.size()]; 1727 futureActivityBounds.toArray(fab); 1728 Rectangle unionBounds=getUnionBounds(fab); 1729 1730 return unionBounds; 1731 } 1732 1733 1737 protected Set getParticipantFutureActivities (Participant par, 1738 ParentMap parentMap) { 1739 if (parentMap==null) { return par.getChildActivities(); 1743 } 1744 Set futureActivities=new HashSet(); 1745 ArrayList emptyPars=((JaWEParentMap)parentMap).emptyParentList(); 1747 if (emptyPars.contains(par)) return futureActivities; 1749 Set changedNodes=parentMap.getChangedNodes(); 1752 futureActivities=new HashSet(par.getChildActivities()); 1755 Object [] previousActivities=futureActivities.toArray(); 1756 for (int i=0; i<previousActivities.length; i++) { 1760 if (changedNodes.contains(previousActivities[i])) { 1761 futureActivities.remove(previousActivities[i]); 1762 } 1763 } 1764 ArrayList nc=((JaWEParentMap)parentMap).getNewChildren(par); 1767 futureActivities.addAll(nc); 1768 1769 return futureActivities; 1770 } 1771 1772 1778 protected Participant getLeafParticipantForYPos (int yPos,Map propertyMap, 1779 ParentMap parentMap) { 1780 Participant[] pars=getParticipantsForYPos(yPos,2,propertyMap,parentMap); 1782 1783 if (pars == null) return null; 1785 1786 Set leafPars=new HashSet(); 1788 for (int i=0; i<pars.length; i++) { 1789 if (!hasAnyParticipant(pars[i],parentMap)) { 1790 leafPars.add(pars[i]); 1791 } 1792 } 1793 1794 if (leafPars.size()==0) return null; 1797 1798 Iterator it=leafPars.iterator(); 1800 Object rightPar=it.next(); 1801 1802 if (leafPars.size()>1) { 1805 int upperLeftY; 1806 int minUpperLeftY; 1807 Rectangle parRect; 1808 1809 parRect=getBounds(rightPar,propertyMap).getBounds(); upperLeftY=parRect.getLocation().y; 1813 minUpperLeftY=upperLeftY; 1814 1815 while (it.hasNext()) { 1817 Object curPar=it.next(); 1818 parRect=getBounds(curPar,propertyMap).getBounds(); upperLeftY=parRect.getLocation().y; 1820 if (upperLeftY<minUpperLeftY) { 1821 minUpperLeftY=upperLeftY; 1822 rightPar=curPar; 1823 } 1824 } 1825 } 1826 1827 return (Participant)rightPar; 1829 1830 } 1831 1832 1840 protected Participant[] getParticipantsForYPos (int yPos,int direction, 1841 Map propertyMap,ParentMap parentMap) { 1842 Set participants=JaWEGraphModel.getAllParticipantsInModel(graphModel()); 1844 1845 if (participants == null) return null; 1847 1848 if (parentMap != null) { 1850 participants.removeAll(((JaWEParentMap)parentMap).getRemovedNodes()); 1851 } 1852 1853 Participant[] pars=new Participant[participants.size()]; 1855 participants.toArray(pars); 1856 1857 Set yPosPars=new HashSet(); 1859 1860 for (int i = 0; i < pars.length; i++) { 1861 Rectangle r=(Rectangle)getBounds(pars[i],propertyMap); switch (direction) { 1863 case 0: 1864 if (r.y >=yPos) { 1865 yPosPars.add(pars[i]); 1866 } 1867 break; 1868 case 1: 1869 if (r.y <yPos) { 1870 yPosPars.add(pars[i]); 1871 } 1872 break; 1873 case 2: 1874 if ((r.y <= yPos) && (r.y+r.height >= yPos)) { 1875 yPosPars.add(pars[i]); 1876 } 1877 break; 1878 } 1879 } 1880 1881 if (yPosPars.size()>0) { 1882 pars=new Participant[yPosPars.size()]; 1883 yPosPars.toArray(pars); 1884 return pars; 1885 } 1886 else { 1887 return null; 1888 } 1889 } 1890 1891 1892 1895 protected int getNewRootParYPos (Map propertyMap,ParentMap parentMap) { 1896 int newRootParYPos=0; 1897 1898 Set rootPars=JaWEGraphModel.getRootParticipants(graphModel()); 1899 1900 1904 if (propertyMap != null) { 1905 Iterator it=propertyMap.keySet().iterator(); 1906 while (it.hasNext()) { 1907 Object rootPar=it.next(); 1908 if ((rootPar instanceof Participant) && 1909 (((DefaultGraphCell)rootPar).getParent()==null)) { 1910 rootPars.add(rootPar); 1911 } 1912 } 1913 } 1914 1915 1919 if (parentMap != null) { 1920 rootPars.removeAll(((JaWEParentMap)parentMap).getRemovedNodes()); 1921 } 1922 1923 if (rootPars==null || rootPars.size()==0) return newRootParYPos; 1925 1926 newRootParYPos=minParHeight; 1927 Iterator it=rootPars.iterator(); 1929 while(it.hasNext()) { 1930 Rectangle bounds=(Rectangle)getBounds(it.next(),propertyMap); if (bounds.y+bounds.height>newRootParYPos) { 1932 newRootParYPos=bounds.y+bounds.height; 1933 } 1934 } 1935 1936 return newRootParYPos; 1937 } 1938 1939 1944 protected int getRootParticipantWidth (Map propertyMap,ParentMap parentMap) { 1945 int rootParWidth=minParWidth; 1946 Set rootPars=JaWEGraphModel.getRootParticipants(graphModel()); 1947 1948 if (rootPars==null) return rootParWidth; 1950 1951 if (parentMap != null) { 1954 rootPars.removeAll(((JaWEParentMap)parentMap).getRemovedNodes()); 1955 } 1956 1957 if (rootPars.size()==0) return rootParWidth; 1959 1960 Iterator it=rootPars.iterator(); 1962 Object firstPar=it.next(); 1963 rootParWidth=getParticipantWidth(firstPar,propertyMap); 1964 1965 return rootParWidth; 1966 } 1967 1968 1977 protected boolean hasAnyParticipant (Participant par,ParentMap parentMap) { 1978 if (parentMap==null || !parentMap.getChangedNodes().contains(par)) { 1981 return par.hasAnyParticipant(); 1982 } 1983 else { 1985 return ((JaWEParentMap)parentMap).hasAnyParticipant(par); 1986 } 1987 } 1988 1989 1996 protected boolean hasAnyActivity (Participant par,ParentMap parentMap) { 1997 if (parentMap==null || !parentMap.getChangedNodes().contains(par)) { 2000 return par.hasAnyActivity(); 2001 } 2002 else { 2004 ArrayList emptyPars=((JaWEParentMap)parentMap).emptyParentList(); 2006 if (emptyPars.contains(par)) { 2008 return false; 2009 } 2010 else { 2011 return true; 2012 } 2013 } 2014 } 2015 2016 2019 protected Set getStarts () { 2020 Set starts=new HashSet(); 2021 Set allActivities=graphModel().getAllActivitiesInModel(graphModel()); 2022 2023 if (allActivities!=null) { 2024 Iterator it=allActivities.iterator(); 2025 while (it.hasNext()) { 2026 Object act=it.next(); 2027 if (act instanceof Start) { 2028 starts.add(act); 2029 } 2030 } 2031 } 2032 return starts; 2033 } 2034 2035 2038 protected Set getEnds () { 2039 Set ends=new HashSet(); 2040 Set allActivities=graphModel().getAllActivitiesInModel(graphModel()); 2041 2042 if (allActivities!=null) { 2043 Iterator it=allActivities.iterator(); 2044 while (it.hasNext()) { 2045 Object act=it.next(); 2046 if (act instanceof End) { 2047 ends.add(act); 2048 } 2049 } 2050 } 2051 return ends; 2052 } 2053 2054 2057 public CellView getView (Object cell) { 2058 return graph.getGraphLayoutCache().getMapping(cell,false); 2060 } 2061 2062 2066 protected int getParticipantWidth (Object par,Map propertyMap) { 2067 return getBounds(par,propertyMap).getBounds().width; } 2069 2070 2074 protected int getParticipantHeight (Object par,Map propertyMap) { 2075 return getBounds(par,propertyMap).getBounds().height; } 2077 2078 2084 protected void changeBounds(Object cell,Map propertyMap,Rectangle r) { 2085 Map map; 2086 if (propertyMap==null || !propertyMap.containsKey(cell)) { 2087 map=GraphConstants.createMap(); 2088 GraphConstants.setBounds(map,r); 2089 propertyMap.put(cell,map); 2090 } 2091 else { 2092 map=(Map)propertyMap.get(cell); 2093 GraphConstants.setBounds(map,r); 2094 } 2095 } 2096 2097 2103 public Rectangle2D getBounds (Object cell,Map propertyMap) { if (propertyMap != null && propertyMap.containsKey(cell)) { 2105 Map map=(Map)propertyMap.get(cell); 2106 return GraphConstants.getBounds(map); 2107 } 2108 else { 2109 CellView view=getView(cell); 2110 return view.getBounds(); 2111 } 2112 } 2113 2114 2117 protected Rectangle getUnionBounds (Rectangle[] rects) { 2118 if (rects != null && rects.length > 0) { 2119 Rectangle unionRect = null; 2120 for (int i=0; i<rects.length; i++) { 2121 if (unionRect == null) { 2122 unionRect = new Rectangle(rects[i]); 2123 } 2124 else { 2125 SwingUtilities.computeUnion(rects[i].x,rects[i].y, 2126 rects[i].width,rects[i].height,unionRect); 2127 } 2128 } 2129 return unionRect; 2130 } 2131 return null; 2132 } 2133 2134 2139 private void createGraphParticipants (WorkflowProcess wp,java.util.List entitiesToInsert) { 2140 boolean participantInserted=false; 2141 Iterator it=entitiesToInsert.iterator(); 2142 while (it.hasNext()) { 2143 Object p=it.next(); 2144 if (p instanceof org.enhydra.jawe.xml.elements.Participant) { 2145 showNode((org.enhydra.jawe.xml.elements.Participant)p); 2146 participantInserted=true; 2147 } 2148 } 2149 if (!participantInserted) { 2150 Participants pcs=(Participants)wp.get("Participants"); 2151 Activities acts=null; 2152 if (graph instanceof BlockActivityGraph) { 2153 ActivitySet as=getBlockActivitySet( 2154 ((BlockActivityGraph)graph).getMyBlockActivity()); 2155 if (as!=null) { 2156 acts=(Activities)as.get("Activities"); 2157 } 2158 } else { 2159 acts=(Activities)wp.get("Activities"); 2160 } 2161 2162 if (acts!=null && acts.size()>0) { 2163 showNode(org.enhydra.jawe.xml.elements.Participant.getFreeTextExpressionParticipant()); 2164 } 2165 } 2166 } 2168 2169 2174 private void createGraphActivitiesAndBlockActivities (WorkflowProcess wp, 2175 java.util.List entitiesToInsert,boolean isMine) { 2176 2178 Iterator it=entitiesToInsert.iterator(); 2179 while (it.hasNext()) { 2180 Object mayBeActivity=it.next(); 2181 if (mayBeActivity instanceof org.enhydra.jawe.xml.elements.Activity) { 2183 insertActivity( 2185 (org.enhydra.jawe.xml.elements.Activity)mayBeActivity, 2186 wp,isMine); 2187 } 2188 } 2189 } 2190 2191 2198 private void insertActivity( 2199 org.enhydra.jawe.xml.elements.Activity a, 2200 WorkflowProcess wp, 2201 boolean isMine) { 2202 2203 Participants pcs=(Participants)wp.get("Participants"); 2205 Rectangle rPar; 2206 Point p=null; 2207 Activity act; 2208 Participant par; 2209 Map viewMap; 2210 Object performer; 2211 int actType; 2212 2213 performer=a.get("Performer").toValue(); 2216 2217 String participantID=""; 2218 if (isMine) { 2219 participantID=a.getParticipantID(); 2220 } 2221 if (participantID.length()==0) { 2222 if (performer!=null && performer instanceof 2223 org.enhydra.jawe.xml.elements.Participant) { 2224 participantID= 2225 ((org.enhydra.jawe.xml.elements.Participant) 2226 performer).getID(); 2227 } else { 2228 participantID=performer.toString(); 2229 } 2230 } 2231 2232 par=getGraphObjectForXMLParticipant(pcs.getParticipant(participantID)); 2233 if (par==null) { 2234 par=getGraphObjectForXMLParticipant(org.enhydra.jawe.xml.elements.Participant.getFreeTextExpressionParticipant()); 2235 } 2236 if (par!=null) { 2237 rPar=(Rectangle)getBounds(par,null); p=new Point(rPar.getLocation()); 2239 p.x+=10; p.y+=10; 2240 } else { 2241 rPar=null; 2242 p=new Point(10,10); 2243 } 2244 2245 viewMap = new Hashtable(); 2246 actType=a.getType(); 2247 switch (actType) { 2248 case 0: 2249 act=createRoute(p,viewMap); 2250 break; 2251 case 3: 2252 act=createSubflow(p,viewMap); 2253 break; 2254 case 4: 2255 act=createBlockActivity(p,viewMap); 2256 ((ActivitySets)wp.get("ActivitySets")).decrementID(); 2257 break; 2258 default: 2259 act=createActivity(p,viewMap); 2260 break; 2261 } 2262 getActivitiesCollection().decrementID(); 2263 act.setUserObject(a); 2264 2265 updateModelAndArrangeParticipants(new Object [] {act},null,null,viewMap,"", 2267 false,null); 2268 int xOffset=0, yOffset=0; 2269 if (isMine) { 2270 xOffset=a.getXOffset(); 2271 yOffset=a.getYOffset(); 2272 } 2273 adjustActivityPosition(act,xOffset,yOffset,rPar); 2274 a.set("Performer",performer); 2276 if (actType==4) { 2278 ((BlockActivity)act). 2279 createBlockActivityGraph(graph.getEditor().getWindow()); 2280 } 2281 } 2282 2283 2288 private void createGraphTransitions (WorkflowProcess wp, 2289 java.util.List entitiesToInsert,boolean isMine) { 2290 2291 String IDFrom, IDTo; 2292 Activity source, target; 2293 org.enhydra.jawe.xml.elements.Transition trans; 2294 Transition t; 2295 2296 Iterator it=entitiesToInsert.iterator(); 2297 while (it.hasNext()) { 2298 Object tr=it.next(); 2299 if (tr instanceof org.enhydra.jawe.xml.elements.Transition) { 2300 trans=(org.enhydra.jawe.xml.elements.Transition)tr; 2301 IDFrom=trans.get("From").toValue().toString(); 2302 IDTo=trans.get("To").toValue().toString(); 2303 source=getActivity(IDFrom); 2304 target=getActivity(IDTo); 2305 String rt=trans.getRoutingType(); 2306 boolean isRouting=(rt!=null && !rt.equals(trans.NO_ROUTING)); 2307 t=connectActivities(source,target,isRouting); 2308 if (t!=null) { 2309 if (!isRouting) { 2310 TransitionView tv=(TransitionView)getView(t); 2311 Map ordNoToPoint=trans.getBreakPoints(); 2312 for (int i=1; i<=ordNoToPoint.size(); i++) { 2314 tv.addPointProgramatically((Point)ordNoToPoint.get(new Integer (i)),i); 2315 } 2316 } 2317 t.setUserObject(trans); 2318 } 2319 2320 } 2323 } 2324 } 2325 2326 2327 protected void createGraphStarts (WorkflowProcess wp,boolean isMine,boolean automaticCreation) { 2328 Activity source=null; 2329 Activity target=null; 2330 2331 Hashtable viewMap = new Hashtable(); 2332 org.enhydra.jawe.xml.elements.Activity a=null; 2333 2334 if (isMine && !automaticCreation) { 2336 Set startDescriptions=new HashSet(); 2337 if (graph instanceof BlockActivityGraph) { 2338 a=(org.enhydra.jawe.xml.elements.Activity) 2339 getVisualOwner(); 2340 startDescriptions=a.getStartDescriptions(); 2341 } else { 2342 startDescriptions=wp.getStartDescriptions(); 2343 } 2344 2345 if (startDescriptions.size()==0) return; 2346 2347 Participants pcs=(Participants)wp.get("Participants"); 2348 String ID; 2349 Participant par; 2350 Rectangle rPar; 2351 Point p; 2352 2353 Iterator it=startDescriptions.iterator(); 2354 String startDesc; 2355 String [] startD; 2356 while (it.hasNext()) { 2357 startDesc=(String )it.next(); 2358 startD=Utils.tokenize(startDesc,";"); 2359 ID=""; 2360 try { 2361 ID=startD[0]; 2362 } catch (Exception ex) {} 2363 par=getGraphObjectForXMLParticipant(pcs.getParticipant(ID)); 2364 2365 if (par==null) { 2366 par=getGraphObjectForXMLParticipant(org.enhydra.jawe.xml.elements.Participant.getFreeTextExpressionParticipant()); 2367 } 2368 2369 if (par!=null) { 2370 rPar=(Rectangle)getBounds(par,null); p=new Point(rPar.getLocation()); 2372 p.x+=10; p.y+=10; 2373 } else { 2374 rPar=null; 2375 p=new Point(10,10); 2376 } 2377 viewMap=new Hashtable(); 2378 source=createStart(p,viewMap); 2379 updateModelAndArrangeParticipants(new Object [] {source},null, 2380 null,viewMap,"",false,null); 2381 2382 try { 2384 adjustActivityPosition(source,Integer.parseInt(startD[2]), 2385 Integer.parseInt(startD[3]),rPar); 2386 } catch (Exception ex) {} 2387 2388 try { 2389 target=getActivity(startD[1]); 2390 } catch (Exception ex) {} 2391 2392 boolean isTransitionRouted=false; 2393 try { 2394 String itr=startD[4]; 2395 if (itr.equals(org.enhydra.jawe.xml.elements.Transition.NO_ROUTING)) { 2396 isTransitionRouted=false; 2397 } else { 2398 isTransitionRouted=true; 2399 } 2400 } catch (Exception ex) { 2401 isTransitionRouted=false; 2402 } 2403 if (source!=null && target!=null) { 2404 connectActivities(source,target,isTransitionRouted); 2405 } 2406 } 2407 } else { 2409 Set acs=JaWEGraphModel.getAllActivitiesInModel(graphModel()); 2410 if (acs!=null) { 2411 int translY=10; 2412 Iterator it=acs.iterator(); 2413 while (it.hasNext()) { 2414 Activity act=(Activity)it.next(); 2415 if ((act instanceof Start) || (act instanceof End)) continue; 2416 if (Utils.isStartingActivity(act) && !Utils.hasConnectedStartBubble(act)) { 2417 target=act; 2418 viewMap = new Hashtable(); 2419 source=createStart(new Point(10,translY),viewMap); 2420 translY+=30; 2421 updateModelAndArrangeParticipants(new Object [] {source}, 2422 null,null,viewMap,"",false,null); 2423 2424 if (source!=null && target!=null) { 2425 connectActivities(source,target,false); 2426 } 2427 } 2428 } 2429 } 2430 } 2431 } 2432 2433 2434 protected void createGraphEnds (WorkflowProcess wp,boolean isMine,boolean automaticCreation) { 2435 Activity source=null; 2436 Activity target=null; 2437 2438 Hashtable viewMap; 2439 2440 org.enhydra.jawe.xml.elements.Activity a=null; 2441 if (isMine && !automaticCreation) { 2443 Set endDescriptions=new HashSet(); 2444 if (graph instanceof BlockActivityGraph) { 2445 a=(org.enhydra.jawe.xml.elements.Activity) 2446 getVisualOwner(); 2447 endDescriptions=a.getEndDescriptions(); 2448 } else { 2449 endDescriptions=wp.getEndDescriptions(); 2450 } 2451 2452 if (endDescriptions.size()==0) return; 2453 2454 Participants pcs=(Participants)wp.get("Participants"); 2455 String ID; 2456 Participant par; 2457 Rectangle rPar; 2458 Point p; 2459 2460 Iterator it=endDescriptions.iterator(); 2461 String endDesc; 2462 String [] endD; 2463 while (it.hasNext()) { 2464 endDesc=(String )it.next(); 2465 endD=Utils.tokenize(endDesc,";"); 2466 ID=""; 2467 try { 2468 ID=endD[0]; 2469 } catch (Exception ex) {} 2470 par=getGraphObjectForXMLParticipant(pcs.getParticipant(ID)); 2471 if (par==null) { 2472 par=getGraphObjectForXMLParticipant(org.enhydra.jawe.xml.elements.Participant.getFreeTextExpressionParticipant()); 2473 } 2474 if (par!=null) { 2475 rPar=(Rectangle)getBounds(par,null); p=new Point(rPar.getLocation()); 2477 p.x+=10; p.y+=10; 2478 } else { 2479 rPar=null; 2480 p=new Point(10,10); 2481 } 2482 viewMap = new Hashtable(); 2483 target=createEnd(p,viewMap); 2484 updateModelAndArrangeParticipants(new Object [] {target},null,null, 2485 viewMap,"",false,null); 2486 try { 2488 adjustActivityPosition(target,Integer.parseInt(endD[2]), 2489 Integer.parseInt(endD[3]),rPar); 2490 } catch (Exception ex) {} 2491 try { 2493 source=getActivity(endD[1]); 2494 } catch (Exception ex) {} 2495 2496 boolean isTransitionRouted=false; 2497 try { 2498 String itr=endD[4]; 2499 if (itr.equals(org.enhydra.jawe.xml.elements.Transition.NO_ROUTING)) { 2500 isTransitionRouted=false; 2501 } else { 2502 isTransitionRouted=true; 2503 } 2504 } catch (Exception ex) { 2505 isTransitionRouted=false; 2506 } 2507 2508 if (source!=null && target!=null) { 2509 connectActivities(source,target,isTransitionRouted); 2510 } 2511 } 2512 } else { 2514 Set acs=JaWEGraphModel.getAllActivitiesInModel(graphModel()); 2515 if (acs!=null) { 2516 int translY=10; 2517 Iterator it=acs.iterator(); 2518 while (it.hasNext()) { 2519 Activity act=(Activity)it.next(); 2520 if ((act instanceof Start) || (act instanceof End)) continue; 2521 if (Utils.isEndingActivity(act) && !Utils.hasConnectedEndBubble(act)) { 2522 source=act; 2523 viewMap = new Hashtable(); 2524 target=createEnd(new Point(600,translY),viewMap); 2525 translY+=10; 2526 updateModelAndArrangeParticipants(new Object [] {target}, 2527 null,null,viewMap,"",false,null); 2528 2529 if (source!=null && target!=null) { 2530 connectActivities(source,target,false); 2531 } 2532 } 2533 } 2534 } 2535 } 2536 } 2537 2538 2539 private void adjustActivityPosition (Activity act,int xOff,int yOff, 2540 Rectangle rPar) { 2541 if (rPar==null || (xOff==0 && yOff==0)) return; 2542 int yPar=rPar.y; int xPar=rPar.x; 2543 Map attrib=GraphConstants.cloneMap(act.getAttributes()); 2544 Map propertyMap=new Hashtable(); 2545 ParentMap parentMap=new JaWEParentMap(); 2546 2547 propertyMap.put(act,attrib); 2548 2549 Rectangle bounds=(Rectangle)GraphConstants.getBounds(attrib); 2551 int inc=rPar.height-5; 2552 int nextYOff=inc; 2553 2554 if (yOff<inc) { 2555 inc=yOff; 2556 nextYOff=yOff; 2557 } 2558 2559 bounds.setLocation(new Point(xPar+xOff,yPar+inc)); 2560 arrangeParticipants(propertyMap,parentMap); 2561 2562 if (yOff>nextYOff) { 2563 inc=defActivityHeight; 2564 do { 2565 nextYOff+=inc; 2566 if (nextYOff>yOff) { 2567 nextYOff-=inc; 2568 inc=yOff-nextYOff; 2569 nextYOff+=inc; 2570 } 2571 bounds.translate(0,inc); 2572 arrangeParticipants(propertyMap,parentMap); 2573 } while (nextYOff<yOff); 2574 } 2575 graphModel().edit(propertyMap,null,parentMap,null); 2578 graph.paintImmediately(graph.getBounds()); 2580 } 2581 2582 2586 private Transition connectActivities (Activity source,Activity target, 2587 boolean isRouting) { 2588 Point startP=getCenter(source); 2590 Point endP=getCenter(target); 2591 try { 2592 Transition t=insertTransition (startP,endP,(PortView)getView(source.getPort()), 2593 (PortView)getView(target.getPort()),isRouting,false); 2594 return t; 2595 } catch (Exception ex) { 2596 System.err.println("Error while connecting activities "+source+" and "+target+" !!!"); 2597 return null; 2598 } 2599 } 2600 2601 2602 2606 private void layoutActivities () { 2607 Set participants=JaWEGraphModel.getAllParticipantsInModel(graphModel()); 2608 if (participants != null) { 2609 Iterator it=participants.iterator(); 2610 while (it.hasNext()) { 2611 Participant par=(Participant)it.next(); 2612 Set activities=par.getChildActivities(); 2613 Iterator itAct=activities.iterator(); 2614 2615 int cnt=0; 2616 double chngDir=(int)Math.sqrt(activities.size()); 2617 2618 int incX=2*defActivityWidth; 2619 int incY=defActivityHeight+5; 2620 int translateX=0; 2621 int translateY=0; 2622 2623 while (itAct.hasNext()) { 2624 Activity act=(Activity)itAct.next(); 2625 if (!(act instanceof Start) && !(act instanceof End)) { 2626 cnt++; 2627 if ((cnt/chngDir)==((int)(cnt/chngDir))) { 2628 incX=-incX; 2630 translateY+=incY; 2631 } else { 2632 translateX+=incX; 2633 } 2634 2635 Map attrib=GraphConstants.cloneMap(act.getAttributes()); 2636 Map propertyMap=new Hashtable(); 2637 ParentMap parentMap=new JaWEParentMap(); 2638 2639 propertyMap.put(act,attrib); 2640 Rectangle bounds=(Rectangle)GraphConstants.getBounds(attrib); 2642 if (act instanceof End) { 2643 bounds.translate(0,translateY); 2644 } else { 2645 bounds.translate(translateX,translateY); 2646 } 2647 2648 arrangeParticipants(propertyMap,parentMap); 2649 graphModel().edit(propertyMap,null,parentMap,null); 2652 } 2655 } 2656 } 2657 } 2658 } 2659 2660 2664 public Activity getActivity (String ID) { 2665 Set allActs=JaWEGraphModel.getAllActivitiesInModel(graphModel()); 2666 if (allActs != null) { 2667 Iterator it=allActs.iterator(); 2668 Activity act; 2669 String curID; 2670 while (it.hasNext()) { 2671 act=(Activity)it.next(); 2672 if (!(act instanceof Start) && !(act instanceof End)) { 2673 curID=act.get("Id").toValue().toString(); 2674 if (curID!=null && curID.equals(ID)) { 2675 return act; 2676 } 2677 } 2678 } 2679 } 2680 return null; 2681 } 2682 2683 2687 public Transition getTransition (String ID) { 2688 Set allTrans=JaWEGraphModel.getAllTransitionsInModel(graphModel()); 2689 if (allTrans != null) { 2690 Iterator it=allTrans.iterator(); 2691 Transition tr; 2692 String curID; 2693 while (it.hasNext()) { 2694 tr=(Transition)it.next(); 2695 org.enhydra.jawe.xml.elements.Transition xmlT= 2696 (org.enhydra.jawe.xml.elements.Transition) 2697 tr.getUserObject(); 2698 if (xmlT.getFrom()!=null && xmlT.getTo()!=null) { 2699 curID=tr.get("Id").toValue().toString(); 2700 if (curID!=null && curID.equals(ID)) { 2701 return tr; 2702 } 2703 } 2704 } 2705 } 2706 return null; 2707 } 2708 2709 2713 public Participant getParticipant (String ID) { 2714 Set allPartic=JaWEGraphModel.getAllParticipantsInModel(graphModel()); 2715 if (allPartic != null) { 2716 Iterator it=allPartic.iterator(); 2717 Participant p; 2718 String curID; 2719 while (it.hasNext()) { 2720 p=(Participant)it.next(); 2721 if (p.get("Id").toString().equals(ID)) { 2722 return p; 2723 } 2724 } 2725 } 2726 return null; 2727 } 2728 2729 2732 private Point getCenter (Object go) { 2733 if (go==null) return null; 2734 Rectangle r=(Rectangle)getBounds(go,null); if (!(go instanceof Participant)) { 2736 return new Point(r.x+(int)(r.width / 2),r.y+(int)(r.height / 2)); 2737 } else { 2738 return new Point(r.x+defParNameWidth/2,r.y+(int)(r.height / 2)); 2739 } 2740 } 2741 2742 2752 protected void refreshCollections ( 2753 Object [] cellsToAddOrRemove,boolean toAdd) { 2754 2755 Set xmlaAR=new HashSet(); 2757 Set xmltAR=new HashSet(); 2759 Set xmlwAR=new HashSet(); 2761 2762 Set baAR=new HashSet(); 2764 2765 if (cellsToAddOrRemove!=null && cellsToAddOrRemove.length>0) { 2766 for (int i=0; i<cellsToAddOrRemove.length; i++) { 2767 Object cell=cellsToAddOrRemove[i]; 2768 manageParticipantReferences(cell,toAdd); 2771 if (cell instanceof Transition) { 2772 Transition tr=(Transition)cell; 2773 boolean isValid=manageTransition(tr); 2774 if (toAdd) { 2775 if (isValid) { 2776 xmltAR.add(tr.getUserObject()); 2777 } 2778 } else { 2779 xmltAR.add(tr.getUserObject()); 2780 } 2781 } else if (cell instanceof org.enhydra.jawe.graph.Process) { 2782 org.enhydra.jawe.graph.Process proc=(org.enhydra.jawe.graph.Process)cell; 2783 WorkflowProcess wp=(WorkflowProcess)proc.getUserObject(); 2784 xmlwAR.add(wp); 2785 if (toAdd) { 2787 JaWE.getInstance().getPackageEditor().putProcessObjectMapping(wp,proc); 2788 } else { 2789 JaWE.getInstance().getPackageEditor().removeProcessObjectMapping(wp); 2790 } 2791 2792 } else if (cell instanceof BlockActivity) { 2793 xmlaAR.add(((Activity)cell).getUserObject()); 2794 baAR.add(cell); 2795 } else if (cell instanceof Activity && !(cell instanceof Start) 2796 && !(cell instanceof End)) { 2797 xmlaAR.add(((Activity)cell).getUserObject()); 2798 } 2799 } 2800 } 2801 Package pkg=getXMLPackage(); 2802 WorkflowProcesses wps=(WorkflowProcesses)pkg.get("WorkflowProcesses"); 2803 wps.refreshCollection(xmlwAR,toAdd); 2804 2805 XMLElement el=graph.getPropertyObject(); 2806 if (el instanceof WorkflowProcess) { 2807 WorkflowProcess wp=(WorkflowProcess)el; 2808 ActivitySets xmlactsts=(ActivitySets)wp.get("ActivitySets"); 2809 Activities xmlacts=getActivitiesCollection(); 2810 Transitions xmltrans=getTransitionsCollection(); 2811 2812 xmlacts.refreshCollection(xmlaAR,toAdd); 2813 xmltrans.refreshCollection(xmltAR,toAdd); 2814 2815 Iterator it=baAR.iterator(); 2817 while (it.hasNext()) { 2818 BlockActivity ba=(BlockActivity)it.next(); 2819 ActivitySet as=null; 2820 String ID=ba.getBlockID(); 2821 if (toAdd) { 2822 as=new ActivitySet(xmlactsts,wp); 2823 as.set("Id",ID); 2824 as.setIDPrefixForCollections(); 2825 xmlactsts.add(as); 2826 } else { 2827 as=xmlactsts.getActivitySet(ID); 2828 xmlactsts.remove(as); 2829 } 2830 } 2831 } 2832 2833 if (cellsToAddOrRemove!=null && cellsToAddOrRemove.length>0) { 2835 getGraph().getEditor().getStatusBar().updateMessage(); 2836 } 2837 2838 } 2839 2840 public boolean manageTransition (Transition tr) { 2841 org.enhydra.jawe.xml.elements.Transition xmlT= 2842 (org.enhydra.jawe.xml.elements.Transition) 2843 tr.getUserObject(); 2844 Activity s=null; 2845 try { 2846 s=tr.getSourceActivity(); 2847 } catch (Exception ex) { 2848 try { 2849 s=getActivity(xmlT.get("From").toString()); 2850 } catch (Exception ex2) { 2851 } 2852 } 2853 Activity t=null; 2854 try { 2855 t=tr.getTargetActivity(); 2856 } catch (Exception ex) { 2857 try { 2858 t=getActivity(xmlT.get("To").toString()); 2859 } catch (Exception ex2) { 2860 } 2861 } 2862 if (s!=null) updateSplit(s); 2863 if (t!=null) updateJoin(t); 2864 2865 if (s!=null && !(s instanceof Start) && s.getUserObject() instanceof XMLElement 2866 && t!=null && !(s instanceof Start) && t.getUserObject() instanceof XMLElement) { 2867 return true; 2868 } else { 2869 return false; 2870 } 2871 2872 } 2873 2874 public void correctXMLTransition (Transition tr) { 2875 org.enhydra.jawe.xml.elements.Transition xmlT= 2876 (org.enhydra.jawe.xml.elements.Transition) 2877 tr.getUserObject(); 2878 Activity s=tr.getSourceActivity(); 2879 Activity t=tr.getTargetActivity(); 2880 if (s!=null && s.getUserObject() instanceof XMLElement 2881 && t!=null && t.getUserObject() instanceof XMLElement) { 2882 xmlT.setFrom(s.getPropertyObject()); 2883 xmlT.setTo(t.getPropertyObject()); 2884 } 2885 } 2886 2887 public void updateSplit (Activity s) { 2888 if (s!=null && s.getUserObject() instanceof XMLElement) { 2890 org.enhydra.jawe.xml.elements.Activity a= 2891 (org.enhydra.jawe.xml.elements.Activity)s.getUserObject(); 2892 int noft=s.getOutgoingTransitions().size(); 2893 String type=a.getSplit().get("Type").toString().trim(); 2894 if (type.length()==0) { 2895 if (noft>1) { 2896 a.setSplitType(ResourceManager.getLanguageDependentString("XORKey")); 2897 } 2898 } else { 2899 if (noft<=1) { 2900 a.setSplitType(""); 2901 } 2902 } 2903 } 2904 } 2905 2906 public void updateJoin (Activity t) { 2907 if (t!=null && t.getUserObject() instanceof XMLElement) { 2909 org.enhydra.jawe.xml.elements.Activity a= 2910 (org.enhydra.jawe.xml.elements.Activity)t.getUserObject(); 2911 int noft=t.getIncomingTransitions().size(); 2912 String type=a.getJoin().get("Type").toString().trim(); 2913 if (type.length()==0) { 2914 if (noft>1) { 2915 a.setJoinType(ResourceManager.getLanguageDependentString("XORKey")); 2916 } 2917 } else { 2918 if (noft<=1) { 2919 a.setJoinType(""); 2920 } 2921 } 2922 } 2923 } 2924 2925 private void manageParticipantReferences (Set cellsToDelete,boolean toAdd) { 2926 Iterator it=cellsToDelete.iterator(); 2927 while (it.hasNext()) { 2928 manageParticipantReferences(it.next(),toAdd); 2929 } 2930 } 2931 2932 private void manageParticipantReferences (Object cellToDelete,boolean toAdd) { 2933 if (cellToDelete instanceof org.enhydra.jawe.graph.Process) { 2934 org.enhydra.jawe.graph.Process pr= 2935 (org.enhydra.jawe.graph.Process)cellToDelete; 2936 try { 2937 Set s=JaWEGraphModel.getAllParticipantsInModel(pr.getImplementationEditor().getGraph().getModel()); 2938 if (s!=null){ 2939 Iterator iter = s.iterator(); 2940 while (iter.hasNext()) { 2941 manageParticipantReferences(iter.next(),toAdd); 2943 } 2944 } 2945 manageParticipantReferences(pr.getImplementationEditor().getGraph(). 2946 getWorkflowManager().getBlockActivities(true),toAdd); 2947 } catch (Exception ex) {} 2948 } else if (cellToDelete instanceof BlockActivity) { 2949 BlockActivity b=(BlockActivity)cellToDelete; 2950 try { 2951 Set s=JaWEGraphModel.getAllParticipantsInModel(b.getImplementationEditor().getGraph().getModel()); 2953 if (s!=null){ 2954 Iterator iter = s.iterator(); 2955 while (iter.hasNext()) { 2956 manageParticipantReferences(iter.next(),toAdd); 2958 } 2959 } 2960 } catch (Exception ex) {} 2961 } else if (cellToDelete instanceof Participant) { 2962 Participant par=(Participant)cellToDelete; 2963 try { 2964 org.enhydra.jawe.xml.elements.Participant puo= 2965 (org.enhydra.jawe.xml.elements.Participant) 2966 par.getUserObject(); 2967 if (toAdd) { 2968 puo.graphReferenceAdded(); 2969 } else { 2970 puo.graphReferenceRemoved(); 2971 } 2972 } catch (Exception ex) {} 2973 } 2974 } 2975 2976 2985 public Object findNearestCell (Object selectedCell,int direction) { 2986 Set cellSet=JaWEGraphModel.getAllCellsInModel(graphModel()); 2988 if (cellSet==null || cellSet.size()==0) return null; 2991 2992 Object [] cells=cellSet.toArray(); 2993 if (selectedCell==null) return cells[0]; 2996 2997 Point centerOfSelectedCell=getCenter(selectedCell); 2999 if (centerOfSelectedCell==null) return cells[0]; 3001 3002 Object nearestCell=null; 3005 double minDistance=Double.MAX_VALUE; 3006 3007 for (int i=0; i<cells.length; i++) { 3009 if (cells[i]==selectedCell || cells[i] instanceof Port) continue; 3012 3013 Point centerOfCell=getCenter(cells[i]); 3015 Point ref=new Point(centerOfCell.x,centerOfSelectedCell.y); 3016 double dist=centerOfSelectedCell.distance(centerOfCell); 3017 double absOfTan=centerOfCell.distance(ref)/ref.distance(centerOfSelectedCell); 3018 3019 switch (direction) { 3020 case 1: if (centerOfCell.y>=centerOfSelectedCell.y) { 3022 if (dist<minDistance && absOfTan>=1) { 3023 minDistance=dist; 3024 nearestCell=cells[i]; 3025 } 3026 } 3027 break; 3028 case 2: if (centerOfCell.x<=centerOfSelectedCell.x) { 3030 if (dist<minDistance && absOfTan<=1) { 3031 minDistance=dist; 3032 nearestCell=cells[i]; 3033 } 3034 } 3035 break; 3036 case 3: if (centerOfCell.x>=centerOfSelectedCell.x) { 3038 if (dist<minDistance && absOfTan<=1) { 3039 minDistance=dist; 3040 nearestCell=cells[i]; 3041 } 3042 } 3043 break; 3044 default: if (centerOfCell.y<=centerOfSelectedCell.y) { 3046 if (dist<minDistance && absOfTan>=1) { 3047 minDistance=dist; 3048 nearestCell=cells[i]; 3049 } 3050 } 3051 break; 3052 } 3053 } 3054 return nearestCell; 3055 } 3056 3057 public Object findCell (Point p,Map propertyMap) { 3058 Set cellSet=JaWEGraphModel.getAllCellsInModel(graphModel()); 3060 if (cellSet==null || cellSet.size()==0) return null; 3063 3064 Object [] cells=cellSet.toArray(); 3065 3066 for (int i=0; i<cells.length; i++) { 3068 Rectangle r=getBounds(cells[i],propertyMap).getBounds(); if (r.contains(p) && !(cells[i] instanceof Port)) { 3071 return cells[i]; 3072 } 3073 } 3074 return null; 3075 } 3076 3077 3081 private void arrangeProcesses (Map propertyMap,Rectangle deletedProcessBounds) { 3082 int nextHowMany=JaWEGraphModel.getAllActivitiesInModel(graphModel()).size()-1; 3083 int deletedOrdNoX=(int)Math.round((deletedProcessBounds.x-JaWEConstants.PROCESS_OFFSET)/ 3085 (defProcessWidth*JaWEConstants.PROCESS_DISTANCE_COEFF)); 3086 int deletedOrdNoY=(int)Math.round((deletedProcessBounds.y-JaWEConstants.PROCESS_OFFSET)/ 3087 (defProcessHeight*JaWEConstants.PROCESS_DISTANCE_COEFF)); 3088 int deletedOrdNo=(deletedOrdNoX+1)+deletedOrdNoY* 3089 JaWEConstants.HOW_MANY_PROCESSES_IN_ONE_ROW; 3090 if (nextHowMany>=deletedOrdNo) { 3092 for (int i=deletedOrdNo+1; i<=nextHowMany+1; i++) { 3093 int xon=(i-1)%JaWEConstants.HOW_MANY_PROCESSES_IN_ONE_ROW; 3094 int yon=(i-1)/JaWEConstants.HOW_MANY_PROCESSES_IN_ONE_ROW; 3095 Point p=new Point((int)(JaWEConstants.PROCESS_OFFSET+ 3098 xon*JaWEConstants.PROCESS_DISTANCE_COEFF*defProcessWidth+defProcessWidth/2), 3099 (int)(JaWEConstants.PROCESS_OFFSET+ 3100 yon*JaWEConstants.PROCESS_DISTANCE_COEFF*defProcessHeight+defProcessHeight/2)); 3101 org.enhydra.jawe.graph.Process pr= 3103 (org.enhydra.jawe.graph.Process)findCell(p,propertyMap); 3104 if (pr!=null) { 3106 int xo=getBounds(pr,propertyMap).getBounds().x; int yo=getBounds(pr,propertyMap).getBounds().y; int xn=(int)(JaWEConstants.PROCESS_OFFSET+ 3111 ((i-2)%JaWEConstants.HOW_MANY_PROCESSES_IN_ONE_ROW)* 3112 JaWEConstants.PROCESS_DISTANCE_COEFF*defProcessWidth); 3113 int yn=(int)(JaWEConstants.PROCESS_OFFSET+ 3114 ((i-2)/JaWEConstants.HOW_MANY_PROCESSES_IN_ONE_ROW)* 3115 JaWEConstants.PROCESS_DISTANCE_COEFF*defProcessHeight); 3116 Map attrib=GraphConstants.cloneMap(pr.getAttributes()); 3118 Rectangle bounds=(Rectangle)GraphConstants.getBounds(attrib); bounds.translate(xn-xo,yn-yo); 3120 propertyMap.put(pr,attrib); 3121 } 3122 } 3123 } 3124 } 3125 3126 public void moveParticipants (Object [] cellsToMove, boolean direction) { 3131 Map propertyMap=new HashMap(); 3132 ParentMap parentMap=new JaWEParentMap(); 3133 3134 if (cellsToMove != null && cellsToMove.length>0) { 3135 boolean updated=false; 3136 for (int i=0; i<cellsToMove.length; i++) { 3137 if (cellsToMove[i] instanceof Participant) { 3138 Participant parSource=(Participant)cellsToMove[i]; 3139 Rectangle rSource=(Rectangle)getBounds(parSource,propertyMap); 3141 Rectangle matching=new Rectangle(rSource); 3143 int yPos; 3144 Participant[] parts; 3145 if (direction){ yPos=rSource.y-1; 3147 parts = getParticipantsForYPos(yPos,2,propertyMap,parentMap); 3148 if (parts != null && parts.length>0){ 3149 Participant parTarget = parts[0]; 3150 Rectangle rTarget=(Rectangle)getBounds(parTarget,propertyMap); 3152 translateParticipant(parSource,propertyMap,parentMap,0,-rTarget.height); 3154 translateParticipant(parTarget,propertyMap,parentMap,0,rSource.height); } 3156 } 3157 else{ yPos=rSource.y+rSource.height+1; 3159 parts = getParticipantsForYPos(yPos,2,propertyMap,parentMap); 3160 if (parts != null && parts.length>0){ 3161 Participant parTarget = parts[0]; 3162 Rectangle rTarget=(Rectangle)getBounds(parTarget,propertyMap); 3164 translateParticipant(parSource,propertyMap,parentMap,0,rTarget.height); 3166 translateParticipant(parTarget,propertyMap,parentMap,0,-rSource.height); } 3168 } 3169 3170 Rectangle toMatch=(Rectangle)getBounds(parSource,propertyMap); arrangeParticipants(propertyMap,parentMap); 3172 3173 if (!toMatch.equals(matching)) { 3174 updated=true; 3175 } 3176 } 3177 } 3178 if (updated) { 3181 graphModel().insertAndEdit(null,propertyMap,null,parentMap,null,""); 3182 } 3183 } 3184 } 3185 3187 public Dimension getGraphsPreferredSize () { 3188 return new Dimension(getRootParticipantWidth(null,null)+50, 3189 getNewRootParYPos(null,null)+50); 3190 } 3191 3192} 3193 3194 3195 3196 | Popular Tags |