Search in sources :

Example 1 with ValueControlledDialogPane

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

Aggregations

IOException (java.io.IOException)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 DataContainerException (org.knime.core.data.container.DataContainerException)1 FileStorePortObject (org.knime.core.data.filestore.FileStorePortObject)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 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)1 PortType (org.knime.core.node.port.PortType)1 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)1 FlowVariablePortObjectSpec (org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec)1 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)1 InactiveBranchPortObjectSpec (org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec)1 FlowObjectStack (org.knime.core.node.workflow.FlowObjectStack)1 VirtualSubNodeInputNodeModel (org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel)1