|
Re: How to create a handler by id? [message #987133 is a reply to message #987082] |
Fri, 23 November 2012 17:29 |
Eclipse User |
|
|
|
Handlers aren't required to have elementIds, and a command can have many possible handlers. You'd typically request that a handler be executed through the EHandlerService by specifying the command and parameters.
|
|
|
|
|
Re: How to create a handler by id? [message #987638 is a reply to message #987414] |
Tue, 27 November 2012 12:00 |
Alex Kipling Messages: 260 Registered: July 2012 |
Senior Member |
|
|
Because getting information from an extension point is heavyweight:
IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(
MODULE_ID);
for (IConfigurationElement configElement : configElements) {
//search the Element here...
}
contributing a Handler for a Command and executing it by ID is clearer.
It would be even better to contribute JUST THE Handler (no command), because I know that there will be only one Handler, and so I started this thread.
[Updated on: Tue, 27 November 2012 12:00] Report message to a moderator
|
|
|
Re: How to create a handler by id? [message #987670 is a reply to message #987638] |
Tue, 27 November 2012 14:16 |
Eclipse User |
|
|
|
Quote:
Is there a way to create the handler by id only?
Can I somehow resolve the id to bundleURI?
Short answer: no. You'll need to do the search and creation yourself. You might want to check if the MHandler has an object already before creating a new one.
Quote: contributing a Handler for a Command and executing it by ID is clearer.
I'm not sure how it's more clear considering it's (mis-?) using a part of the framework for a totally unanticipated and unintended purpose.
First, heavyweight is usually used in the context of execution time or memory consumption, not in having to code a loop. If you're seeing a performance hit iterating over the extension registry, you should be clear and file a bug report with reproducible data -- it's been pretty heavily tuned.
Second, all the model searches come down to iterating over the model elements. I.e., equally "heavyweight". In fact, it's even more "heavyweight" as handlers can be installed at many different points in the model (see the implementors of MHandlerContainer) -- so you're looking at a complete graph traversal, which is "expensive" in terms of stack (e.g., you'll be implementing BFS or DFS of some kind).
Finally, I'm not understanding your desire for pursuing this appraoch. If you know a handler, why are you using the E4 framework at all? The E4 command/handler design was intended to separate the intent (the command) from the implementation (the handler), where the implementation is identified based on the current context. This allows one part to contribute a completely different "org.eclipse.ui.delete" handler from the Package Explorer, for example. This seems to be an example of "when you have a hammer, everything looks like a nail".
Anyways, best of luck.
Brian.
|
|
|
Re: How to create a handler by id? [message #987794 is a reply to message #987670] |
Wed, 28 November 2012 08:31 |
Alex Kipling Messages: 260 Registered: July 2012 |
Senior Member |
|
|
Thnx for the answer, Brian!
Maybe I should provide some explanation:
You are right - I used "heavyweight" as a large, chunky piece of code, it was not about the erformance.
The Handler I know, because I'm getting a Plugin earlier in my code. This plugin is found dynamically, using the e4 way.
Now this plugin should contribute some own funcitonality. Plugin does this, by providing a handler. How else plugin could contribute some executable piece of code?
For now, to execute the code - plugin has to provide a command either. This is redundant, and so i would like to execute the handler directly.
I am aware about the purposes, which handlers and commands were introduced for.
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06576 seconds