Satya
Satya

Reputation: 2124

How to disable MenuBar in GWT

I have a MenuBar in my app and need to disable that based on some condition. The setEnabled(boolean) method is not available on GWT MenuBar hence there is no straight way to go ahead with this requirement.

For Ex: If you look into NestedAnchor.setEnabled(boolean enabled) it disables the events on that widget and adds a style too. I would like to do the same behavior on MenuBar where click events are not triggered to show the popup.

Also tried with jquery to add disabled attr, still no success

Upvotes: 2

Views: 940

Answers (4)

Adarsha
Adarsha

Reputation: 895

Menu bar is a container for menu items. Containers don't support disable property. So yohu have to manually iterate over the menu items list to disable each of them. Below code snippet does that by adding setEnable method to the Menu Bar -

MenuBar menuBar = new MenuBar()
{
         public void setEnable(boolean enableFl)
         {
              for( MenuItem item : getItems() )
              {
                    item.setEnable( enableFl );
              }
         }
};

Upvotes: 2

Satya
Satya

Reputation: 2124

This will serve the purpose : menuBar.unsinkEvents(Event.MOUSEEVENTS | Event.ONCLICK | Event.FOCUSEVENTS | Event.KEYEVENTS);

Upvotes: 1

Abhijith Nagaraja
Abhijith Nagaraja

Reputation: 3380

You can use the following Api

DOM.setElementPropertyBoolean(menubar.getElement(), "disabled", !enabled);

Upvotes: 0

Parvathy
Parvathy

Reputation: 2455

You can make your menubar invisible

menuBar.setVisible(false);

When ever you want to enable menubar then menuBar.setVisible(true);

or

if you want disable style then add styleDisable in .css file and set style to

menuBar.setStyleName(styleDisable); 

then check style

if(menuBar.getStyleName().equals("styleDisable")){

// write code here
}

Upvotes: 1

Related Questions