1 10 11 package org.enhydra.jawe; 12 13 import org.enhydra.jawe.actions.*; 14 import org.enhydra.jawe.graph.*; 15 import org.enhydra.jawe.xml.*; 16 import org.enhydra.jawe.xml.elements.WorkflowProcess; 17 18 import org.jgraph.*; 19 import org.jgraph.graph.*; 20 import org.jgraph.plaf.basic.*; 21 import java.awt.*; 22 import java.awt.print.*; 23 import java.awt.event.*; 24 import java.util.*; 25 import java.io.*; 26 import javax.swing.*; 27 import javax.swing.border.*; 28 import javax.swing.tree.DefaultMutableTreeNode ; 29 import org.enhydra.jawe.PackageEditor; 30 31 34 public class PackageGraph extends AbstractGraph { 35 36 private static final int processWidth=JaWEConfig.getInstance().getProcessWidth(); 37 private static final int processHeight=JaWEConfig.getInstance().getProcessHeight(); 38 41 public PackageGraph(GraphModel model,PackageEditor pe) { 42 super(model,pe); 43 } 44 45 public PackageGraph(GraphModel model,GraphLayoutCache view) { 46 super(model,view); 47 } 48 49 public org.enhydra.jawe.xml.elements.Package getXMLPackage () { 50 return (org.enhydra.jawe.xml.elements.Package)xmlObject; 51 } 52 53 public void setPropertyObject (XMLComplexElement ce) { 54 xmlObject=ce; 55 } 56 57 60 public Point getNextInsertionPoint() { 61 int hmp; 62 try { 63 hmp=JaWEGraphModel.getAllActivitiesInModel(graphModel).size(); 64 } catch (Exception ex) { 65 hmp=0; 66 } 67 68 return new Point((int)(JaWEConstants.PROCESS_OFFSET+ 69 processWidth*JaWEConstants.PROCESS_DISTANCE_COEFF* 70 (hmp%JaWEConstants.HOW_MANY_PROCESSES_IN_ONE_ROW)), 71 (int)(JaWEConstants.PROCESS_OFFSET+ 72 processHeight*JaWEConstants.PROCESS_DISTANCE_COEFF* 73 ((int)hmp/JaWEConstants.HOW_MANY_PROCESSES_IN_ONE_ROW))); 74 } 75 76 public void createWorkflowGraph (Window pFrame) { 77 org.enhydra.jawe.xml.elements.Package p= 78 (org.enhydra.jawe.xml.elements.Package)xmlObject; 79 org.enhydra.jawe.xml.elements.WorkflowProcesses wps= 80 (org.enhydra.jawe.xml.elements.WorkflowProcesses) 81 p.get("WorkflowProcesses"); 82 Iterator it=wps.toCollection().iterator(); 83 84 while (it.hasNext()) { 85 org.enhydra.jawe.xml.elements.WorkflowProcess wp= 86 (org.enhydra.jawe.xml.elements.WorkflowProcess) 87 it.next(); 88 createWorkflowObject(pFrame,wp); 89 wps.decrementID(); 91 } 92 } 93 94 public void createWorkflowObject (Window pFrame, 95 org.enhydra.jawe.xml.elements.WorkflowProcess wp) { 96 org.enhydra.jawe.graph.Process pr=workflowManager. 97 insertProcess(getNextInsertionPoint(),false); 98 pr.setUserObject(wp); 99 pr.createWorkflowGraph(pFrame); 100 paintImmediately(getBounds()); 101 ((PackageEditor)editor).putProcessObjectMapping(wp,pr); 102 } 103 104 107 public String getTooltip () { 108 return ""; 109 } 110 111 114 protected VertexView createVertexView(JGraph graph,CellMapper cm,Object cell) { if (cell instanceof org.enhydra.jawe.graph.Process) { 116 return new ProcessView(cell,this,cm); 117 } else { 118 return super.createVertexView(graph,cm,cell); } 122 } 123 124 127 public String convertValueToString(Object value) { 128 if (value instanceof CellView) { 129 value=((CellView)value).getCell(); 130 } 131 if (value instanceof org.enhydra.jawe.graph.Process && 132 ((DefaultMutableTreeNode )value).getUserObject() != null) { 133 return ((DefaultMutableTreeNode )value).getUserObject().toString(); 134 } else if (value != null) { 135 return value.toString(); 136 } 137 return null; 138 } 139 140 156 public String getToolTipText(MouseEvent event) { 157 if(event != null) { 158 Object cell=getFirstCellForLocation(event.getX(),event.getY()); 159 if (cell != null) { 160 String s=convertValueToString(cell); 161 if (cell instanceof WorkflowElement) { 162 s=((WorkflowElement)cell).getTooltip(); 163 } 164 return s; 165 } 166 } 167 return null; 168 } 169 170 public boolean validateAgainsXPDLSchema () { 171 Save.updateExtendedAttributesForWorkflowProcesses(); 172 PackageValidator pv=new PackageValidator(getXMLPackage(),true,true,false,true, 173 JaWEConfig.getInstance().getAllowUndefinedStartActivity(), 174 JaWEConfig.getInstance().getAllowUndefinedEndActivity(), 175 JaWEConfig.getInstance().getEncoding()); 176 boolean isValid=pv.validateAgainstXPDLSchema(); 177 xpdlSchemaValidationErrors=pv.getXPDLSchemaValidationErrors(); 178 if (!isValid && xpdlSchemaValidationErrors.size()>0) { 179 basicXpdlSchemaValidationError=ResourceManager. 180 getLanguageDependentString("MessageThereAreSomeSchemaValidationErrors"); 181 } else { 182 basicXpdlSchemaValidationError=null; 183 } 184 return isValid; 185 } 186 187 public boolean checkConnections (boolean fullCheck) { 188 updateXMLObjectsBeforeChecking(); 189 PackageValidator pv=new PackageValidator(getXMLPackage(),true,true, false,true, 190 JaWEConfig.getInstance().getAllowUndefinedStartActivity(), 191 JaWEConfig.getInstance().getAllowUndefinedEndActivity(), 192 JaWEConfig.getInstance().getEncoding()); 193 boolean areGraphsWellConnected=pv.checkGraphConnections(fullCheck); 194 basicGraphConnectionError=pv.getBasicGraphConnectionError(getXMLPackage()); 195 graphConnectionErrors=pv.getGraphsConnectionErrors(getXMLPackage()); 196 if (JaWEConfig.getInstance().getUseBubblesStatus() && (fullCheck || areGraphsWellConnected)) { 197 areGraphsWellConnected=checkStartAndEndsConnections(fullCheck) && areGraphsWellConnected; 198 } 199 return areGraphsWellConnected; 200 } 201 202 protected boolean checkStartAndEndsConnections (boolean fullCheck) { 203 boolean wellConnected=true; 204 Set activities=JaWEGraphModel.getAllActivitiesInModel(graphModel); 205 if (activities!=null) { 206 Iterator it=activities.iterator(); 207 while(it.hasNext() && (fullCheck || wellConnected)) { 208 Activity act=(Activity)it.next(); 209 ProcessEditor pe=act.getImplementationEditor(); 210 if (pe!=null) { 211 WorkflowProcess wp=(WorkflowProcess)act.getUserObject(); 212 ProcessGraph pg=(ProcessGraph)pe.getGraph(); 213 if (pg.getImproperlyConnectedStarts(false).size()>0 || 214 pg.getImproperlyConnectedEnds(false).size()>0) { 215 wellConnected=false; 216 basicGraphConnectionError=ResourceManager. 217 getLanguageDependentString("InformationOneOrMoreProcessesHaveImproperlyConnectedElements"); 218 if (!fullCheck){ 219 break; 220 } 221 if (graphConnectionErrors==null) { 222 graphConnectionErrors=new HashMap(); 223 } 224 225 graphConnectionErrors.put(wp,basicGraphConnectionError); 226 } 227 Set blockActs=workflowManager.getBlockActivities(true); 229 Iterator itBas=blockActs.iterator(); 230 while (itBas.hasNext()) { 231 BlockActivity ba=(BlockActivity)itBas.next(); 232 ProcessEditor bwe=ba.getImplementationEditor(); 233 if (bwe!=null) { 234 ProcessGraph bag=(ProcessGraph)bwe.getGraph(); 235 if (bag.getImproperlyConnectedStarts(false).size()>0 || 236 bag.getImproperlyConnectedEnds(false).size()>0) { 237 wellConnected=false; 238 basicGraphConnectionError=ResourceManager. 239 getLanguageDependentString("InformationOneOrMoreProcessesHaveImproperlyConnectedElements"); 240 if (!fullCheck){ 241 break; 242 } 243 graphConnectionErrors.put(wp,basicGraphConnectionError); 244 } 245 246 } 247 } 248 } 249 } 250 } 251 return wellConnected; 252 } 253 254 protected void updateXMLObjectsBeforeChecking () { 255 Set activities=JaWEGraphModel.getAllActivitiesInModel(graphModel); 257 if (activities!=null) { 258 Iterator it=activities.iterator(); 259 while(it.hasNext()) { 260 Activity act=(Activity)it.next(); 261 ProcessEditor pe=act.getImplementationEditor(); 262 if (pe!=null) { 263 WorkflowProcess wp=(WorkflowProcess)act.getUserObject(); 264 wp.setStartDescriptions(Utils.getStartDescriptions(pe)); 265 wp.setEndDescriptions(Utils.getEndDescriptions(pe)); 266 Set blockActs=workflowManager.getBlockActivities(true); 268 Iterator itBas=blockActs.iterator(); 269 while (itBas.hasNext()) { 270 BlockActivity ba=(BlockActivity)itBas.next(); 271 ProcessEditor bwe=ba.getImplementationEditor(); 272 org.enhydra.jawe.xml.elements.Activity bap= 273 (org.enhydra.jawe.xml.elements.Activity) 274 ba.getUserObject(); 275 bap.setStartDescriptions(Utils.getStartDescriptions(bwe)); 276 bap.setEndDescriptions(Utils.getEndDescriptions(bwe)); 277 } 278 } 279 } 280 } 281 } 282 283 289 public boolean checkGraphConformance(boolean fullCheck) { 290 PackageValidator pv=new PackageValidator(getXMLPackage(),true,true, false,true, 291 JaWEConfig.getInstance().getAllowUndefinedStartActivity(), 292 JaWEConfig.getInstance().getAllowUndefinedEndActivity(), 293 JaWEConfig.getInstance().getEncoding()); 294 boolean areGraphsConformant=pv.checkGraphConformance(fullCheck); 295 basicGraphConformanceErrors=pv.getBasicGraphConformanceErrors(getXMLPackage()); 296 graphConformanceErrors=pv.getGraphConformanceErrors(getXMLPackage()); 297 return areGraphsConformant; 298 } 299 300 public boolean checkLogic (boolean fullCheck) { 301 PackageValidator pv=new PackageValidator(getXMLPackage(),true,true,false,true, 302 JaWEConfig.getInstance().getAllowUndefinedStartActivity(), 303 JaWEConfig.getInstance().getAllowUndefinedEndActivity(), 304 JaWEConfig.getInstance().getEncoding()); 305 boolean isLogical=pv.checkPackage(fullCheck); 306 basicLogicError=pv.getBasicLogicError(getXMLPackage()); 307 logicErrors=pv.getLogicErrors(getXMLPackage()); 308 return isLogical; 309 } 310 311 315 public void xmlElementChanged (XMLElement el) { 316 if (el instanceof org.enhydra.jawe.xml.elements.Activity) { 317 editor.getStatusBar().updateMessage(); 318 } 319 } 320 321 } 322 | Popular Tags |