Search in sources :

Example 36 with WorkflowPackage

use of com.centurylink.mdw.plugin.designer.model.WorkflowPackage in project mdw-designer by CenturyLinkCloud.

the class ProcessExplorerDropTarget method handleDropWorkflowAsset.

private boolean handleDropWorkflowAsset(String assetInfo, WorkflowPackage targetPackage, int operation) {
    if (!targetPackage.getProject().checkRequiredVersion(5, 0)) {
        String msg = "Packaging of Definition Documents (such as scripts and pages) is only supported for MDWFramework 5.0 and later.";
        MessageDialog.openError(getViewer().getControl().getShell(), "Package Def Doc", msg);
        return false;
    }
    Long assetId = getWorkflowAssetId(assetInfo);
    WorkflowProject workflowProject = targetPackage.getProject();
    WorkflowPackage sourcePackage = workflowProject.getPackage(getPackageName(assetInfo));
    DesignerProxy designerProxy = workflowProject.getDesignerProxy();
    if (operation == DND.DROP_COPY) {
        WorkflowAsset existing = workflowProject.getAsset(assetId);
        CopyDialog copyDialog = new CopyDialog(getViewer().getControl().getShell(), existing, existing.getName(), String.valueOf(existing.getVersion()), targetPackage);
        if (copyDialog.open() == Dialog.OK) {
            String newName = copyDialog.getNewName();
            if (!existing.isLoaded())
                existing.load();
            WorkflowAsset newCopy;
            try {
                // try and use reflection to make it the correct type
                Constructor<? extends WorkflowAsset> ctor = existing.getClass().getConstructor(existing.getClass());
                newCopy = ctor.newInstance(existing);
            } catch (Exception ex) {
                PluginMessages.log(ex);
                newCopy = new WorkflowAsset(existing);
            }
            newCopy.setName(newName);
            newCopy.setVersion(1);
            newCopy.setPackage(targetPackage);
            try {
                designerProxy.createNewWorkflowAsset(newCopy, true);
            } catch (Exception ex) {
                PluginMessages.uiError(ex, "Copy " + existing.getTitle(), existing.getProject());
            }
            newCopy.addElementChangeListener(workflowProject);
            newCopy.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, newCopy);
            WorkflowAssetFactory.registerAsset(newCopy);
            ((TreeViewer) getViewer()).refresh(targetPackage, true);
            return true;
        }
        return false;
    } else if (operation == DND.DROP_MOVE) {
        // don't allow multiple versions of the same asset in a package
        if (!targetPackage.isDefaultPackage()) {
            WorkflowAsset asset = workflowProject.getAsset(assetId);
            if (targetPackage.getAsset(asset.getName()) != null) {
                MessageDialog.openError(MdwPlugin.getShell(), "Asset Exists", "Asset '" + asset.getName() + "' already exists in package '" + targetPackage.getName() + "'.");
                return false;
            }
        }
        if (targetPackage.isDefaultPackage()) {
            designerProxy.removeWorkflowAssetFromPackage(assetId, sourcePackage);
        } else {
            assetId = designerProxy.moveWorkflowAssetToPackage(assetId, targetPackage);
        }
        ((TreeViewer) getViewer()).refresh(targetPackage.getProject(), true);
        WorkflowAssetFactory.registerAsset(workflowProject.getAsset(assetId));
        return true;
    } else {
        return false;
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) CopyDialog(com.centurylink.mdw.plugin.designer.dialogs.CopyDialog) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) SWTException(org.eclipse.swt.SWTException)

Example 37 with WorkflowPackage

use of com.centurylink.mdw.plugin.designer.model.WorkflowPackage in project mdw-designer by CenturyLinkCloud.

the class ParameterizedCombo method fillParamCombo.

