jawecontroller.java

来自「jawe的最新版本,基于Java的图形化工作流编辑器。图形化工作流编辑器 。使用」· Java 代码 · 共 1,644 行 · 第 1/5 页

JAVA
1,644
字号
               Set allOtherEPIds = new HashSet(otherEPIds);               List l = XMLUtil.getAllExternalPackageIds(xpdlhmain,                                                         mainPkg,                                                         new HashSet());               List ids = new ArrayList(xpdlhmain.getAllPackageIds());               ids.removeAll(l);               allOtherEPIds.addAll(ids);               Iterator it = otherEPIds.iterator();               while (it.hasNext()) {                  String pkgId = (String) it.next();                  Package p = xpdlhmain.getPackageById(pkgId);                  allOtherEPIds.addAll(XMLUtil.getAllExternalPackageIds(xpdlhmain,                                                                        p,                                                                        new HashSet()));               }               pkgIdsToInsert.removeAll(allOtherEPIds);               Set pkgsToInsert = new HashSet();               it = pkgIdsToInsert.iterator();               while (it.hasNext()) {                  String pkgId = (String) it.next();                  Package tAdd = xpdlh.getPackageById(pkgId);                  pkgsToInsert.add(tAdd);               }               xpdlhmain.synchronizePackages(xpdlh);               Package realPkg = xpdlhmain.getPackageById(pkg.getId());               ExternalPackage ep = null;               // insert ExternalPackage               ExternalPackages eps = mainPkg.getExternalPackages();               File f = new File(xpdlhmain.getAbsoluteFilePath(mainPkg));               String parentF = f.getParent();               Path newPath = new Path(parentF);               String eppath = xpdlhmain.getAbsoluteFilePath(realPkg);               String relativePath = Path.getRelativePath(new Path(eppath), newPath);               ep = JaWEManager.getInstance()                  .getXPDLObjectFactory()                  .createXPDLObject(eps, "", false);               ep.setHref(relativePath);               JaWEEAHandler.setExternalPackageEA(ep, realPkg.getId());               mainPkg.addExternalPackageMapping(relativePath, realPkg.getId());               eps.add(ep);               // List inserted=new ArrayList();               // inserted.add(ep);               // setChanged();               // notifyObservers(createInfo(eps,inserted,               // XPDLElementChangeInfo.INSERTED));               it = pkgsToInsert.iterator();               while (it.hasNext()) {                  Package p = (Package) it.next();                  boolean changed = adjustXPDL(p);                  XPDLListenerAndObservable xpdl;                  xpdl = createNewXPDLListenerObservable(p, false, false);                  p.setReadOnly(true);                  xpdl.setModified(changed);               }               setChanged();               notifyObservers(createInfo(mainPkg,                                          new ArrayList(pkgsToInsert),                                          XMLElementChangeInfo.INSERTED));               if (ep != null) {                  getSelectionManager().setSelection(ep, true);               }               // if (settings.isDesingTimeValidationEnabled()) {               // it = pkgsToInsert.iterator();               // while (it.hasNext()) {               // Package p = (Package) it.next();               // JaWEManager.getInstance()               // .getXPDLValidator()               // .reCheckExternalPackage(p);               // }               //               // checkValidity(mainPkg, true, true);               // }            } else {               getJaWEFrame().message(settings.getLanguageDependentString("InformationExternalPackageCannotBeInserted"),                                      JOptionPane.INFORMATION_MESSAGE);               xpdlh.closeAllPackages();            }         } catch (Exception ex) {            ex.printStackTrace();            getJaWEFrame().message(settings.getLanguageDependentString("InformationExternalPackageCannotBeInserted"),                                   JOptionPane.INFORMATION_MESSAGE);            if (xpdlh != null) {               xpdlh.closeAllPackages();            }         }      }      // xpdlhmain.printDebug();   }   public void removeExternalPackage() {      Package mainPkg = getMainPackage();      XPDLHandler xpdlh = JaWEManager.getInstance().getXPDLHandler();      Package toRemove = (Package) getSelectionManager().getSelectedElement();      Set pkgIdsToRemove = new HashSet();      pkgIdsToRemove.add(toRemove.getId());      pkgIdsToRemove.addAll(XMLUtil.getAllExternalPackageIds(xpdlh,                                                             toRemove,                                                             new HashSet()));      Set otherEPIds = new HashSet(mainPkg.getExternalPackageIds());      otherEPIds.remove(toRemove.getId());      Set allOtherEPIds = new HashSet(otherEPIds);      Iterator it = otherEPIds.iterator();      while (it.hasNext()) {         String pkgId = (String) it.next();         Package p = xpdlh.getPackageById(pkgId);         allOtherEPIds.addAll(XMLUtil.getAllExternalPackageIds(xpdlh, p, new HashSet()));      }      pkgIdsToRemove.removeAll(allOtherEPIds);      Set pkgsToRemove = new HashSet();      it = pkgIdsToRemove.iterator();      while (it.hasNext()) {         String pkgId = (String) it.next();         Package tRem = xpdlh.getPackageById(pkgId);         if (tRem != mainPkg && !tRem.isTransient()) {            pkgsToRemove.add(tRem);         }      }      ExternalPackages eps = mainPkg.getExternalPackages();      ExternalPackage ep = mainPkg.getExternalPackage(toRemove.getId());      if (pkgsToRemove.size() > 0) {         boolean warningMessage = false;         it = pkgsToRemove.iterator();         while (it.hasNext()) {            Package tRem = (Package) it.next();            List refs = JaWEManager.getInstance().getXPDLUtils().getReferences(mainPkg,                                                                               tRem);            if (refs.size() > 0) {               warningMessage = true;               break;            }         }         if (warningMessage) {            int yn = JOptionPane.showConfirmDialog(getJaWEFrame(),                                                   settings.getLanguageDependentString("MessageReferencedDoYouReallyWantToDeleteSelectedItem"),                                                   settings.getLanguageDependentString("DeletingKey"),                                                   JOptionPane.YES_NO_OPTION);            if (yn != JOptionPane.YES_OPTION) {               return;            }         }      }      try {         if (ep != null) {            mainPkg.removeExternalPackageMapping(ep.getHref());         }         if (pkgsToRemove.size() > 0) {            it = pkgsToRemove.iterator();            while (it.hasNext()) {               Package pkg = (Package) it.next();               XPDLListenerAndObservable xpdllo = getXPDLListenerObservable(pkg);               xpdllo.unregisterFromXPDL();               xpdlListenerObservables.remove(xpdllo);               xpdlh.closePackageVersion(pkg.getId(), pkg.getInternalVersion());            }            setChanged();            notifyObservers(createInfo(mainPkg,                                       new ArrayList(pkgsToRemove),                                       XMLElementChangeInfo.REMOVED));         }         if (ep != null) {            eps.remove(ep);            List remove = new ArrayList();            remove.add(ep);            setChanged();            notifyObservers(createInfo(eps, remove, XMLElementChangeInfo.REMOVED));         }         getSelectionManager().setSelection(eps, true);         if (pkgsToRemove.size() > 0) {            if (settings.isDesingTimeValidationEnabled()) {               it = pkgsToRemove.iterator();               while (it.hasNext()) {                  Package pkg = (Package) it.next();                  JaWEManager.getInstance().getXPDLValidator().clearCache(pkg);               }               checkValidity(mainPkg, true, true, true);            }         }      } catch (Exception ex) {         ex.printStackTrace();         getJaWEFrame().message(settings.getLanguageDependentString("ErrorCannotRemoveExternalPackage"),                                JOptionPane.INFORMATION_MESSAGE);      }      // xpdlh.printDebug();   }   public void addTransientPackage() {      getSelectionManager().setSelection((XMLElement) null, true);      String filename = "";      String message = settings.getLanguageDependentString("DialogChooseFile");      filename = JaWEXMLUtil.dialog(getJaWEFrame(), message, 0, 0, null);      if (filename != null && filename.length() > 0) {         boolean added = addTransientPackage(filename);         if (!added) {            getJaWEFrame().message(settings.getLanguageDependentString("InformationTransientPackageCannotBeInserted"),                                   JOptionPane.INFORMATION_MESSAGE);         }      }   }   public boolean addTransientPackage(String filename) {      XPDLHandler xpdlhmain = JaWEManager.getInstance().getXPDLHandler();      XPDLHandler xpdlh = null;      if (filename != null && filename.length() > 0) {         try {            xpdlh = JaWEManager.getInstance()               .createXPDLHandler(xpdlhmain.getXPDLRepositoryHandler());            Package pkg = xpdlh.openPackage(filename, false);            // do not allow insertion if package has the same Id as the main one,            // or as some of its external packages            Set allpkgids = new HashSet(xpdlhmain.getAllPackageIds());            boolean canInsert = true;            if (allpkgids.contains(pkg.getId())) {               canInsert = false;            }            // System.err.println("CI1="+canInsert);            if (canInsert) {               Package mainPkg = getMainPackage();               if (mainPkg != null) {                  canInsert = checkInsertion(xpdlhmain, xpdlh, mainPkg.getId());               }            }            // System.err.println("CI2="+canInsert);            if (canInsert) {               xpdlhmain.synchronizePackages(xpdlh);               Package realPkg = xpdlhmain.getPackageById(pkg.getId());               adjustXPDL(realPkg);               XPDLListenerAndObservable xpdl = createNewXPDLListenerObservable(realPkg,                                                                                false,                                                                                false);               realPkg.setReadOnly(true);               xpdl.setModified(false);               List pkgsToInsert = new ArrayList();               pkgsToInsert.add(realPkg);               setChanged();               notifyObservers(createInfo(realPkg,                                          new ArrayList(pkgsToInsert),                                          XMLElementChangeInfo.INSERTED));               return true;            }            xpdlh.closeAllPackages();            return false;         } catch (Exception ex) {            ex.printStackTrace();            if (xpdlh != null) {               xpdlh.closeAllPackages();            }         }      }      return false;   }   public void removeTransientPackage() {      XPDLHandler xpdlh = JaWEManager.getInstance().getXPDLHandler();      Package toRemove = XMLUtil.getPackage(getSelectionManager().getSelectedElement());      try {         XPDLListenerAndObservable xpdllo = getXPDLListenerObservable(toRemove);         xpdllo.unregisterFromXPDL();         xpdlListenerObservables.remove(xpdllo);         xpdlh.closePackageVersion(toRemove.getId(), toRemove.getInternalVersion());         setChanged();         List pkgsToRemove = new ArrayList();         pkgsToRemove.add(toRemove);         notifyObservers(createInfo(toRemove, pkgsToRemove, XMLElementChangeInfo.REMOVED));         getSelectionManager().setSelection(getMainPackage(), true);      } catch (Exception ex) {         ex.printStackTrace();         getJaWEFrame().message(settings.getLanguageDependentString("ErrorCannotRemoveTransientPackage"),                                JOptionPane.INFORMATION_MESSAGE);      }      // xpdlh.printDebug();   }   protected boolean checkInsertion(XPDLHandler xpdlhmain,                                    XPDLHandler xpdlh,                                    String mainPkgId) {      boolean canInsert = true;      Collection allPackages = xpdlh.getAllPackages();      Iterator it = allPackages.iterator();      while (it.hasNext()) {         // do not allow insertion if package has the same path as the one of the main         // package or some of the packages that are already referenced         Package pkg = (Package) it.next();         // System.err.println("Checking pkg "+pkg.getId()+" agains mp "+mainPkgId);         if (pkg.getId().equals(mainPkgId)) {            canInsert = false;            // System.err.println("CI11="+canInsert);            break;         }         String filename = xpdlh.getAbsoluteFilePath(pkg);         Package pkgbfn = xpdlhmain.getPackageByFilename(filename);         // System.err.println("Checking filename "+filename+": found pkg "+pkgbfn);         if (pkgbfn != null && !pkgbfn.getId().equals(pkg.getId())) {            canInsert = false;            // System.err.println("CI12="+canInsert);            break;         }      }      return canInsert;   }   public void closePackage(String xpdlId, boolean closeTransient) {      clearAll();      XPDLHandler xpdlhandler = JaWEManager.getInstance().getXPDLHandler();      Package mainPackage = getMainPackage();      if (xpdlId == null && mainPackage != null) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?