Hi
My custom developed node has a setting that needs to be limited to the number of rows in the input column. But I am having some issues with this:
- I tried to detect the number of rows when connecting the node. However, using breakpoints I did not find a function that is triggered when this happens. And even if it would be triggered, I think that the nr of rows are only known in the execute function, correct?
- Assuming my previous assumption is correct (the nr of rows are only known in the execute function) I tried to add a changeListener to the SettingsModelInteger that I want to limit. I followed the procedure as described here: https://www.knime.com/developer/settingsmodellistener. However, it doesnt work. Perhaps the listeners only work within the Dialog (not between dialog and model?) In the execute function I can change the SettingsModelInteger, that triggers the stateChanged function and I can see it has changed the value. But I cannot see the updated value when opening the dialog (with F6). I put a breakpoint in the Dialog code and noticed that the SettingsModelInteger value did not change here. Below are some snippets of the parts that I think are essential for this issue.
Thanks Ashgard
The Dialog:
public class MyNodeDialog extends DefaultNodeSettingsPane {
SettingsModelInteger mySettings;
protected MyNodeDialog() {
super();
mySettings= MyNodeModel.createMySettingsModel();
mySettings.addChangeListener(new MyListener());
this.getPanel().repaint();
new DialogComponentNumberEdit(mySettings, "mySettingValue", 10);
}
private void Repaint() { // Not sure if this is needed. But in here the value is back to the unchanged value
this.getPanel().repaint();
}
class MyListener implements ChangeListener {
@Override
public void stateChanged(ChangeEvent e) { // This works fine
mySettings.setIntValue(mySettings.getIntValue());
MyNodeDialog.this.Repaint();
}
}
}
and the model
public class MyNodeModel extends NodeModel {
public static final SettingsModelInteger mySettings = createMySettingsModel();
static SettingsModelInteger createMySettingsModel() {
return new SettingsModelInteger(KEY_RANDOM_ROW_COUNT, 0);
}
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) {
BufferedDataTable inputTable = inData[0];
mySettings.setIntValue((int) Math.min(inputTable.size(), mySettings.getIntValue()));
}
}