Search in sources :

Example 1 with CopyDialog

use of com.centurylink.mdw.plugin.designer.dialogs.CopyDialog in project mdw-designer by CenturyLinkCloud.

the class ProcessExplorerDropTarget method handleDropExternalEvent.

private boolean handleDropExternalEvent(String externalEventInfo, WorkflowPackage targetPackage, int operation) {
    Long externalEventId = getExternalEventId(externalEventInfo);
    WorkflowProject workflowProject = targetPackage.getProject();
    WorkflowPackage sourcePackage = workflowProject.getPackage(getPackageName(externalEventInfo));
    DesignerProxy designerProxy = workflowProject.getDesignerProxy();
    if (operation == DND.DROP_COPY) {
        ExternalEvent existing = workflowProject.getExternalEvent(externalEventId);
        CopyDialog copyDialog = new CopyDialog(getViewer().getControl().getShell(), existing, existing.getName(), null, targetPackage);
        if (copyDialog.open() == Dialog.OK) {
            String newPattern = copyDialog.getNewName();
            ExternalEvent newCopy = new ExternalEvent(existing);
            newCopy.setName(newPattern);
            newCopy.setPackage(targetPackage);
            designerProxy.registerExternalEventHandler(newCopy);
            newCopy.addElementChangeListener(workflowProject);
            newCopy.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, newCopy);
            ((TreeViewer) getViewer()).refresh(targetPackage, true);
            return true;
        }
        return false;
    } else if (operation == DND.DROP_MOVE) {
        if (targetPackage.isDefaultPackage()) {
            designerProxy.removeExternalEventFromPackage(externalEventId, sourcePackage);
        } else {
            designerProxy.moveExternalEventToPackage(externalEventId, targetPackage);
        }
        ((TreeViewer) getViewer()).refresh(targetPackage.getProject(), true);
        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) ExternalEvent(com.centurylink.mdw.plugin.designer.model.ExternalEvent) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject)

Example 2 with CopyDialog

use of com.centurylink.mdw.plugin.designer.dialogs.CopyDialog in project mdw-designer by CenturyLinkCloud.

the class ProcessExplorerDropTarget method handleDropProcess.

/**
 * @param processInfo
 * @param targetPackage
 * @param operation
 * @return
 */
private boolean handleDropProcess(String processInfo, WorkflowPackage targetPackage, int operation) {
    String processName = getProcessName(processInfo);
    String version = getProcessVersion(processInfo);
    WorkflowProject targetProject = targetPackage.getProject();
    WorkflowPackage sourcePackage = targetProject.getPackage(getPackageName(processInfo));
    DesignerProxy designerProxy = targetProject.getDesignerProxy();
    if (operation == DND.DROP_COPY) {
        String workflowProjectName = getWorkflowProjectName(processInfo);
        WorkflowProcess existing = targetProject.getProcess(processName, version);
        if (!targetPackage.getProject().getName().equals(workflowProjectName)) {
            // copying from remote project
            if (existing != null) {
                MessageDialog.openError(getViewer().getControl().getShell(), "Copy Foreign Process", "' " + processName + " v" + version + "' already exists in workflow project '" + targetPackage.getProject().getLabel() + "'.");
                return false;
            }
            WorkflowProject sourceProject = WorkflowProjectManager.getInstance().getWorkflowProject(workflowProjectName);
            designerProxy.copyForeignProcess(processName, version, sourceProject, targetPackage);
            WorkflowProcess newCopy = targetProject.getProcess(processName, "0.1");
            if (newCopy != null) {
                newCopy.addElementChangeListener(targetProject);
                newCopy.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, newCopy);
            }
            ((TreeViewer) getViewer()).refresh(targetPackage, true);
            return true;
        } else {
            // is there a dirty editor open?
            if (existing != null) {
                IEditorPart editor = findOpenEditor(existing);
                if (editor != null && editor.isDirty()) {
                    MessageDialog.openWarning(getViewer().getControl().getShell(), "Copy Process", "' " + processName + " v" + version + "' is currently open in an editor.\nPlease save or close before copying.");
                    return false;
                }
            }
            CopyDialog copyDialog = new CopyDialog(getViewer().getControl().getShell(), existing, processName, version, targetPackage);
            if (copyDialog.open() == Dialog.OK) {
                String newName = copyDialog.getNewName();
                designerProxy.copyProcess(processName, version, newName, targetPackage);
                WorkflowProcess newCopy = targetProject.getProcess(newName, "0.1");
                if (newCopy != null) {
                    newCopy.addElementChangeListener(targetProject);
                    newCopy.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, newCopy);
                }
                ((TreeViewer) getViewer()).refresh(targetPackage, true);
                return true;
            }
        }
        return false;
    } else if (operation == DND.DROP_MOVE) {
        // don't allow multiple versions of the same process in a package
        if (!targetPackage.isDefaultPackage() && targetPackage.getProcess(processName) != null) {
            MessageDialog.openError(MdwPlugin.getShell(), "Process Exists", "Process '" + processName + "' already exists in package '" + targetPackage.getName() + "'.");
            return false;
        }
        if (targetPackage.isDefaultPackage()) {
            designerProxy.removeProcessFromPackage(processName, version, sourcePackage);
        } else {
            designerProxy.moveProcessToPackage(processName, version, targetPackage);
        }
        ((TreeViewer) getViewer()).refresh(targetPackage.getProject(), true);
        if (sourcePackage != null)
            ((TreeViewer) getViewer()).refresh(sourcePackage.getProject(), true);
        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) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IEditorPart(org.eclipse.ui.IEditorPart) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess)

Example 3 with CopyDialog

use of com.centurylink.mdw.plugin.designer.dialogs.CopyDialog 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)

Aggregations

DesignerProxy (com.centurylink.mdw.plugin.designer.DesignerProxy)3 CopyDialog (com.centurylink.mdw.plugin.designer.dialogs.CopyDialog)3 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)3 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 ExternalEvent (com.centurylink.mdw.plugin.designer.model.ExternalEvent)1 WorkflowAsset (com.centurylink.mdw.plugin.designer.model.WorkflowAsset)1 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)1 SWTException (org.eclipse.swt.SWTException)1 IEditorPart (org.eclipse.ui.IEditorPart)1