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;
}
Aggregations