Tree Menu Item


I want to dynamically enable / disable an item in a menu on a tree.

I find no way to do that, so I have tried another way by changing the caption using colors :black (allowed) and (gray) not allowed and doing nothing if it’s gray for example.

Here is the method :

void setEnableSelectType(boolean t){
if (t == true){
ACTION_SELECT_TYPE.setCaption(“<span style="color:Black">Select Type”);
} else
ACTION_SELECT_TYPE.setCaption(“<span style="color:Gray">Select Type”);

I have debug the code and it go through the method correctly but on the menu it changes the color only once !

say I have started black, the code goes well and the item goes gray, I change the state, the code goes to change to black again but visually nothing change it stays gray…

Questions :
Have you an idea on how enable/disable an item in a tree menu ?
Do you see why my workaround failed ? (apart from the fact that it’s not a true enable / disable :wink:

Thank You

We’re you actually able to get the HTML code rendered, or did it just display the whole thing as a string as the item’s caption?

I’d go and try using Tree.ItemStyleGenerator to change the colors of the items (and the mouse cursor too), and then set some other property on the items to indicate if they are disabled or enabled. You can then prevent the selection on the server side by checking that property on each value change event.

But seriously, we should have a way to really disable tree items with a simple API. Same goes for all other selects as well (Table, ComboBox etc.).

It displays the text “Select Type” in black color
then the first time I change the GUI state in order to disable the menu item, it displays “Select Type” in gray
then if I change again the GUI state in order to enable the menu item, it stays Gray.

I have debugged the code to be sure it goes through the method with the right value. It seems that if I change the caption nothing happens visually. I have even tried with another text “Not Select the Type” and the string did not appear visually. It display always “Select Type”.

Ok I’m a newbie with Vaadin so I will explore this solution. I’m not at the moment aware of the Tree.ItemStyleGenerator :wink:

I agree with you… all others solutions will only be workarounds

Thx for your answers :slight_smile: