Parameters provided to IElementUpdater.updateElement() [message #332986] |
Tue, 18 November 2008 09: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 #332989 is a reply to message #332986] |
Tue, 18 November 2008 11:03   |
Eclipse User |
|
|
|
Marcel Hoetter wrote:
> 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?
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:
"[..] The locator may be used to obtain services that are scoped in
the same way as the {@link UIElement}. Such services include but are
not limited to {@link IWorkbench}, {@link IWorkbenchWindow}, and
{@link IWorkbenchPartSite}.[..]"
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.
I suggest using the official route: Retrieve the IWorkbenchPartSite
from the UIElement#getServiceLocator() and you are done.
HTH & Greetings from Bremen,
Daniel Krügler
|
|
|
Re: Parameters provided to IElementUpdater.updateElement() [message #332994 is a reply to message #332989] |
Tue, 18 November 2008 15:42   |
Eclipse User |
|
|
|
> 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"?
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?)
|
|
|
Re: Parameters provided to IElementUpdater.updateElement() [message #333001 is a reply to message #332994] |
Wed, 19 November 2008 09: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
|
|
|
|
Re: Parameters provided to IElementUpdater.updateElement() [message #333075 is a reply to message #333001] |
Mon, 24 November 2008 16:16   |
Eclipse User |
|
|
|
> 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).
Ah! I new that those parameters could be retrieved from the
ExecutionEvent object passed by the framework to the IHandler.execute() method.
I was not aware that they are also provided to the IElementUpdater.updateElement()
method. Makes sense, i guess! Thanks! :)
>
> http://kickjava.com/src/org/eclipse/ui/internal/handlers/Tog gleCoolbarHandler.java.htm
Nice website! Bookmarked it...
>
> 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);
I already make use of the filter to scope the refreshElements() method to the one view that
actually needs to be updated.
>> 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.
No wonder: this is a bug according to Pauls post. (see below)
|
|
|
|
Powered by
FUDForum. Page generated in 0.03672 seconds