Parameters provided to IElementUpdater.updateElement() [message #332986] |
Tue, 18 November 2008 04:14  |
Eclipse User |
|
|
|
Hi there!
I have a command handler implementing IElementUpdater. Through debugging and trial & error i found
out that the parameters Map contains a IWorkbenchPartSite that can be accessed like this:
public void updateElement(final UIElement element, final Map parameters) {
final IWorkbenchPartSite partSite = (IWorkbenchPartSite) parameters
.get("org.eclipse.ui.part.IWorkbenchPartSite");
...
}
I guess it is the IWorkbenchPartSite where the given UIElement is "shown" in the GUI. That is, the
code works as expected.
Can somebody please confirm this?
Is there some more documentation about IElementUpdater?
Thnx,
Marcel
|
|
|
|
|
Re: Parameters provided to IElementUpdater.updateElement() [message #333001 is a reply to message #332994] |
Wed, 19 November 2008 04:37   |
Eclipse User |
|
|
|
Marcel Hoetter wrote:
>> You should have a look at the documentation of UIElement, which
>> is one of the function parameters. The documentation of it's method
>> getServiceLocator() says:
>
> Well, i did have a look at the documentation of IElementUpdater, but...
>
> > The documentation of it's Map parameter says only that it contains all
> > parameters registered with the callback, so this seems of little help
> here.
>
> ...exactly. How and where does one "register parameters with the callback"?
AFAIK you can add parameters via the <parameter> section of the
org.eclipse.ui.menus ext.pt (child of <command>). It should also
be possible to add parameters programmatically (see below).
> Regarding the UIElement and it's getServiceLocator() method:
>
> > I suggest using the official route: Retrieve the IWorkbenchPartSite
> > from the UIElement#getServiceLocator() and you are done.
>
> Thanks for this input! However, I tried this and obviously the
> IServiceLocator returned by this method does not have an
> IWorkbenchPartSite in it's scope. In other words..
>
> public void updateElement(final UIElement element, final Map parameters) {
> final IWorkbenchPartSite partSite =
> (IWorkbenchPartSite)element.getServiceLocator()
> .getService(IWorkbenchPartSite.class);
> ...
> }
>
> ...only returns null. (Or am i doing something wrong here?)
Interesting, I hadn't expected that. I found another example
http://kickjava.com/src/org/eclipse/ui/internal/handlers/Tog gleCoolbarHandler.java.htm
which seems to imply that you need to add the IWorkbenchPartSite
in your AbstractHandler#execute method (untested):
public Object JavaDoc execute(ExecutionEvent event) throws
ExecutionException {
final IWorkbenchSite activeSite = HandlerUtil
.getActiveSiteChecked(event);
[...]
Map filter = new HashMap();
filter.put(IServiceScopes.PARTSITE_SCOPE, activeSite);
commandService.refreshElements(event.getCommand().getId(), filter);
}
HTH,
Daniel
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03583 seconds