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