Search in sources :

Example 1 with VirtualSubNodeInputNodeModel

use of org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel in project knime-core by knime.

the class Node method getDialogPaneWithSettings.

/**
 * @param inSpecs The input specs, which will be forwarded to the dialog's
 *        {@link NodeDialogPane#loadSettingsFrom(NodeSettingsRO,
 *        PortObjectSpec[])}.
 * @param settings The current settings of this node. The settings object
 *        will also contain the settings of the outer SNC.
 * @param isWriteProtected Whether write protected, see
 *        {@link org.knime.core.node.workflow.WorkflowManager#isWriteProtected()}.
 * @return The dialog pane which holds all the settings' components. In
 *         addition this method loads the settings from the model into the
 *         dialog pane.
 * @throws NotConfigurableException if the dialog cannot be opened because
 *             of real invalid settings or if any preconditions are not
 *             fulfilled, e.g. no predecessor node, no nominal column in
 *             input table, etc.
 * @throws IllegalStateException If node has no dialog.
 * @see #hasDialog()
 * @since 2.6
 */
public NodeDialogPane getDialogPaneWithSettings(final PortObjectSpec[] inSpecs, final PortObject[] inData, final NodeSettingsRO settings, final boolean isWriteProtected) throws NotConfigurableException {
    NodeDialogPane dialogPane = getDialogPane();
    PortObjectSpec[] corrInSpecs = new PortObjectSpec[inSpecs.length - 1];
    PortObject[] corrInData = new PortObject[inData.length - 1];
    for (int i = 1; i < inSpecs.length; i++) {
        if (inSpecs[i] instanceof InactiveBranchPortObjectSpec) {
            if (!isInactiveBranchConsumer()) {
                throw new NotConfigurableException("Cannot configure nodes in inactive branches.");
            }
        }
        PortType t = getInputType(i);
        if (!t.acceptsPortObjectSpec(inSpecs[i]) && !(inSpecs[i] instanceof InactiveBranchPortObjectSpec)) {
            // table(!) connection)
            throw new NotConfigurableException("Invalid incoming port object spec \"" + inSpecs[i].getClass().getSimpleName() + "\", expected \"" + t.getPortObjectSpecClass().getSimpleName() + "\"");
        } else if (inSpecs[i] == null && BufferedDataTable.TYPE.equals(t) && !t.isOptional()) {
            corrInSpecs[i - 1] = new DataTableSpec();
        } else {
            corrInSpecs[i - 1] = inSpecs[i];
            corrInData[i - 1] = inData[i];
        }
    }
    // the sub node virtual input node shows in its dialog all flow variables that are available to the rest
    // of the subnode. It's the only case where the flow variables shown in the dialog are not the ones available
    // to the node model class ...
    final FlowObjectStack flowObjectStack = m_model instanceof VirtualSubNodeInputNodeModel ? ((VirtualSubNodeInputNodeModel) m_model).getSubNodeContainerFlowObjectStack() : getFlowObjectStack();
    dialogPane.internalLoadSettingsFrom(settings, corrInSpecs, corrInData, flowObjectStack, getCredentialsProvider(), isWriteProtected);
    if (m_model instanceof ValueControlledNode && dialogPane instanceof ValueControlledDialogPane) {
        NodeSettings currentValue = new NodeSettings("currentValue");
        try {
            ((ValueControlledNode) m_model).saveCurrentValue(currentValue);
            ((ValueControlledDialogPane) dialogPane).loadCurrentValue(currentValue);
        } catch (Exception ise) {
            final String msg = "Could not load current value into dialog: " + ise.getMessage();
            if (ise instanceof InvalidSettingsException) {
                LOGGER.warn(msg, ise);
            } else {
                LOGGER.coding(msg, ise);
            }
        }
    }
    return dialogPane;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InactiveBranchPortObjectSpec(org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec) FlowObjectStack(org.knime.core.node.workflow.FlowObjectStack) IOException(java.io.IOException) DataContainerException(org.knime.core.data.container.DataContainerException) VirtualSubNodeInputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel) InactiveBranchPortObjectSpec(org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FlowVariablePortObjectSpec(org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec) ValueControlledDialogPane(org.knime.core.node.dialog.ValueControlledDialogPane) ValueControlledNode(org.knime.core.node.dialog.ValueControlledNode) PortObject(org.knime.core.node.port.PortObject) FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) PortType(org.knime.core.node.port.PortType)

Example 2 with VirtualSubNodeInputNodeModel

use of org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel in project knime-core by knime.

the class SubNodeContainer method checkInOutNodesAfterLoad.

/**
 * Fixes in- and output nodes after loading (in case they don't exist or have errors).
 */
