Search in sources :

Example 1 with UpdateMetaNodeLinkCommand

use of org.knime.workbench.editor2.commands.UpdateMetaNodeLinkCommand 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)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 Status (org.eclipse.core.runtime.Status)1 Shell (org.eclipse.swt.widgets.Shell)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IProgressService (org.eclipse.ui.progress.IProgressService)1 NodeContainerTemplate (org.knime.core.node.workflow.NodeContainerTemplate)1 NodeID (org.knime.core.node.workflow.NodeID)1 UpdateMetaNodeLinkCommand (org.knime.workbench.editor2.commands.UpdateMetaNodeLinkCommand)1