use of org.knime.workbench.ui.wrapper.WrappedNodeDialog 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.workbench.ui.wrapper.WrappedNodeDialog in project knime-core by knime.
the class DropNodeCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
// Add node to workflow and get the container
WorkflowManager hostWFM = getHostWFM();
try {
NodeID id = hostWFM.addNodeAndApplyContext(m_factory, m_dropContext);
m_container = hostWFM.getNodeContainer(id);
// create extra info and set it
NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(m_location.x, m_location.y, -1, -1).setHasAbsoluteCoordinates(false).setSnapToGrid(m_snapToGrid).setIsDropLocation(true).build();
m_container.setUIInformation(info);
// Open the dialog. Some times.
if (m_container instanceof SingleNodeContainer && m_container.getNodeContainerState().isIdle() && m_container.hasDialog() && // and has only a variable in port
m_container.getNrInPorts() == 1) {
// if not executable and has a dialog and is fully connected
// This is embedded in a special JFace wrapper dialog
//
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
WrappedNodeDialog dlg = new WrappedNodeDialog(Display.getCurrent().getActiveShell(), m_container);
dlg.open();
} catch (Exception e) {
// they need to open it manually then
}
}
});
}
} catch (Throwable t) {
// if fails notify the user
LOGGER.debug("Node cannot be created.", t);
MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_WARNING | SWT.OK);
mb.setText("Node cannot be created.");
mb.setMessage("The selected node could not be created " + "due to the following reason:\n" + t.getMessage());
mb.open();
return;
}
}
Aggregations