Search in sources :

Example 6 with DialogNode

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

the class SubNodeContainer method getXMLDescription.

/* -------------------- NodeContainer info properties -------------- */
@SuppressWarnings("rawtypes")
/**
 * {@inheritDoc}
 */
@Override
public Element getXMLDescription() {
    VirtualSubNodeInputNodeModel inNode = getVirtualInNodeModel();
    VirtualSubNodeOutputNodeModel outNode = getVirtualOutNodeModel();
    String description = inNode.getSubNodeDescription();
    String sDescription;
    if (StringUtils.isEmpty(description)) {
        sDescription = "";
    } else {
        sDescription = StringUtils.split(description, ".\n")[0];
        sDescription = StringUtils.abbreviate(sDescription, 200);
    }
    String[] inPortNames = inNode.getPortNames();
    String[] inPortDescriptions = inNode.getPortDescriptions();
    String[] outPortNames = outNode.getPortNames();
    String[] outPortDescriptions = outNode.getPortDescriptions();
    Map<NodeID, DialogNode> nodes = m_wfm.findNodes(DialogNode.class, false);
    List<String> optionNames = new ArrayList<String>();
    List<String> optionDescriptions = new ArrayList<String>();
    for (DialogNode dialogNode : nodes.values()) {
        DialogNodeRepresentation representation = dialogNode.getDialogRepresentation();
        if (representation instanceof QuickFormRepresentation) {
            optionNames.add(((QuickFormRepresentation) representation).getLabel());
            optionDescriptions.add(((QuickFormRepresentation) representation).getDescription());
        }
    }
    try {
        // Document
        Document doc = NodeDescription.getDocumentBuilderFactory().newDocumentBuilder().getDOMImplementation().createDocument("http://knime.org/node2012", "knimeNode", null);
        // knimeNode
        Element knimeNode = doc.getDocumentElement();
        knimeNode.setAttribute("type", "Unknown");
        knimeNode.setAttribute("icon", "subnode.png");
        // name
        Element name = doc.createElement("name");
        knimeNode.appendChild(name);
        name.appendChild(doc.createTextNode(getName()));
        // shortDescription
        Element shortDescription = doc.createElement("shortDescription");
        knimeNode.appendChild(shortDescription);
        addText(shortDescription, sDescription, NO_DESCRIPTION_SET);
        // fullDescription
        Element fullDescription = doc.createElement("fullDescription");
        knimeNode.appendChild(fullDescription);
        // intro
        Element intro = doc.createElement("intro");
        fullDescription.appendChild(intro);
        addText(intro, description, NO_DESCRIPTION_SET + "\nIn order to set a description browse the input node " + "contained in the Wrapped Metanode and change its configuration.");
        // option
        for (int i = 0; i < optionNames.size(); i++) {
            Element option = doc.createElement("option");
            fullDescription.appendChild(option);
            option.setAttribute("name", optionNames.get(i));
            addText(option, optionDescriptions.get(i), "");
        }
        // ports
        Element ports = doc.createElement("ports");
        knimeNode.appendChild(ports);
        // inPort
        for (int i = 0; i < inPortNames.length; i++) {
            Element inPort = doc.createElement("inPort");
            ports.appendChild(inPort);
            inPort.setAttribute("index", "" + i);
            inPort.setAttribute("name", inPortNames[i]);
            String defaultText = NO_DESCRIPTION_SET;
            if (i == 0) {
                defaultText += "\nChange this label by browsing the input node contained in the Wrapped Metanode " + "and changing its configuration.";
            }
            addText(inPort, inPortDescriptions[i], defaultText);
        }
        // outPort
        for (int i = 0; i < outPortNames.length; i++) {
            Element outPort = doc.createElement("outPort");
            ports.appendChild(outPort);
            outPort.setAttribute("index", "" + i);
            outPort.setAttribute("name", outPortNames[i]);
            String defaultText = NO_DESCRIPTION_SET;
            if (i == 0) {
                defaultText += "\nChange this label by browsing the output node contained in the Wrapped Metanode " + "and changing its configuration.";
            }
            addText(outPort, outPortDescriptions[i], defaultText);
        }
        return new NodeDescription27Proxy(doc).getXMLDescription();
    } catch (ParserConfigurationException | DOMException | XmlException e) {
        LOGGER.warn("Could not generate Wrapped Metanode description", e);
    }
    return null;
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) DialogNode(org.knime.core.node.dialog.DialogNode) MetaNodeDialogNode(org.knime.core.node.dialog.MetaNodeDialogNode) DialogNodeRepresentation(org.knime.core.node.dialog.DialogNodeRepresentation) Document(org.w3c.dom.Document) DOMException(org.w3c.dom.DOMException) QuickFormRepresentation(org.knime.core.quickform.QuickFormRepresentation) NodeDescription27Proxy(org.knime.core.node.NodeDescription27Proxy) VirtualSubNodeInputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel) XmlException(org.apache.xmlbeans.XmlException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) VirtualSubNodeOutputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeModel)