private void checkInOutNodesAfterLoad(final SubNodeContainerPersistor subNodePersistor, final LoadResult loadResult) {
    /* Fix output node */
    NodeID virtualOutID = getVirtualOutNodeID();
    // non null in case not is not present of of wrong type
    String error = null;
    // settings of previous node if present or null
    NodeSettings outputSettings = null;
    // assigned with node insertion, used for node placement
    Pair<int[], int[]> minMaxCoordinates;
    if (m_wfm.containsNodeContainer(virtualOutID)) {
        NodeContainer virtualOutNC = m_wfm.getNodeContainer(virtualOutID);
        if (virtualOutNC instanceof NativeNodeContainer) {
            NodeModel virtualOutModel = ((NativeNodeContainer) virtualOutNC).getNodeModel();
            if (!(virtualOutModel instanceof VirtualSubNodeOutputNodeModel)) {
                // this is very likely a missing node (placeholder)
                error = String.format("Virtual output node is not of expected type (expected %s, actual %s)", VirtualSubNodeOutputNodeModel.class.getName(), virtualOutModel.getClass().getName());
                try {
                    NodeSettings temp = new NodeSettings("temp");
                    m_wfm.saveNodeSettings(virtualOutID, temp);
                    outputSettings = temp;
                } catch (InvalidSettingsException ise) {
                // silently ignore; this is minor given that the node is not there.
                }
            }
        } else {
            error = String.format("Virtual output node with ID %s is not a native node", virtualOutID);
        }
    } else {
        error = String.format("Virtual output node with ID %s does not exist", virtualOutID);
    }
    if (error != null) {
        minMaxCoordinates = getMinMaxCoordinates();
        m_virtualOutNodeIDSuffix = addVirtualOutNode(Output.getPortTypesNoFlowVariablePort(m_outputs), minMaxCoordinates).getIndex();
        error = error.concat(String.format(" - creating new instance (ID %s)", m_virtualOutNodeIDSuffix));
        loadResult.addError(error);
        if (outputSettings != null) {
            try {
                m_wfm.loadNodeSettings(getVirtualOutNodeID(), outputSettings);
            } catch (InvalidSettingsException e) {
            // again, ignore as the node was missing, which is much more critical
            }
        }
    }
    /* Fix input node */
    NodeID virtualInID = getVirtualInNodeID();
    // non null in case not is not present of of wrong type
    error = null;
    // settings of previous node if present or null
    NodeSettings inputSettings = null;
    if (m_wfm.containsNodeContainer(virtualInID)) {
        NodeContainer virtualInNC = m_wfm.getNodeContainer(virtualInID);
        if (virtualInNC instanceof NativeNodeContainer) {
            NodeModel virtualInModel = ((NativeNodeContainer) virtualInNC).getNodeModel();
            if (!(virtualInModel instanceof VirtualSubNodeInputNodeModel)) {
                // this is very likely a missing node (placeholder)
                error = String.format("Virtual input node is not of expected type (expected %s, actual %s)", VirtualSubNodeInputNodeModel.class.getName(), virtualInModel.getClass().getName());
                try {
                    NodeSettings temp = new NodeSettings("temp");
                    m_wfm.saveNodeSettings(virtualInID, temp);
                    inputSettings = temp;
                } catch (InvalidSettingsException ise) {
                // silently ignore; this is minor given that the node is not there.
                }
            }
        } else {
            error = String.format("Virtual input node with ID %s is not a native node", virtualInID);
        }
    } else {
        error = String.format("Virtual input node with ID %s does not exist", virtualInID);
    }
    if (error != null) {
        minMaxCoordinates = getMinMaxCoordinates();
        // skip flow var port
        PortType[] inportTypes = new PortType[getNrInPorts() - 1];
        for (int i = 1; i < getNrInPorts(); i++) {
            inportTypes[i - 1] = getInPort(i).getPortType();
        }
        m_virtualInNodeIDSuffix = addVirtualInNode(inportTypes, minMaxCoordinates).getIndex();
        error = error.concat(String.format(" - creating new instance (ID %s)", m_virtualInNodeIDSuffix));
        loadResult.addError(error);
        if (inputSettings != null) {
            try {
                m_wfm.loadNodeSettings(getVirtualInNodeID(), inputSettings);
            } catch (InvalidSettingsException e) {
            // again, ignore as the node was missing, which is much more critical
            }
        }
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) VirtualSubNodeOutputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeModel) VirtualSubNodeInputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel) NodeModel(org.knime.core.node.NodeModel) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) VirtualSubNodeInputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel) VirtualSubNodeOutputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeModel) PortType(org.knime.core.node.port.PortType)

Example 3 with VirtualSubNodeInputNodeModel

use of org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel 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

VirtualSubNodeInputNodeModel (org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel)3 PortType (org.knime.core.node.port.PortType)2 VirtualSubNodeOutputNodeModel (org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeModel)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XmlException (org.apache.xmlbeans.XmlException)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 DataContainerException (org.knime.core.data.container.DataContainerException)1 FileStorePortObject (org.knime.core.data.filestore.FileStorePortObject)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NodeDescription27Proxy (org.knime.core.node.NodeDescription27Proxy)1 NodeModel (org.knime.core.node.NodeModel)1 NodeSettings (org.knime.core.node.NodeSettings)1 DialogNode (org.knime.core.node.dialog.DialogNode)1 DialogNodeRepresentation (org.knime.core.node.dialog.DialogNodeRepresentation)1 MetaNodeDialogNode (org.knime.core.node.dialog.MetaNodeDialogNode)1 ValueControlledDialogPane (org.knime.core.node.dialog.ValueControlledDialogPane)1 ValueControlledNode (org.knime.core.node.dialog.ValueControlledNode)1 PortObject (org.knime.core.node.port.PortObject)1