Search in sources :

Example 1 with WizardNode

use of org.knime.core.node.wizard.WizardNode in project knime-core by knime.

the class NodeUsageComposite method createNodeGrid.

private void createNodeGrid(final SubNodeContainer subNodeContainer, @SuppressWarnings("rawtypes") final Map<NodeIDSuffix, WizardNode> viewNodes) {
    ScrolledComposite scrollPane = new ScrolledComposite(this, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    scrollPane.setExpandHorizontal(true);
    scrollPane.setExpandVertical(true);
    Composite composite = new Composite(scrollPane, SWT.NONE);
    scrollPane.setContent(composite);
    scrollPane.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    composite.setLayout(new GridLayout(3, false));
    composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
    // titles
    new Composite(composite, SWT.NONE);
    /* Placeholder */
    Label wizardLabel = new Label(composite, SWT.CENTER);
    FontData fontData = wizardLabel.getFont().getFontData()[0];
    Font boldFont = new Font(Display.getCurrent(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
    wizardLabel.setText("WebPortal /\nWrapped Metanode View");
    wizardLabel.setFont(boldFont);
    Label dialogLabel = new Label(composite, SWT.CENTER);
    dialogLabel.setText("\nWrapped Metanode Dialog");
    dialogLabel.setFont(boldFont);
    // select all checkboxes
    Label selectAllLabel = new Label(composite, SWT.LEFT);
    selectAllLabel.setText("Enable/Disable");
    Button selectAllWizard = createCheckbox(composite);
    Button selectAllDialog = createCheckbox(composite);
    // individual nodes
    for (@SuppressWarnings("rawtypes") Entry<NodeIDSuffix, WizardNode> entry : viewNodes.entrySet()) {
        NodeIDSuffix suffix = entry.getKey();
        NodeID id = suffix.prependParent(subNodeContainer.getWorkflowManager().getID());
        NodeContainer nodeContainer = viewNodes.containsKey(suffix) ? subNodeContainer.getWorkflowManager().getNodeContainer(id) : null;
        createNodeLabelComposite(composite, id, nodeContainer);
        @SuppressWarnings("rawtypes") WizardNode model = entry.getValue();
        Button wizardButton = createCheckbox(composite);
        wizardButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                checkAllSelected(m_wizardUsageMap, selectAllWizard);
            }
        });
        wizardButton.setToolTipText("Enable/disable for usage in WebPortal and wizard execution.");
        wizardButton.setSelection(!((WizardNode<?, ?>) model).isHideInWizard());
        m_wizardUsageMap.put(id, wizardButton);
        if (model instanceof DialogNode) {
            Button dialogButton = createCheckbox(composite);
            dialogButton.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(final SelectionEvent e) {
                    checkAllSelected(m_dialogUsageMap, selectAllDialog);
                }
            });
            dialogButton.setToolTipText("Enable/disable for usage in wrapped metanode configure dialog.");
            dialogButton.setSelection(!((DialogNode<?, ?>) model).isHideInDialog());
            m_dialogUsageMap.put(id, dialogButton);
        } else {
            new Composite(composite, SWT.NONE);
        /* Placeholder */
        }
    }
    checkAllSelected(m_wizardUsageMap, selectAllWizard);
    checkAllSelected(m_dialogUsageMap, selectAllDialog);
    selectAllWizard.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            selectAllWizard.setGrayed(false);
            for (Button b : m_wizardUsageMap.values()) {
                b.setSelection(selectAllWizard.getSelection());
            }
        }
    });
    if (m_wizardUsageMap.size() < 1) {
        selectAllWizard.setEnabled(false);
    }
    selectAllDialog.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            selectAllDialog.setGrayed(false);
            for (Button b : m_dialogUsageMap.values()) {
                b.setSelection(selectAllDialog.getSelection());
            }
        }
    });
    if (m_dialogUsageMap.size() < 1) {
        selectAllDialog.setEnabled(false);
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) FontData(org.eclipse.swt.graphics.FontData) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) DialogNode(org.knime.core.node.dialog.DialogNode) WizardNode(org.knime.core.node.wizard.WizardNode) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) NodeID(org.knime.core.node.workflow.NodeID) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite)

Example 2 with WizardNode

use of org.knime.core.node.wizard.WizardNode in project knime-core by knime.

