Search in sources :

Example 1 with WrappedNodeDialog

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);
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NotConfigurableException(org.knime.core.node.NotConfigurableException) Point(org.eclipse.draw2d.geometry.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) Callable(java.util.concurrent.Callable) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) MessageBox(org.eclipse.swt.widgets.MessageBox) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Future(java.util.concurrent.Future) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) WrappedNodeDialog(org.knime.workbench.ui.wrapper.WrappedNodeDialog)

Example 2 with WrappedNodeDialog

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;
    }
}
Also used : NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) WrappedNodeDialog(org.knime.workbench.ui.wrapper.WrappedNodeDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

MessageBox (org.eclipse.swt.widgets.MessageBox)2 WrappedNodeDialog (org.knime.workbench.ui.wrapper.WrappedNodeDialog)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 TimeoutException (java.util.concurrent.TimeoutException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Point (org.eclipse.draw2d.geometry.Point)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 Shell (org.eclipse.swt.widgets.Shell)1 NotConfigurableException (org.knime.core.node.NotConfigurableException)1 NodeID (org.knime.core.node.workflow.NodeID)1 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)1 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)1 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)1 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)1