private void fillParamCombo(String[] types) {
    paramCombo.removeAll();
    Comparator<WorkflowElement> comparator = new Comparator<WorkflowElement>() {

        public int compare(WorkflowElement we1, WorkflowElement we2) {
            return we1.getName().compareTo(we2.getName());
        }
    };
    List<WorkflowAsset> assets = workflowProject.getAssetList(Arrays.asList(types));
    Map<WorkflowPackage, List<WorkflowAsset>> packageAssets = new TreeMap<>();
    for (WorkflowAsset asset : assets) {
        List<WorkflowAsset> assetsForPkg = packageAssets.get(asset.getPackage());
        if (assetsForPkg == null) {
            assetsForPkg = new ArrayList<>();
            packageAssets.put(asset.getPackage(), assetsForPkg);
        }
        assetsForPkg.add(asset);
    }
    for (WorkflowPackage pkg : packageAssets.keySet()) {
        CTreeComboItem packageItem = new CTreeComboItem(paramCombo, SWT.NONE);
        packageItem.setText(pkg.getName());
        packageItem.setImage(pkg.getIconImage());
        List<WorkflowAsset> assetsForPkg = packageAssets.get(pkg);
        Collections.sort(assetsForPkg, comparator);
        for (WorkflowAsset assetForPkg : assetsForPkg) {
            CTreeComboItem assetItem = new CTreeComboItem(packageItem, SWT.NONE);
            assetItem.setText(assetForPkg.getName());
            assetItem.setImage(assetForPkg.getIconImage());
        }
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) CTreeComboItem(com.centurylink.swt.widgets.CTreeComboItem) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement) Comparator(java.util.Comparator)

Example 38 with WorkflowPackage

use of com.centurylink.mdw.plugin.designer.model.WorkflowPackage in project mdw-designer by CenturyLinkCloud.

the class ParameterizedCombo method assetFromAttr.

