Search in sources :

Example 56 with WorkflowPackage

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

the class WorkflowElementActionHandler method delete.

public void delete(WorkflowElement[] elements) {
    boolean globalConf = false;
    boolean includeInstances = false;
    if (elements.length > 1) {
        boolean globalConfAllowed = true;
        List<WorkflowElement> lockedElems = new ArrayList<WorkflowElement>();
        for (WorkflowElement element : elements) {
            if ((element instanceof WorkflowProject) || (element instanceof WorkflowPackage)) {
                globalConfAllowed = false;
                break;
            } else if (element instanceof WorkflowProcess) {
                WorkflowProcess pv = (WorkflowProcess) element;
                if (pv.getLockingUser() != null && !pv.isLockedToUser())
                    lockedElems.add(pv);
            } else if (element instanceof WorkflowAsset) {
                WorkflowAsset dd = (WorkflowAsset) element;
                if (dd.getLockingUser() != null && !dd.isLockedToUser())
                    lockedElems.add(dd);
            }
        }
        if (!lockedElems.isEmpty()) {
            PluginMessages.uiList(getShell(), "Error: The following elements are locked to other users.\nPlease exclude them from your selection or have them unlocked before proceeding.", "Delete Elements", lockedElems);
            return;
        }
        if (globalConfAllowed) {
            WorkflowElementDeleteDialog multipleDeleteDialog = new WorkflowElementDeleteDialog(getShell(), Arrays.asList(elements));
            int res = multipleDeleteDialog.open();
            if (res == Dialog.CANCEL)
                return;
            else if (res == Dialog.OK) {
                globalConf = true;
                includeInstances = multipleDeleteDialog.isIncludeInstances();
            }
        }
    }
    for (WorkflowElement element : elements) {
        if (element instanceof WorkflowProject) {
            WorkflowProject workflowProject = (WorkflowProject) element;
            if (!workflowProject.isRemote()) {
                MessageDialog.openWarning(getShell(), "Delete Project", "Please delete the underlying Java Project in Package Explorer view.");
                return;
            }
            boolean confirmed = MessageDialog.openConfirm(getShell(), "Confirm Delete", "Delete workflow project: " + workflowProject.getName() + "?");
            if (confirmed) {
                WorkflowProjectManager.getInstance().deleteProject(workflowProject);
                workflowProject.fireElementChangeEvent(ChangeType.ELEMENT_DELETE, null);
            } else {
                return;
            }
        } else if (element instanceof AutomatedTestCase && ((AutomatedTestCase) element).isLegacy()) {
            // still allow deletion of legacy test stuff
            final AutomatedTestCase testCase = (AutomatedTestCase) element;
            if (globalConf || MessageDialog.openConfirm(getShell(), "Delete Legacy Test Case", "Delete " + testCase.getLabel() + "?")) {
                BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

                    public void run() {
                        File tcDir = testCase.getTestCaseDirectory();
                        try {
                            PluginUtil.deleteDirectory(tcDir);
                            testCase.getTestSuite().getTestCases().remove(testCase);
                            try {
                                IFolder folder = testCase.getProject().getOldTestCasesFolder();
                                if (folder.exists())
                                    folder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
                            } catch (CoreException ex) {
                                PluginMessages.uiError(ex, "Delete Legacy Test Case", testCase.getProject());
                            }
                            testCase.fireElementChangeEvent(ChangeType.ELEMENT_DELETE, null);
                            testCase.removeElementChangeListener(testCase.getProject());
                        } catch (IOException ex) {
                            PluginMessages.uiError(ex, "Delete Test Case", testCase.getProject());
                        }
                    }
                });
            }
        } else if (element instanceof LegacyExpectedResults) {
            final LegacyExpectedResults expectedResult = (LegacyExpectedResults) element;
            if (globalConf || MessageDialog.openConfirm(getShell(), "Delete Legacy Expected Result", "Delete " + expectedResult.getLabel() + "?")) {
                BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

                    public void run() {
                        File file = expectedResult.getExpectedResultFile();
                        if (file.delete()) {
                            expectedResult.getTestCase().getLegacyExpectedResults().remove(expectedResult);
                            try {
                                IFolder folder = expectedResult.getProject().getOldTestCasesFolder();
                                if (folder.exists())
                                    folder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
                            } catch (CoreException ex) {
                                PluginMessages.uiError(ex, "Delete Legacy Expected Result", expectedResult.getProject());
                            }
                            expectedResult.fireElementChangeEvent(ChangeType.ELEMENT_DELETE, null);
                            expectedResult.removeElementChangeListener(expectedResult.getProject());
                        } else {
                            PluginMessages.uiError("Cannot delete expected result " + expectedResult.getName(), "Delete Result", expectedResult.getProject());
                        }
                    }
                });
            }
        } else if (element instanceof com.centurylink.mdw.plugin.designer.model.File) {
            final com.centurylink.mdw.plugin.designer.model.File file = (com.centurylink.mdw.plugin.designer.model.File) element;
            if (globalConf || MessageDialog.openConfirm(getShell(), "Delete File", "Delete " + file.getLabel() + "?")) {
                BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

                    public void run() {
                        IFile workspaceFile = file.getWorkspaceFile();
                        try {
                            workspaceFile.delete(true, null);
                            WorkflowElement parent = file.getParent();
                            if (parent instanceof AutomatedTestCase) {
                                AutomatedTestCase testCase = (AutomatedTestCase) parent;
                                testCase.getFiles().remove(file);
                            }
                            file.fireElementChangeEvent(ChangeType.ELEMENT_DELETE, null);
                            file.removeElementChangeListener(file.getProject());
                            refresh(file.getProject().getLegacyTestSuite());
                        } catch (Exception ex) {
                            PluginMessages.uiError("Cannot delete file " + file.getName(), "Delete File", file.getProject());
                        }
                    }
                });
            }
        } else {
            WorkflowProject workflowProject = element.getProject();
            DesignerProxy designerProxy = workflowProject.getDesignerProxy();
            if (element instanceof WorkflowPackage) {
                WorkflowPackage packageToDelete = (WorkflowPackage) element;
                PackageDeleteDialog packageDeleteDialog = new PackageDeleteDialog(getShell(), packageToDelete);
                if (packageDeleteDialog.open() == Dialog.OK) {
                    designerProxy.deletePackage(packageToDelete);
                } else {
                    return;
                }
            } else if (element instanceof WorkflowProcess) {
                WorkflowProcess processVersion = (WorkflowProcess) element;
                if (!processVersion.getProject().isFilePersist() && processVersion.getLockingUser() != null && !processVersion.isLockedToUser()) {
                    MessageDialog.openError(getShell(), "Cannot Delete", "Process '" + processVersion.getLabel() + "' is locked to user '" + processVersion.getLockingUser() + "'.\nPlease have it unlocked before deleting.");
                    return;
                }
                ProcessDeleteDialog deleteDialog = new ProcessDeleteDialog(getShell(), processVersion);
                if (globalConf || deleteDialog.open() == Dialog.OK) {
                    closeOpenEditor(processVersion, false);
                    includeInstances = includeInstances || deleteDialog.isIncludeInstances();
                    designerProxy.deleteProcess(processVersion, includeInstances);
                } else {
                    return;
                }
            } else if (element instanceof TaskTemplate) {
                TaskTemplate taskTemplate = (TaskTemplate) element;
                if (globalConf || MessageDialog.openConfirm(getShell(), "Confirm Delete", "Delete " + taskTemplate.getTitle() + " '" + taskTemplate.getLabel() + "'?")) {
                    designerProxy.deleteTaskTemplate(taskTemplate);
                } else {
                    return;
                }
            } else if (element instanceof WorkflowAsset) {
                WorkflowAsset asset = (WorkflowAsset) element;
                if (!asset.getProject().isFilePersist() && asset.getLockingUser() != null && !asset.isLockedToUser()) {
                    MessageDialog.openError(getShell(), "Cannot Delete", asset.getTitle() + " '" + asset.getLabel() + "' is locked to user '" + asset.getLockingUser() + "'.\nPlease have it unlocked before deleting");
                    return;
                }
                if (globalConf || MessageDialog.openConfirm(getShell(), "Confirm Delete", "Delete " + asset.getTitle() + " '" + asset.getLabel() + "'?")) {
                    if (asset.getFileEditor() != null) {
                        IEditorInput editorInput = asset.getFileEditor().getEditorInput();
                        if (editorInput != null)
                            closeOpenEditor(editorInput, false);
                    }
                    WorkflowAssetFactory.deRegisterAsset(asset);
                    designerProxy.deleteWorkflowAsset(asset);
                } else {
                    return;
                }
            } else if (element instanceof ActivityImpl) {
                ActivityImpl activityImpl = (ActivityImpl) element;
                ActivityImplDeleteDialog deleteDialog = new ActivityImplDeleteDialog(getShell(), activityImpl);
                if (globalConf || deleteDialog.open() == Dialog.OK) {
                    designerProxy.deleteActivityImpl(activityImpl, deleteDialog.isIncludeActivities());
                } else {
                    return;
                }
            } else if (element instanceof ExternalEvent) {
                ExternalEvent externalEvent = (ExternalEvent) element;
                if (globalConf || MessageDialog.openConfirm(getShell(), "Confirm Delete", "Delete Event Handler: " + externalEvent.getLabel() + "?")) {
                    designerProxy.deleteExternalEvent(externalEvent);
                } else {
                    return;
                }
            } else if (element instanceof TaskTemplate) {
                MessageDialog.openWarning(getShell(), "TODO", "Delete task template not yet implemented");
            }
            if (RunnerStatus.SUCCESS.equals(designerProxy.getRunnerStatus())) {
                // notify listeners
                element.fireElementChangeEvent(ChangeType.ELEMENT_DELETE, null);
                element.removeElementChangeListener(workflowProject);
            }
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) WorkflowElementDeleteDialog(com.centurylink.mdw.plugin.designer.dialogs.WorkflowElementDeleteDialog) ProcessDeleteDialog(com.centurylink.mdw.plugin.designer.dialogs.ProcessDeleteDialog) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) PackageDeleteDialog(com.centurylink.mdw.plugin.designer.dialogs.PackageDeleteDialog) ExternalEvent(com.centurylink.mdw.plugin.designer.model.ExternalEvent) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) TaskTemplate(com.centurylink.mdw.plugin.designer.model.TaskTemplate) DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) ActivityImpl(com.centurylink.mdw.plugin.designer.model.ActivityImpl) LegacyExpectedResults(com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults) ActivityImplDeleteDialog(com.centurylink.mdw.plugin.designer.dialogs.ActivityImplDeleteDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File) JarFile(com.centurylink.mdw.plugin.designer.model.JarFile) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement) IEditorInput(org.eclipse.ui.IEditorInput) IFolder(org.eclipse.core.resources.IFolder)

