Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Using specific selection to enable/disable commands
Using specific selection to enable/disable commands [message #637168] Thu, 04 November 2010 12:55 Go to next message
Erik Cognus is currently offline Erik CognusFriend
Messages: 6
Registered: November 2010
Junior Member
Hi all,

I'm trying to dynamically change the state of a command (contained in a view toolbar) depending on a specific selection in a tree of this view. I first used the selection variable of the command framework. But this caused the command always to be disabled when the view was not focused but the correct item was selected in the tree.

I always want the command to be enabled when an appropriate item is selected within the tree. Even when the view lost it focus and e.g. an editor gets the focus. Do you know a way how to handle this?

Thanks,
Cognus
Re: Using specific selection to enable/disable commands [message #637400 is a reply to message #637168] Fri, 05 November 2010 11:46 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Create your handler in your view so it can see the instance of the
viewer (or its selection provider).

Then as you want it enabled/disabled, call
org.eclipse.core.commands.AbstractHandler.setBaseEnabled(boo lean)

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: Using specific selection to enable/disable commands [message #637435 is a reply to message #637400] Fri, 05 November 2010 13:50 Go to previous messageGo to next message
Erik Cognus is currently offline Erik CognusFriend
Messages: 6
Registered: November 2010
Junior Member
But in this case I can't configure my handlers and commands within the plugin XML, right? I have to set the commands and handlers programmatically.

Cognus
Re: Using specific selection to enable/disable commands [message #637446 is a reply to message #637435] Fri, 05 November 2010 14:21 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Erik Cognus wrote:
> But in this case I can't configure my handlers and commands within the
> plugin XML, right? I have to set the commands and handlers
> programmatically.

commands are always in XML. it's only this specific handler you need to
activate from your createPartControl(*) (although you might have to take
special care to enable it at the global level, since normally activated
handlers within a view are only active within that view).


handlers through XML only have access to the global application state
(selection, activeMenuSelection, etc). That's why you end up disabled
when your view is not active. The XML alternative is to use
activeWorkbenchWindow and then extract your view using
org.eclipse.ui.IWorkbenchPage.findViewReference(String) and query its
ISelectionProvider (viewPart.getSite().getSelectionProvider()) directly.

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: Using specific selection to enable/disable commands [message #638340 is a reply to message #637446] Wed, 10 November 2010 21:21 Go to previous messageGo to next message
Heiko Ahlig is currently offline Heiko AhligFriend
Messages: 62
Registered: July 2009
Member
Another approache are:
-define a SourceProvider and a special variable,
- inside your view, add a selection change listerner, who comits the
value to this SourceProvider
- add a activation/deactivation check with the state of this variable

A good example for this are:

http://blog.eclipse-tips.com/2009/02/commands-part-5-authent ication-in-rcp.html

Hope it helps


Am 05.11.2010 15:21, schrieb Paul Webster:
> Erik Cognus wrote:
>> But in this case I can't configure my handlers and commands within the
>> plugin XML, right? I have to set the commands and handlers
>> programmatically.
>
> commands are always in XML. it's only this specific handler you need to
> activate from your createPartControl(*) (although you might have to take
> special care to enable it at the global level, since normally activated
> handlers within a view are only active within that view).
>
>
> handlers through XML only have access to the global application state
> (selection, activeMenuSelection, etc). That's why you end up disabled
> when your view is not active. The XML alternative is to use
> activeWorkbenchWindow and then extract your view using
> org.eclipse.ui.IWorkbenchPage.findViewReference(String) and query its
> ISelectionProvider (viewPart.getSite().getSelectionProvider()) directly.
>
> PW
>
>
Re: Using specific selection to enable/disable commands [message #641211 is a reply to message #638340] Wed, 24 November 2010 14:53 Go to previous message
Erik Cognus is currently offline Erik CognusFriend
Messages: 6
Registered: November 2010
Junior Member
Heiko Ahlig wrote on Wed, 10 November 2010 16:21
Another approache are:
-define a SourceProvider and a special variable,
- inside your view, add a selection change listerner, who comits the
value to this SourceProvider
- add a activation/deactivation check with the state of this variable



I'm not sure how this can help me solving the problem? Actually, I'm doing so and allowing only to open an empty view. But the desired way would be to totally prevent opening the perspective. I'm afraid that this is not possible in my case or with the facilities of eclipse in general.
Previous Topic:Eclipse Jobs to populate an SWT table
Next Topic:Text Editor Default Preference page
Goto Forum:
  


Current Time: Fri Apr 26 13:08:29 GMT 2024

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

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

Back to the top