the class SubnodeLayoutWizard method addPages.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("rawtypes")
@Override
public void addPages() {
    setWindowTitle("Node Usage and Layout");
    setDefaultPageImageDescriptor(ImageRepository.getImageDescriptor(KNIMEEditorPlugin.PLUGIN_ID, "icons/layout_55.png"));
    WorkflowManager wfManager = m_subNodeContainer.getWorkflowManager();
    // Map<NodeID, SubNodeContainer> nestedSubnodes = wfManager.findNodes(SubNodeContainer.class, false);
    Map<NodeID, WizardNode> viewNodes = wfManager.findNodes(WizardNode.class, false);
    LinkedHashMap<NodeIDSuffix, WizardNode> resultMap = new LinkedHashMap<>();
    for (Map.Entry<NodeID, WizardNode> entry : viewNodes.entrySet()) {
        NodeID.NodeIDSuffix idSuffix = NodeID.NodeIDSuffix.create(wfManager.getID(), entry.getKey());
        resultMap.put(idSuffix, entry.getValue());
    }
    List<NodeID> nodeIDs = new ArrayList<NodeID>();
    nodeIDs.addAll(viewNodes.keySet());
    /*for (NodeID subnodeID : nestedSubnodes.keySet()) {
            WorkflowManager nestedWFManager = nestedSubnodes.get(subnodeID).getWorkflowManager();
            if (!nestedWFManager.findNodes(WizardNode.class, true).isEmpty()) {
                nodeIDs.add(subnodeID);
            }
        }*/
    Collections.sort(nodeIDs);
    m_page = new SubnodeLayoutJSONEditorPage("Change the layout configuration");
    m_page.setNodes(wfManager, m_subNodeContainer, resultMap);
    addPage(m_page);
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) ArrayList(java.util.ArrayList) WizardNode(org.knime.core.node.wizard.WizardNode) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) LinkedHashMap(java.util.LinkedHashMap) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) NodeID(org.knime.core.node.workflow.NodeID) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with WizardNode

use of org.knime.core.node.wizard.WizardNode in project knime-core by knime.

the class WebResourceController method getWizardNodeForVerifiedID.

/**
 * Returns a wizard node to a given subnode and node id
 * @param subnodeID the subnode id, which is the container for the wizard node
 * @param wizardNodeID the node id of the wizard node
 * @return the resolved wizard node or null, if node id does not denote a wizard node
 * @since 3.7
 */
@SuppressWarnings("rawtypes")
protected WizardNode getWizardNodeForVerifiedID(final NodeID subnodeID, final NodeID wizardNodeID) {
    CheckUtils.checkNotNull(subnodeID);
    CheckUtils.checkNotNull(wizardNodeID);
    WorkflowManager manager = m_manager;
    assert manager.isLockedByCurrentThread();
    SubNodeContainer subNodeNC = manager.getNodeContainer(subnodeID, SubNodeContainer.class, true);
    NodeContainer cont = subNodeNC.getWorkflowManager().findNodeContainer(wizardNodeID);
    if (cont instanceof NativeNodeContainer) {
        NodeModel model = ((NativeNodeContainer) cont).getNodeModel();
        if (model instanceof WizardNode) {
            return (WizardNode) model;
        } else {
            LOGGER.error("Node model is not of type WizardNode");
        }
        LOGGER.error("Node container is not of type NativeNodeContainer");
    }
    return null;
}
Also used : NodeModel(org.knime.core.node.NodeModel) WizardNode(org.knime.core.node.wizard.WizardNode)

Example 4 with WizardNode

use of org.knime.core.node.wizard.WizardNode in project knime-core by knime.

the class WebResourceController method validateViewValuesInternal.

/**
 * Validates a given set of serialized view values for a given subnode.
 *
 * @param viewValues the values to validate
 * @param subnodeID the id of the subnode containing the appropriate view nodes
 * @param wizardNodeSet the set of view nodes that the view values correspond to.
 * @return an empty map if validation succeeds, map of errors otherwise
 * @throws IllegalArgumentException if the provided subnode id is <code>null</code>
 * @throws IllegalStateException if there are no nodes with the provided id prefixes in the page or the provided
 *             wizard-node-set doesn't contain the required wizard nodes
 */
