开发者

Dynamic GWT Menu

开发者 https://www.devze.com 2022-12-17 06:05 出处:网络
How can I modify a GWT menu - grey out some entries, put a checkmark next to others, according to my application state?

How can I modify a GWT menu - grey out some entries, put a checkmark next to others, according to my application state?

My app has a menu bar across the top - File, Edit, View, Insert, Format, etc. I have a number of paragraphs, each of which could have a different format. When the user clicks on Format, I want the format menu to show a checkmark next to the menuItem that co开发者_如何学Crresponds to the format of the currently selected paragraph. If some formats are inappropriate for the currently selected paragraph, I want to grey those menuItems out.

The main issue is when to do the update: (a) when the Format menu button is clicked, or (b) each time my user selects a new paragraph?

I find option (a) more appealing. But how can I detect this? A MenuItem doesn't have any facility for adding event listeners. It could be a mouseClick that I need, but it might be a mouseOver: if the user clicks on the Insert menuItem the Insert menu will appear, but then if the mouse is moved over Format, then the Format menu will appear.

Option (b) sounds simpler, but wastes more processor time.

For my contextMenu (right click on the paragraph), it's much easier, because the menu is only constructed when the right click happens.

I've resorted to using the square-root symbol (&#8730) for a tick. Does anyone know a nicer way? Do I need to use HTML and use "   Plain-Format" for my menu item?

Finally, is there a way to disable (grey-out) a menu item so that it can't be selected?


Option (a) sounds better from a conserving resources point of view.

Instead of using the square-root symbol, why don't you use an image (using the com.google.gwt.user.client.ui.Image class)?

I think a more elegant/simple solution might be to use the checkbox class for your menu items. That way you could have automatic ticks/checks instead of having to use an image or the square-root symbol. Also, you will be able to "grey-out" items with setEnabled(false). Otherwise, you will have to write your own widget or add your own functionality to your menu labels in order to "grey-out" items.

0

精彩评论

暂无评论...
验证码 换一张
取 消