开发者

Handling Application commands in GWT

开发者 https://www.devze.com 2023-04-11 06:56 出处:网络
Swing uses Actions to share functionality and state 开发者_开发知识库across multiple GUI components like menu items and toobar buttons. XUL uses a similar approach with their Command framework.

Swing uses Actions to share functionality and state 开发者_开发知识库across multiple GUI components like menu items and toobar buttons. XUL uses a similar approach with their Command framework.

What are typical/best approaches to handle similar requirements in GWT? I’m particularly interested in showing whether a menu item or a button is enabled or disabled.


I use the Command class. GWT MenuItems can have a Command associated with them. Here are some relevant code fragments:

Command printCommand = new Command() {
      @Override
      public void execute() {
        myEventBus.fireEvent(new PrintEvent());
      }
    };

MenuItem print = new MenuItem();

print.setCommand(printCommand);

Notice that you can cause printCommand to execute simply by calling printCommand.execute(). For instance, you can have a print Button for which the ClickHandler calls printCommand.execute(), so it has the same effect exactly as the menu item in the above code.

Now I know in Swing there is a clever interaction between the Action and the Widget so that all the Widgets are enabled or disabled at the same time by enabling or disabling the Action. The Command is not so tightly tied in, and I don't think there is anything in GWT like what you have in Swing for that sort of one-stop enable/disable feature. Having said that, you might be able to extend Command so that you somehow register widgets that fire that command with the command, and the command has a enable methid that, when called, walks through the list of widgets enabling and disabling them as required.

0

精彩评论

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

关注公众号