Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » How to disable/enable view toolbar menu/action in Eclipse Plugin Development(Eclipse Plugin Development)
How to disable/enable view toolbar menu/action in Eclipse Plugin Development [message #864708] Mon, 30 April 2012 03:55 Go to next message
Agung Pratama is currently offline Agung Pratama
Messages: 2
Registered: April 2012
Junior Member
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 11:59 Go to previous message
Kondal Kolipaka is currently offline Kondal Kolipaka
Messages: 7
Registered: November 2010
Junior Member
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);

}

}

}

}

Previous Topic:Help needed with link error
Next Topic:ECLIPSE JUNO RCP application.e4xmi eventBroker
Goto Forum:
  


Current Time: Tue Sep 23 12:38:54 GMT 2014

Powered by FUDForum. Page generated in 0.04699 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software