Search in sources :

Example 16 with NodeContainerUI

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);
    }
}
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 17 with NodeContainerUI

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;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) ArrayList(java.util.ArrayList) NodePortUI(org.knime.core.ui.node.workflow.NodePortUI) Point(org.eclipse.draw2d.geometry.Point)

Example 18 with NodeContainerUI

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);
        }
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) NodeContainerTemplate(org.knime.core.node.workflow.NodeContainerTemplate) Image(org.eclipse.swt.graphics.Image) MetaNodeTemplateInformation(org.knime.core.node.workflow.MetaNodeTemplateInformation) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure)

Example 19 with NodeContainerUI

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();
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure)

Example 20 with NodeContainerUI

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;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Aggregations

NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)59 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)28 SubNodeContainerUI (org.knime.core.ui.node.workflow.SubNodeContainerUI)17 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)16 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)10 NodeContainerFigure (org.knime.workbench.editor2.figures.NodeContainerFigure)9 SingleNodeContainerUI (org.knime.core.ui.node.workflow.SingleNodeContainerUI)8 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)7 HashMap (java.util.HashMap)5 Point (org.eclipse.draw2d.geometry.Point)5 Image (org.eclipse.swt.graphics.Image)5 ConnectionUIInformation (org.knime.core.node.workflow.ConnectionUIInformation)5 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)5 NodeID (org.knime.core.node.workflow.NodeID)5 ArrayList (java.util.ArrayList)4 EditPart (org.eclipse.gef.EditPart)4 LoopEndNode (org.knime.core.node.workflow.LoopEndNode)4 IContainer (org.eclipse.core.resources.IContainer)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3