1 10 11 package org.enhydra.jawe; 12 13 import java.util.*; 14 import java.io.*; 15 import java.net.*; 16 import java.awt.*; 17 import java.awt.event.*; 18 import javax.swing.*; 19 20 import org.enhydra.jawe.misc.*; 21 import org.enhydra.jawe.ldap.*; 22 import org.enhydra.jawe.misc.*; 23 import org.enhydra.jawe.xml.*; 24 import org.enhydra.jawe.xml.elements.*; 25 26 31 public final class JaWE implements XMLElementChangeListener { 32 33 private static JaWE jawe; 34 35 public static ImageIcon appIcon; 37 private static ImageIcon logoIcon; 39 private static String appTitle; 41 42 private static XMLInterface xmlInterface=new XML(); 45 46 public static XMLInterface getXMLInterface () { 47 return xmlInterface; 48 } 49 50 private static String mandatoryConformanceClass= 52 JaWEConfig.getInstance().getMandatoryConformanceClass(); 53 54 private static final int recentFileListSize= 55 JaWEConfig.getInstance().getRecentFileListSize(); 56 57 58 62 static { 63 try { 64 String vers = System.getProperty("java.version"); 65 if (vers.compareTo("1.4") < 0) { 66 System.out.println("!!!WARNING: JaWE must be run with a " + 67 "1.4 or higher version VM!!!"); 68 System.exit(1); 69 } 70 71 72 appTitle = ResourceManager.getLanguageDependentString("Title"); 74 75 URL url = ResourceManager.getResource("Logo"); 77 if (url != null) logoIcon = new ImageIcon(url); 78 79 url = ResourceManager.getResource("Icon"); 81 if (url != null) appIcon = new ImageIcon(url); 82 83 JaWEPortView.setPortSize(java.lang.Math.min(JaWEConfig.getInstance().getActivityWidth(), 85 JaWEConfig.getInstance().getActivityHeight())-10); 86 87 File ujdir=new File(JaWEConstants.JAWE_USER_HOME); 89 if (!ujdir.exists()) { 90 try { 91 ujdir.mkdir(); 92 } catch (Exception exc) {}; 93 } 94 95 ((XML)xmlInterface).setFileLockingStatus(JaWEConfig.getInstance().getFileLockingStatus()); 96 97 } catch (Throwable t) { 98 System.err.println("uncaught exception: " + t); 99 t.printStackTrace(); 100 } 101 } 102 103 107 public static JaWE getInstance () { 108 if (JaWE.jawe==null) { 109 JaWE.jawe=new JaWE(); 110 JaWE.jawe.init(null); 111 } 112 return jawe; 113 } 114 115 118 public static String getAppTitle () { 119 return appTitle; 120 } 121 122 125 public static ImageIcon getLogoIcon () { 126 return logoIcon; 127 } 128 129 132 public static ImageIcon getAppIcon () { 133 return appIcon; 134 } 135 136 137 private JFrame mainFrame; 138 139 143 private PackageEditor packageEditor; 144 145 146 private String filename; 147 148 149 private boolean modified=false; 150 151 private Action save; 152 private Action exit; 153 154 private JMenu recentFilesMenu; 155 156 159 private JaWE () { 160 mainFrame = new JFrame(); 161 mainFrame.setBackground(Color.lightGray); 162 mainFrame.getContentPane().setLayout(new BorderLayout()); 163 mainFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); 164 if (appIcon != null) mainFrame.setIconImage(appIcon.getImage()); 165 XMLUtil.setApplicationWindow(mainFrame); 166 XMLElementDialog.addXMLElementChangedListener(this); 168 } 170 171 private void init (String filename) { 172 org.enhydra.jawe.xml.elements.Package pkg= 173 openDocument(filename,true,false); 174 packageEditor = new PackageEditor(pkg); 175 mainFrame.getContentPane().add(packageEditor,BorderLayout.CENTER); 176 177 if (filename!=null && new File(filename).exists()) { 178 boolean validationStatus=JaWEConfig.getInstance().getValidationStatus(); 179 PackageValidator pv=new PackageValidator(pkg,false,true,true,true, 180 JaWEConfig.getInstance().getAllowUndefinedStartActivity(), 181 JaWEConfig.getInstance().getAllowUndefinedEndActivity(), 182 JaWEConfig.getInstance().getEncoding()); 183 ValidationErrorDisplay ved=null; 184 if (validationStatus && !pv.validateAll(true)) { 185 try { 186 JaWESplash.getSplash().hideSplash(); 187 } catch (Exception ex) {} 188 Map xpdlSchemaValidationErrors=pv.getXPDLSchemaValidationErrors(); 189 Map connectionErrors=pv.getGraphsConnectionErrors(pkg); 190 java.util.List basicGraphConformanceErrors=pv.getBasicGraphConformanceErrors(pkg); 191 Map graphConformanceErrors=pv.getGraphConformanceErrors(pkg); 192 Map logicErrors=pv.getLogicErrors(pkg); 193 String title=ResourceManager.getLanguageDependentString("DialogValidationReport"); 197 ved=new ValidationErrorDisplay(xpdlSchemaValidationErrors,connectionErrors, 198 basicGraphConformanceErrors,graphConformanceErrors,logicErrors, 199 mainFrame,title,true); 200 } 201 202 if (ved==null || !ved.hasBeenStoped()) { 203 packageEditor.setNewPackage(pkg,true); 204 if (!packageEditor.isInitialized() || pkg.get("Id").toString().trim().length()==0) { 205 if (ved!=null && !ved.hasBeenStoped()) { 206 message(ResourceManager.getLanguageDependentString("InformationErrorWhileOpeningFile"), 207 JOptionPane.INFORMATION_MESSAGE); 208 } 209 this.filename=null; 210 packageEditor.update(); 211 packageEditor.enterPackageID(); 212 } else { 213 try { 214 JaWESplash.getSplash().hideSplash(); 215 } catch (Exception ex) {} 216 processConformanceClassAttribute(pkg); 218 } 219 } else { 220 org.enhydra.jawe.actions.New.openNewPackage(); 221 } 222 packageEditor.update(); 223 } else { 224 this.filename=null; 225 packageEditor.setNewPackage(pkg,true); 226 } 227 228 save = packageEditor.getAction("Save"); 229 exit = packageEditor.getAction("Exit"); 230 recentFilesMenu=(JMenu)packageEditor.getMenuItem("RecentFiles"); 234 initRecentFileMenu(); 236 if (this.filename!=null && new File(this.filename).exists()) { 237 addToRecentFiles(this.filename); 238 } 239 240 mainFrame.addWindowListener(createAppCloser()); 241 mainFrame.pack(); 242 Dimension screenSize = 245 GraphicsEnvironment 246 .getLocalGraphicsEnvironment() 247 .getDefaultScreenDevice() 248 .getDefaultConfiguration() 249 .getBounds() 250 .getSize(); 251 252 253 int xMinus=50, yMinus=100; 254 mainFrame.setBounds(xMinus/2, yMinus/2, screenSize.width - xMinus, 255 screenSize.height - yMinus); 256 ToolTipManager.sharedInstance().setEnabled(JaWEConfig.getInstance().getTooltipStatus()); 257 } 258 259 260 public String getFilename () { 261 return filename; 262 } 263 264 265 public void setFilename (String filename) { 266 this.filename=filename; 267 } 268 269 272 protected WindowAdapter createAppCloser() { 273 return new JaWE.AppCloser(); 274 } 275 276 280 private final class AppCloser extends WindowAdapter { 281 public void windowClosing(WindowEvent e) { 282 exit.actionPerformed(null); 283 } 284 } 285 287 288 289 public JMenu getRecentFilesMenu() { 290 return recentFilesMenu; 291 } 292 293 private void initRecentFileMenu () { 294 String rfl = XMLUtil.fileToString( 295 JaWEConstants.JAWE_USER_HOME + JaWEConstants.RFL_FILENAME); 296 if (rfl != null) { 297 for (StringTokenizer st = new StringTokenizer(rfl,"\n"); 298 st.hasMoreTokens();) { 299 addToRecentFiles(st.nextToken()); 300 } 301 } 302 } 303 304 307 public void addToRecentFiles(String filename) { 308 JMenuItem mItem; 309 for (int i = 0; i < recentFilesMenu.getItemCount(); ++i) { 310 mItem=(JMenuItem)recentFilesMenu.getMenuComponent(i); 311 if (filename.equals(mItem.getText().substring(2))) { 312 recentFilesMenu.remove(i); 313 } 314 } 315 if (recentFilesMenu.getItemCount()==recentFileListSize) { 316 recentFilesMenu.remove(recentFileListSize-1); 317 } 318 mItem = new JMenuItem("1 "+filename); 319 mItem.addActionListener(new ActionListener() { 320 public void actionPerformed(ActionEvent e) { 321 String filename = e.getActionCommand().substring(2); 322 if (JaWE.getInstance().close()) { 323 checkNameAndOpenDocumentIfPossible(filename); 324 } 325 } 326 }); 327 recentFilesMenu.insert(mItem,0); 328 for (int i = 0; i < recentFilesMenu.getItemCount(); ++i) { 330 mItem=(JMenuItem)recentFilesMenu.getMenuComponent(i); 331 String oldText=mItem.getText(); 332 String ordNo=String.valueOf(i+1); 333 String mnemonic=ordNo.substring(ordNo.length()-1,ordNo.length()); 334 mItem.setText(mnemonic+" " +oldText.substring(2)); 335 BarFactory.setMnemonic(mItem,mnemonic); 336 } 337 338 } 339 340 344 public boolean close() { 345 int r = JOptionPane.NO_OPTION; 346 if (isModified()) { 347 r=JOptionPane.showConfirmDialog(mainFrame, 348 ResourceManager.getLanguageDependentString("SaveChangesDialog"), 349 appTitle, JOptionPane.YES_NO_CANCEL_OPTION); 350 } 351 if (r == JOptionPane.YES_OPTION) { 352 save.actionPerformed(null); 353 if (isModified()) { 354 r = JOptionPane.CANCEL_OPTION; 355 } 356 } 357 if (r == JOptionPane.CANCEL_OPTION) { 358 return false; 360 } 361 return true; 362 } 363 364 365 368 public PackageEditor getPackageEditor () { 369 return packageEditor; 370 } 371 372 375 public org.enhydra.jawe.xml.elements.Package 376 getRealXMLPackage () { 377 return packageEditor.getRealXMLPackage(); 378 } 379 380 384 public WorkflowProcess showProcess (Window parentWindow, 385 WorkflowProcess wp,String processID) { 386 return packageEditor.showProcess(parentWindow,wp,processID); 387 } 388 389 392 public void setModified (boolean modified) { 393 if (this.modified!=modified) { 394 this.modified=modified; 395 getPackageEditor().update(); 396 } 397 } 398 399 402 public boolean isModified () { 403 return modified; 404 } 405 406 public void checkNameAndOpenDocumentIfPossible (String name) { 407 if (name!=null && new File(name).exists()) { 408 packageEditor.displayPackage(packageEditor.getRealXMLPackage()); 409 org.enhydra.jawe.xml.elements.Package pkg= 410 openDocument(name,true,false); 411 412 boolean validationStatus=JaWEConfig.getInstance().getValidationStatus(); 413 414 PackageValidator pv=new PackageValidator(pkg,false,true,true,true, 415 JaWEConfig.getInstance().getAllowUndefinedStartActivity(), 416 JaWEConfig.getInstance().getAllowUndefinedEndActivity(), 417 JaWEConfig.getInstance().getEncoding()); 418 ValidationErrorDisplay ved=null; 419 if (validationStatus && !pv.validateAll(true)) { 420 Map xpdlSchemaValidationErrors=pv.getXPDLSchemaValidationErrors(); 421 Map connectionErrors=pv.getGraphsConnectionErrors(pkg); 422 java.util.List basicGraphConformanceErrors=pv.getBasicGraphConformanceErrors(pkg); 423 Map graphConformanceErrors=pv.getGraphConformanceErrors(pkg); 424 Map logicErrors=pv.getLogicErrors(pkg); 425 426 String title=ResourceManager.getLanguageDependentString("DialogValidationReport"); 430 ved=new ValidationErrorDisplay(xpdlSchemaValidationErrors,connectionErrors, 431 basicGraphConformanceErrors,graphConformanceErrors,logicErrors, 432 mainFrame,title,true); 433 } 434 435 if (ved==null || !ved.hasBeenStoped()) { 436 packageEditor.setNewPackage(pkg,true); 437 if (!packageEditor.isInitialized() || pkg.get("Id").toString().trim().length()==0) { 438 if (ved!=null && !ved.hasBeenStoped()) { 439 message(ResourceManager.getLanguageDependentString("InformationErrorWhileOpeningFile"), 440 JOptionPane.INFORMATION_MESSAGE); 441 } 442 this.filename=null; 443 packageEditor.update(); 444 packageEditor.enterPackageID(); 445 } else { 446 addToRecentFiles(this.filename); 447 processConformanceClassAttribute(pkg); 449 } 450 } else { 451 org.enhydra.jawe.actions.New.openNewPackage(); 452 } 453 packageEditor.update(); 454 } else { 455 message(ResourceManager.getLanguageDependentString("InformationErrorWhileOpeningFile"), 456 JOptionPane.INFORMATION_MESSAGE); 457 } 458 } 459 460 public void openPackageFromStream (String name,String pkgCnt) { 461 if (name!=null && pkgCnt!=null) { 462 this.filename = name; 463 464 packageEditor.displayPackage(packageEditor.getRealXMLPackage()); 465 xmlInterface.closeAllPackages(); 466 467 xmlInterface.putPkgIdToFileContentMapping(name,pkgCnt); 468 469 org.enhydra.jawe.xml.elements.Package pkg=null; 470 471 472 pkg=xmlInterface.openPackage(name,true); 473 System.out.println("pkg="+pkg); 474 if (pkg==null) { 475 pkg=new org.enhydra.jawe.xml.elements.Package(xmlInterface); 476 } 477 478 boolean validationStatus=JaWEConfig.getInstance().getValidationStatus(); 479 480 PackageValidator pv=new PackageValidator(pkg,false,true,true,false, 481 JaWEConfig.getInstance().getAllowUndefinedStartActivity(), 482 JaWEConfig.getInstance().getAllowUndefinedEndActivity(), 483 JaWEConfig.getInstance().getEncoding()); 484 ValidationErrorDisplay ved=null; 485 if (validationStatus && !pv.validateAll(true)) { 486 Map xpdlSchemaValidationErrors=pv.getXPDLSchemaValidationErrors(); 487 Map connectionErrors=pv.getGraphsConnectionErrors(pkg); 488 java.util.List basicGraphConformanceErrors=pv.getBasicGraphConformanceErrors(pkg); 489 Map graphConformanceErrors=pv.getGraphConformanceErrors(pkg); 490 Map logicErrors=pv.getLogicErrors(pkg); 491 492 String title=ResourceManager.getLanguageDependentString("DialogValidationReport"); 496 ved=new ValidationErrorDisplay(xpdlSchemaValidationErrors,connectionErrors, 497 basicGraphConformanceErrors,graphConformanceErrors,logicErrors, 498 mainFrame,title,true); 499 } 500 501 if (ved==null || !ved.hasBeenStoped()) { 502 packageEditor.setNewPackage(pkg,false); 503 if (!packageEditor.isInitialized() || pkg.get("Id").toString().trim().length()==0) { 504 if (ved!=null && !ved.hasBeenStoped()) { 505 message(ResourceManager.getLanguageDependentString("InformationErrorWhileOpeningFile"), 506 JOptionPane.INFORMATION_MESSAGE); 507 } 508 this.filename=null; 509 packageEditor.update(); 510 packageEditor.enterPackageID(); 511 } else { 512 filename=null; 513 processConformanceClassAttribute(pkg); 515 } 516 } else { 517 org.enhydra.jawe.actions.New.openNewPackage(); 518 } 519 packageEditor.update(); 520 } else { 521 message(ResourceManager.getLanguageDependentString("InformationErrorWhileOpeningFile"), 522 JOptionPane.INFORMATION_MESSAGE); 523 } 524 } 525 526 530 public org.enhydra.jawe.xml.elements.Package openDocument ( 531 String filename,boolean clearOtherPackages,boolean openFromStream) { 532 this.filename = filename; 533 org.enhydra.jawe.xml.elements.Package pkg=null; 534 if (clearOtherPackages) { 535 xmlInterface.closeAllPackages(); 536 } 537 if (filename!=null) { 538 pkg=xmlInterface.openPackage(filename,openFromStream); 539 } 540 if (pkg==null) { 541 pkg=new org.enhydra.jawe.xml.elements.Package(xmlInterface); 542 } 543 544 return pkg; 545 } 546 547 549 public String openDialog(String message) { 550 return XMLUtil.dialog(mainFrame,message,0,0,null); 551 } 552 553 554 public String saveDialog(String message,int filteringMode,String initialName) { 555 return XMLUtil.dialog(mainFrame,message,1,filteringMode,initialName); 556 } 557 558 559 public void message(String message,int type) { 560 JOptionPane.showMessageDialog(mainFrame,message,JaWE.getAppTitle(),type); 561 } 562 563 public void setRecentFilesMenu (JMenu rfm) { 564 recentFilesMenu=rfm; 565 } 566 567 568 public JFrame getMainFrame() { 569 return mainFrame; 570 } 571 575 public void xmlElementChanged (XMLElement el) { 576 if (!(((el instanceof XMLCollection) && 577 !(el instanceof ExternalPackages) && !el.getClass().getName().startsWith( 578 "org.enhydra.jawe.xml.elements.Activity$")) || (el instanceof Responsible) || 579 (el instanceof ExtendedAttribute) || (el instanceof DataTypes) || 580 (el instanceof EnumerationValue) || (el instanceof Tool) || 581 (el instanceof ActualParameter) || (el instanceof ExternalProcesses) || 582 (el instanceof ExternalParticipants) || (el instanceof Deadline) || 583 el.getClass().getName().startsWith( 584 "org.enhydra.jawe.xml.panels.XMLListChoiceControlPanel$"))) { 585 setModified(true); 586 } 587 588 if (!JaWEConfig.getInstance().getStatusBarStatus()) return; 589 if (el instanceof org.enhydra.jawe.xml.elements.Activity || 591 el instanceof org.enhydra.jawe.xml.elements.Transition) { 592 packageEditor.getStatusBar().updateMessage(); 593 XMLCollectionElement actOrTrans=(XMLCollectionElement)el; 594 org.enhydra.jawe.graph.Process pr=null; 595 if (actOrTrans.getCollection().getOwner() instanceof WorkflowProcess) { 596 pr=packageEditor. 597 getProcessObject((WorkflowProcess)actOrTrans.getCollection().getOwner()); 598 pr.getImplementationEditor().getStatusBar().updateMessage(); 599 } else { 600 ActivitySet actSet=(ActivitySet)actOrTrans.getCollection().getOwner(); 601 pr=packageEditor. 602 getProcessObject((WorkflowProcess)actSet.getCollection().getOwner()); 603 604 Set baObjects=pr.getImplementationEditor().getGraph().getWorkflowManager().getBlockActivities(true); 605 Iterator baObjs =baObjects.iterator(); 608 while(baObjs.hasNext()) { 609 org.enhydra.jawe.graph.BlockActivity ba= 610 (org.enhydra.jawe.graph.BlockActivity)baObjs.next(); 611 AbstractEditor bae=ba.getImplementationEditor(); 612 if (bae!=null) { 613 Object xpdlObj=bae.getGraph().getXPDLObject(); 614 if (xpdlObj.equals(actSet)) { 615 bae.getStatusBar().updateMessage(); 616 } 617 } 618 } 619 620 } 621 } 622 if (el instanceof org.enhydra.jawe.xml.elements.Package) { 623 packageEditor.getStatusBar().updateMessage(); 624 } 625 } 626 627 631 private void processConformanceClassAttribute ( 632 org.enhydra.jawe.xml.elements.Package pkg) { 633 ConformanceClass cc=(ConformanceClass)pkg.get("ConformanceClass"); 634 String gct=cc.get("GraphConformance").toValue().toString(); 635 int mct=XMLUtil.getConformanceClassNo(mandatoryConformanceClass); 636 int ct=XMLUtil.getConformanceClassNo(gct); 637 if (mct>0) { 638 if (mct!=ct) { 639 message(ResourceManager.getLanguageDependentString( 640 "WarningYouHaveOpenedPackageWithConformanceClassDiferentThenMandatoryOne"), 641 JOptionPane.WARNING_MESSAGE); 642 } else { 643 cc.setReadOnly(true); 644 } 645 } 646 } 647 648 public String getMandatoryConformanceClass () { 649 return mandatoryConformanceClass; 650 } 651 652 653 public static void main(String [] args) { 654 JaWE.jawe=new JaWE(); 655 656 JaWESplash splash = new JaWESplash("SplashImage", null, 9000); 657 String fn=null; 659 String sl=null; 661 String mcc=null; 663 664 if (args!=null && args.length>0) { 668 for (int i = 0; i < args.length; ++i) { 669 if(args[i].compareTo("-mcc")==0) { 670 if (++i == args.length) { 671 System.err.println("error: Missing argument to -mcc option."); 672 continue; 673 } 674 mcc = args[i]; 675 String oldMCC=JaWEConfig.getInstance().getMandatoryConformanceClass(); 676 JaWEConfig.getInstance().setMandatoryConformanceClass(mcc); 677 jawe.mandatoryConformanceClass=JaWEConfig.getInstance().getMandatoryConformanceClass(); 678 JaWEConfig.getInstance().setMandatoryConformanceClass(oldMCC); 679 } 680 if(args[i].compareTo("-sl")==0) { 681 if (++i == args.length) { 682 System.err.println("error: Missing argument to -sl option."); 683 continue; 684 } 685 sl = args[i]; 686 try { 687 PFLocale pfl=PFLocale.createPFLocale(sl); 688 if (pfl==null) { 689 pfl=new PFLocale(Locale.getDefault()); 690 } 691 ResourceManager.setChoosen(pfl.getLocale()); 692 } catch (Exception ex) { 693 System.err.println("warning: Can't start with locale "+sl); 694 } 695 } 696 } 697 if (args.length/2!=(args.length/2.0)) { 699 fn=args[args.length-1]; 700 } 701 } 702 JaWE.jawe.init(fn); 706 splash.dispose(); 707 splash=null; 708 jawe.getPackageEditor().showWindow(null,jawe.getPackageEditor().getTitle()); 709 } 710 711 712 } 713 714 | Popular Tags |