Search in sources :

Example 26 with MessageBox

use of org.eclipse.swt.widgets.MessageBox in project knime-core by knime.

the class CancelAllAction method runOnNodes.

/**
 * This cancels all running jobs.
 *
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
    mb.setText("Confirm cancel all...");
    mb.setMessage("Do you really want to cancel all running node(s) ?");
    if (mb.open() != SWT.YES) {
        return;
    }
    LOGGER.debug("(Cancel all)  cancel all running jobs.");
    WorkflowManager manager = getManager();
    manager.getParent().cancelExecution(manager);
    try {
        // Give focus to the editor again. Otherwise the actions (selection)
        // is not updated correctly.
        getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
    } catch (Exception e) {
    // ignore
    }
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 27 with MessageBox

use of org.eclipse.swt.widgets.MessageBox in project knime-core by knime.

the class ExpandMetaNodeAction method runOnNodes.

/**
 * Expand metanode!
 *
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    if (nodeParts.length < 1) {
        return;
    }
    LOGGER.debug("Creating 'Expand MetaNode' job for " + nodeParts.length + " node(s)...");
    try {
        WorkflowManager manager = getManager();
        WorkflowManagerUI metaNode = (WorkflowManagerUI) nodeParts[0].getNodeContainer();
        if (!Wrapper.unwrapWFM(metaNode).unlock(new GUIWorkflowCipherPrompt())) {
            return;
        }
        // reset the metanode
        if (manager.canResetNode(metaNode.getID())) {
            // yes: ask if we can reset, otherwise bail
            MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.OK | SWT.CANCEL);
            mb.setMessage("Executed Nodes inside Metanode will be reset" + " - are you sure?");
            mb.setText("Reset Executed Nodes");
            int dialogreturn = mb.open();
            if (dialogreturn == SWT.CANCEL) {
                return;
            }
            // perform reset
            if (manager.canResetNode(metaNode.getID())) {
                manager.resetAndConfigureNode(metaNode.getID());
            }
        }
        String res = manager.canExpandMetaNode(metaNode.getID());
        if (res != null) {
            throw new IllegalArgumentException(res);
        }
        ExpandMetaNodeCommand emnc = new ExpandMetaNodeCommand(manager, metaNode.getID(), getEditor());
        execute(emnc);
    } catch (IllegalArgumentException e) {
        MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ERROR);
        mb.setMessage("Sorry, expanding Metanode failed: " + e.getMessage());
        mb.setText("Expand failed");
        mb.open();
    }
    try {
        // Give focus to the editor again. Otherwise the actions (selection)
        // is not updated correctly.
        getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
    } catch (Exception e) {
    // ignore
    }
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) GUIWorkflowCipherPrompt(org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt) MessageBox(org.eclipse.swt.widgets.MessageBox) ExpandMetaNodeCommand(org.knime.workbench.editor2.commands.ExpandMetaNodeCommand)

Example 28 with MessageBox

use of org.eclipse.swt.widgets.MessageBox 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 29 with MessageBox

use of org.eclipse.swt.widgets.MessageBox in project knime-core by knime.

the class ExpandSubNodeAction method runOnNodes.

/**
 * Expand sub node!
 *
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    if (nodeParts.length < 1) {
        return;
    }
    LOGGER.debug("Creating 'Expand Wrapped Metanode' job for " + nodeParts.length + " node(s)...");
    try {
        WorkflowManager manager = getManager();
        SubNodeContainer subNode = Wrapper.unwrap(nodeParts[0].getNodeContainer(), SubNodeContainer.class);
        if (!subNode.getWorkflowManager().unlock(new GUIWorkflowCipherPrompt())) {
            return;
        }
        // reset the metanode
        if (manager.canResetNode(subNode.getID())) {
            // yes: ask if we can reset, otherwise bail
            MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.OK | SWT.CANCEL);
            mb.setMessage("Executed Nodes inside Wrapped Metanode will be reset" + " - are you sure?");
            mb.setText("Reset Executed Nodes");
            int dialogreturn = mb.open();
            if (dialogreturn == SWT.CANCEL) {
                return;
            }
            // perform reset
            if (manager.canResetNode(subNode.getID())) {
                manager.resetAndConfigureNode(subNode.getID());
            }
        }
        String res = manager.canExpandSubNode(subNode.getID());
        if (res != null) {
            throw new IllegalArgumentException(res);
        }
        ExpandSubNodeCommand emnc = new ExpandSubNodeCommand(manager, subNode.getID(), getEditor());
        execute(emnc);
    } catch (IllegalArgumentException e) {
        MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ERROR);
        mb.setMessage("Expanding Wrapped Metanode failed: " + e.getMessage());
        mb.setText("Expand failed");
        mb.open();
    }
    try {
        // Give focus to the editor again. Otherwise the actions (selection)
        // is not updated correctly.
        getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
    } catch (Exception e) {
    // ignore
    }
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) ExpandSubNodeCommand(org.knime.workbench.editor2.commands.ExpandSubNodeCommand) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) GUIWorkflowCipherPrompt(org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 30 with MessageBox

use of org.eclipse.swt.widgets.MessageBox in project knime-core by knime.

the class OpenViewAction method run.

/**
 * {@inheritDoc}
 */
@Override
public void run() {
    LOGGER.debug("Open Node View " + m_nodeContainer.getName() + " (#" + m_index + ")");
    try {
        final String title = m_nodeContainer.getViewName(m_index) + " - " + m_nodeContainer.getDisplayLabel();
        final java.awt.Rectangle knimeWindowBounds = OpenViewAction.getAppBoundsAsAWTRec();
        SwingUtilities.invokeLater(() -> Node.invokeOpenView(m_nodeContainer.getView(m_index), title, knimeWindowBounds));
    } catch (Throwable t) {
        MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_ERROR | SWT.OK);
        mb.setText("View cannot be opened");
        mb.setMessage("The view cannot be opened for the following reason:\n" + t.getMessage());
        mb.open();
        LOGGER.error("The view for node '" + m_nodeContainer.getNameWithID() + "' has thrown a '" + t.getClass().getSimpleName() + "'. That is most likely an " + "implementation error.", t);
    }
}
Also used : MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

MessageBox (org.eclipse.swt.widgets.MessageBox)99 Shell (org.eclipse.swt.widgets.Shell)17 ArrayList (java.util.ArrayList)13 File (java.io.File)11 IOException (java.io.IOException)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 GridData (org.eclipse.swt.layout.GridData)9 GridLayout (org.eclipse.swt.layout.GridLayout)9 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)9 Point (org.eclipse.swt.graphics.Point)8 Button (org.eclipse.swt.widgets.Button)8 Display (org.eclipse.swt.widgets.Display)8 Composite (org.eclipse.swt.widgets.Composite)7 FileDialog (org.eclipse.swt.widgets.FileDialog)7 Label (org.eclipse.swt.widgets.Label)7 List (java.util.List)6 SWTError (org.eclipse.swt.SWTError)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 SelectionListener (org.eclipse.swt.events.SelectionListener)6 SWT (org.eclipse.swt.SWT)5