1 10 11 package org.enhydra.jawe; 12 13 import java.awt.*; 14 import java.io.*; 15 import java.util.*; 16 17 import javax.swing.*; 18 19 import org.jgraph.event.*; 20 import org.enhydra.jawe.actions.*; 21 import org.enhydra.jawe.actions.Applications; 22 import org.enhydra.jawe.actions.ExternalPackages; 23 import org.enhydra.jawe.actions.Participants; 24 import org.enhydra.jawe.actions.TypeDeclarations; 25 import org.enhydra.jawe.ldap.*; 26 import org.enhydra.jawe.misc.*; 27 import org.enhydra.jawe.xml.*; 28 import org.enhydra.jawe.xml.elements.*; 29 import org.enhydra.jawe.xml.panels.*; 30 31 40 41 public class PackageEditor extends AbstractEditor { 42 43 private Map pkgIdToGraph; 44 private Map processToProcessObject; 45 46 private org.enhydra.jawe.xml.elements.Package realXMLPackage; 47 private PackageGraph realGraph; 48 49 private boolean isInitialized=false; 51 52 private JSplitPane splitPane; 53 private PackageTreePanel packageTreePanel; 54 private TextTreePanel packagePrintTreePanel; 55 56 public PackageEditor(XMLComplexElement pkgOrProcess) { 57 super(pkgOrProcess); 58 } 59 60 public PackageTreePanel getPackageTreePanel () { 61 return packageTreePanel; 62 } 63 64 public TextTreePanel getPackagePrintTreePanel () { 65 return packagePrintTreePanel; 66 } 67 68 public boolean isInitialized () { 69 return isInitialized; 70 } 71 72 public boolean isPackageGraphCreated (String pkgId) { 73 if (pkgIdToGraph==null) { 74 pkgIdToGraph=new Hashtable(); 75 } 76 return pkgIdToGraph.containsKey(pkgId); 77 } 78 79 public boolean isProcessObjectCreated (WorkflowProcess wp) { 80 if (processToProcessObject==null) { 81 processToProcessObject=new Hashtable(); 82 } 83 return processToProcessObject.containsKey(wp); 84 } 85 86 public PackageGraph getPackageGraph (String pkgId) { 87 if (pkgIdToGraph==null) { 88 pkgIdToGraph=new Hashtable(); 89 } 90 return (PackageGraph)pkgIdToGraph.get(pkgId); 91 } 92 93 public void putPackageGraphMapping (String pkgId,PackageGraph peg) { 94 if (pkgIdToGraph==null) { 95 pkgIdToGraph=new Hashtable(); 96 } 97 pkgIdToGraph.put(pkgId,peg); 98 } 99 100 public Map getPkgIdToGraphMap () { 101 if (pkgIdToGraph==null) { 102 pkgIdToGraph=new Hashtable(); 103 } 104 return Collections.unmodifiableMap(pkgIdToGraph); 105 } 106 107 public void removePackageGraphMapping (String pkgId) { 108 if (pkgIdToGraph==null) { 109 pkgIdToGraph=new Hashtable(); 110 } 111 pkgIdToGraph.remove(pkgId); 112 } 113 114 public void clearPackageGraphMap() { 115 if (pkgIdToGraph==null) { 116 pkgIdToGraph=new Hashtable(); 117 } 118 pkgIdToGraph.clear(); 119 } 120 121 public org.enhydra.jawe.graph.Process getProcessObject (WorkflowProcess wp) { 122 if (processToProcessObject==null) { 123 processToProcessObject=new Hashtable(); 124 } 125 return (org.enhydra.jawe.graph.Process)processToProcessObject.get(wp); 126 } 127 128 public void putProcessObjectMapping (WorkflowProcess wp,org.enhydra.jawe.graph.Process pr) { 129 if (processToProcessObject==null) { 130 processToProcessObject=new Hashtable(); 131 } 132 processToProcessObject.put(wp,pr); 133 } 134 135 public void removeProcessObjectMapping (WorkflowProcess wp) { 136 if (processToProcessObject==null) { 137 processToProcessObject=new Hashtable(); 138 } 139 processToProcessObject.remove(wp); 140 } 141 142 public void clearProcessObjectMap() { 143 if (processToProcessObject==null) { 144 processToProcessObject=new Hashtable(); 145 } 146 processToProcessObject.clear(); 147 } 148 149 154 protected Component createCenterComponent() { 155 packageTreePanel=new PackageTreePanel(getXMLPackage(),this, 156 ResourceManager.getLanguageDependentString("PackageAndExternalPackagesKey"),false); 157 158 splitPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, 159 packageTreePanel,super.createCenterComponent()); 160 161 return splitPane; 162 } 163 164 167 protected AbstractGraph createGraph() { 168 realGraph=new PackageGraph(new JaWEGraphModel(),this); 169 return realGraph; 170 } 171 172 protected void createActions () { 173 defaultActions=new Action[] { 174 new New(this), 175 new Open(this), 176 new Reopen(this), 177 new Save(this), 178 new SaveAs(this), 179 new ChangeLanguage(this), 180 new WfXML(this), 181 new Exit(this), 182 new org.enhydra.jawe.actions.Namespaces(this), 183 new PackageProperties(this), 184 new Processes(this), 185 new ExternalPackages(this), 186 new ImportExternalProcess(this), 187 new ImportExternalParticipants(this), 188 new TypeDeclarations(this), 189 new Participants(this), 190 new Applications(this), 191 new WorkflowRelevantData(this), 192 new ReferredDocument(this), 193 new CheckValidity(this), 194 undoAction, 195 redoAction, 196 new Delete(this), 197 new EditCell(this), 198 new EditProperties(this), 199 new MakeCopyOfProcess(this), 200 new HelpTutorial(this), 201 new HelpManual(this), 202 new HelpAbout(this), 203 new Config(this) 204 }; 205 } 206 207 209 public void valueChanged(GraphSelectionEvent e) { 210 boolean enabled = !graph.isSelectionEmpty(); 212 if (realGraph!=graph) { 213 getToolbarComponent(JaWEConstants.PROCESS_ACTIVITY_TOOL).setEnabled(false); 214 getToolbarComponent(JaWEConstants.AUTOMATIC_START_END_TOOL).setEnabled(false); 215 getAction(Utils.getUnqualifiedClassName(Delete.class)).setEnabled(false); 216 undoAction.setEnabled(false); 217 redoAction.setEnabled(false); 218 getAction(Utils.getUnqualifiedClassName(EditCell.class)).setEnabled(enabled); 219 getAction(Utils.getUnqualifiedClassName(EditProperties.class)).setEnabled(enabled); 220 getAction(Utils.getUnqualifiedClassName(MakeCopyOfProcess.class)).setEnabled(false); 221 return; 222 } else { 223 getToolbarComponent(JaWEConstants.PROCESS_ACTIVITY_TOOL).setEnabled(true); 224 if (JaWEConfig.getInstance().getUseBubblesStatus()) { 225 getToolbarComponent(JaWEConstants.AUTOMATIC_START_END_TOOL).setEnabled(true); 226 } 227 } 228 229 try { 230 getAction(Utils.getUnqualifiedClassName(Delete.class)).setEnabled(enabled); 231 getAction(Utils.getUnqualifiedClassName(EditCell.class)).setEnabled(enabled); 232 getAction(Utils.getUnqualifiedClassName(EditProperties.class)).setEnabled(enabled); 233 getAction(Utils.getUnqualifiedClassName(MakeCopyOfProcess.class)).setEnabled(enabled); 234 } catch (Exception ex) {} 235 236 try { 237 update(); 238 } catch (Exception ex) {} 239 } 240 242 243 246 public org.enhydra.jawe.xml.elements.Package getXMLPackage () { 247 return graph.getXMLPackage(); 248 } 249 250 253 public org.enhydra.jawe.xml.elements.Package getRealXMLPackage () { 254 return realXMLPackage; 255 } 256 257 public void enterPackageID () { 258 String msg=ResourceManager.getLanguageDependentString( 259 "InformationNotAllowedToDoEnythingBeforeEnteringPackageID"); 260 JaWE.getInstance().message(msg,JOptionPane.INFORMATION_MESSAGE); 261 262 XMLElement ID=realXMLPackage.get("Id"); 263 ID.setReadOnly(false); 264 265 String mcl=JaWE.getInstance().getMandatoryConformanceClass(); 267 int mct=XMLUtil.getConformanceClassNo(mcl); 268 if (mct>0) { 269 ConformanceClass cc=(ConformanceClass)getXMLPackage().get("ConformanceClass"); 270 cc.set("GraphConformance",ResourceManager.getLanguageDependentString(mcl+"Key")); 271 cc.setReadOnly(true); 272 } 273 274 XMLPanel p=getXMLPackage().getPanel(1); 275 String message; 276 277 XMLElementDialog d=new XMLElementDialog((JFrame)getWindow(), 278 ResourceManager.getLanguageDependentString("PackageKey")+" '"+ 279 getXMLPackage().get("Id").toString()+"' - "+ 280 ResourceManager.getLanguageDependentString("PropertiesKey")); 281 282 d.editXMLElement(p,false,true); 283 getXMLPackage().setIDPrefixForCollections (); 284 285 ID.setReadOnly(true); 286 287 isInitialized=true; 288 289 JaWE.getInstance().getXMLInterface().register(realXMLPackage); 290 291 putPackageGraphMapping(ID.toString(),(PackageGraph)graph); 293 294 getToolbarComponent(JaWEConstants.PROCESS_ACTIVITY_TOOL).setEnabled(true); 295 getToolbarComponent(JaWEConstants.AUTOMATIC_START_END_TOOL).setEnabled(true); 296 297 splitPane.remove(packageTreePanel); 298 packageTreePanel=new PackageTreePanel(getXMLPackage(),this, 299 ResourceManager.getLanguageDependentString("PackageAndExternalPackagesKey"),false); 300 splitPane.setLeftComponent(packageTreePanel); 301 302 displayPackage(realXMLPackage); 303 update(); 304 } 305 306 public void displayPackage (org.enhydra.jawe.xml.elements.Package pkg) { 307 graph.getSelectionModel().removeGraphSelectionListener(this); 308 graph=getPackageGraph(pkg.get("Id").toString()); 309 310 if (graph==null || getXMLPackage()!=pkg) { 311 graph=realGraph; 312 } 313 graph.refreshGraphConfiguration(); 314 graph.getSelectionModel().addGraphSelectionListener(this); 315 316 getAction(Utils.getUnqualifiedClassName(ImportExternalProcess.class)).setEnabled(graph==realGraph); 317 getAction(Utils.getUnqualifiedClassName(ImportExternalParticipants.class)).setEnabled(graph==realGraph); 318 319 graphScrollPane.setViewportView(graph); 320 valueChanged(null); 321 statusBar.updateMessage(); 322 } 323 324 329 public boolean allowInvalidPackageSaving () { 330 boolean allow=false; 331 RedefinableHeader rh=(RedefinableHeader)getXMLPackage().get("RedefinableHeader"); 332 String pStatus=rh.get("PublicationStatus").toValue().toString(); 333 if (pStatus.equals("UNDER_TEST") || pStatus.equals("UNDER_REVISION")) { 334 allow=true; 335 } 336 return allow; 337 } 338 339 343 public WorkflowProcess showProcess (Window parentWindow, 344 WorkflowProcess wp,String processID) { 345 346 org.enhydra.jawe.graph.Process pr; 347 if (wp==null) { 348 pr=realGraph.getWorkflowManager(). 349 insertProcess(realGraph.getNextInsertionPoint(),true); 350 wp=(WorkflowProcess)pr.getUserObject(); 351 wp.set("Id",processID); 352 putProcessObjectMapping(wp,pr); 353 pr.showProcess(parentWindow); 354 } else { 355 pr=getProcessObject(wp); 356 ProcessEditor pe=pr.getImplementationEditor(); 357 pe.refreshEditorConfiguration(); 358 if (wp.getPackage()!=realXMLPackage || wp.getPackage().isReadOnly()) { 359 pe.setButtonsEnabled(false); 360 } 361 pr.showProcess(parentWindow); 362 } 363 return wp; 364 } 365 366 369 public String getTitle () { 370 String title=""; 371 372 375 if (realXMLPackage!=null && realXMLPackage.get("Id").toString().trim().length()>0) { 376 title+=realXMLPackage.get("Id").toString().trim(); 377 } 378 else { 379 title+=ResourceManager.getLanguageDependentString("UnnamedKey"); 380 } 381 title+=" - JaWE"; 382 383 if (JaWE.getInstance().isModified()) { 384 title+="*"; 385 } 386 return title; 387 } 388 389 392 public String toolbarToLoad () { 393 return "packageToolbars"; 394 } 395 396 399 public String menubarToLoad () { 400 return "packageMenubar"; 401 } 402 403 407 public void setNewPackage ( 408 org.enhydra.jawe.xml.elements.Package pkg, 409 boolean clearOtherPackages) { 410 if (clearOtherPackages) { 411 clearPackageGraphMap(); 412 clearProcessObjectMap(); 413 } 414 if (pkg!=null) { 415 putPackageGraphMapping(pkg.get("Id").toString(),(PackageGraph)graph); 416 } 417 418 graph.updateUI(); 421 422 realXMLPackage=pkg; 423 graph.setPropertyObject(pkg); 424 425 graph.clearSelection(); 427 graph.paintImmediately(graph.getBounds()); 428 429 graph.getModel().removeGraphModelListener(this); 430 graph.getModel().removeUndoableEditListener(undoHandler); 431 graph.setModel(new JaWEGraphModel()); 432 433 valueChanged(null); 435 if (JaWE.getInstance().getFilename()!=null && 440 (new File(JaWE.getInstance().getFilename()).exists() || !clearOtherPackages)) { 441 isInitialized=true; 442 Window w=getWindow(); 443 graph.createWorkflowGraph(w); 444 createGraphsForExternalPackages(realXMLPackage); 446 } else { 447 isInitialized=false; 448 } 449 450 if (splitPane!=null) { 451 452 splitPane.remove(packageTreePanel); 453 packageTreePanel=new PackageTreePanel(getXMLPackage(),this, 454 ResourceManager.getLanguageDependentString("PackageAndExternalPackagesKey"),false); 455 splitPane.setLeftComponent(packageTreePanel); 456 } 457 458 try { 459 displayPackage(realXMLPackage); 460 } catch(Exception ex) {} 461 JaWE.getInstance().setModified(false); 462 graph.getModel().addGraphModelListener(this); 463 graph.getModel().addUndoableEditListener(undoHandler); 464 resetUndoManager(); 465 466 467 try { 468 getWindow().requestFocus(); 469 } catch (Exception ex) {} 470 471 if (!isInitialized) { 472 getToolbarComponent(JaWEConstants.PROCESS_ACTIVITY_TOOL).setEnabled(false); 473 getToolbarComponent(JaWEConstants.AUTOMATIC_START_END_TOOL).setEnabled(false); 474 } 475 476 } 477 478 483 public void createGraphsForExternalPackages( 484 org.enhydra.jawe.xml.elements.Package pkg) { 485 Set ems=pkg.getAllExternalPackages(); 486 org.enhydra.jawe.xml.elements.Package ep; 487 Iterator it=ems.iterator(); 488 while (it.hasNext()) { 489 ep=(org.enhydra.jawe.xml.elements.Package)it.next(); 490 createGraphForPackage(ep,true); 491 } 492 } 493 494 497 public void createGraphForPackage ( 498 org.enhydra.jawe.xml.elements.Package pkg, 499 boolean isReadOnly) { 500 Window w=getWindow(); 501 if (!isPackageGraphCreated(pkg.get("Id").toString())) { 502 pkg.setReadOnly(isReadOnly); 507 PackageGraph peg=new PackageGraph(new JaWEGraphModel(),this); 508 ToolTipManager.sharedInstance().registerComponent(peg); 510 peg.setPropertyObject(pkg); 511 peg.setAdditionalKeyboardShortcuts(); 512 peg.createWorkflowGraph(w); 513 putPackageGraphMapping(pkg.get("Id").toString(),peg); 514 } 515 } 516 517 } 518 519 | Popular Tags |