@SuppressWarnings({ "rawtypes" })
protected Map<String, ValidationError> validateViewValuesInternal(final Map<String, String> viewValues, final NodeID subnodeID, final Map<NodeID, NativeNodeContainer> wizardNodeSet) {
    if (subnodeID == null) {
        throw new IllegalArgumentException("No node ID supplied for validating view values of wizard page");
    }
    WorkflowManager manager = m_manager;
    assert manager.isLockedByCurrentThread();
    Map<String, ValidationError> resultMap = new LinkedHashMap<>();
    for (Map.Entry<String, String> entry : viewValues.entrySet()) {
        NodeID.NodeIDSuffix suffix = NodeID.NodeIDSuffix.fromString(entry.getKey());
        NodeID id = suffix.prependParent(manager.getProjectWFM().getID());
        CheckUtils.checkState(id.hasPrefix(subnodeID), "The wizard page content for ID %s (suffix %s) does not belong to the current Component (ID %s)", id, entry.getKey(), subnodeID);
        NativeNodeContainer wizardNode = wizardNodeSet.get(id);
        CheckUtils.checkState(wizardNode != null, "No wizard node with ID %s in Component, valid IDs are: " + "%s", id, ConvenienceMethods.getShortStringFrom(wizardNodeSet.entrySet(), 10));
        ValidationError validationError = null;
        try {
            if (wizardNode.getNodeModel() instanceof WizardNode) {
                validationError = validateViewValueForWizardNode((WizardNode) wizardNode.getNodeModel(), entry.getValue());
            } else if (wizardNode.getNode().getFactory() instanceof WizardPageContribution) {
                validationError = ((WizardPageContribution) wizardNode.getNode().getFactory()).validateViewValue(wizardNode, entry.getValue()).map(ValidationError::new).orElse(null);
            }
        } catch (Exception e) {
            // NOSONAR
            validationError = new ValidationError("An unexpected error occurred while validating the view value: " + entry.getValue() + ": \n" + e.getMessage());
        }
        if (validationError != null) {
            resultMap.put(entry.getKey(), validationError);
        }
    }
    if (!resultMap.isEmpty()) {
        return resultMap;
    }
    return Collections.emptyMap();
}
Also used : WizardNode(org.knime.core.node.wizard.WizardNode) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) WizardPageContribution(org.knime.core.node.wizard.page.WizardPageContribution) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) ViewRequestHandlingException(org.knime.core.node.interactive.ViewRequestHandlingException) LinkedHashMap(java.util.LinkedHashMap) ValidationError(org.knime.core.node.web.ValidationError) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with WizardNode

use of org.knime.core.node.wizard.WizardNode in project knime-core by knime.

the class SubNodeContainer method setHideNodeFromWizard.

/**
 * Sets a flag on a given {@link WizardNode} of nested subnode, whether or not it is hidden from wizard execution
 * @param id the node to set the flag on
 * @param hide true if the node is supposed to be hidden from WebPortal or wizard execution, false otherwise
 * @since 3.5
 * @noreference This method is not intended to be referenced by clients.
 */
public void setHideNodeFromWizard(final NodeID id, final boolean hide) {
    try (WorkflowLock lock = lock()) {
        NodeContainer container = m_wfm.getNodeContainer(id, NodeContainer.class, true);
        ViewHideable vh = null;
        NativeNodeContainer nnc = null;
        if (container instanceof SubNodeContainer) {
            vh = (SubNodeContainer) container;
        } else if (container instanceof NativeNodeContainer) {
            nnc = (NativeNodeContainer) container;
            NodeModel model = nnc.getNodeModel();
            CheckUtils.checkArgument(model instanceof WizardNode, "Can't set hide in wizard flag on non-wizard nodes.");
            vh = (WizardNode<?, ?>) model;
        } else {
            throw new IllegalArgumentException("Node with id " + id + " needs to be a native node or a subnode container!");
        }
        if (vh != null) {
            if (hide != vh.isHideInWizard()) {
                vh.setHideInWizard(hide);
                if (nnc != null) {
                    nnc.saveNodeSettingsToDefault();
                    nnc.setDirty();
                }
            }
        }
    }
}
Also used : VirtualSubNodeOutputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeModel) VirtualSubNodeInputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel) NodeModel(org.knime.core.node.NodeModel) ViewHideable(org.knime.core.node.wizard.ViewHideable) WizardNode(org.knime.core.node.wizard.WizardNode)

Aggregations

WizardNode (org.knime.core.node.wizard.WizardNode)12 NodeIDSuffix (org.knime.core.node.workflow.NodeID.NodeIDSuffix)10 IOException (java.io.IOException)6 LinkedHashMap (java.util.LinkedHashMap)6 Map (java.util.Map)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 HashMap (java.util.HashMap)3 NodeModel (org.knime.core.node.NodeModel)3 ViewRequestHandlingException (org.knime.core.node.interactive.ViewRequestHandlingException)3 ValidationError (org.knime.core.node.web.ValidationError)3 NodeID (org.knime.core.node.workflow.NodeID)3 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Font (org.eclipse.swt.graphics.Font)2 FontData (org.eclipse.swt.graphics.FontData)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2