Search in sources :

Example 11 with ProcessInstanceVO

use of com.centurylink.mdw.model.value.process.ProcessInstanceVO in project mdw-designer by CenturyLinkCloud.

the class DesignerProxy method loadProcessInstance.

public RunTimeDesignerCanvas loadProcessInstance(WorkflowProcess processVersion, ProcessInstancePage processInstancePage) {
    CodeTimer timer = new CodeTimer("loadProcessInstance()");
    ProcessInstanceVO processInstanceInfo = processVersion.getProcessInstance();
    ProcessInstanceLoader instanceLoadThread = new ProcessInstanceLoader(processInstanceInfo, processInstancePage);
    String errorMessage = null;
    try {
        Graph processGraph = dataAccess.getDesignerDataModel().findProcessGraph(processVersion.getId(), null);
        if (processGraph == null)
            processGraph = processInstancePage.loadProcess(processInstanceInfo.getProcessId(), null);
        processVersion.setProcessVO(processGraph.getProcessVO());
        DesignerDataAccess dao = processVersion.getDesignerDataAccess() == null ? processInstancePage.frame.dao : processVersion.getDesignerDataAccess();
        Graph procInstGraph = instanceLoadThread.loadCompletionMap(processGraph.getProcessVO(), processInstanceInfo, dao);
        ProcessInstanceTreeModel model = instanceLoadThread.createOrUpdateModel(null);
        model.getCurrentProcess().setGraph(procInstGraph);
        processInstancePage.setData(model, processInstancePage);
        Map<Long, List<TaskInstanceVO>> taskInstances = new HashMap<>();
        // embedded subprocesses
        List<ProcessInstanceVO> embeddedSubs = new ArrayList<>();
        if (procInstGraph.subgraphs != null) {
            for (SubGraph instSubGraph : procInstGraph.subgraphs) {
                if (instSubGraph.getInstances() != null) {
                    if (instSubGraph.nodes != null) {
                        List<Long> taskActivityIds = new ArrayList<>();
                        for (Node node : instSubGraph.nodes) {
                            if (node.isTaskActivity()) {
                                for (ProcessInstanceVO embeddedProcInst : instSubGraph.getInstances()) {
                                    if (!embeddedProcInst.getActivityInstances(node.getActivityId()).isEmpty())
                                        taskActivityIds.add(node.getActivityId());
                                }
                            }
                        }
                        if (!taskActivityIds.isEmpty()) {
                            for (ProcessInstanceVO embeddedProcInst : instSubGraph.getInstances()) {
                                ProcessVO embeddedProc = instSubGraph.getGraph().getProcessVO();
                                Map<Long, List<TaskInstanceVO>> embeddedTaskInsts = dao.getTaskInstances(embeddedProc, embeddedProcInst, taskActivityIds);
                                for (Map.Entry<Long, List<TaskInstanceVO>> embeddedTaskInst : embeddedTaskInsts.entrySet()) {
                                    if (taskInstances.get(embeddedTaskInst.getKey()) == null)
                                        taskInstances.put(embeddedTaskInst.getKey(), new ArrayList<TaskInstanceVO>());
                                    taskInstances.get(embeddedTaskInst.getKey()).addAll(embeddedTaskInst.getValue());
                                }
                            }
                        }
                    }
                    embeddedSubs.addAll(instSubGraph.getInstances());
                }
            }
        }
        processVersion.setEmbeddedSubProcessInstances(embeddedSubs);
        // manual task instances
        if (processGraph.nodes != null) {
            List<Long> taskActivityIds = new ArrayList<>();
            for (Node node : processGraph.nodes) {
                if (node.isTaskActivity() && !processInstanceInfo.getActivityInstances(node.getActivityId()).isEmpty())
                    taskActivityIds.add(node.getActivityId());
            }
            if (!taskActivityIds.isEmpty()) {
                Map<Long, List<TaskInstanceVO>> taskInsts = dao.getTaskInstances(processVersion.getProcessVO(), processInstanceInfo, taskActivityIds);
                for (Map.Entry<Long, List<TaskInstanceVO>> taskInst : taskInsts.entrySet()) {
                    if (taskInstances.get(taskInst.getKey()) == null)
                        taskInstances.put(taskInst.getKey(), new ArrayList<TaskInstanceVO>());
                    taskInstances.get(taskInst.getKey()).addAll(taskInst.getValue());
                }
            }
        }
        processVersion.setTaskInstances(taskInstances);
    } catch (Exception ex) {
        PluginMessages.log(ex);
        errorMessage = PluginMessages.getUserMessage(ex);
    }
    if (errorMessage == null)
        errorMessage = instanceLoadThread.getErrorMessage();
    if (errorMessage != null) {
        PluginMessages.uiError(errorMessage, "Load Process Instance");
    }
    timer.stopAndLog();
    return processInstancePage.canvas;
}
Also used : HashMap(java.util.HashMap) Node(com.centurylink.mdw.designer.display.Node) ProcessInstanceTreeModel(com.centurylink.mdw.designer.runtime.ProcessInstanceTreeModel) ArrayList(java.util.ArrayList) ProcessInstanceLoader(com.centurylink.mdw.designer.runtime.ProcessInstanceLoader) JSONException(org.json.JSONException) TranslationException(com.centurylink.mdw.common.exception.TranslationException) AuthenticationException(com.centurylink.mdw.auth.AuthenticationException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) ValidationException(com.centurylink.mdw.designer.utils.ValidationException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) ZipException(java.util.zip.ZipException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) Graph(com.centurylink.mdw.designer.display.Graph) SubGraph(com.centurylink.mdw.designer.display.SubGraph) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) ArrayList(java.util.ArrayList) List(java.util.List) ProcessList(com.centurylink.mdw.model.value.process.ProcessList) DesignerDataAccess(com.centurylink.mdw.designer.DesignerDataAccess) CodeTimer(com.centurylink.mdw.plugin.CodeTimer) SubGraph(com.centurylink.mdw.designer.display.SubGraph) Map(java.util.Map) HashMap(java.util.HashMap) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO)

