Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Parameters provided to IElementUpdater.updateElement()
Parameters provided to IElementUpdater.updateElement() [message #332986] Tue, 18 November 2008 09:14 Go to next message
Marcel Hoetter is currently offline Marcel HoetterFriend
Messages: 28
Registered: July 2009
Junior Member
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 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
Marcel Hoetter is currently offline Marcel HoetterFriend
Messages: 28
Registered: July 2009
Junior Member
> 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 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
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 #333067 is a reply to message #332994] Mon, 24 November 2008 13:20 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Gah! I almost dropped my coffee (that's twice in 2 weeks :-)

That appears to be a regression from 3.3. Please open a bug at
https://bugs.eclipse.org/bugs/



--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: Parameters provided to IElementUpdater.updateElement() [message #333075 is a reply to message #333001] Mon, 24 November 2008 16:16 Go to previous messageGo to next message
Marcel Hoetter is currently offline Marcel HoetterFriend
Messages: 28
Registered: July 2009
Junior Member
> 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)
Re: Parameters provided to IElementUpdater.updateElement() [message #333076 is a reply to message #333067] Mon, 24 November 2008 16:20 Go to previous message
Marcel Hoetter is currently offline Marcel HoetterFriend
Messages: 28
Registered: July 2009
Junior Member
Paul Webster schrieb:
> Gah! I almost dropped my coffee (that's twice in 2 weeks :-)
>
> That appears to be a regression from 3.3. Please open a bug at
> https://bugs.eclipse.org/bugs/

Done: https://bugs.eclipse.org/bugs/show_bug.cgi?id=256293
Previous Topic:Cannot find the button to reset or forget the dialog settings
Next Topic:Lateral menu using fast view / Presentation framework
Goto Forum:
  


Current Time: Thu Dec 26 22:07:09 GMT 2024

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

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

Back to the top