Package org.enhydra.shark.xpdl.elements

Examples of org.enhydra.shark.xpdl.elements.Package


        }
        //END CUSTOM
    }

    public void addExternalPackage(String filename) {
        Package mainPkg = getMainPackage();
        XPDLHandler xpdlhmain = JaWEManager.getInstance().getXPDLHandler();
        XPDLHandler xpdlh = null;
        if (filename != null && filename.length() > 0) {
            try {
                xpdlh = new XPDLHandler(new DefaultXPDLHandlerSettings());
                Package pkg = xpdlh.openPackage(filename, true);
                // do not allow insertion if package has the same Id as the main one,
                // or as some of its external packages
                Set mainPkgExtPkgIds = new HashSet(mainPkg.getExternalPackageIds());
                boolean canInsert = true;
                if (mainPkgExtPkgIds.contains(pkg.getId())) {
                    canInsert = false;
                }
                if (canInsert) {
                    canInsert = checkInsertion(xpdlhmain, xpdlh, mainPkg.getId());
                }
                if (canInsert) {
                    List l = XMLUtil.getAllExternalPackageIds(xpdlhmain,
                            mainPkg,
                            new HashSet());
                    if (!l.contains(pkg.getId()) && xpdlhmain.getPackageById(pkg.getId()) != null) {
                        canInsert = false;
                    }
                }
                if (canInsert) {
                    Set pkgIdsToInsert = new HashSet(xpdlh.getAllPackageIds());
                    Set otherEPIds = new HashSet(mainPkg.getExternalPackageIds());
                    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);

                    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,
View Full Code Here


            }
        }
    }

    public void addExternalPackage() {
        Package mainPkg = getMainPackage();
        XPDLHandler xpdlhmain = JaWEManager.getInstance().getXPDLHandler();
        getSelectionManager().setSelection(mainPkg.getExternalPackages(), false);

        String filename = "";
        String message = settings.getLanguageDependentString("DialogChooseFile");
        filename = JaWEXMLUtil.dialog(getJaWEFrame(), message, 0, 0, null);
        XPDLHandler xpdlh = null;
        if (filename != null && filename.length() > 0) {
            try {
                xpdlh = JaWEManager.getInstance().createXPDLHandler(xpdlhmain.getXPDLRepositoryHandler());
                Package pkg = xpdlh.openPackage(filename, true);
                // do not allow insertion if package has the same Id as the main one,
                // or as some of its external packages
                Set mainPkgExtPkgIds = new HashSet(mainPkg.getExternalPackageIds());
                boolean canInsert = true;
                if (mainPkgExtPkgIds.contains(pkg.getId())) {
                    canInsert = false;
                }
                if (canInsert) {
                    canInsert = checkInsertion(xpdlhmain, xpdlh, mainPkg.getId());
                }
                if (canInsert) {
                    List l = XMLUtil.getAllExternalPackageIds(xpdlhmain,
                            mainPkg,
                            new HashSet());
                    if (!l.contains(pkg.getId()) && xpdlhmain.getPackageById(pkg.getId()) != null) {
                        canInsert = false;
                    }
                }
                if (canInsert) {
                    Set pkgIdsToInsert = new HashSet(xpdlh.getAllPackageIds());
                    Set otherEPIds = new HashSet(mainPkg.getExternalPackageIds());
                    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);

                    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,
View Full Code Here

            }
        }
    }

    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);
                }
            }
View Full Code Here

        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;
                }
                if (canInsert) {
                    Package mainPkg = getMainPackage();
                    if (mainPkg != null) {
                        canInsert = checkInsertion(xpdlhmain, xpdlh, mainPkg.getId());
                    }
                }
                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();
View Full Code Here

        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);
View Full Code Here

        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();
            if (pkg.getId().equals(mainPkgId)) {
                canInsert = false;
                break;
            }

            String filename = xpdlh.getAbsoluteFilePath(pkg);
            Package pkgbfn = xpdlhmain.getPackageByFilename(filename);
            if (pkgbfn != null && !pkgbfn.getId().equals(pkg.getId())) {
                canInsert = false;
                break;
            }
        }
        return canInsert;
View Full Code Here

    }

    public void closePackage(String xpdlId, boolean closeTransient) {
        clearAll();
        XPDLHandler xpdlhandler = JaWEManager.getInstance().getXPDLHandler();
        Package mainPackage = getMainPackage();
        if (xpdlId == null && mainPackage != null) {
            xpdlId = mainPackage.getId();
        }
        JaWEManager.getInstance().getLoggingManager().info("JaWEController -> closing package " + xpdlId);
        if (mainPackage != null && mainPackage.getId().equals(xpdlId)) {
            String filePath = JaWEManager.getInstance().getXPDLHandler().getAbsoluteFilePath(mainPackage);
            List allPackages = new ArrayList(xpdlhandler.getAllPackages());
            List notToClose = new ArrayList();
            for (int i = 0; i < allPackages.size(); i++) {
                Package pkg = (Package) allPackages.get(i);
                if (!pkg.isTransient() || closeTransient) {
                    xpdlhandler.closePackageVersion(pkg.getId(), pkg.getInternalVersion());
                } else {
                    notToClose.add(pkg);
                }
            }
            allPackages.removeAll(notToClose);
View Full Code Here

        return false;
    }

    public void savePackage(String xpdlId, String filename) {
        XPDLHandler xpdlhandler = JaWEManager.getInstance().getXPDLHandler();
        Package pkg = xpdlhandler.getPackageById(xpdlId);
        String oldFilename = xpdlhandler.getAbsoluteFilePath(pkg);
        try {

            // if SaveAs was performed and the document was previously saved,
            // change ExternalPackage's relative paths
View Full Code Here

        Iterator eps = pkg.getExternalPackages().toElements().iterator();
        while (eps.hasNext()) {
            ExternalPackage ep = (ExternalPackage) eps.next();
            String oldRelativePath = ep.getHref();
            try {
                Package extP = xpdlhandler.getExternalPackageByRelativeFilePath(oldRelativePath,
                        pkg);
                String oldFullPath = xpdlhandler.getAbsoluteFilePath(extP);
                String relativePath = Path.getRelativePath(new Path(oldFullPath), newPath);
                ep.setHref(XMLUtil.replaceBackslashesWithSlashes(relativePath));
            } catch (Exception ex) {
View Full Code Here

        if (col instanceof TransitionRestrictions || col instanceof TransitionRefs) {
            return false;
        } else if (col instanceof ExternalPackages) {
            if (el != null) {
                String href = ((ExternalPackage) el).getHref();
                Package pkg = XMLUtil.getPackage(col);
                String epId = pkg.getExternalPackageId(href);
                if (epId != null) {
                    return false;
                }
            }
        } else if (col instanceof ExtendedAttributes && col.getParent() instanceof ExternalPackage) {
View Full Code Here

TOP

Related Classes of org.enhydra.shark.xpdl.elements.Package

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.