Example 12 with ProcessInstanceVO

use of com.centurylink.mdw.model.value.process.ProcessInstanceVO in project mdw-designer by CenturyLinkCloud.

the class MdwWorkbenchWindowAdvisor method getProcessInstance.

private WorkflowProcess getProcessInstance(Long processInstanceId) {
    PluginDataAccess dataAccess = projectToImport.getDataAccess();
    ProcessInstanceVO processInstanceInfo = dataAccess.getProcessInstance(processInstanceId);
    ProcessVO processVO = new ProcessVO();
    processVO.setProcessId(processInstanceInfo.getProcessId());
    processVO.setProcessName(processInstanceInfo.getProcessName());
    WorkflowProcess instanceVersion = new WorkflowProcess(projectToImport, processVO);
    instanceVersion.setProcessInstance(processInstanceInfo);
    return instanceVersion;
}
Also used : ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO) PluginDataAccess(com.centurylink.mdw.plugin.designer.PluginDataAccess)

Example 13 with ProcessInstanceVO

use of com.centurylink.mdw.model.value.process.ProcessInstanceVO in project mdw-designer by CenturyLinkCloud.

the class ProcessHierarchyLabelProvider method getText.

public String getText(Object element) {
    if (element instanceof LinkedProcessInstance) {
        LinkedProcessInstance instance = (LinkedProcessInstance) element;
        ProcessInstanceVO procInst = instance.getProcessInstance();
        return procInst.getProcessName() + " v" + procInst.getProcessVersion() + " (" + procInst.getId() + ")";
    } else if (element instanceof LinkedProcess) {
        return ((LinkedProcess) element).getProcess().getLabel();
    } else {
        return null;
    }
}
Also used : LinkedProcess(com.centurylink.mdw.plugin.designer.views.ProcessHierarchyContentProvider.LinkedProcess) LinkedProcessInstance(com.centurylink.mdw.model.value.process.LinkedProcessInstance) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO)

Example 14 with ProcessInstanceVO

use of com.centurylink.mdw.model.value.process.ProcessInstanceVO in project mdw-designer by CenturyLinkCloud.

the class ProcessCanvasWrapper method buildPopupMenu.

/**
 * Needs to run on the SWT UI thread.
 */
