I have a simple hierarchical entity Location with locName, locLevel, locParent and locChildren attributes. I created a lookup form with hierarchcal data source and TreeTable and I want to select locations with locLevel=3 only. I added this code in form controller:
But the selectButton remains enabled always and any item can be selected by the lookup form.
When I comment the line //lookupSelectAction.setEnabled(selectButton.isEnabled());
the selectButton becomes enabled only when locLevel=3 (it is right), but despite that I can select any location item by mouse doubleclick.
How can I restrict lookup selection?
If an Action instance is defined for a Button, the button will take the following properties from it: caption, description, icon, enable, visible. So, instead of disabling the button, you need to disable the action.
I inserted in you code this line: selectAction.setEnabled(locationsTable.getSingleSelected() != null && locationsTable.getSingleSelected().getLocLevel() == 3);
Yes, with this code the selectButton becomes enabled only with level==3, but I still can select any item with mouse doubleclick. How to intercept the doubleclick event?
Thanks, this works well, I inserted the same validation “level==3” and actionPerform instead of “do nothing”:
Is there a possibility to replace inner event handlers without such undocumented kludges?
You can rewrite the code above using particular table component, so you won’t need any casts. I just used the most generic code. Alternatively, you can completely rewrite the initLookupLayout and setLookupComponent methods.