Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » refreshing commands based on workbench selection
refreshing commands based on workbench selection [message #335368] Fri, 03 April 2009 22:32 Go to next message
Del Myers is currently offline Del MyersFriend
Messages: 82
Registered: July 2009
Member
Hi,

I'm trying to contribute a command to a toolbar using the command framework. I'm
able to get it there, but I need it to be updated according to the selection in
the workbench. With the old action delegates, this was done with no trouble.
But, commands aren't so nice.

So, basically, what I have done is I've registered my own listeners to track the
active window/selection, and I try to run ICommandService.refreshElements() when
the selection gets changed, but updateElement() never gets called on my command
handler because "no user action has been performed on the command" yet, and my
command handler hasn't been loaded. I don't understand why things are done this
way. I need to be able to update the icon, text, and enablement based on the
selection. Is there any way that I can do this? It seems like it should be
simple. Thanks.

Del
Re: refreshing commands based on workbench selection [message #335377 is a reply to message #335368] Sun, 05 April 2009 01:25 Go to previous messageGo to next message
Ben Vitale is currently offline Ben VitaleFriend
Messages: 247
Registered: July 2009
Senior Member
You should be able to do this for your handler in plugin.xml

<enabledWhen>
<with
variable="selection">
<!-- Appropriate equals, instanceof, etc. test here -->
</with>
</enabledWhen>

-Ben

Del Myers wrote:
> Hi,
>
> I'm trying to contribute a command to a toolbar using the command
> framework. I'm able to get it there, but I need it to be updated
> according to the selection in the workbench. With the old action
> delegates, this was done with no trouble. But, commands aren't so nice.
>
> So, basically, what I have done is I've registered my own listeners to
> track the active window/selection, and I try to run
> ICommandService.refreshElements() when the selection gets changed, but
> updateElement() never gets called on my command handler because "no user
> action has been performed on the command" yet, and my command handler
> hasn't been loaded. I don't understand why things are done this way. I
> need to be able to update the icon, text, and enablement based on the
> selection. Is there any way that I can do this? It seems like it should
> be simple. Thanks.
>
> Del
Re: refreshing commands based on workbench selection [message #335398 is a reply to message #335368] Mon, 06 April 2009 13:54 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Until your plugin is loaded, your updateElement(*) won't be called (this
is the same with IActionDelegates).

As of 3.4 if you handler also implements IHandler2 it can be notified of
the current state via #setEnabled(Object) which is usually an
IEvaluationContext. This is called before most calls to
IHandler#isEnabled().

PW


--
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: refreshing commands based on workbench selection [message #335405 is a reply to message #335377] Mon, 06 April 2009 16:06 Go to previous messageGo to next message
Del Myers is currently offline Del MyersFriend
Messages: 82
Registered: July 2009
Member
Almost, but not quite. I need to change more than enablement. It is a "toggle"
command, and it will be either checked or unchecked depending on the current
selection. What I need is for my command to get loaded earlier than it is. There
has got to be a way to do this. I understand the platform's efforts to cut back
on memory used for a command, but, seriously, my command handler is smaller than
the proxy command. Is it really so important? Maybe, I guess, but the action
delegates seemed to work fine without memory overloads, or noticeable slowdown.

Del

Ben Vitale wrote:
> You should be able to do this for your handler in plugin.xml
>
> <enabledWhen>
> <with
> variable="selection">
> <!-- Appropriate equals, instanceof, etc. test here -->
> </with>
> </enabledWhen>
>
> -Ben
>
> Del Myers wrote:
>> Hi,
>>
>> I'm trying to contribute a command to a toolbar using the command
>> framework. I'm able to get it there, but I need it to be updated
>> according to the selection in the workbench. With the old action
>> delegates, this was done with no trouble. But, commands aren't so nice.
>>
>> So, basically, what I have done is I've registered my own listeners to
>> track the active window/selection, and I try to run
>> ICommandService.refreshElements() when the selection gets changed, but
>> updateElement() never gets called on my command handler because "no
>> user action has been performed on the command" yet, and my command
>> handler hasn't been loaded. I don't understand why things are done
>> this way. I need to be able to update the icon, text, and enablement
>> based on the selection. Is there any way that I can do this? It seems
>> like it should be simple. Thanks.
>>
>> Del
Re: refreshing commands based on workbench selection [message #335406 is a reply to message #335398] Mon, 06 April 2009 16:15 Go to previous messageGo to next message
Del Myers is currently offline Del MyersFriend
Messages: 82
Registered: July 2009
Member
Thanks, but like said in my reply to Ben (and in my original posting), my
problem isn't just with enablement, various things need to change about the
command because it toggles its state based on the state of the current
selection. Is there anything that can be done?

Paul Webster wrote:
> Until your plugin is loaded, your updateElement(*) won't be called (this
> is the same with IActionDelegates).
>
> As of 3.4 if you handler also implements IHandler2 it can be notified of
> the current state via #setEnabled(Object) which is usually an
> IEvaluationContext. This is called before most calls to
> IHandler#isEnabled().
>
> PW
>
>
Re: refreshing commands based on workbench selection [message #335443 is a reply to message #335406] Wed, 08 April 2009 14:16 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Del Myers wrote:
> Thanks, but like said in my reply to Ben (and in my original posting),
> my problem isn't just with enablement, various things need to change
> about the command because it toggles its state based on the state of the

You mean before your plugin is started? No, updating of text and icons
is only supported from the active handler, and that handler will be
proxied until the bundle is started by some user action (like actually
creating a view, or using a menu item or tool item).

PW


--
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


Previous Topic:Quick Fix Handler enabled when there are not resolutions
Next Topic:FormText Tabbing.
Goto Forum:
  


Current Time: Fri May 10 22:04:54 GMT 2024

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

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

Back to the top