Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » [Commands] Semantics of IHandlerService.activateHandler
[Commands] Semantics of IHandlerService.activateHandler [message #655143] Fri, 18 February 2011 13:41 Go to next message
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
The specification of the overload

IHandlerActivation activateHandler(String commandId, IHandler handler);

says (emphasis mine):

"If this service was retrieved from the workbench, then this handler
will be active globally. **If the service was retrieved from a nested
component, then the handler will only be active within that component**."

I'm particularly interested in the precise meaning of "active within
that component": What does that mean?

I stumbled across this when I constructed a view which behaves similar
to the Outline view, i.e. it provides dynamically changing contents
based on a "page" concept". Within some some currently active page I
retrieved the IHandlerService from the site of the presenting view, but
all activated handlers behaved like disabled ones (i.e. the menus where
visible, but not enabled). After hours of searching for the cause I
finally tried to use the IHandlerService from the workbench instead,
which worked. This looks like a pity to me, because certainly the active
page is "within" the site of my hosting view.

I would appreciate any hints what's going on here and why I need to use
the global provider - which does not look like a reasonable approach to me.

Thanks & Greetings from Bremen,

Daniel Krügler
Re: [Commands] Semantics of IHandlerService.activateHandler [message #655156 is a reply to message #655143] Fri, 18 February 2011 14:06 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 02/18/2011 08:41 AM, Daniel Krügler wrote:
> "If this service was retrieved from the workbench, then this handler
> will be active globally. **If the service was retrieved from a nested
> component, then the handler will only be active within that component**."

Perhaps "active within that component" should read "active while that
component is active".

ex: refresh.

I could activate a handler from the IHandlerService I got from the
IWorkbenchWindow for each window I open. The handler is considered for
activation while it's IWorkbenchWindow is active.

I then activate a handler for refresh in the Package Explorer and
another one in my TobleroneEditor. When the Package Explorer is active,
its refresh handler is considered for activation (and wins)
File>Refresh will use that handler. When I activate my TobleroneEditor
its refresh handler is considered for activation (and wins).
File>Refresh will use the TobleroneEditor refresh handler.

If I activate a view other than the Package Explorer or TobleroneEditor,
the the refresh handler from my IWorkbenchWindow is used.

Does that help?

In theory, if you use a PageBookView based view (which provides a
PageSite) then activating the handler for a page should provide that
handler as long as the view is active.

PW


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


Re: [Commands] Semantics of IHandlerService.activateHandler [message #655184 is a reply to message #655156] Fri, 18 February 2011 15:11 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
On 2011-02-18 15:06, Paul Webster wrote:
> On 02/18/2011 08:41 AM, Daniel Krügler wrote:
>> "If this service was retrieved from the workbench, then this handler
>> will be active globally. **If the service was retrieved from a nested
>> component, then the handler will only be active within that component**."
>
> Perhaps "active within that component" should read "active while that
> component is active".
>
> ex: refresh.
>
> I could activate a handler from the IHandlerService I got from the
> IWorkbenchWindow for each window I open. The handler is considered for
> activation while it's IWorkbenchWindow is active.
>
> I then activate a handler for refresh in the Package Explorer and
> another one in my TobleroneEditor. When the Package Explorer is active,
> its refresh handler is considered for activation (and wins) File>Refresh
> will use that handler. When I activate my TobleroneEditor its refresh
> handler is considered for activation (and wins). File>Refresh will use
> the TobleroneEditor refresh handler.
>
> If I activate a view other than the Package Explorer or TobleroneEditor,
> the the refresh handler from my IWorkbenchWindow is used.
>
> Does that help?

Thanks for your explanations, but unfortunately the problem cause still
remains unclear to me, see below.

> In theory, if you use a PageBookView based view (which provides a
> PageSite) then activating the handler for a page should provide that
> handler as long as the view is active.

I'm indeed using the IPageSite from a view (not a PageBookView, though,
but a view which contains a PageBook) and I also found out that I can
use the workbenchwindow belonging to this site as working
IServicelocator, but the page-site still does not work as service
locator. I noticed that a pre-defined command (e.g restart) does work,
but this does not require manual activation anyway. The problem occurs
when I'm trying to use a handler that is very similar to the pre-defined
CollapseAllHandler and needs manual activateHandler calls.

Could the problem be that I indeed need something like a PageBookView to
realize that? I noticed that this view internally keeps an individual
site per page.

Thanks again,

- Daniel
Re: [Commands] Semantics of IHandlerService.activateHandler [message #655198 is a reply to message #655184] Fri, 18 February 2011 15:48 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 02/18/2011 10:11 AM, Daniel Krügler wrote:
> Could the problem be that I indeed need something like a PageBookView to
> realize that? I noticed that this view internally keeps an individual
> site per page.

PageBookView creates PageSites (which generate NestableHandlerService in
3.x). PageBookView also does the work to activate/deactivate them as
the pages turn, like org.eclipse.ui.part.PageBookView.showPageRec(PageRec).

If you simply use the view site, activating page1handler would provide a
handler for that command ... activating page2handler for the same
command would disable the command (since they conflict).

PW

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


Re: [Commands] Semantics of IHandlerService.activateHandler [message #655212 is a reply to message #655198] Fri, 18 February 2011 16:21 Go to previous message
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
On 2011-02-18 16:48, Paul Webster wrote:
> On 02/18/2011 10:11 AM, Daniel Krügler wrote:
>> Could the problem be that I indeed need something like a PageBookView to
>> realize that? I noticed that this view internally keeps an individual
>> site per page.
>
> PageBookView creates PageSites (which generate NestableHandlerService in
> 3.x). PageBookView also does the work to activate/deactivate them as the
> pages turn, like org.eclipse.ui.part.PageBookView.showPageRec(PageRec).
>
> If you simply use the view site, activating page1handler would provide a
> handler for that command ... activating page2handler for the same
> command would disable the command (since they conflict).

Brilliant, Paul, that was the solution of my problem!

Thanks and have a nice weekend,

- Daniel
Previous Topic:Property testers Versus Source Providers
Next Topic:Tying Editor & View
Goto Forum:
  


Current Time: Sat Oct 25 08:49:25 GMT 2014

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

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