Search in sources :

Example 31 with MessageBox

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

the class CollapseMetaNodeCommand method create.

/**
 * @param manager
 * @param nodeParts
 * @param annoParts
 * @param encapsulateAsSubnode TODO
 * @return
 */
public static Optional<CollapseMetaNodeCommand> create(final WorkflowManager manager, final NodeContainerEditPart[] nodeParts, final AnnotationEditPart[] annoParts, final boolean encapsulateAsSubnode) {
    NodeID[] nodeIds = new NodeID[nodeParts.length];
    for (int i = 0; i < nodeParts.length; i++) {
        nodeIds[i] = nodeParts[i].getNodeContainer().getID();
    }
    WorkflowAnnotation[] annos = AnnotationEditPart.extractWorkflowAnnotations(annoParts);
    try {
        // before testing anything, let's see if we should reset
        // the selected nodes:
        List<NodeID> resetableIDs = new ArrayList<NodeID>();
        for (NodeID id : nodeIds) {
            if (manager.canResetNode(id)) {
                resetableIDs.add(id);
            }
        }
        if (resetableIDs.size() > 0) {
            // found some: ask if we can reset, otherwise bail
            MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.OK | SWT.CANCEL);
            mb.setMessage("Executed Nodes will be reset - are you sure?");
            mb.setText("Reset Executed Nodes");
            int dialogreturn = mb.open();
            if (dialogreturn == SWT.CANCEL) {
                return Optional.empty();
            }
        } else {
            // if there are no resetable nodes we can check if
            // we can collapse - otherwise we need to first reset
            // those nodes (which we don't want to do before we
            // have not gathered all info - and allowed the user
            // to cancel the operation!)
            String res = manager.canCollapseNodesIntoMetaNode(nodeIds);
            if (res != null) {
                throw new IllegalArgumentException(res);
            }
        }
        // let the user enter a name
        String name = "Metanode";
        InputDialog idia = new InputDialog(Display.getCurrent().getActiveShell(), "Enter Name of Metanode", "Enter name of Metanode:", name, null);
        int dialogreturn = idia.open();
        if (dialogreturn == Window.CANCEL) {
            return Optional.empty();
        }
        if (dialogreturn == Window.OK) {
            if (resetableIDs.size() > 0) {
                // and skip the ones that were already reset in passing.
                for (NodeID id : resetableIDs) {
                    if (manager.canResetNode(id)) {
                        manager.resetAndConfigureNode(id);
                    }
                }
            }
            // check if there is another reason why we cannot collapse
            String res = manager.canCollapseNodesIntoMetaNode(nodeIds);
            if (res != null) {
                throw new IllegalArgumentException(res);
            }
            name = idia.getValue();
            return Optional.of(new CollapseMetaNodeCommand(manager, nodeIds, annos, name, encapsulateAsSubnode));
        }
    } catch (IllegalArgumentException e) {
        MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ERROR);
        final String error = "Collapsing to metanode failed: " + e.getMessage();
        LOGGER.error(error, e);
        mb.setMessage(error);
        mb.setText("Collapse failed");
        mb.open();
    }
    return Optional.empty();
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) NodeID(org.knime.core.node.workflow.NodeID) ArrayList(java.util.ArrayList) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 32 with MessageBox

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

Example 33 with MessageBox

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

the class CreateNewConnectedNodeCommand method createNewNode.

/**
 * {@inheritDoc}
 */
@Override
protected NodeID createNewNode() {
    // Add node to workflow and get the container
    NodeID newID = null;
    WorkflowManager hostWFM = getHostWFM();
    try {
        newID = hostWFM.createAndAddNode(m_factory);
        NodeTimer.GLOBAL_TIMER.addNodeCreation(hostWFM.getNodeContainer(newID));
    } 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 node could not be created " + "due to the following reason:\n" + t.getMessage());
        mb.open();
        return null;
    }
    return newID;
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 34 with MessageBox

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

the class AbstractP2Action method checkSDKAndReadOnly.

/**
 * Checks whether the current instance is run from an SDK and if the configuration area is writable.
 *
 * @return <code>true</code> if the action should continue, <code>false</code> if it should be aborted
 */
protected final boolean checkSDKAndReadOnly() {
    final ProvisioningUI provUI = ProvisioningUI.getDefaultUI();
    if (provUI.getRepositoryTracker() == null) {
        MessageBox mbox = new MessageBox(ProvUI.getDefaultParentShell(), SWT.ICON_WARNING | SWT.OK);
        mbox.setText("Action impossible");
        mbox.setMessage("It seems you are running KNIME from an SDK. " + "Installing extension is not possible in this case.");
        mbox.open();
        return false;
    }
    String installLocation = Platform.getInstallLocation().getURL().toString();
    String configurationLocation = Platform.getConfigurationLocation().getURL().toString();
    if (!configurationLocation.contains(installLocation)) {
        MessageBox mbox = new MessageBox(ProvUI.getDefaultParentShell(), SWT.ICON_WARNING | SWT.YES | SWT.NO);
        mbox.setText("Permission problem");
        mbox.setMessage("Your KNIME installation directory seems to be " + "read-only, maybe because KNIME was installed by a " + "different user. Installing extensions or updating KNIME " + "may cause problems. Do you really want to continue?");
        return (mbox.open() == SWT.YES);
    }
    return true;
}
Also used : ProvisioningUI(org.eclipse.equinox.p2.ui.ProvisioningUI) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 35 with MessageBox

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

the class AbstractWrappedDialog method showWarningMessage.

/**
 * Shows the latest error message of the dialog in a MessageBox.
 *
 * @param message The error string.
 */
protected void showWarningMessage(final String message) {
    MessageBox mb = new MessageBox(getShell(), SWT.ICON_WARNING);
    mb.setText("Warning");
    mb.setMessage(message != null ? message : "(no message)");
    mb.open();
}
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