private Menu buildPopupMenu(final int x, final int y) {
    if (popupMenu != null)
        popupMenu.dispose();
    popupMenu = new Menu(getParent().getShell(), SWT.POP_UP);
    if (!isInstance()) {
        if (designerCanvasSelection instanceof WorkflowProcess) {
            if (process.getPackage() != null && process.isUserAuthorized(UserRoleVO.ASSET_DESIGN)) {
                // save as
                MenuItem saveAsItem = new MenuItem(popupMenu, SWT.PUSH);
                saveAsItem.setText("Save as...");
                ImageDescriptor propsImageDescForSave = MdwPlugin.getImageDescriptor("icons/save.gif");
                saveAsItem.setImage(propsImageDescForSave.createImage());
                saveAsItem.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        saveProcessAs();
                    }
                });
            }
            MenuItem exportAsItem = new MenuItem(popupMenu, SWT.PUSH);
            exportAsItem.setText("Export as...");
            ImageDescriptor exportAsDesc = MdwPlugin.getImageDescriptor("icons/export_as.gif");
            exportAsItem.setImage(exportAsDesc.createImage());
            exportAsItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    exportAs(ProcessCanvasWrapper.this.getDisplay().getActiveShell());
                }
            });
        }
        if (!process.isReadOnly()) {
            if (designerCanvasSelection instanceof WorkflowProcess) {
                if (process.isInRuleSet()) {
                    // notes
                    MenuItem noteItem = new MenuItem(popupMenu, SWT.PUSH);
                    noteItem.setText("Add Note");
                    ImageDescriptor noteImageDesc = MdwPlugin.getImageDescriptor(ICON_DOC_GIF);
                    noteItem.setImage(noteImageDesc.createImage());
                    noteItem.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            addNote(x, y);
                        }
                    });
                }
                // paste
                MenuItem pasteItem = new MenuItem(popupMenu, SWT.PUSH);
                pasteItem.setText("Paste\tCtrl+V");
                ImageDescriptor pasteImageDesc = MdwPlugin.getImageDescriptor("icons/paste.gif");
                pasteItem.setImage(pasteImageDesc.createImage());
                pasteItem.setEnabled(GraphClipboard.getInstance().get() != null);
                pasteItem.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        pasteSelection();
                    }
                });
            } else {
                // cut
                MenuItem cutItem = new MenuItem(popupMenu, SWT.PUSH);
                cutItem.setText("Cut\tCtrl+X");
                ImageDescriptor cutImageDesc = MdwPlugin.getImageDescriptor("icons/cut.gif");
                cutItem.setImage(cutImageDesc.createImage());
                cutItem.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        cutSelection();
                    }
                });
            }
        }
        if (!(designerCanvasSelection instanceof WorkflowProcess)) {
            // copy
            MenuItem copyItem = new MenuItem(popupMenu, SWT.PUSH);
            copyItem.setText("Copy\tCtrl+C");
            ImageDescriptor copyImageDesc = MdwPlugin.getImageDescriptor("icons/copy.gif");
            copyItem.setImage(copyImageDesc.createImage());
            copyItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    copySelection();
                }
            });
            // delete
            if (!process.isReadOnly()) {
                MenuItem deleteItem = new MenuItem(popupMenu, SWT.PUSH);
                deleteItem.setText("Delete\tDel");
                ImageDescriptor deleteImageDesc = MdwPlugin.getImageDescriptor("icons/delete.gif");
                deleteItem.setImage(deleteImageDesc.createImage());
                deleteItem.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        deleteSelection();
                    }
                });
            }
        }
    }
    // properties
    MenuItem propsItem = new MenuItem(popupMenu, SWT.PUSH);
    propsItem.setText("Show Properties");
    ImageDescriptor propsImageDesc = MdwPlugin.getImageDescriptor("icons/properties.gif");
    propsItem.setImage(propsImageDesc.createImage());
    propsItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            showPropertiesView();
        }
    });
    // documentation
    if (!isInstance()) {
        MenuItem docsItem = new MenuItem(popupMenu, SWT.PUSH);
        docsItem.setText("Documentation");
        ImageDescriptor docsImageDesc = MdwPlugin.getImageDescriptor("icons/word.gif");
        docsItem.setImage(docsImageDesc.createImage());
        docsItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                openDocumentation();
            }
        });
    }
    // process definition xml
    if (!isInstance() && (designerCanvasSelection instanceof WorkflowProcess) && getProcess().isInRuleSet()) {
        MenuItem defXmlItem = new MenuItem(popupMenu, SWT.PUSH);
        defXmlItem.setText("Definition Doc");
        ImageDescriptor docsImageDesc = MdwPlugin.getImageDescriptor(ICON_DOC_GIF);
        defXmlItem.setImage(docsImageDesc.createImage());
        defXmlItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                openDefinitionXml();
            }
        });
    }
    // open subprocess
    boolean isSubProcessActivity = designerCanvasSelection instanceof Activity && ((Activity) designerCanvasSelection).isSubProcessInvoke();
    if (!isInstance() && isSubProcessActivity) {
        final Activity subProcessActivity = (Activity) designerCanvasSelection;
        if (!subProcessActivity.isHeterogeneousSubProcInvoke()) {
            MenuItem subProcItem = new MenuItem(popupMenu, SWT.PUSH);
            subProcItem.setText(OPEN_SUBPROCESS);
            ImageDescriptor subProcImageDesc = MdwPlugin.getImageDescriptor("icons/designer.gif");
            subProcItem.setImage(subProcImageDesc.createImage());
            subProcItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    openSubProcess(subProcessActivity);
                }
            });
        }
    }
    // edit script
    boolean isScript = designerCanvasSelection instanceof Activity && ((Activity) designerCanvasSelection).isScript();
    if (!isInstance() && isScript) {
        final Activity scriptActivity = (Activity) designerCanvasSelection;
        MenuItem editScriptItem = new MenuItem(popupMenu, SWT.PUSH);
        String artifactTitle = "Script";
        if (scriptActivity.isRule())
            artifactTitle = "Rule";
        else if (TransformEditorValueProvider.isTransformActivity(scriptActivity))
            artifactTitle = "Transform";
        else if (scriptActivity.getAttribute("Rule") != null)
            artifactTitle += " *";
        if (process.isReadOnly())
            editScriptItem.setText("View " + artifactTitle);
        else
            editScriptItem.setText("Edit " + artifactTitle);
        ImageDescriptor scriptImageDesc = MdwPlugin.getImageDescriptor("icons/script.gif");
        editScriptItem.setImage(scriptImageDesc.createImage());
        editScriptItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                openScript(scriptActivity);
            }
        });
    }
    // edit java
    boolean isJava = designerCanvasSelection instanceof Activity && ((Activity) designerCanvasSelection).isDynamicJava();
    if (!isInstance() && isJava) {
        final Activity javaActivity = (Activity) designerCanvasSelection;
        MenuItem editJavaItem = new MenuItem(popupMenu, SWT.PUSH);
        String artifactTitle = "Java";
        if (process.isReadOnly())
            editJavaItem.setText("View " + artifactTitle);
        else
            editJavaItem.setText("Edit " + artifactTitle);
        ImageDescriptor javaImageDesc = MdwPlugin.getImageDescriptor("icons/java.gif");
        editJavaItem.setImage(javaImageDesc.createImage());
        editJavaItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                openJava(javaActivity);
            }
        });
    }
    // open task instance or process instance
    if (isInstance() && designerCanvasSelection instanceof Activity) {
        final Activity activity = (Activity) designerCanvasSelection;
        if (activity.isManualTask()) {
            if (activity.getTaskInstances() != null && !activity.getTaskInstances().isEmpty()) {
                MenuItem viewTaskItem = new MenuItem(popupMenu, SWT.PUSH);
                viewTaskItem.setText("View Task");
                viewTaskItem.setImage(MdwPlugin.getImageDescriptor("icons/taskmgr.gif").createImage());
                viewTaskItem.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        TaskInstanceVO taskInstanceVO = null;
                        for (TaskInstanceVO taskInstance : activity.getTaskInstances()) {
                            if (taskInstanceVO == null || taskInstance.getTaskInstanceId() > taskInstanceVO.getTaskInstanceId())
                                taskInstanceVO = taskInstance;
                        }
                        if (taskInstanceVO != null) {
                            boolean assigned = activity.getProject().getUser().getUsername().equals(taskInstanceVO.getTaskClaimUserCuid());
                            String taskInstParams = activity.getProject().getTaskInstancePath(taskInstanceVO.getTaskInstanceId(), assigned);
                            WorkflowPackage packageVersion = activity.getPackage();
                            String packageParam = packageVersion.isDefaultPackage() ? "" : "&packageName=" + packageVersion.getName();
                            WebApp webapp = activity.getProject().checkRequiredVersion(5, 5) ? WebApp.MdwHub : WebApp.TaskManager;
                            WebLaunchActions.getLaunchAction(activity.getProject(), webapp).launch(activity.getProject(), taskInstParams + packageParam);
                        }
                    }
                });
            }
        } else if (activity.isSubProcessInvoke() && activity.getSubProcessInstances() != null && !activity.getSubProcessInstances().isEmpty() && activity.getSubProcessInstances().size() < 50) {
            MenuItem subMenuItem = new MenuItem(popupMenu, SWT.CASCADE);
            subMenuItem.setText("SubProcesses");
            subMenuItem.setImage(MdwPlugin.getImageDescriptor("icons/processfolder.gif").createImage());
            Menu subMenu = new Menu(subMenuItem);
            subMenuItem.setMenu(subMenu);
            for (final ProcessInstanceVO subProcInst : activity.getSubProcessInstances()) {
                MenuItem subProcItem = new MenuItem(subMenu, SWT.PUSH);
                subProcItem.setText("Instance " + subProcInst.getId());
                subProcItem.setImage(MdwPlugin.getImageDescriptor(ICON_PROCESS_GIF).createImage());
                subProcItem.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        openProcessInstance(subProcInst);
                    }
                });
            }
        }
    }
    // launch process, lock, show instances, find calling processes
    if (!isInstance() && designerCanvasSelection instanceof WorkflowProcess) {
        if (designerCanvasSelection.isUserAuthorized(UserRoleVO.PROCESS_EXECUTION)) {
            MenuItem runItem = new MenuItem(popupMenu, SWT.PUSH);
            runItem.setText("Run...");
            ImageDescriptor runImageDesc = MdwPlugin.getImageDescriptor(ICON_RUN_GIF);
            runItem.setImage(runImageDesc.createImage());
            runItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    launchProcess((WorkflowProcess) designerCanvasSelection, false);
                }
            });
            MenuItem runPageItem = new MenuItem(popupMenu, SWT.PUSH);
            runPageItem.setText("Run Start Page...");
            ImageDescriptor runPageImageDesc = MdwPlugin.getImageDescriptor(ICON_RUN_GIF);
            runPageItem.setImage(runPageImageDesc.createImage());
            runPageItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    launchProcessPage((WorkflowProcess) designerCanvasSelection);
                }
            });
            if (!MdwPlugin.isRcp()) {
                MenuItem debugItem = new MenuItem(popupMenu, SWT.PUSH);
                debugItem.setText("Debug...");
                ImageDescriptor debugImageDesc = MdwPlugin.getImageDescriptor("icons/debug.gif");
                debugItem.setImage(debugImageDesc.createImage());
                debugItem.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        launchProcess((WorkflowProcess) designerCanvasSelection, true);
                    }
                });
            }
        }
        if (isLockAllowed()) {
            MenuItem lockItem = new MenuItem(popupMenu, SWT.PUSH);
            lockItem.setText(getProcess().isLockedToUser() ? "Unlock Process" : "Lock Process");
            ImageDescriptor lockImageDesc = MdwPlugin.getImageDescriptor("icons/lock.gif");
            lockItem.setImage(lockImageDesc.createImage());
            lockItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    toggleProcessLock(!((WorkflowProcess) designerCanvasSelection).isLockedToUser());
                }
            });
        }
        if (getProcess().getProject().isPureMdw52()) {
            MenuItem callersItem = new MenuItem(popupMenu, SWT.PUSH);
            callersItem.setText("Find Calling Processes");
            ImageDescriptor callersImageDesc = MdwPlugin.getImageDescriptor(ICON_PROCESS_GIF);
            callersItem.setImage(callersImageDesc.createImage());
            callersItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    actionHandler.findCallers(designerCanvasSelection);
                }
            });
            if (getProject().isFilePersist()) {
                MenuItem hierarchyItem = new MenuItem(popupMenu, SWT.PUSH);
                hierarchyItem.setText("Process Hierarchy");
                ImageDescriptor hierarchyImageDesc = MdwPlugin.getImageDescriptor("icons/hierarchy.gif");
                hierarchyItem.setImage(hierarchyImageDesc.createImage());
                hierarchyItem.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        actionHandler.showHierarchy(designerCanvasSelection);
                    }
                });
            }
        }
        MenuItem instancesItem = new MenuItem(popupMenu, SWT.PUSH);
        instancesItem.setText("View Instances");
        ImageDescriptor instancesImageDesc = MdwPlugin.getImageDescriptor("icons/list.gif");
        instancesItem.setImage(instancesImageDesc.createImage());
        instancesItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                showProcessInstances((WorkflowProcess) designerCanvasSelection);
            }
        });
    }
    // launch activity
    if (!isInstance() && designerCanvasSelection instanceof Activity && ((Activity) designerCanvasSelection).getProcess().isUserAuthorized(UserRoleVO.PROCESS_EXECUTION)) {
        MenuItem runItem = new MenuItem(popupMenu, SWT.PUSH);
        runItem.setText("Run from Here...");
        ImageDescriptor runImageDesc = MdwPlugin.getImageDescriptor(ICON_RUN_GIF);
        runItem.setImage(runImageDesc.createImage());
        runItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                launchProcess((Activity) designerCanvasSelection, false);
            }
        });
        if (!MdwPlugin.isRcp()) {
            MenuItem debugItem = new MenuItem(popupMenu, SWT.PUSH);
            debugItem.setText("Debug from Here...");
            ImageDescriptor debugImageDesc = MdwPlugin.getImageDescriptor("icons/debug.gif");
            debugItem.setImage(debugImageDesc.createImage());
            debugItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    launchProcess((Activity) designerCanvasSelection, true);
                }
            });
        }
    }
    // refresh
    if (designerCanvasSelection instanceof WorkflowProcess) {
        MenuItem refreshItem = new MenuItem(popupMenu, SWT.PUSH);
        refreshItem.setText("Refresh");
        ImageDescriptor refreshImageDesc = MdwPlugin.getImageDescriptor("icons/refresh.gif");
        refreshItem.setImage(refreshImageDesc.createImage());
        refreshItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                refresh();
            }
        });
        // open in hub
        if (getProject().checkRequiredVersion(6)) {
            MenuItem hubItem = new MenuItem(popupMenu, SWT.PUSH);
            hubItem.setText("Open in MDWHub");
            ImageDescriptor hubImageDesc = MdwPlugin.getImageDescriptor("icons/webtools.gif");
            hubItem.setImage(hubImageDesc.createImage());
            hubItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    String resourcePath;
                    if (isInstance())
                        resourcePath = "#/workflow/processes/" + getProcess().getProcessInstance().getId();
                    else
                        resourcePath = "#/workflow/definitions/" + getProcess().getPackage().getName() + "/" + getProcess().getName();
                    WebLaunchActions.getLaunchAction(getProject(), WebApp.MdwHub).launch(getProject(), resourcePath);
                }
            });
        }
    }
    // process definition and open calling process instance
    if (isInstance() && designerCanvasSelection instanceof WorkflowProcess) {
        final WorkflowProcess processInstVersion = (WorkflowProcess) designerCanvasSelection;
        MenuItem procDefItem = new MenuItem(popupMenu, SWT.PUSH);
        procDefItem.setText("Process Definition");
        ImageDescriptor procDefImageDesc = MdwPlugin.getImageDescriptor(ICON_PROCESS_GIF);
        procDefItem.setImage(procDefImageDesc.createImage());
        procDefItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                openProcessDefinition(new WorkflowProcess(processInstVersion));
            }
        });
        if (OwnerType.PROCESS_INSTANCE.equals(processInstVersion.getProcessInstance().getOwner())) {
            MenuItem callingInstanceItem = new MenuItem(popupMenu, SWT.PUSH);
            callingInstanceItem.setText("Calling Process Instance");
            ImageDescriptor callerImageDesc = MdwPlugin.getImageDescriptor("icons/launch.gif");
            callingInstanceItem.setImage(callerImageDesc.createImage());
            callingInstanceItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    openCallingInstance();
                }
            });
        }
        MenuItem instanceHierarchyItem = new MenuItem(popupMenu, SWT.PUSH);
        instanceHierarchyItem.setText("Instance Hierarchy");
        ImageDescriptor hierarchyImageDesc = MdwPlugin.getImageDescriptor("icons/hierarchy.gif");
        instanceHierarchyItem.setImage(hierarchyImageDesc.createImage());
        instanceHierarchyItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                actionHandler.showHierarchy(designerCanvasSelection);
            }
        });
        if (OwnerType.ERROR.equals(processInstVersion.getProcessInstance().getOwner())) {
            MenuItem errorTriggerItem = new MenuItem(popupMenu, SWT.PUSH);
            errorTriggerItem.setText("Triggering Process");
            ImageDescriptor errorImageDesc = MdwPlugin.getImageDescriptor("icons/error.gif");
            errorTriggerItem.setImage(errorImageDesc.createImage());
            errorTriggerItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    openTriggeringInstance();
                }
            });
        }
    }
    // retry and skip
    if (isInstance() && designerCanvasSelection instanceof Activity && ((Activity) designerCanvasSelection).hasInstanceInfo() && ((Activity) designerCanvasSelection).getProcess().isUserAuthorized(UserRoleVO.PROCESS_EXECUTION)) {
        MenuItem retryItem = new MenuItem(popupMenu, SWT.PUSH);
        retryItem.setText("Retry");
        ImageDescriptor retryImageDesc = MdwPlugin.getImageDescriptor("icons/retry.gif");
        retryItem.setImage(retryImageDesc.createImage());
        retryItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                PanelBusyIndicator pbi = new PanelBusyIndicator(getDisplay(), getCanvas());
                try {
                    pbi.busyWhile(new Runnable() {

                        public void run() {
                            Activity activity = (Activity) designerCanvasSelection;
                            Shell shell = MdwPlugin.getActiveWorkbenchWindow().getShell();
                            ActivityInstanceVO actInstVO = activity.getInstances().get(activity.getInstances().size() - 1);
                            ActivityInstanceDialog actInstDlg = new ActivityInstanceDialog(shell, activity, actInstVO, Mode.RETRY);
                            actInstDlg.open();
                        }
                    });
                } catch (InvocationTargetException ex) {
                    PluginMessages.uiError(ex, "Retry Activity", getProject());
                }
            }
        });
        MenuItem skipItem = new MenuItem(popupMenu, SWT.PUSH);
        skipItem.setText("Proceed");
        ImageDescriptor skipImageDesc = MdwPlugin.getImageDescriptor("icons/skip.gif");
        skipItem.setImage(skipImageDesc.createImage());
        skipItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                PanelBusyIndicator pbi = new PanelBusyIndicator(getDisplay(), getCanvas());
                try {
                    pbi.busyWhile(new Runnable() {

                        public void run() {
                            Activity activity = (Activity) designerCanvasSelection;
                            Shell shell = MdwPlugin.getActiveWorkbenchWindow().getShell();
                            ActivityInstanceVO actInstVO = activity.getInstances().get(activity.getInstances().size() - 1);
                            ActivityInstanceDialog actInstDlg = new ActivityInstanceDialog(shell, activity, actInstVO, Mode.SKIP);
                            actInstDlg.open();
                        }
                    });
                } catch (InvocationTargetException ex) {
                    PluginMessages.uiError(ex, "Skip Activity", getProject());
                }
            }
        });
    }
    // view owning document
    if (isInstance() && designerCanvasSelection instanceof WorkflowProcess && (OwnerType.DOCUMENT.equals(getProcess().getProcessInstance().getOwner()) || OwnerType.TESTER.equals(getProcess().getProcessInstance().getOwner()))) {
        MenuItem docItem = new MenuItem(popupMenu, SWT.PUSH);
        docItem.setText("View Owning Document");
        ImageDescriptor docImageDesc = MdwPlugin.getImageDescriptor(ICON_DOC_GIF);
        docItem.setImage(docImageDesc.createImage());
        docItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                PanelBusyIndicator pbi = new PanelBusyIndicator(getDisplay(), getCanvas());
                try {
                    pbi.busyWhile(new Runnable() {

                        public void run() {
                            IStorage storage = new DocumentStorage(getProject(), new DocumentReference(getProcess().getProcessInstance().getOwnerId(), null));
                            final IStorageEditorInput input = new StorageEditorInput(storage);
                            final IWorkbenchPage page = MdwPlugin.getActivePage();
                            if (page != null) {
                                try {
                                    page.openEditor(input, "org.eclipse.ui.DefaultTextEditor");
                                } catch (PartInitException ex) {
                                    PluginMessages.uiError(ex, "View Document", getProject());
                                }
                            }
                        }
                    });
                } catch (InvocationTargetException ex) {
                    PluginMessages.uiError(ex, "View Document", getProject());
                }
            }
        });
    }
    return popupMenu;
}
Also used : DocumentStorage(com.centurylink.mdw.plugin.designer.storage.DocumentStorage) WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) Activity(com.centurylink.mdw.plugin.designer.model.Activity) StorageEditorInput(com.centurylink.mdw.plugin.designer.storage.StorageEditorInput) IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) Shell(org.eclipse.swt.widgets.Shell) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Menu(org.eclipse.swt.widgets.Menu) PartInitException(org.eclipse.ui.PartInitException) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) DocumentReference(com.centurylink.mdw.model.value.variable.DocumentReference) IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) ActivityInstanceDialog(com.centurylink.mdw.plugin.designer.dialogs.ActivityInstanceDialog) ActivityInstanceVO(com.centurylink.mdw.model.value.work.ActivityInstanceVO) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) IStorage(org.eclipse.core.resources.IStorage) InvocationTargetException(java.lang.reflect.InvocationTargetException) TaskInstanceVO(com.centurylink.mdw.model.value.task.TaskInstanceVO) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO) WebApp(com.centurylink.mdw.plugin.actions.WebLaunchActions.WebApp)

