Search in sources :

Example 1 with NodeContainerTemplate

use of org.knime.core.node.workflow.NodeContainerTemplate in project knime-core by knime.

the class CheckUpdateMetaNodeLinkAction method runInSWT.

/**
 * {@inheritDoc}
 */
@Override
public void runInSWT() {
    List<NodeID> candidateList = getMetaNodesToCheck();
    final Shell shell = Display.getCurrent().getActiveShell();
    IWorkbench wb = PlatformUI.getWorkbench();
    IProgressService ps = wb.getProgressService();
    LOGGER.debug("Checking for updates for " + candidateList.size() + " node link(s)...");
    CheckUpdateRunnableWithProgress runner = new CheckUpdateRunnableWithProgress(getManager(), candidateList);
    try {
        ps.busyCursorWhile(runner);
    } catch (InvocationTargetException e) {
        LOGGER.warn("Failed to check for updates: " + e.getMessage(), e);
        return;
    } catch (InterruptedException e) {
        return;
    }
    List<NodeID> updateList = runner.getUpdateList();
    Status status = runner.getStatus();
    if (status.getSeverity() == IStatus.ERROR || status.getSeverity() == IStatus.WARNING) {
        ErrorDialog.openError(Display.getDefault().getActiveShell(), null, "Errors while checking for " + "updates on node links", status);
        if (candidateList.size() == 1) {
            /* As only one node is selected and its update failed,
                 * there is nothing else to do. */
            return;
        }
    }
    // find nodes that will be reset as part of the update
    int nodesToResetCount = 0;
    for (NodeID id : updateList) {
        NodeContainerTemplate templateNode = (NodeContainerTemplate) getManager().findNodeContainer(id);
        // TODO problematic with through-connections
        if (templateNode.containsExecutedNode()) {
            nodesToResetCount += 1;
        }
    }
    if (updateList.isEmpty()) {
        if (m_showInfoMsgIfNoUpdateAvail) {
            MessageDialog.openInformation(shell, "Node Update", "No updates available");
        } else {
            LOGGER.info("No updates available (" + candidateList.size() + " node link(s))");
        }
    } else {
        boolean isSingle = updateList.size() == 1;
        String title = "Update Node" + (isSingle ? "" : "s");
        StringBuilder messageBuilder = new StringBuilder();
        messageBuilder.append("Update available for ");
        if (isSingle && candidateList.size() == 1) {
            messageBuilder.append("node \"");
            messageBuilder.append(getManager().findNodeContainer(candidateList.get(0)).getNameWithID());
            messageBuilder.append("\".");
        } else if (isSingle) {
            messageBuilder.append("one node.");
        } else {
            messageBuilder.append(updateList.size());
            messageBuilder.append(" nodes.");
        }
        messageBuilder.append("\n\n");
        if (nodesToResetCount > 0) {
            messageBuilder.append("Reset nodes and update now?");
        } else {
            messageBuilder.append("Update now?");
        }
        String message = messageBuilder.toString();
        if (MessageDialog.openQuestion(shell, title, message)) {
            LOGGER.debug("Running update for " + updateList.size() + " node(s): " + updateList);
            execute(new UpdateMetaNodeLinkCommand(getManager(), updateList.toArray(new NodeID[updateList.size()])));
        }
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) UpdateMetaNodeLinkCommand(org.knime.workbench.editor2.commands.UpdateMetaNodeLinkCommand) InvocationTargetException(java.lang.reflect.InvocationTargetException) IWorkbench(org.eclipse.ui.IWorkbench) Shell(org.eclipse.swt.widgets.Shell) NodeContainerTemplate(org.knime.core.node.workflow.NodeContainerTemplate) IProgressService(org.eclipse.ui.progress.IProgressService) NodeID(org.knime.core.node.workflow.NodeID)

Example 2 with NodeContainerTemplate

use of org.knime.core.node.workflow.NodeContainerTemplate in project knime-core by knime.

the class CheckUpdateMetaNodeLinkAction method getMetaNodesToCheck.

protected List<NodeID> getMetaNodesToCheck() {
    List<NodeID> list = new ArrayList<NodeID>();
    for (NodeContainerEditPart p : getSelectedParts(NodeContainerEditPart.class)) {
        NodeContainerUI model = p.getNodeContainer();
        if (Wrapper.wraps(model, NodeContainerTemplate.class)) {
            NodeContainerTemplate tnc = Wrapper.unwrap(model, NodeContainerTemplate.class);
            if (tnc.getTemplateInformation().getRole().equals(Role.Link)) {
                if (!getManager().canUpdateMetaNodeLink(tnc.getID())) {
                    return Collections.emptyList();
                }
                list.add(tnc.getID());
            }
            list.addAll(getNCTemplatesToCheck(tnc));
        }
    }
    return list;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) NodeContainerTemplate(org.knime.core.node.workflow.NodeContainerTemplate) NodeID(org.knime.core.node.workflow.NodeID) ArrayList(java.util.ArrayList)

Example 3 with NodeContainerTemplate

use of org.knime.core.node.workflow.NodeContainerTemplate in project knime-core by knime.

the class NodeContainerEditPart method checkMetaNodeTemplateIcon.

private void checkMetaNodeTemplateIcon() {
    NodeContainerUI nc = getNodeContainer();
    MetaNodeTemplateInformation templInfo = null;
    if (Wrapper.wraps(nc, NodeContainerTemplate.class)) {
        NodeContainerTemplate t = Wrapper.unwrap(nc, NodeContainerTemplate.class);
        templInfo = t.getTemplateInformation();
    }
    if (templInfo != null) {
        NodeContainerFigure fig = (NodeContainerFigure) getFigure();
        switch(templInfo.getRole()) {
            case Link:
                Image i;
                switch(templInfo.getUpdateStatus()) {
                    case HasUpdate:
                        i = META_NODE_LINK_RED_ICON;
                        break;
                    case UpToDate:
                        i = META_NODE_LINK_GREEN_ICON;
                        break;
                    default:
                        i = META_NODE_LINK_PROBLEM_ICON;
                }
                fig.setMetaNodeLinkIcon(i);
                break;
            default:
                fig.setMetaNodeLinkIcon(null);
        }
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) NodeContainerTemplate(org.knime.core.node.workflow.NodeContainerTemplate) Image(org.eclipse.swt.graphics.Image) MetaNodeTemplateInformation(org.knime.core.node.workflow.MetaNodeTemplateInformation) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure)

Example 4 with NodeContainerTemplate

use of org.knime.core.node.workflow.NodeContainerTemplate in project knime-core by knime.

the class UpdateMetaNodeTemplateRunnable method run.

/**
 * {@inheritDoc}
 */
@Override
public void run(final IProgressMonitor pm) throws InterruptedException {
    m_newIDs = new ArrayList<NodeID>();
    m_undoPersistors = new ArrayList<WorkflowPersistor>();
    // create progress monitor
    ProgressHandler progressHandler = new ProgressHandler(pm, 101, "Updating node links...");
    final CheckCancelNodeProgressMonitor progressMonitor = new CheckCancelNodeProgressMonitor(pm);
    progressMonitor.addProgressListener(progressHandler);
    final Display d = Display.getDefault();
    ExecutionMonitor exec = new ExecutionMonitor(progressMonitor);
    IStatus[] stats = new IStatus[m_ids.length];
    for (int i = 0; i < m_ids.length; i++) {
        NodeID id = m_ids[i];
        NodeContainerTemplate tnc = (NodeContainerTemplate) m_parentWFM.findNodeContainer(id);
        LOGGER.debug("Updating " + tnc.getNameWithID() + " from " + tnc.getTemplateInformation().getSourceURI());
        ExecutionMonitor subExec = exec.createSubProgress(1.0 / m_ids.length);
        String progMsg = "Node Link \"" + tnc.getNameWithID() + "\"";
        exec.setMessage(progMsg);
        GUIWorkflowLoadHelper loadHelper = new GUIWorkflowLoadHelper(d, progMsg, null, null, null, true);
        NodeContainerTemplateLinkUpdateResult updateMetaNodeLinkResult;
        try {
            updateMetaNodeLinkResult = tnc.getParent().updateMetaNodeLink(id, subExec, loadHelper);
        } catch (CanceledExecutionException e) {
            String message = "Node update canceled";
            LOGGER.warn(message, e);
            throw new InterruptedException(message);
        }
        WorkflowPersistor p = updateMetaNodeLinkResult.getUndoPersistor();
        if (p != null) {
            // no error
            m_newIDs.add(updateMetaNodeLinkResult.getNCTemplate().getID());
            m_undoPersistors.add(p);
        }
        // metanodes don't have data
        // data load errors are unexpected but OK
        IStatus status = createStatus(updateMetaNodeLinkResult, true);
        subExec.setProgress(1.0);
        switch(status.getSeverity()) {
            case IStatus.OK:
                break;
            case IStatus.WARNING:
                logPreseveLineBreaks("Warnings during load: " + updateMetaNodeLinkResult.getFilteredError("", LoadResultEntryType.Warning), false);
                break;
            default:
                logPreseveLineBreaks("Errors during load: " + updateMetaNodeLinkResult.getFilteredError("", LoadResultEntryType.Warning), true);
        }
        stats[i] = status;
    }
    pm.done();
    final IStatus status = createMultiStatus("Update node links", stats);
    final String message;
    switch(status.getSeverity()) {
        case IStatus.OK:
            message = "No problems during node link update.";
            break;
        case IStatus.WARNING:
            message = "Warnings during node link update";
            break;
        default:
            message = "Errors during node link update";
    }
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            // will not open if status is OK.
            ErrorDialog.openError(Display.getDefault().getActiveShell(), "Update Node Links", message, status);
        }
    });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) WorkflowPersistor(org.knime.core.node.workflow.WorkflowPersistor) NodeContainerTemplateLinkUpdateResult(org.knime.core.node.workflow.WorkflowPersistor.NodeContainerTemplateLinkUpdateResult) NodeContainerTemplate(org.knime.core.node.workflow.NodeContainerTemplate) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) NodeID(org.knime.core.node.workflow.NodeID) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) Display(org.eclipse.swt.widgets.Display)

