Bug 180203 - Enablement of toolbar icons
Summary: Enablement of toolbar icons
Status: ASSIGNED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P5 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 180206 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-03-30 10:23 EDT by Tomas Krecmer CLA
Modified: 2019-09-06 16:15 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tomas Krecmer CLA 2007-03-30 10:23:08 EDT
Hi,
i have problem with enablement of toolbar icons. I created menu and toolbar with one command behind and one handler. Menu and command have defined visibleWhen condition. It looks like following:

<menuContribution locationURI="toolbar:biz.wss.rcp.fxmanager.toolbar">
 <command commandId="biz.wss.rcp.fxmanager.apply"
        disabledIcon="icons/sample.gif"
        icon="icons/apply.gif"
        id="biz.wss.rcp.fxmanager.menu.apply"
        style="push">
  <visibleWhen>
   <with variable="activeContexts">
    <iterate operator="or">
     <equals value="biz.wss.rcp.fxmanager.FXDealEntryEditor"/>
    </iterate>
   </with>
  </visibleWhen>
 </command>
</menuContribution>

<menuContribution locationURI="menu:biz.wss.rcp.fxmanager.menu.command">
 <command
        commandId="biz.wss.rcp.fxmanager.apply"
        id="biz.wss.rcp.fxmanager.menu.apply"
        label="Apply">      		
  <visibleWhen>
   <with variable="activeContexts">
     <iterate operator="or">
       <equals value="biz.wss.rcp.fxmanager.FXDealEntryEditor"/>
     </iterate>
    </with>
  </visibleWhen>
 </command>
</menuContribution>

<handler
  commandId="biz.wss.rcp.fxmanager.apply"
  class="biz.wss.rcp.rcpmanager.core.handler.GenericHandler">
</handler>

<command
   id="biz.wss.rcp.fxmanager.apply"
   name="Apply">
</command>

Enablement logic is implemented in biz.wss.rcp.rcpmanager.core.handler.GenericHandler::isEnabled().

I have some controls in editor and when i move from one to other i am trying to push Ecplise update enablement state of menus/toolbars. I created listener and when i move to other control inside editor.
My first idea was this listener will change selection (ISelection) on active part, but it didnt work. Selection provider was properly set and 4 listeners from platform was registered. But state of widgets remained same.
I did another attempt and listener tried to set/unset some fake context. Then menu enablement started to work but toolbars remained untouched.

All widgets are properly enabled only when you open another editor, switch to it and back...

Thanks in advance
Tomas Krecmer
Comment 1 Tomas Krecmer CLA 2007-03-30 10:42:02 EDT
*** Bug 180206 has been marked as a duplicate of this bug. ***
Comment 2 Paul Webster CLA 2007-03-30 12:04:41 EDT
What version of eclipse are you running?

Also, if your handler uses programmatic enablement your icons should be enabled until some user action causes them to load.

PW
Comment 3 Tomas Krecmer CLA 2007-04-02 03:13:35 EDT
I am using 3.3M6. I expect if menu with same command behind is enabled properly then toolbar icon should be enabled as well. When i click to toolbar icon i get org.eclipse.core.commands.NotEnabledException.

Tomas
Comment 4 Paul Webster CLA 2007-04-02 07:12:28 EDT
(In reply to comment #3)
> I am using 3.3M6. I expect if menu with same command behind is enabled properly
> then toolbar icon should be enabled as well. When i click to toolbar icon i get
> org.eclipse.core.commands.NotEnabledException.

If you click on the toolbar button and then the menu item, the menu item works?

What if you click on the menu item first?

PW
Comment 5 Paul Webster CLA 2007-04-02 07:14:01 EDT
Is you generic handler firing HandlerEvents?

PW
Comment 6 Tomas Krecmer CLA 2007-04-02 08:54:10 EDT
"If you click on the toolbar button and then the menu item, the menu item works?
What if you click on the menu item first?
PW"

I am not able to click to menu item as it is properly disabled.

"Is you generic handler firing HandlerEvents?"

No, i do not fire any events from my handler. It is inherited from AbstractHandler. It implements isEnabled() method.

When i switch to other editor and back it is enabled properly. Seems like some notification to toolbars is missing.

Comment 7 Paul Webster CLA 2007-04-02 19:29:01 EDT
(In reply to comment #6)
> "Is you generic handler firing HandlerEvents?"
> 
> No, i do not fire any events from my handler. It is inherited from
> AbstractHandler. It implements isEnabled() method.
> 

If you override isEnabled() you must fire a handler event.  See the class doc for AbstractHandler and the javadoc for HandlerEvent.

PW

Comment 8 Tomas Krecmer CLA 2007-04-03 05:30:24 EDT
I tried to fire HandlerEvent when status of my application changed and it started to work. Anyway i am not sure how to fire HandlerEvent properly. I can make in my implementation of handler fireHandlerChanged() public, but i am not able to get list of all registered handlers. I am able to get list of Commands and its handlers via CommandService, but i get HandlerProxy instead of my implementation.
Comment 9 Tomas Krecmer CLA 2007-04-03 05:56:52 EDT
I see another problem. Handlers created via plugin.xml are singletons through whole workbench. If you have more workbench windows opened with the same editor and you want to change enablement you will fire HandlerEvent on your handler. It will properly change enablement in active editor but also in other inactive...
Comment 10 Paul Webster CLA 2007-04-03 08:17:21 EDT
(In reply to comment #8)
> I tried to fire HandlerEvent when status of my application changed and it
> started to work. Anyway i am not sure how to fire HandlerEvent properly. I can
> make in my implementation of handler fireHandlerChanged() public, but i am not
> able to get list of all registered handlers. 

Your handler should be listening to events from your model, and update its enablement state as appropriate (and then fire the HandlerEvent).

Before it is instantiated, you can use the enabledWhen clause to build an declarative enablement condition that will be managed for you.

We use org.eclipse.ui.internal.AbstractEnabledHandler and when our listeners detect a change we care about, we just call setEnabled(*)

PW
Comment 11 Paul Webster CLA 2007-04-03 08:18:59 EDT
If your handler enablement state depends on the active editor you should keep track of it.

At least for now it will show the odd state in the inactive window (we're working on that under another bug).  But it can't effect anything.

PW
Comment 12 Eclipse Webmaster CLA 2019-09-06 16:15:38 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.