Search in sources :

Example 1 with DialogNodeRepresentation

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

Example 2 with DialogNodeRepresentation

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

Aggregations

ArrayList (java.util.ArrayList)2 DialogNode (org.knime.core.node.dialog.DialogNode)2 DialogNodeRepresentation (org.knime.core.node.dialog.DialogNodeRepresentation)2 MetaNodeDialogNode (org.knime.core.node.dialog.MetaNodeDialogNode)2 BorderLayout (java.awt.BorderLayout)1 FlowLayout (java.awt.FlowLayout)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 BoxLayout (javax.swing.BoxLayout)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XmlException (org.apache.xmlbeans.XmlException)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NodeDescription27Proxy (org.knime.core.node.NodeDescription27Proxy)1 NotConfigurableException (org.knime.core.node.NotConfigurableException)1 DialogNodePanel (org.knime.core.node.dialog.DialogNodePanel)1 DialogNodeValue (org.knime.core.node.dialog.DialogNodeValue)1 VirtualSubNodeInputNodeModel (org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel)1 VirtualSubNodeOutputNodeModel (org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeModel)1