Skip to main content

Posts

Showing posts with the label ActionContributionItem

IAction and Widget mapping

This post explains how you can map a IAction as an model to a Button. In this case IAction will act as an model to your UI component Button by which you can control the behaviour of the button. In fact in the same way you can use IAction for MenuItem and ToolItem . IAction belong to jface and button is and SWT component. Well   ActionContributionItem in the package org.eclipse.jface.action from the plugin org.eclipse.jface comes to rescue, the class provides API for the conversion. Below are the step wise instructions needs to be followed to achieve it: Instantiate  ActionContributionItem  with IAction object Call the fill method on the  ActionContributionItem object with appropriate parameter (in our case it should be instanceof Composite ) That's all you are done now call a getWidget API to work on your SWT widget. Benefits: Listeners are managed automatically so you need bother about them Look an...

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: Create and IAction object  Create the Wrapper around IAction object of ActionContributionItem 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 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: You don't have to bother about the state change and propagation of events   You can work on Action object on the back-end which is easier and simpler than working on UI objects Your UI layer can be automated without worrying about sync problems