Example 5 with NodeContainerTemplate

use of org.knime.core.node.workflow.NodeContainerTemplate in project knime-core by knime.

the class CheckUpdateMetaNodeLinkAction method getNCTemplatesToCheck.

private List<NodeID> getNCTemplatesToCheck(final NodeContainerTemplate template) {
    List<NodeID> list = new ArrayList<NodeID>();
    for (NodeContainer nc : template.getNodeContainers()) {
        if (nc instanceof NodeContainerTemplate) {
            NodeContainerTemplate tnc = (NodeContainerTemplate) nc;
            if (tnc.getTemplateInformation().getRole().equals(Role.Link)) {
                if (!getManager().canUpdateMetaNodeLink(tnc.getID())) {
                    return Collections.emptyList();
                }
                list.add(tnc.getID());
            }
            list.addAll(getNCTemplatesToCheck(tnc));
        }
    }
    return list;
}
Also used : NodeContainerTemplate(org.knime.core.node.workflow.NodeContainerTemplate) NodeID(org.knime.core.node.workflow.NodeID) ArrayList(java.util.ArrayList) NodeContainer(org.knime.core.node.workflow.NodeContainer)

Aggregations

NodeContainerTemplate (org.knime.core.node.workflow.NodeContainerTemplate)7 NodeID (org.knime.core.node.workflow.NodeID)6 ArrayList (java.util.ArrayList)2 IStatus (org.eclipse.core.runtime.IStatus)2 NodeContainer (org.knime.core.node.workflow.NodeContainer)2 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)2 WorkflowPersistor (org.knime.core.node.workflow.WorkflowPersistor)2 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 Status (org.eclipse.core.runtime.Status)1 Image (org.eclipse.swt.graphics.Image)1 Display (org.eclipse.swt.widgets.Display)1 Shell (org.eclipse.swt.widgets.Shell)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IProgressService (org.eclipse.ui.progress.IProgressService)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)1 MetaNodeTemplateInformation (org.knime.core.node.workflow.MetaNodeTemplateInformation)1 NodeContainerTemplateLinkUpdateResult (org.knime.core.node.workflow.WorkflowPersistor.NodeContainerTemplateLinkUpdateResult)1