Example 7 with DialogNode

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

the class SubNodeContainer method setHideNodeFromDialog.

/**
 * Sets a flag on a given {@link DialogNode}, whether or not it is hidden from a containing metanode dialog
 * @param id the node to set the flag on
 * @param hide true if the node is supposed to be hidden from a containing metanode dialog, false otherwise
 * @since 3.5
 * @noreference This method is not intended to be referenced by clients.
 */
public void setHideNodeFromDialog(final NodeID id, final boolean hide) {
    try (WorkflowLock lock = lock()) {
        NativeNodeContainer nnc = m_wfm.getNodeContainer(id, NativeNodeContainer.class, true);
        NodeModel model = nnc.getNodeModel();
        CheckUtils.checkArgument(model instanceof DialogNode, "Can't set hide in dialog flag on non-dialog nodes.");
        DialogNode<?, ?> dn = (DialogNode<?, ?>) model;
        if (hide != dn.isHideInDialog()) {
            dn.setHideInDialog(hide);
            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) DialogNode(org.knime.core.node.dialog.DialogNode) MetaNodeDialogNode(org.knime.core.node.dialog.MetaNodeDialogNode)

Example 8 with DialogNode

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

the class SubNodeContainer method loadModelSettingsIntoDialogNodes.

/**
 * Applies the "modelSettings" (stored in the {@link SingleNodeContainerSettings} into the {@link DialogNode}
 * contained in this workflow.
 * @param modelSettings The new model settings.
 * @param performReset true when called via dialog, false when called during load.
 * @throws InvalidSettingsException ...
 */
@SuppressWarnings("rawtypes")
private void loadModelSettingsIntoDialogNodes(final NodeSettingsRO modelSettings, final boolean performReset) throws InvalidSettingsException {
    assert isLockedByCurrentThread();
    synchronized (m_nodeMutex) {
        // check state of contained WFM as state of this Subnode may already be "MARKED".
        if (m_wfm.getInternalState().isExecutionInProgress()) {
            throw new IllegalStateException("Cannot load settings as the Wrapped Metanode is currently executing");
        }
        Map<NodeID, DialogNode> nodes = m_wfm.findNodes(DialogNode.class, false);
        // contains all nodes that have new value (different to previous value, even if null now).
        Map<NodeID, DialogNodeValue> newDialogValueMap = new HashMap<>();
        // but do not set it yet in order to verify/load all settings before applying them
        for (Map.Entry<NodeID, DialogNode> entry : nodes.entrySet()) {
            final NodeID id = entry.getKey();
            final DialogNode node = entry.getValue();
            final String parameterName = getDialogNodeParameterName(node, id);
            // the old/previously set value in the node
            final DialogNodeValue oldDialogValue = node.getDialogValue();
            final NodeSettings oldDialogValueSettings;
            if (oldDialogValue != null) {
                oldDialogValueSettings = new NodeSettings(parameterName);
                oldDialogValue.saveToNodeSettings(oldDialogValueSettings);
            } else {
                oldDialogValueSettings = null;
            }
            final NodeSettingsRO newDialogValueSettings = modelSettings.containsKey(parameterName) ? modelSettings.getNodeSettings(parameterName) : null;
            // #equals on DialogNodeValue might not be implemented.
            if (ObjectUtils.notEqual(newDialogValueSettings, oldDialogValueSettings)) {
                final DialogNodeValue newDialogValue;
                if (newDialogValueSettings != null) {
                    newDialogValue = node.createEmptyDialogValue();
                    try {
                        newDialogValue.loadFromNodeSettings(newDialogValueSettings);
                    } catch (InvalidSettingsException e) {
                        throw new InvalidSettingsException(String.format("Cannot load dialog value for node \"%s\": %s", m_wfm.getNodeContainer(id).getNameWithID(), e.getMessage()), e);
                    }
                } else {
                    newDialogValue = null;
                }
                newDialogValueMap.put(id, newDialogValue);
            }
        }
        // apply all new dialog values and reset/configure those nodes with modified config.
        for (Map.Entry<NodeID, DialogNodeValue> modifiedNodesEntry : newDialogValueMap.entrySet()) {
            final DialogNode node = nodes.get(modifiedNodesEntry.getKey());
            node.setDialogValue(modifiedNodesEntry.getValue());
            if (performReset) {
                m_wfm.resetAndConfigureNode(modifiedNodesEntry.getKey());
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) DialogNode(org.knime.core.node.dialog.DialogNode) MetaNodeDialogNode(org.knime.core.node.dialog.MetaNodeDialogNode) NodeSettings(org.knime.core.node.NodeSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DialogNodeValue(org.knime.core.node.dialog.DialogNodeValue) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with DialogNode

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

the class SubNodeContainer method performSaveModelSettingsTo.

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("rawtypes")
void performSaveModelSettingsTo(final NodeSettings modelSettings) {
    Map<NodeID, DialogNode> nodes = m_wfm.findNodes(DialogNode.class, false);
    for (Map.Entry<NodeID, DialogNode> entry : nodes.entrySet()) {
        final DialogNode dialogNode = entry.getValue();
        final String parameterName = getDialogNodeParameterName(dialogNode, entry.getKey());
        final DialogNodeValue dialogValue = dialogNode.getDialogValue();
        if (dialogValue != null) {
            NodeSettingsWO subSettings = modelSettings.addNodeSettings(parameterName);
            dialogValue.saveToNodeSettings(subSettings);
        }
    }
}
Also used : NodeSettingsWO(org.knime.core.node.NodeSettingsWO) 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 10 with DialogNode

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

the class SubNodeContainer method getDialogPaneWithSettings.

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("rawtypes")
NodeDialogPane getDialogPaneWithSettings(final PortObjectSpec[] inSpecs, final PortObject[] inData) throws NotConfigurableException {
    NodeDialogPane dialogPane = getDialogPane();
    // find all dialog nodes and update subnode dialog
    Map<NodeID, MetaNodeDialogNode> nodes = m_wfm.findNodes(MetaNodeDialogNode.class, new NodeModelFilter<MetaNodeDialogNode>() {

        @Override
        public boolean include(final MetaNodeDialogNode nodeModel) {
            return nodeModel instanceof DialogNode && !((DialogNode) nodeModel).isHideInDialog();
        }
    }, false);
    ((MetaNodeDialogPane) dialogPane).setQuickformNodes(nodes);
    NodeSettings settings = new NodeSettings("subnode_settings");
    saveSettings(settings);
    // remove the flow variable port from the specs and data
    PortObjectSpec[] correctedInSpecs = ArrayUtils.remove(inSpecs, 0);
    PortObject[] correctedInData = ArrayUtils.remove(inData, 0);
    // the next call will call dialogPane.internalLoadSettingsFrom()
    // dialogPane is a MetaNodeDialogPane and does not handle the flow variable port correctly
    // this is why we remove it first
    Node.invokeDialogInternalLoad(dialogPane, settings, correctedInSpecs, correctedInData, getFlowObjectStack(), new CredentialsProvider(this, m_wfm.getCredentialsStore()), getParent().isWriteProtected());
    return dialogPane;
}
Also used : DialogNode(org.knime.core.node.dialog.DialogNode) MetaNodeDialogNode(org.knime.core.node.dialog.MetaNodeDialogNode) NodeSettings(org.knime.core.node.NodeSettings) MetaNodeDialogNode(org.knime.core.node.dialog.MetaNodeDialogNode) NodeDialogPane(org.knime.core.node.NodeDialogPane) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FlowVariablePortObjectSpec(org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec) InactiveBranchPortObjectSpec(org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) PortObject(org.knime.core.node.port.PortObject)

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