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:
Benefits:
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 and feel is also been taken care of
- You need to set the layout data on the Widget
- Icon and/or text should be set on the IAction as per your usability
Comments
Post a Comment