use of org.knime.core.ui.node.workflow.NodeContainerUI in project knime-core by knime.
the class NodeContainerEditPart method openNodeDialog.
/**
* Opens the node's dialog (also metanode dialogs).
*
* @since 2.6
*/
public void openNodeDialog() {
final NodeContainerUI container = (NodeContainerUI) getModel();
// if this node does not have a dialog
if (!container.hasDialog()) {
LOGGER.debug("No dialog for " + container.getNameWithID());
return;
}
final Shell shell = Display.getCurrent().getActiveShell();
shell.setEnabled(false);
try {
if (container.hasDataAwareDialogPane() && !container.isAllInputDataAvailable() && container.canExecuteUpToHere()) {
IPreferenceStore store = KNIMEUIPlugin.getDefault().getPreferenceStore();
String prefPrompt = store.getString(PreferenceConstants.P_EXEC_NODES_DATA_AWARE_DIALOGS);
boolean isExecuteUpstreamNodes;
if (MessageDialogWithToggle.PROMPT.equals(prefPrompt)) {
int returnCode = MessageDialogWithToggle.openYesNoCancelQuestion(shell, "Execute upstream nodes", "The " + container.getName() + " node can be configured using the full input data.\n\n" + "Execute upstream nodes?", "Remember my decision", false, store, PreferenceConstants.P_EXEC_NODES_DATA_AWARE_DIALOGS).getReturnCode();
if (returnCode == Window.CANCEL) {
return;
} else if (returnCode == IDialogConstants.YES_ID) {
isExecuteUpstreamNodes = true;
} else {
isExecuteUpstreamNodes = false;
}
} else if (MessageDialogWithToggle.ALWAYS.equals(prefPrompt)) {
isExecuteUpstreamNodes = true;
} else {
isExecuteUpstreamNodes = false;
}
if (isExecuteUpstreamNodes) {
try {
PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Future<Void> submit = DATA_AWARE_DIALOG_EXECUTOR.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
container.getParent().executePredecessorsAndWait(container.getID());
return null;
}
});
while (!submit.isDone()) {
if (monitor.isCanceled()) {
submit.cancel(true);
throw new InterruptedException();
}
try {
submit.get(300, TimeUnit.MILLISECONDS);
} catch (ExecutionException e) {
LOGGER.error("Error while waiting for execution to finish", e);
} catch (InterruptedException e) {
submit.cancel(true);
throw e;
} catch (TimeoutException e) {
// do another round
}
}
}
});
} catch (InvocationTargetException e) {
String error = "Exception while waiting for completion of execution";
LOGGER.warn(error, e);
ErrorDialog.openError(shell, "Failed opening dialog", error, new Status(IStatus.ERROR, KNIMEEditorPlugin.PLUGIN_ID, error, e));
} catch (InterruptedException e) {
return;
}
}
}
//
try {
if (Wrapper.wraps(container, NodeContainer.class)) {
WrappedNodeDialog dlg = new WrappedNodeDialog(shell, Wrapper.unwrapNC(container));
dlg.open();
}
} catch (NotConfigurableException ex) {
MessageBox mb = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
mb.setText("Dialog cannot be opened");
mb.setMessage("The dialog cannot be opened for the following" + " reason:\n" + ex.getMessage());
mb.open();
} catch (Throwable t) {
LOGGER.error("The dialog pane for node '" + container.getNameWithID() + "' has thrown a '" + t.getClass().getSimpleName() + "'. That is most likely an implementation error.", t);
}
} finally {
shell.setEnabled(true);
}
}
use of org.knime.core.ui.node.workflow.NodeContainerUI in project knime-core by knime.
the class NodeContainerEditPart method getModelChildren.
/**
* Returns the model children (= the ports) of the <code>NodeContainer</code> managed by this edit part. Note that
* in/out ports are handled the same.
*
* {@inheritDoc}
*/
@Override
protected List<NodePortUI> getModelChildren() {
ArrayList<NodePortUI> ports = new ArrayList<NodePortUI>();
NodeContainerUI container = getNodeContainer();
for (int i = 0; i < container.getNrInPorts(); i++) {
ports.add(container.getInPort(i));
}
for (int i = 0; i < container.getNrOutPorts(); i++) {
ports.add(container.getOutPort(i));
}
return ports;
}
use of org.knime.core.ui.node.workflow.NodeContainerUI 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.ui.node.workflow.NodeContainerUI in project knime-core by knime.
the class NodeContainerEditPart method activate.
/**
* {@inheritDoc}
*/
@Override
public void activate() {
super.activate();
initFigure();
// If we already have extra info, init figure now
NodeContainerUI cont = getNodeContainer();
NodeUIInformation uiInfo = cont.getUIInformation();
if (uiInfo != null) {
// takes over all info except the coordinates
updateFigureFromUIinfo(uiInfo);
} else {
// set a new empty UI info
NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(0, 0, -1, -1).build();
// not yet a listener -- no event received
cont.setUIInformation(info);
}
// need to notify node annotation about our presence
// the annotation is a child that's added first (placed in background)
// to the viewer - so it doesn't know about the correct location yet
NodeAnnotation nodeAnnotation = cont.getNodeAnnotation();
NodeAnnotationEditPart nodeAnnotationEditPart = (NodeAnnotationEditPart) getViewer().getEditPartRegistry().get(nodeAnnotation);
if (nodeAnnotationEditPart != null) {
nodeAnnotationEditPart.nodeUIInformationChanged(null);
}
IPreferenceStore store = KNIMEUIPlugin.getDefault().getPreferenceStore();
store.addPropertyChangeListener(this);
// listen to node container (= model object)
cont.addNodeStateChangeListener(this);
cont.addNodeMessageListener(this);
cont.addProgressListener(this);
cont.addUIInformationListener(this);
cont.addNodePropertyChangedListener(this);
addEditPartListener(this);
updateJobManagerIcon();
checkMetaNodeTemplateIcon();
checkMetaNodeLockIcon();
checkNodeLockIcon();
// set the active (or disabled) state
((NodeContainerFigure) getFigure()).setStateFromNC(cont);
// set the node message
updateNodeMessage();
callHideNodeName();
}
use of org.knime.core.ui.node.workflow.NodeContainerUI in project knime-core by knime.
the class ExecuteAction method internalCalculateEnabled.
/**
* @return always <code>true</code>, as the WFM tries to execute as much
* as possible
* @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
*/
@Override
protected boolean internalCalculateEnabled() {
NodeContainerEditPart[] parts = getSelectedParts(NodeContainerEditPart.class);
// enable if we have at least one executable node in our selection
WorkflowManager wm = getEditor().getWorkflowManager().orElse(null);
if (wm == null) {
// fixes NPE when shutting down
return false;
}
for (int i = 0; i < parts.length; i++) {
NodeContainerUI nc = parts[i].getNodeContainer();
if (wm.canExecuteNode(nc.getID())) {
return true;
}
}
return false;
}
Aggregations