public WorkflowAsset assetFromAttr(String attrValue) {
    if (attrValue == null || attrValue.isEmpty() || attrValue.startsWith("$")) {
        return null;
    }
    int slashIdx = attrValue.indexOf('/');
    if (slashIdx <= 0) {
        // prefer asset in same package
        WorkflowAsset pkgDoc = workflowElement.getPackage().getAsset(attrValue);
        if (pkgDoc != null)
            return pkgDoc;
        else
            return workflowProject.getAsset(attrValue);
    } else {
        String pkgName = attrValue.substring(0, slashIdx);
        WorkflowPackage pkg = workflowProject.getPackage(pkgName);
        if (pkg == null)
            return null;
        else
            return pkg.getAsset(attrValue.substring(slashIdx + 1));
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset)

Example 39 with WorkflowPackage

use of com.centurylink.mdw.plugin.designer.model.WorkflowPackage in project mdw-designer by CenturyLinkCloud.

the class ParameterizedCombo method createParamCombo.

private void createParamCombo() {
    paramCombo = new CTreeCombo(this, SWT.BORDER | SWT.FULL_SELECTION);
    GridData gd = new GridData(GridData.BEGINNING);
    gd.widthHint = 200;
    gd.heightHint = 16;
    paramCombo.setLayoutData(gd);
    paramCombo.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            CTreeComboItem[] selItems = paramCombo.getSelection();
            if (selItems.length == 1) {
                CTreeComboItem selItem = selItems[0];
                if (selItem.getItemCount() != 0) {
                    // ignore package selection
                    paramCombo.setSelection(new CTreeComboItem[0]);
                } else {
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException ex) {
                    }
                    // set the definition doc
                    WorkflowPackage pkg = workflowProject.getPackage(selItem.getParentItem().getText());
                    if (pkg == null) {
                        paramAsset = null;
                    } else {
                        paramAsset = pkg.getAsset(selItem.getText());
                    }
                    paramLink.setText(getParamLinkLabel());
                    fireModify(new ModifyEvent(event));
                    paramCombo.dropDown(false);
                }
            }
        }
    });
    paramCombo.addListener(SWT.Modify, new Listener() {

        public void handleEvent(Event event) {
            if (paramCombo.getSelection().length == 0) {
                // something was typed in the combo instead of selected
                paramAsset = assetFromAttr(paramCombo.getText().trim());
                paramLink.setText(getParamLinkLabel());
                String oldVal = workflowElement.getAttribute(paramLabel.getText());
                String newVal;
                if (paramCombo.getText().startsWith("$"))
                    newVal = paramCombo.getText().trim();
                else
                    newVal = paramAsset == null ? paramCombo.getText() : attrFromAsset(paramAsset, false);
                boolean changed = oldVal == null ? newVal != null && newVal.length() > 0 : !oldVal.equals(newVal);
                if (changed && !suppressFire)
                    fireModify(new ModifyEvent(event));
            }
        }
    });
    paramLink = new Link(this, SWT.SINGLE);
    gd = new GridData(GridData.BEGINNING);
    gd.widthHint = 75;
    paramLink.setLayoutData(gd);
    paramLink.setText(getParamLinkLabel());
    paramLink.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (paramAsset == null) {
                String[] paramTypes = valueConverter.getOptionParam(getValue()).getTypes();
                paramAsset = createParamAsset(paramTypes);
                fillParamCombo(paramTypes);
                if (paramAsset != null) {
                    paramCombo.setText(paramAsset.getName());
                    fireModify(new ModifyEvent(new Event()));
                }
            } else {
                openParamAsset();
            }
        }
    });
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) CTreeComboItem(com.centurylink.swt.widgets.CTreeComboItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CTreeCombo(com.centurylink.swt.widgets.CTreeCombo) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Link(org.eclipse.swt.widgets.Link)

Example 40 with WorkflowPackage

use of com.centurylink.mdw.plugin.designer.model.WorkflowPackage in project mdw-designer by CenturyLinkCloud.

the class WorkflowProject method findArchivedPackages.

/**
 * Returns all top-level archived (non-latest) packages, populated with
 * their descendants which include the appropriate process versions. Uses
 * 10% of progressMonitor.
 */
private Folder findArchivedPackages(ProgressMonitor progressMonitor, boolean visiblePkgsOnly) {
    CodeTimer timer = new CodeTimer("findAuthorizedArchivedPackages()");
    if (progressMonitor != null)
        progressMonitor.subTask("Organizing packages");
    Folder archivedPkgFolder = new Folder("Archive", this);
    archivedPkgFolder.setIcon("archive.gif");
    List<WorkflowPackage> topLevelArchivedPackageList = new ArrayList<>();
    List<WorkflowPackage> allArchivedPackages = new ArrayList<>();
    for (PackageVO packageVO : getDataAccess().getPackages(false)) {
        if (isShowDefaultPackage() || !packageVO.isDefaultPackage()) {
            WorkflowPackage potentialArchived = new WorkflowPackage(this, packageVO);
            if (!getTopLevelPackages().contains(potentialArchived)) {
                potentialArchived.setArchived(true);
                potentialArchived.setProcesses(findProcesses(potentialArchived));
                potentialArchived.setAssets(findWorkflowAssets(potentialArchived));
                potentialArchived.setActivityImpls(findActivityImplementors(potentialArchived));
                potentialArchived.setExternalEvents(findExternalEvents(potentialArchived));
                potentialArchived.setTaskTemplates(findTaskTemplates(potentialArchived));
                allArchivedPackages.add(potentialArchived);
            }
        }
    }
    // organize the package version hierarchy
    Map<String, WorkflowPackage> topLevelArchivedPackages = new HashMap<>();
    for (WorkflowPackage archivedPackage : allArchivedPackages) {
        WorkflowPackage topLevel = topLevelArchivedPackages.get(archivedPackage.getName());
        if ((!visiblePkgsOnly || (visiblePkgsOnly && archivedPackage.isVisible())) && (topLevel == null || archivedPackage.getPackageVO().getVersion() > topLevel.getPackageVO().getVersion()))
            topLevelArchivedPackages.put(archivedPackage.getName(), archivedPackage);
    }
    for (WorkflowPackage topLevelArchivedPackage : topLevelArchivedPackages.values()) {
        for (WorkflowPackage archivedPackage : allArchivedPackages) {
            if (topLevelArchivedPackage.getName().equals(archivedPackage.getName()) && (!visiblePkgsOnly || (visiblePkgsOnly && archivedPackage.isVisible()))) {
                if (topLevelArchivedPackage.equals(archivedPackage)) {
                    // clone top-level process for first child
                    WorkflowPackage firstChild = new WorkflowPackage(topLevelArchivedPackage);
                    firstChild.setArchived(true);
                    firstChild.setTopLevelVersion(topLevelArchivedPackage);
                    firstChild.setProcesses(topLevelArchivedPackage.getProcesses());
                    firstChild.setAssets(topLevelArchivedPackage.getAssets());
                    firstChild.setActivityImpls(topLevelArchivedPackage.getActivityImpls());
                    firstChild.setExternalEvents(topLevelArchivedPackage.getExternalEvents());
                    firstChild.setTaskTemplates(topLevelArchivedPackage.getTaskTemplates());
                    topLevelArchivedPackage.addDescendantPackageVersion(firstChild);
                } else {
                    archivedPackage.setTopLevelVersion(topLevelArchivedPackage);
                    topLevelArchivedPackage.addDescendantPackageVersion(archivedPackage);
                }
            }
        }
        topLevelArchivedPackageList.add(topLevelArchivedPackage);
        topLevelArchivedPackage.setArchivedFolder(archivedPkgFolder);
    }
    Collections.sort(topLevelArchivedPackageList);
    if (isShowDefaultPackage()) {
        // add unpackaged (default package)
        PackageVO defaultPackageVO = new PackageVO();
        defaultPackageVO.setPackageId(Long.valueOf(0));
        defaultPackageVO.setPackageName(PackageVO.DEFAULT_PACKAGE_NAME);
        archivedDefaultPackage = new WorkflowPackage(this, defaultPackageVO);
        archivedDefaultPackage.setProcesses(findUnpackagedProcesses());
        archivedDefaultPackage.setChildFolders(findUnpackagedAssetFolders());
        archivedDefaultPackage.setArchived(true);
        topLevelArchivedPackageList.add(0, archivedDefaultPackage);
    }
    List<WorkflowElement> children = new ArrayList<>();
    children.addAll(topLevelArchivedPackageList);
    archivedPkgFolder.setChildren(children);
    if (progressMonitor != null)
        progressMonitor.progress(10);
    timer.stopAndLog();
    return archivedPkgFolder;
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Folder(com.centurylink.mdw.plugin.designer.model.Folder) IVirtualFolder(org.eclipse.wst.common.componentcore.resources.IVirtualFolder) IFolder(org.eclipse.core.resources.IFolder) CodeTimer(com.centurylink.mdw.plugin.CodeTimer) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement)

Aggregations

WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)85 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)31 ArrayList (java.util.ArrayList)27 WorkflowElement (com.centurylink.mdw.plugin.designer.model.WorkflowElement)25 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)21 WorkflowAsset (com.centurylink.mdw.plugin.designer.model.WorkflowAsset)17 AutomatedTestCase (com.centurylink.mdw.plugin.designer.model.AutomatedTestCase)11 GridData (org.eclipse.swt.layout.GridData)11 CoreException (org.eclipse.core.runtime.CoreException)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 DesignerProxy (com.centurylink.mdw.plugin.designer.DesignerProxy)8 List (java.util.List)8 Label (org.eclipse.swt.widgets.Label)8 JSONException (org.json.JSONException)8 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)7 ExternalEvent (com.centurylink.mdw.plugin.designer.model.ExternalEvent)7 Folder (com.centurylink.mdw.plugin.designer.model.Folder)7 IOException (java.io.IOException)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)7