Example 15 with ProcessInstanceVO

use of com.centurylink.mdw.model.value.process.ProcessInstanceVO in project mdw-designer by CenturyLinkCloud.

the class ProcessCanvasWrapper method handleSelection.

private void handleSelection(MouseEvent mouseEvent) {
    Graph lProcess = null;
    if (isInstance())
        lProcess = getProcessInstancePage().getProcess();
    else
        lProcess = getFlowchartPage().getProcess();
    int mouseX = mouseEvent.getX();
    int mouseY = mouseEvent.getY();
    if (lProcess.zoom != 100) {
        mouseX = mouseX * 100 / lProcess.zoom;
        mouseY = mouseY * 100 / lProcess.zoom;
    }
    Object obj = null;
    if (mouseEvent.getID() == MouseEvent.MOUSE_PRESSED) {
        if (isInstance())
            obj = getProcessInstancePage().canvas.objectAt(lProcess, mouseX, mouseY, getProcessInstancePage().canvas.getGraphics());
        else
            obj = getFlowchartPage().canvas.objectAt(lProcess, mouseX, mouseY, getFlowchartPage().canvas.getGraphics());
    } else {
        obj = lProcess.objectAt(mouseX, mouseY, isInstance() ? getProcessInstancePage().canvas.getGraphics() : getFlowchartPage().canvas.getGraphics());
    }
    if (obj != null) {
        DesignerProxy designerProxy = getProcess().getProject().getDesignerProxy();
        // create the appropriate DesignerCanvasSelection
        if (obj instanceof Node) {
            ActivityImpl actImpl = getProcess().getProject().getActivityImpl(((Node) obj).nodet.getImplementorClassName());
            Activity activity = new Activity((Node) obj, getProcess(), actImpl);
            if (isInstance()) {
                activity.setProcessInstance(getProcess().getProcessInstance());
                List<ActivityInstanceVO> activityInstances = getProcess().getProcessInstance().getActivityInstances(activity.getId());
                if (activityInstances.isEmpty() && getProcess().getEmbeddedSubProcessInstances() != null) {
                    // try embedded subprocess instances
                    for (ProcessInstanceVO embeddedSubProcessInstance : getProcess().getEmbeddedSubProcessInstances()) activityInstances.addAll(embeddedSubProcessInstance.getActivityInstances(activity.getId()));
                }
                activity.setInstances(activityInstances);
                if (activity.isManualTask()) {
                    activity.setTaskInstances(getProcess().getMainTaskInstances(activity.getId()));
                    activity.setSubTaskInstances(getProcess().getSubTaskInstances(activity.getId()));
                }
                if (activity.isSubProcessInvoke()) {
                    // TODO: load subprocess instances when process instance
                    // id loaded (like manual task instances above)
                    List<ProcessInstanceVO> subProcessInstances = designerProxy.getSubProcessInstances(getProcess(), activity);
                    if (subProcessInstances.isEmpty() && getProcess().getEmbeddedSubProcessInstances() != null) {
                        for (ProcessInstanceVO embeddedSubProcessInstance : getProcess().getEmbeddedSubProcessInstances()) subProcessInstances.addAll(designerProxy.getSubProcessInstances(embeddedSubProcessInstance, activity));
                    }
                    activity.setSubProcessInstances(subProcessInstances);
                }
            } else {
                if (activity.getLogicalId() == null)
                    activity.setLogicalId(lProcess.generateLogicalId("A"));
                if (Node.ID_SEQUENCE.equals(getNodeIdType()) && activity.getSequenceId() == 0)
                    lProcess.assignSequenceIds();
            }
            designerCanvasSelection = activity;
        } else if (obj instanceof Link) {
            Transition transition = new Transition((Link) obj, getProcess());
            if (isInstance())
                transition.setInstances(getProcess().getProcessInstance().getTransitionInstances(transition.getId()));
            designerCanvasSelection = transition;
        } else if (obj instanceof SubGraph) {
            EmbeddedSubProcess embeddedSubProcess = new EmbeddedSubProcess((SubGraph) obj, getProcess());
            if (isInstance()) {
                embeddedSubProcess.setSubProcessInstances(((SubGraph) obj).getInstances());
            }
            designerCanvasSelection = embeddedSubProcess;
        } else if (obj instanceof TextNote) {
            TextNote textNote = (TextNote) obj;
            Note note = new Note(textNote, getProcess());
            designerCanvasSelection = note;
        } else {
            designerCanvasSelection = getProcess();
        }
    } else {
        designerCanvasSelection = getProcess();
    }
    designerCanvasSelection.addDirtyStateListener(this);
}
Also used : EmbeddedSubProcess(com.centurylink.mdw.plugin.designer.model.EmbeddedSubProcess) ActivityInstanceVO(com.centurylink.mdw.model.value.work.ActivityInstanceVO) Node(com.centurylink.mdw.designer.display.Node) Activity(com.centurylink.mdw.plugin.designer.model.Activity) Graph(com.centurylink.mdw.designer.display.Graph) SubGraph(com.centurylink.mdw.designer.display.SubGraph) ActivityImpl(com.centurylink.mdw.plugin.designer.model.ActivityImpl) Note(com.centurylink.mdw.plugin.designer.model.Note) TextNote(com.centurylink.mdw.designer.display.TextNote) Transition(com.centurylink.mdw.plugin.designer.model.Transition) JSONObject(org.json.JSONObject) TextNote(com.centurylink.mdw.designer.display.TextNote) SubGraph(com.centurylink.mdw.designer.display.SubGraph) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO) Link(com.centurylink.mdw.designer.display.Link)

Aggregations

ProcessInstanceVO (com.centurylink.mdw.model.value.process.ProcessInstanceVO)40 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)10 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)9 IOException (java.io.IOException)9 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)7 HashMap (java.util.HashMap)7 DesignerDataAccess (com.centurylink.mdw.designer.DesignerDataAccess)6 ActivityInstanceVO (com.centurylink.mdw.model.value.work.ActivityInstanceVO)6 ArrayList (java.util.ArrayList)6 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)5 ProcessList (com.centurylink.mdw.model.value.process.ProcessList)5 XmlException (org.apache.xmlbeans.XmlException)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 JSONException (org.json.JSONException)5 Graph (com.centurylink.mdw.designer.display.Graph)4 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)4 Menu (org.eclipse.swt.widgets.Menu)4 MenuItem (org.eclipse.swt.widgets.MenuItem)4 PartInitException (org.eclipse.ui.PartInitException)4