Home » Eclipse Projects » Eclipse 4 » Pitfalls when command executes another command?
Pitfalls when command executes another command? [message #1725761] |
Mon, 07 March 2016 13:28 |
Andreas Sewe Messages: 111 Registered: June 2013 |
Senior Member |
|
|
Hi,
I have a Handled Toolitem toolbar contribution. Previously, this toolitem was handled by org.eclipse.ui.browser.openBrowser, but now I need to not only open a browser, but also perform some other bookkeeping action. To avoid code duplication, I decided to implement my own command such that it executes org.eclipse.ui.browser.openBrowser:
@Execute
public void execute(ECommandService commandService, EHandlerService handlerService) {
// do bookkeeping
Map parameters = new HashMap();
parameters.put("url", "http://www.example.org/");
Command command = commandService.createCommand("org.eclipse.ui.browser.openBrowser", parameters);
handlerService.executeHandler(command);
}
Unfortunately, executing the command like this changes behavior: Where before the browser was opened in an editor, now it opens a new window (of Firefox, in my case).
I suspect this is because the IEclipseContext, in which the org.eclipse.ui.browser.openBrowser command handler is looked up changes. But injecting the IEclipseContext into my custom command and then using
handlerService.executeHandler(command, eclipseContext);
doesn't do the trick either.
So, how do I execute a command from within another command in the same context (or at least in a context so similar that the behavior of openBrowser doesn't change)?
|
|
|
Re: Pitfalls when command executes another command? [message #1725778 is a reply to message #1725761] |
Mon, 07 March 2016 15:10 |
Erdal Karaca Messages: 854 Registered: July 2009 |
Senior Member |
|
|
I would suggest to debug into:
org.eclipse.ui.internal.browser.OpenBrowserHandler.execute(ExecutionEvent)
The handler may grab the wrong browser support (internal vs. external) implementation.
Andreas Sewe wrote on Mon, 07 March 2016 14:28Hi,
I have a Handled Toolitem toolbar contribution. Previously, this toolitem was handled by org.eclipse.ui.browser.openBrowser, but now I need to not only open a browser, but also perform some other bookkeeping action. To avoid code duplication, I decided to implement my own command such that it executes org.eclipse.ui.browser.openBrowser:
@Execute
public void execute(ECommandService commandService, EHandlerService handlerService) {
// do bookkeeping
Map parameters = new HashMap();
parameters.put("url", "http://www.example.org/");
Command command = commandService.createCommand("org.eclipse.ui.browser.openBrowser", parameters);
handlerService.executeHandler(command);
}
Unfortunately, executing the command like this changes behavior: Where before the browser was opened in an editor, now it opens a new window (of Firefox, in my case).
I suspect this is because the IEclipseContext, in which the org.eclipse.ui.browser.openBrowser command handler is looked up changes. But injecting the IEclipseContext into my custom command and then using
handlerService.executeHandler(command, eclipseContext);
doesn't do the trick either.
So, how do I execute a command from within another command in the same context (or at least in a context so similar that the behavior of openBrowser doesn't change)?
|
|
| | | | |
Re: Pitfalls when command executes another command? [message #1728925 is a reply to message #1725878] |
Fri, 08 April 2016 13:33 |
Eclipse User |
|
|
|
Coming to this late. The handler service does not shunt requests onto the UI thread. Although most commands are related to UI features, the command/handler framework can be used for headless or background purposes.
Your @Execute shouldn't make any assumptions of threadedness.
Brian.
|
|
| | | |
Re: Pitfalls when command executes another command? [message #1821728 is a reply to message #1725761] |
Wed, 19 February 2020 08:48 |
Horros Dito Messages: 1 Registered: February 2020 |
Junior Member |
|
|
Andreas Sewe wrote on Mon, 07 March 2016 13:28Hi,
I have a Handled Toolitem toolbar contribution. Previously, this toolitem was handled by org.eclipse.ui.browser.openBrowser, but now I need to not only open a browser, but also perform some other action. To avoid code duplication, I decided to implement my own command such that it executes org.eclipse.ui.browser.openBrowser:
@Execute
public void execute(ECommandService commandService, EHandlerService handlerService) {
// do bookkeeping
Map parameters = new HashMap();
parameters.put("url",
Command command = commandService.createCommand("org.eclipse.ui.browser.openBrowser", parameters);
handlerService.executeHandler(command);
}
Unfortunately, executing the command like this changes behavior: Where before the browser was opened in an editor, now it opens a new window (of Firefox, in my case).
I suspect this is because the IEclipseContext, in which the org.eclipse.ui.browser.openBrowser command handler is looked up changes. But injecting the IEclipseContext into my custom command and then using
handlerService.executeHandler(command, eclipseContext);
doesn't do the trick either.
So, how do I execute a command from within another command in the same context (or at least in a context so similar that the behavior of openBrowser doesn't change)?
how did you solve the issue?
|
|
|
Goto Forum:
Current Time: Wed Apr 24 14:59:43 GMT 2024
Powered by FUDForum. Page generated in 0.05170 seconds
|