Firstly, let me congratulate the developers on a great job. Knime is very useful, and even with no prior knowledge of java, the documentation allows one to put together a custom knime node in next to no time.
I have a simple question, though. I’ve used ChangeListeners to enable/disable components through their SettingsModel, but I also need to enable/disable a DialogComponentButton, which is not associated with any SettingsModel, just an ActionListener.
If I call setEnabled directly on the DialogComponentButton it works as I intended, but eclipse says it’s deprecated (I’m still using knime 1.3.5).
I guess that makes sense, if there is an associated SettingsModel despite not being used in the constructor, but it doesn’t work for me. To be more specific, the following works (read button is initially disabled):
// enable or disable reading workflow from file
final DialogComponentButton read_button = new DialogComponentButton("Read");
// initial state
read_button.setEnabled(Boolean.False);
addDialogComponent(read_button);
but the following doesn’t (write button is initially enabled)
// enabled and disable writing workflow to file
final DialogComponentButton write_button = new DialogComponentButton("Write");
// initial state
write_button.getModel().setEnabled(Boolean.False);
addDialogComponent(write_button);
I did follow that documentation to implement my listeners, but I might have misunderstood it. I think you are refering to keeping the state consistent in the NodeModel - I use factory methods for every SettingsModel that set the initial state to enabled/disabled, and call this factory both from the NodeModel and NodeDialog. For any DialogComponent other than a Button, this seems to be working fine.
I’m sure I’m missing something trivial, but my problem is only with the DialogComponentButton (which defines no settings, so there’s nothing related to it in the NodeModel).
Also, it’s not that the state is inconsistent - with myDialogComponentButton.setEnable(), I can change its state, with myDialogComponentButton.getModel().setEnable(), nothing happens.
Anyway, it’s probably not that important - even if these buttons are always enabled, they are “mostly harmless”
Seems that this is a problem especially related to the button because - as you suspected correctly - it has no settings. I would suggest to use the deprecated method - and its up to us to find a solution for this problem. However, thank you very much for reporting it.
Still related with this issue (but now regarding only the visual effect) , if I disable a DialogComponentBoolean or a DialogComponentButton, the label is also greyed-out, which is good since it facilitates user interaction, but on other components the label does not change.
This is the case of a DialogComponentString, where only the border of the text box is greyed-out, and the DialogComponentFileChooser, where the selection box and the browse button are greyed-out but not the label.
I don’t know if this is a feature or a bug, but at least for my use cases it would be best if the labels were always greyed-out when a component is disabled - is there anything I can do?
Hi Miguel,
There is no good solution to that. I can only think of a hack to get what you want:
In your listener, which is invoked when the SettingsModel changes, recursively traverse the components panel (DialogComponent#getComponentPanel()) and en/disable any JLabel in there.
DialogComponentButton test = new DialogComponentButton("test");
test.getModel().setEnabled(false);
or
test.setEnabled(false);
This is very strange behavior because on another installation the same code worked for me. (same KNIME version)
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.AssertionError
at org.knime.core.node.defaultnodesettings.DialogComponent$EmptySettingsModel.setEnabled(DialogComponent.java:413)
at de.helmholtz_muenchen.ibis.utils.abstractNodes.FileSelector.FileSelectorNodeDialog.<init>(FileSelectorNodeDialog.java:74)
at de.helmholtz_muenchen.ibis.ngs.fastaSelector.FastaSelectorNodeDialog.<init>(FastaSelectorNodeDialog.java:22)
at de.helmholtz_muenchen.ibis.ngs.fastaSelector.FastaSelectorNodeFactory.createNodeDialogPane(FastaSelectorNodeFactory.java:52)
at org.knime.core.node.Node$1.run(Node.java:1901)
at org.knime.core.node.util.ViewUtils$3.run(ViewUtils.java:309)
at org.knime.core.node.util.ViewUtils$2.run(ViewUtils.java:130)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)