Example 57 with WorkflowPackage

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

the class WorkflowElementActionHandler method syncOpenEditors.

public void syncOpenEditors(final WorkflowProject project) {
    final WorkflowProjectManager projectMgr = WorkflowProjectManager.getInstance();
    final List<ProcessEditor> processEditors = getOpenProcessEditors(project);
    final List<IEditorPart> assetEditors = getOpenAssetEditors(project);
    if (!processEditors.isEmpty() || !assetEditors.isEmpty()) {
        // sync open editors
        IRunnableWithProgress loader = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Loading " + project.getLabel(), 100);
                monitor.worked(25);
                // sync process editors
                for (ProcessEditor ed : processEditors) {
                    WorkflowProcess pv = ed.getProcess();
                    pv.setProject(projectMgr.getWorkflowProject(pv.getProject().getName()));
                    if (pv.getPackage() != null && !pv.getPackage().isDefaultPackage()) {
                        WorkflowPackage pkg = pv.getProject().getPackage(pv.getPackage().getName());
                        WorkflowProcess oldPv = pkg.getProcess(pv.getName());
                        if (oldPv != null)
                            pkg.removeProcess(oldPv);
                        pkg.addProcess(pv);
                        pv.setPackage(pkg);
                    }
                }
                monitor.worked(50);
                // sync asset editors
                Map<IFile, AssetWorkbenchListener> assetListeners = WorkflowAssetFactory.getWorkbenchListeners();
                for (IEditorPart assetEd : assetEditors) {
                    FileEditorInput fileInput = (FileEditorInput) assetEd.getEditorInput();
                    AssetWorkbenchListener wbListener = assetListeners.get(fileInput.getFile());
                    if (wbListener != null) {
                        WorkflowAsset asset = wbListener.getAsset();
                        WorkflowProject wfProj = projectMgr.getWorkflowProject(asset.getProject().getName());
                        WorkflowAsset oldAsset = wfProj.getAsset(asset.getName(), asset.getLanguage(), asset.getVersion());
                        if (asset.getPackage() != null && !asset.getPackage().isDefaultPackage()) {
                            WorkflowPackage pkg = wfProj.getPackage(asset.getPackage().getName());
                            if (pkg != null) {
                                pkg.removeAsset(oldAsset);
                                pkg.addAsset(asset);
                                asset.setPackage(pkg);
                            } else {
                                asset.setPackage(wfProj.getDefaultPackage());
                            }
                        } else {
                            asset.setPackage(wfProj.getDefaultPackage());
                        }
                        asset.addElementChangeListener(wfProj);
                        if (oldAsset != null)
                            WorkflowAssetFactory.deRegisterAsset(oldAsset);
                        WorkflowAssetFactory.registerAsset(asset);
                        assetEd.addPropertyListener(asset.new AssetEditorPropertyListener(assetEd));
                        WorkflowAssetFactory.registerWorkbenchListener(fileInput.getFile(), wbListener);
                    }
                }
                monitor.worked(25);
                monitor.done();
            }
        };
        ProgressMonitorDialog progMonDlg = new MdwProgressMonitorDialog(Display.getCurrent().getActiveShell());
        try {
            progMonDlg.run(true, false, loader);
        } catch (Exception ex) {
            PluginMessages.uiError(ex, "Sync Open Editors", project);
        }
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) AssetWorkbenchListener(com.centurylink.mdw.plugin.designer.model.WorkflowAsset.AssetWorkbenchListener) IFile(org.eclipse.core.resources.IFile) MdwProgressMonitorDialog(com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog) MdwProgressMonitorDialog(com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IEditorPart(org.eclipse.ui.IEditorPart) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) WorkflowProjectManager(com.centurylink.mdw.plugin.project.WorkflowProjectManager) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) ProcessEditor(com.centurylink.mdw.plugin.designer.editors.ProcessEditor)

