Search in sources :

Example 1 with DialogNode

use of org.knime.core.node.dialog.DialogNode 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 DialogNode

use of org.knime.core.node.dialog.DialogNode in project knime-core by knime.

the class SubNodeContainer method performValidateSettings.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("rawtypes")
@Override
void performValidateSettings(final NodeSettingsRO modelSettings) throws InvalidSettingsException {
    Map<NodeID, DialogNode> nodes = m_wfm.findNodes(DialogNode.class, false);
    for (Map.Entry<NodeID, DialogNode> entry : nodes.entrySet()) {
        NodeID id = entry.getKey();
        DialogNode node = entry.getValue();
        String parameterName = getDialogNodeParameterName(node, id);
        if (modelSettings.containsKey(parameterName)) {
            NodeSettingsRO conf = modelSettings.getNodeSettings(parameterName);
            NodeContext.pushContext(m_wfm.getNodeContainer(id));
            try {
                final DialogNodeValue validationDialogValue = node.createEmptyDialogValue();
                validationDialogValue.loadFromNodeSettings(conf);
                node.validateDialogValue(validationDialogValue);
            } catch (InvalidSettingsException ise) {
                throw ise;
            } catch (Throwable e) {
                LOGGER.coding("Settings validation threw \"" + e.getClass().getSimpleName() + "\": " + e.getMessage(), e);
                throw new InvalidSettingsException(e.getMessage(), e);
            } finally {
                NodeContext.removeLastContext();
            }
        }
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DialogNode(org.knime.core.node.dialog.DialogNode) MetaNodeDialogNode(org.knime.core.node.dialog.MetaNodeDialogNode) DialogNodeValue(org.knime.core.node.dialog.DialogNodeValue) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with DialogNode

use of org.knime.core.node.dialog.DialogNode in project knime-core by knime.

the class MetaNodeDialogPane method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    // we may have quickform nodes to allow a column selection?)
    for (Map.Entry<NodeID, MetaNodeDialogNode> e : m_nodes.entrySet()) {
        if (e.getValue() instanceof QuickFormInputNode) {
            AbstractQuickFormConfiguration config = ((QuickFormInputNode) e.getValue()).getConfiguration();
            AbstractQuickFormValueInConfiguration valueConfig = config.getValueConfiguration();
            try {
                NodeSettingsRO subSettings = settings.getNodeSettings(Integer.toString(e.getKey().getIndex()));
                valueConfig.loadValueInDialog(subSettings);
                QuickFormConfigurationPanel panel = m_quickFormInputNodePanels.get(e.getKey());
                assert panel != null : "No panel instance for node " + e.getKey();
                panel.loadSettings(valueConfig);
            } catch (InvalidSettingsException ise) {
            // no op
            }
        } else if (e.getValue() instanceof DialogNode) {
            final DialogNode dialogNode = (DialogNode) e.getValue();
            final DialogNodeValue nodeValue = dialogNode.createEmptyDialogValue();
            final String parameterName = SubNodeContainer.getDialogNodeParameterName(dialogNode, e.getKey());
            try {
                NodeSettingsRO subSettings = settings.getNodeSettings(parameterName);
                nodeValue.loadFromNodeSettingsInDialog(subSettings);
                final DialogNodePanel dialogNodePanel = m_dialogNodePanels.get(e.getKey());
                dialogNodePanel.loadNodeValue(nodeValue);
            } catch (InvalidSettingsException ex) {
            // no op
            }
        }
    }
}
Also used : AbstractQuickFormValueInConfiguration(org.knime.core.quickform.AbstractQuickFormValueInConfiguration) QuickFormInputNode(org.knime.core.quickform.in.QuickFormInputNode) QuickFormConfigurationPanel(org.knime.core.quickform.QuickFormConfigurationPanel) DialogNode(org.knime.core.node.dialog.DialogNode) MetaNodeDialogNode(org.knime.core.node.dialog.MetaNodeDialogNode) AbstractQuickFormConfiguration(org.knime.core.quickform.AbstractQuickFormConfiguration) MetaNodeDialogNode(org.knime.core.node.dialog.MetaNodeDialogNode) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DialogNodeValue(org.knime.core.node.dialog.DialogNodeValue) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DialogNodePanel(org.knime.core.node.dialog.DialogNodePanel)

Example 4 with DialogNode

use of org.knime.core.node.dialog.DialogNode in project knime-core by knime.

the class MetaNodeDialogPane method saveSettingsTo.

/**
 * {@inheritDoc}
 */
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
    for (Map.Entry<NodeID, MetaNodeDialogNode> e : m_nodes.entrySet()) {
        final NodeID key = e.getKey();
        if (e.getValue() instanceof QuickFormInputNode) {
            AbstractQuickFormConfiguration config = ((QuickFormInputNode) e.getValue()).getConfiguration();
            AbstractQuickFormValueInConfiguration valueConfig = config.createValueConfiguration();
            QuickFormConfigurationPanel value = m_quickFormInputNodePanels.get(key);
            value.saveSettings(valueConfig);
            NodeSettingsWO subSettings = settings.addNodeSettings((Integer.toString(key.getIndex())));
            valueConfig.saveValue(subSettings);
        } else if (e.getValue() instanceof DialogNode) {
            DialogNode dialogNode = (DialogNode) e.getValue();
            DialogNodePanel nodePanel = m_dialogNodePanels.get(key);
            DialogNodeValue nodeValue = nodePanel.getNodeValue();
            final String parameterName = SubNodeContainer.getDialogNodeParameterName(dialogNode, key);
            if (nodeValue != null) {
                NodeSettingsWO subSettings = settings.addNodeSettings((parameterName));
                nodeValue.saveToNodeSettings(subSettings);
            }
        }
    }
}
Also used : AbstractQuickFormValueInConfiguration(org.knime.core.quickform.AbstractQuickFormValueInConfiguration) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) QuickFormInputNode(org.knime.core.quickform.in.QuickFormInputNode) QuickFormConfigurationPanel(org.knime.core.quickform.QuickFormConfigurationPanel) DialogNode(org.knime.core.node.dialog.DialogNode) MetaNodeDialogNode(org.knime.core.node.dialog.MetaNodeDialogNode) AbstractQuickFormConfiguration(org.knime.core.quickform.AbstractQuickFormConfiguration) MetaNodeDialogNode(org.knime.core.node.dialog.MetaNodeDialogNode) DialogNodeValue(org.knime.core.node.dialog.DialogNodeValue) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DialogNodePanel(org.knime.core.node.dialog.DialogNodePanel)

