Search in sources :

Example 1 with InactiveBranchConsumer

use of org.knime.core.node.port.inactive.InactiveBranchConsumer in project knime-core by knime.

the class Node method initDialogPaneWithSettings.

/**
 * Helper method to initialize a node dialog pane with settings etc.
 *
 * @param dialogPane the dialog pane to initialize with the settings etc.
 * @param inSpecs The input specs, which will be forwarded to the dialog's
 *            {@link NodeDialogPane#loadSettingsFrom(NodeSettingsRO, PortObjectSpec[])}.
 * @param portTypes the types of the input ports
 * @param inData the input data if available (can be <code>null</code>)
 * @param settings The current settings to load. 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()}.
 * @param model the node model instance. Can be <code>null</code> if not of type @{@link InactiveBranchConsumer},
 *            {@link ValueControlledNode} or {@link VirtualSubNodeInputNodeModel}
 * @param flowObjectStack stack holding all available flow variables required for the configuration
 * @param credentialsProvider in case (workflow) credentials are required to configure the dialog
 * @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 NotConfigurableException if something went wrong with the initialization
 * @since 3.6
 */
public static NodeDialogPane initDialogPaneWithSettings(final NodeDialogPane dialogPane, final PortObjectSpec[] inSpecs, final PortType[] portTypes, final PortObject[] inData, final NodeSettingsRO settings, final boolean isWriteProtected, final NodeModel model, final FlowObjectStack flowObjectStack, final CredentialsProvider credentialsProvider) throws NotConfigurableException {
    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 (!(model instanceof InactiveBranchConsumer)) {
                throw new NotConfigurableException("Cannot configure nodes in inactive branches.");
            }
        }
        PortType t = portTypes[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 actualFlowObjectStack = model instanceof VirtualSubNodeInputNodeModel ? ((VirtualSubNodeInputNodeModel) model).getSubNodeContainerFlowObjectStack() : flowObjectStack;
    dialogPane.internalLoadSettingsFrom(settings, corrInSpecs, corrInData, actualFlowObjectStack, credentialsProvider, isWriteProtected);
    if (model instanceof ValueControlledNode && dialogPane instanceof ValueControlledDialogPane) {
        NodeSettings currentValue = new NodeSettings("currentValue");
        try {
            ((ValueControlledNode) 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) InactiveBranchConsumer(org.knime.core.node.port.inactive.InactiveBranchConsumer) 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 InactiveBranchConsumer (org.knime.core.node.port.inactive.InactiveBranchConsumer)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