Example 58 with WorkflowPackage

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

the class WorkflowElementActionHandler method importAttributes.

public void importAttributes(String attributePrefix, WorkflowElement element) {
    if (element instanceof WorkflowPackage || element instanceof WorkflowProcess) {
        ImportAttributesWizard importAttributesWizard = new ImportAttributesWizard();
        importAttributesWizard.init(getWorkbench(), element);
        importAttributesWizard.setPrefix(attributePrefix);
        new WizardDialog(getShell(), importAttributesWizard).open();
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) ImportAttributesWizard(com.centurylink.mdw.plugin.designer.wizards.ImportAttributesWizard) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 59 with WorkflowPackage

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

the class WorkflowElementActionHandler method rename.

public void rename(WorkflowElement element) {
    RenameDialog renameDialog = new RenameDialog(getShell(), element);
    renameDialog.setTitle("Rename " + element.getTitle());
    if (element instanceof WorkflowProcess) {
        WorkflowProcess processVersion = (WorkflowProcess) element;
        String lbl = "'" + processVersion.getLabel() + "'";
        IEditorPart editor = findOpenEditor(processVersion);
        if (editor != null) {
            String message = lbl + " is currently open in an editor.\nPlease save and close before renaming.";
            MessageDialog.openError(getShell(), "Process Explorer", message);
            return;
        }
        if (processVersion.getLockingUser() != null && !processVersion.isLockedToUser()) {
            String message = lbl + " is currently locked to " + processVersion.getLockingUser() + ", so it cannot be renamed";
            MessageDialog.openError(getShell(), "Process Explorer", message);
            return;
        }
    } else if (element instanceof WorkflowAsset) {
        WorkflowAsset asset = (WorkflowAsset) element;
        if (asset.getFileEditor() != null) {
            IEditorPart assetEditor = findOpenEditor(asset.getFileEditor().getEditorInput());
            if (assetEditor != null) {
                String message = "'" + asset.getName() + "' is currently open in an editor.\nPlease save and close before renaming.";
                MessageDialog.openError(getShell(), "Process Explorer", message);
                return;
            }
        }
    } else if (element instanceof WorkflowProject) {
        WorkflowProject workflowProject = (WorkflowProject) element;
        if (!workflowProject.isRemote()) {
            if (workflowProject.isCloudProject())
                MessageDialog.openWarning(getShell(), "Cloud Project", "Please rename the underlying Java Project in Package Explorer and then refresh the Process Explorer view.");
            return;
        }
    }
    int result = renameDialog.open();
    if (result == Dialog.OK) {
        String newName = renameDialog.getNewName();
        if (element instanceof WorkflowProject) {
            WorkflowProject workflowProject = (WorkflowProject) element;
            if (!workflowProject.isRemote())
                return;
            WorkflowProjectManager.renameRemoteProject(workflowProject, newName);
            workflowProject.fireElementChangeEvent(ChangeType.RENAME, null);
        } else {
            WorkflowProject workflowProject = element.getProject();
            DesignerProxy designerProxy = workflowProject.getDesignerProxy();
            if (element instanceof WorkflowProcess) {
                WorkflowProcess processVersion = (WorkflowProcess) element;
                designerProxy.renameProcess(processVersion, newName);
            } else if (element instanceof WorkflowPackage) {
                WorkflowPackage packageVersion = (WorkflowPackage) element;
                designerProxy.renamePackage(packageVersion, newName);
            } else if (element instanceof WorkflowAsset) {
                WorkflowAsset asset = (WorkflowAsset) element;
                designerProxy.renameWorkflowAsset(asset, newName);
            }
            element.fireElementChangeEvent(ChangeType.RENAME, element.getName());
        }
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) RenameDialog(com.centurylink.mdw.plugin.designer.dialogs.RenameDialog) DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IEditorPart(org.eclipse.ui.IEditorPart) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess)

Example 60 with WorkflowPackage

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

the class WorkflowElementActionHandler method update.

public void update(WorkflowElement element) {
    if (element instanceof WorkflowPackage) {
        WorkflowPackage packageVersion = (WorkflowPackage) element;
        if (MessageDialog.openConfirm(getShell(), "Update Package", "Bring latest versions of Processes and Workflow Assets into package '" + packageVersion.getLabel() + "'?")) {
            packageVersion.getProject().getDesignerProxy().updateProcessesAndAssetsToLatest(packageVersion);
            packageVersion.fireElementChangeEvent(packageVersion, ChangeType.SETTINGS_CHANGE, null);
        }
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage)

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