How to disable/enable view toolbar menu/action in Eclipse Plugin Development [message #864708] |
Sun, 29 April 2012 23:55  |
Eclipse User |
|
|
|
I have View that extends ViewPart. In this view, I want to add toolbar menu. What I know, we can add toolbar menu by using ActionContributionItem or Action, and add it to ToolBarMenu from createPartControl method in ViewPart. But what I don't know, how we disable/enable the toolbar menu programmatically. So basically, I want to add Play, Stop, and Pause button to toolbar view. So at first, the Play button is on enabled mode, and the others are disabled. When I pressed Play button, it is disabled, and others will be enabled. For more details, what I want to achieve is something like the image I attached.
In the red circle are disabled button, and in the blue circle are enabled button.
|
|
|
Re: How to disable/enable view toolbar menu/action in Eclipse Plugin Development [message #977586 is a reply to message #864708] |
Fri, 09 November 2012 06:59  |
Eclipse User |
|
|
|
Hi Agung,
Do the following.
1. Implement your actions. ex: PlayAction, StopAction.
2. Register your view part(Player view part)
public class Playerview extends ViewPart
{
@Override
public void createPartControl(Composite parent) {
//your player code here.
//Listener registration. This is very important.
addListenerObject(this);
//Attach selection changed listener to the object where you want to perform the action based on the selection type. ex; viewer
viewer.addselectionchanged(new SelectionChangedListener())
}
}
//selection changed
private class SelectionChangedListener implements ISelectionChangedListener {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = Viewer.getSelection();
if (selection != null && selection instanceof StructuredSelection) {
Object firstElement = ((StructuredSelection)selection).getFirstElement();
//here you can handle the enable or disable based on your selection. that could be your viewer selection or toolbar.
if (playaction.isEnabled()) {
//enable stop action also
stopaction.setEnabled(true); //Do required actions here.
playaction.setEnabled (false);
}
}
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.07407 seconds