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()])));
}
}
}
Aggregations