Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Hook into button from Toolbar
Hook into button from Toolbar [message #892458] Thu, 28 June 2012 10:06 Go to next message
Lars Schütze is currently offline Lars Schütze
Messages: 12
Registered: March 2012
Junior Member
Hello,

I want to change the behavior of a button in the toolbar of another plug-in.
I already added a button to this toolbar through the viewActions extension. But the IViewActionDelegate#selectionChanged() method is not called when other buttons of the view's toolbar are pressed, but mine.

How can I achieve to hook in there? The best would be to get notified when the button is pressed, before the action defined for this button is executed.

Regards,
Lars.
Re: Hook into button from Toolbar [message #900172 is a reply to message #892458] Sun, 05 August 2012 01:34 Go to previous message
John Steele is currently offline John Steele
Messages: 49
Registered: January 2010
Member
If it's a Command, you know it's ID, and you have access to a service locator, you can hook a listener to it using the IExecutionListener and the CommandService:

ICommandService commandService = (ICommandService) super.getSite().getService(ICommandService.class);
Command command = commandService.getCommand("the_command_id");
command.addExecutionListener(new IExecutionListener() {
 @Override
 public void preExecute(String commandId, ExecutionEvent event) {
 }
			
 @Override
 public void postExecuteSuccess(String commandId, Object returnValue) {
 }
			
 @Override
 public void postExecuteFailure(String commandId, ExecutionException exception) {
 }
			
 @Override
 public void notHandled(String commandId, NotHandledException exception) {
 }
});			


You can also add a global execution listener to be notified when any command is executed:

ICommandService commandService = (ICommandService) super.getSite().getService(ICommandService.class);
commandService.addExecutionListener(new IExecutionListener() {
 ...
});


Hope this helps!

[Updated on: Sun, 05 August 2012 01:34]

Report message to a moderator

Previous Topic:JavaCompletionProposalSorters extension does nothing
Next Topic:Disable lazy loading of pages
Goto Forum:
  


Current Time: Tue Sep 16 15:35:33 GMT 2014

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

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