Example 5 with DialogNode

use of org.knime.core.node.dialog.DialogNode in project knime-core by knime.

the class MetaNodeDialogPane method setQuickformNodes.

/**
 * Set quickform nodes into this dialog; called just before
 * {@link #loadSettingsFrom(NodeSettingsRO,
 * org.knime.core.data.DataTableSpec[])} is called.
 * @param nodes the quickform nodes to show settings for
 */
final void setQuickformNodes(final Map<NodeID, MetaNodeDialogNode> nodes) {
    m_nodes.clear();
    m_quickFormInputNodePanels.clear();
    m_dialogNodePanels.clear();
    // remove all quickform components from current panel
    m_panel.removeAll();
    List<Pair<Integer, Pair<NodeID, MetaNodeDialogNode>>> sortedNodeList = new ArrayList<Pair<Integer, Pair<NodeID, MetaNodeDialogNode>>>();
    for (Map.Entry<NodeID, MetaNodeDialogNode> e : nodes.entrySet()) {
        // only accept old qf nodes for metanodes
        if (!m_usedInSubnode && e.getValue() instanceof QuickFormInputNode) {
            AbstractQuickFormConfiguration<? extends AbstractQuickFormValueInConfiguration> config = ((QuickFormInputNode) e.getValue()).getConfiguration();
            if (config == null) {
                // quickform nodes has no valid configuration
                continue;
            }
            QuickFormConfigurationPanel<? extends AbstractQuickFormValueInConfiguration> quickform = config.createController();
            m_nodes.put(e.getKey(), e.getValue());
            m_quickFormInputNodePanels.put(e.getKey(), quickform);
            Pair<Integer, Pair<NodeID, MetaNodeDialogNode>> weightNodePair = new Pair<Integer, Pair<NodeID, MetaNodeDialogNode>>(config.getWeight(), new Pair<NodeID, MetaNodeDialogNode>(e.getKey(), e.getValue()));
            sortedNodeList.add(weightNodePair);
        // only accept new qf nodes for subnodes
        } else if (m_usedInSubnode && e.getValue() instanceof DialogNode) {
            DialogNodeRepresentation<? extends DialogNodeValue> representation = ((DialogNode) e.getValue()).getDialogRepresentation();
            if (((DialogNode) e.getValue()).isHideInDialog() || representation == null) {
                // no valid representation
                continue;
            }
            try {
                DialogNodePanel dialogPanel = representation.createDialogPanel();
                m_nodes.put(e.getKey(), e.getValue());
                m_dialogNodePanels.put(e.getKey(), dialogPanel);
                Pair<Integer, Pair<NodeID, MetaNodeDialogNode>> weightNodePair = new Pair<Integer, Pair<NodeID, MetaNodeDialogNode>>(Integer.MAX_VALUE, new Pair<NodeID, MetaNodeDialogNode>(e.getKey(), e.getValue()));
                sortedNodeList.add(weightNodePair);
            } catch (Exception ex) {
                LOGGER.error("The dialog pane for node " + e.getKey() + " could not be created.", ex);
            }
        }
    }
    Collections.sort(sortedNodeList, new Comparator<Pair<Integer, Pair<NodeID, MetaNodeDialogNode>>>() {

        /**
         * {@inheritDoc}
         */
        @Override
        public int compare(final Pair<Integer, Pair<NodeID, MetaNodeDialogNode>> o1, final Pair<Integer, Pair<NodeID, MetaNodeDialogNode>> o2) {
            return o1.getFirst() - o2.getFirst();
        }
    });
    for (Pair<Integer, Pair<NodeID, MetaNodeDialogNode>> weightNodePair : sortedNodeList) {
        NodeID id = weightNodePair.getSecond().getFirst();
        MetaNodeDialogNode node = weightNodePair.getSecond().getSecond();
        if (node instanceof QuickFormInputNode) {
            final QuickFormConfigurationPanel<?> qconfPanel = m_quickFormInputNodePanels.get(id);
            JPanel qpanel = new JPanel();
            final BoxLayout boxLayout2 = new BoxLayout(qpanel, BoxLayout.Y_AXIS);
            qpanel.setLayout(boxLayout2);
            qpanel.setBorder(BorderFactory.createTitledBorder((String) null));
            JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
            p.add(qconfPanel);
            qpanel.add(p);
            m_panel.add(qpanel);
        } else if (node instanceof DialogNode) {
            DialogNodePanel<? extends DialogNodeValue> nodePanel = m_dialogNodePanels.get(id);
            JPanel dpanel = new JPanel();
            final BoxLayout boxLayout2 = new BoxLayout(dpanel, BoxLayout.Y_AXIS);
            dpanel.setLayout(boxLayout2);
            dpanel.setBorder(BorderFactory.createTitledBorder((String) null));
            JPanel p = new JPanel(new BorderLayout());
            p.add(nodePanel, BorderLayout.CENTER);
            dpanel.add(p);
            m_panel.add(dpanel);
        }
    }
    if (m_nodes.isEmpty()) {
        m_panel.add(new JLabel("No valid Quickform configurations."));
    }
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) BoxLayout(javax.swing.BoxLayout) ArrayList(java.util.ArrayList) DialogNode(org.knime.core.node.dialog.DialogNode) MetaNodeDialogNode(org.knime.core.node.dialog.MetaNodeDialogNode) BorderLayout(java.awt.BorderLayout) Pair(org.knime.core.util.Pair) JLabel(javax.swing.JLabel) QuickFormInputNode(org.knime.core.quickform.in.QuickFormInputNode) DialogNodeRepresentation(org.knime.core.node.dialog.DialogNodeRepresentation) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NotConfigurableException(org.knime.core.node.NotConfigurableException) MetaNodeDialogNode(org.knime.core.node.dialog.MetaNodeDialogNode) DialogNodeValue(org.knime.core.node.dialog.DialogNodeValue) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DialogNodePanel(org.knime.core.node.dialog.DialogNodePanel)

Aggregations

DialogNode (org.knime.core.node.dialog.DialogNode)10 MetaNodeDialogNode (org.knime.core.node.dialog.MetaNodeDialogNode)9 Map (java.util.Map)6 DialogNodeValue (org.knime.core.node.dialog.DialogNodeValue)6 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)3 DialogNodePanel (org.knime.core.node.dialog.DialogNodePanel)3 QuickFormInputNode (org.knime.core.quickform.in.QuickFormInputNode)3 ArrayList (java.util.ArrayList)2 NodeSettings (org.knime.core.node.NodeSettings)2 NodeSettingsWO (org.knime.core.node.NodeSettingsWO)2 DialogNodeRepresentation (org.knime.core.node.dialog.DialogNodeRepresentation)2 VirtualSubNodeInputNodeModel (org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel)2 VirtualSubNodeOutputNodeModel (org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeModel)2 AbstractQuickFormConfiguration (org.knime.core.quickform.AbstractQuickFormConfiguration)2 AbstractQuickFormValueInConfiguration (org.knime.core.quickform.AbstractQuickFormValueInConfiguration)2 QuickFormConfigurationPanel (org.knime.core.quickform.QuickFormConfigurationPanel)2 BorderLayout (java.awt.BorderLayout)1