JFace's IAction and SWT's Button Mapping

Has it ever occurred to you that, you use the IAction/Action as a model for the swt's button widget.

Well there is very simple way of doing it, following steps help you achieve just that:
  1. Create and IAction object 
  2. Create the Wrapper around IAction object of ActionContributionItem
  3. Call the fill method (there are 3 overridden fill method are present choose as per your requirement) of the class ActionContributionItem passing the parent composite on which you want your button widget to be created
  4. That's it your button widget is ready with Action model on the backend :)
Following are the benefits of keeping the model and UI separate:
  1. You don't have to bother about the state change and propagation of events  
  2. You can work on Action object on the back-end which is easier and simpler than working on UI objects
  3. Your UI layer can be automated without worrying about sync problems

Comments

Popular posts from this blog

java.net.SocketException: Connection reset

Hide empty last column from Table/Tree Viewer

Spring: implements interface not working in @Controller