Bug 231304 - [Contributions] Tooltip for Menu Contributions placed on toolbar: does not include keybinding sequence(inconsistency in migrating from ActionSets to MenuContributions)
Summary: [Contributions] Tooltip for Menu Contributions placed on toolbar: does not in...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M3   Edit
Assignee: Prakash Rangaraj CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-09 10:06 EDT by Piotr Haratym CLA
Modified: 2009-01-26 18:43 EST (History)
5 users (show)

See Also:


Attachments
sample rcp application that shows the bug (54.28 KB, application/octet-stream)
2008-09-09 16:13 EDT, Thorsten Wärtel CLA
no flags Details
A patch for the bug (4.25 KB, patch)
2008-09-29 18:29 EDT, Prakash Rangaraj CLA
no flags Details | Diff
Patch adding the listerner for binding changes (11.96 KB, patch)
2008-10-03 06:20 EDT, Prakash Rangaraj CLA
no flags Details | Diff
v02 + generic method getToolTipText() added (11.93 KB, patch)
2008-10-06 06:40 EDT, Prakash Rangaraj CLA
no flags Details | Diff
CCI v03 (11.57 KB, patch)
2008-10-06 12:40 EDT, Paul Webster CLA
no flags Details | Diff
v03 + NLS string instead of JFaceResources.format (14.91 KB, patch)
2008-10-07 10:08 EDT, Prakash Rangaraj CLA
no flags Details | Diff
v04 - patch based on v03 (14.95 KB, patch)
2008-10-08 02:18 EDT, Prakash Rangaraj CLA
pwebster: iplog+
Details | Diff
Test v01 (6.04 KB, patch)
2008-10-15 08:31 EDT, Prakash Rangaraj CLA
pwebster: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Piotr Haratym CLA 2008-05-09 10:06:09 EDT
Build ID: M20071023-1652

Steps To Reproduce:
1. Create a command with a valid key binding
2. Place it through Menu Contributions extension on toolbar
3. Put mouse pointer over newly created button(command) on toolbar => tooltip shows but without key sequence
4. Press the keys from keybinding sequence => command is executed
5. Bind the command Action/ActionSet and place it in workbench => when tooltip is shown it includes binded key sequence


More information:
We are trying to migrate from ActionSets to new MenuContribution solutions. In older solution keybindings were shown to user, in new one they are not. This is not acceptable  for our clients...
Comment 1 Remy Suen CLA 2008-07-20 08:49:20 EDT
Do you have a sample plug-in project that you can attach to this bug to reproduce the behaviour?
Comment 2 Thorsten Wärtel CLA 2008-09-09 16:13:13 EDT
Created attachment 112126 [details]
sample rcp application that shows the bug

The attached rcp application shows the described bug. The application provides contributions via org.eclipse.ui.menus to add the save command to a file menu and to a toolbar.

While the default key binding CTRL+S is shown in the menu item, the toolbar button's tooltip only shows the command's name.

To demonstrate the previous behaviour, I added another toolbar and added the default workbench action SAVE to it (see ApplicationActionBarAdvisor). The action button's tooltip does show the key binding in the tooltip.
Comment 3 Paul Webster CLA 2008-09-11 09:06:12 EDT
This can be fixed in org.eclipse.ui.menus.CommandContributionItem.update(String).  When creating the tooltip, it needs to get the best active binding from org.eclipse.ui.keys.IBindingService.getBestActiveBindingFor(ParameterizedCommand)

PW
Comment 4 Thorsten Wärtel CLA 2008-09-11 15:03:15 EDT
(In reply to comment #3)
> This can be fixed in
> org.eclipse.ui.menus.CommandContributionItem.update(String).  When creating the
> tooltip, it needs to get the best active binding from
> org.eclipse.ui.keys.IBindingService.getBestActiveBindingFor(ParameterizedCommand)
> 

I tried this in my ganymede installtion (build id I20080617-2000) but didn't get any binding returned from getBestActiveBindingFor(command).

I did a little debugging and noticed that the BindigService's BindingManager does not contain any active bindings at the time the toolbar contributions are evaluated. The menu bar contribution seems to get evaluated later, when the file menu is actually opened and debugging this showed, that the CommandContributionItem instance for the menu item gets an active binding from the BindingService - the BindingManager then contains a filled HashMap of active bindings.

Digging a bit deeper I found, that org.eclipse.jface.bindings.BindingManager.recomputeBindings() is called to initialize the BindingManager when a kex binding is queried from BindingService. At the time the toolbar contributions are evaluated there don't seem to be any active contexts yet, hence the empty activeBindings. Later in application initialization, recomputeBindings() gets called again from contextManagerChanged(ContextManagerEvent). This results in all the bindings being set as active and later to be found by the menu contribution.

Could it be that the initialization code is in wrong order and the toolbar contributions should be evaluated after the active contexts are set? I'm not that deep in the platzform code, so I didn't know where to check for this.

regards,
Thorsten
Comment 5 Paul Webster CLA 2008-09-12 08:24:38 EDT
(In reply to comment #4)
> Could it be that the initialization code is in wrong order and the toolbar
> contributions should be evaluated after the active contexts are set? I'm not
> that deep in the platzform code, so I didn't know where to check for this.
> 

Wow, you've already dug deeply into the platform code.

I had hoped to avoid this, but it looks like CommandContributionItems will have to add themselves using org.eclipse.jface.bindings.BindingManager.addBindingManagerListener(IBindingManagerListener)

There is no BindingManager currently exposed as API, so I'll need to do some investigation to find out where is a good place to make it happen.  Then org.eclipse.jface.bindings.BindingManagerEvent.isActiveBindingsChangedFor(ParameterizedCommand) can be used by each CCI to see if its tooltip needs to be updated.

PW
Comment 6 Prakash Rangaraj CLA 2008-09-29 18:29:27 EDT
Created attachment 113819 [details]
A patch for the bug

Paul,

       I've attached a fix. Please review and let me know whether this is fine.
Comment 7 Paul Webster CLA 2008-10-01 14:18:38 EDT
(In reply to comment #6)
> Created an attachment (id=113819) [details]
> A patch for the bug

You are definitely heading in the correct direction. Good catch on that ExternalActionManager bug :-)

Because CCI can see services, I would like to not use the ExternalActionManager.  Instead look at exposing the BindingManager add/remove listener functionality through the IBindingService, similar to the pattern used for the CommandManager listener/ICommandService.

In CCI then you would want code similar to org.eclipse.jface.action.ExternalActionManager.CommandCallback.bindingManagerChanged(BindingManagerEvent), where you check for the binding changes using event.isActiveBindingsChanged() and event.isActiveBindingsChangedFor(command) instead of the property change listener.


Thanx,
PW
Comment 8 Prakash Rangaraj CLA 2008-10-03 04:58:48 EDT
(In reply to comment #7)

> You are definitely heading in the correct direction. Good catch on that
> ExternalActionManager bug :-)

Paul,
    As per your suggestion, I'm looking at not using ExternalActionManager. That means the bug in that class would be irrelevant to this bug. I don't want to leave it as it is, so filed a bug separately (Bug#249574) and submitted a patch. For this bug I'll concentrate on the CCI and the API additions for now.
Comment 9 Prakash Rangaraj CLA 2008-10-03 06:20:41 EDT
Created attachment 114173 [details]
Patch adding the listerner for binding changes

(In reply to comment #7)
> Because CCI can see services, I would like to not use the
> ExternalActionManager.  Instead look at exposing the BindingManager add/remove
> listener functionality through the IBindingService, similar to the pattern used
> for the CommandManager listener/ICommandService.
> 
> In CCI then you would want code similar to
> org.eclipse.jface.action.ExternalActionManager.CommandCallback.bindingManagerChanged(BindingManagerEvent),
> where you check for the binding changes using event.isActiveBindingsChanged()
> and event.isActiveBindingsChangedFor(command) instead of the property change
> listener.

Paul, 
     I've implemented your suggestions. Also I'm not a big fan of methods spawning several lines. So when adding the code for setting the tooltip, I've refactored the update method into smaller methods. Let me know whether this is fine or should revert it to the same old large method.
Comment 10 Paul Webster CLA 2008-10-03 13:55:53 EDT
Good work.

Here are some comments:

1) could you change the setToolTipText(*) method to a getToolTipText() method that can calculate the correct tooltip?  Then you can use it in updateToolItem() and updateButton()

2) Instead of using JFaceResources.format(*) you should use org.eclipse.ui.internal.WorkbenchMessages for the workbench level i18n message.  You'll have to create an equivalent method/property in messages.properties and then use org.eclipse.osgi.util.NLS.bind(String, Object, Object)

3) splitting up the method seems fine to me.

PW
Comment 11 Prakash Rangaraj CLA 2008-10-06 06:40:36 EDT
Created attachment 114290 [details]
v02 + generic method getToolTipText() added

(In reply to comment #10)
> 1) could you change the setToolTipText(*) method to a getToolTipText() method
> that can calculate the correct tooltip?  Then you can use it in
> updateToolItem() and updateButton()

    Done. Available in the attached patch. I didn't do this earlier, because the  button's tooltip was not displaying the key bindings earlier!

> 2) Instead of using JFaceResources.format(*) you should use
> org.eclipse.ui.internal.WorkbenchMessages for the workbench level i18n message.
>  You'll have to create an equivalent method/property in messages.properties and
> then use org.eclipse.osgi.util.NLS.bind(String, Object, Object)

    hmmmm. Not sure whether we should be using WorkbenchMessages here. Can you verify it again?
Comment 12 Paul Webster CLA 2008-10-06 12:40:26 EDT
Created attachment 114330 [details]
CCI v03

Your patch v02 looks good.  I move the update*() methods around so they reflect the order of the if statements (shows up as fewer diffs) and added a null check (the UI Test Suites were failing with many errors).

You are correct, WorkbenchMessages isn't really the right place.  You should add an NLS class and properties file for the internal package that matches the public package: org.eclipse.ui.internal.menus (we don't generally put NLS classes in public packages, unless the intent is to make something i18n API).

PW
Comment 13 Prakash Rangaraj CLA 2008-10-07 10:08:11 EDT
Created attachment 114419 [details]
v03 + NLS string instead of JFaceResources.format

(In reply to comment #12)
> You should add an NLS class and properties file for the internal package

   Done.
Comment 14 Paul Webster CLA 2008-10-07 14:52:58 EDT
(In reply to comment #13)
> Created an attachment (id=114419) [details]
> v03 + NLS string instead of JFaceResources.format
> 

Please respin this patch based on 

> Created an attachment (id=114330) [details]
> CCI v03

it includes the update*() method order change, plus NPE protection (I have 29 failures + 712 errors in my UI Test Suites).  Please run the tests before patch review.

The NLS addition looks good.

PW
Comment 15 Prakash Rangaraj CLA 2008-10-08 02:18:12 EDT
Created attachment 114510 [details]
v04 - patch based on v03

(In reply to comment #14)

> Please respin this patch based on 
> 
> > Created an attachment (id=114330) [details] [details]
> > CCI v03
> 

      Done.
Comment 16 Paul Webster CLA 2008-10-08 08:20:59 EDT
(In reply to comment #15)
> Created an attachment (id=114510) [details]
> v04 - patch based on v03

Looks good.

Released to HEAD >20081008

We'll need to write some tests for this in the /org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/menus/MenusTestSuite.java

PW
Comment 17 Prakash Rangaraj CLA 2008-10-15 08:31:17 EDT
Created attachment 115137 [details]
Test v01

(In reply to comment #16)
> We'll need to write some tests for this in the /org.eclipse.ui.tests/Eclipse UI
> Tests/org/eclipse/ui/tests/menus/MenusTestSuite.java
> 
> PW
> 

Done.
Comment 18 Paul Webster CLA 2008-10-15 15:26:53 EDT
(In reply to comment #17)
> Created an attachment (id=115137) [details]
> Test v01

This failed with a 
junit.framework.ComparisonFailure: expected:<Testing Tooltip ([Alt+Shif]t+1)> but was:<Testing Tooltip ([Shift+Al]t+1)> on linux :-)  I updated the code to use KeySequence (the format() calls should make it match on either platform).

The patch included 2 parts from the dynamic contribution item patch (it didn't compiled, but I simply removed them).

I simplified the test by one level, filling a ToolBarManager and then instantiating the ToolBar (and removing the toolbar element from the menuContribution).

Released to HEAD >20081015

PW




Comment 19 Paul Webster CLA 2008-10-21 10:31:32 EDT
Reassign
Comment 20 Paul Webster CLA 2008-10-21 10:32:03 EDT
done
Comment 21 A Patel CLA 2009-01-26 18:43:26 EST
This bug seems very familiar to what we are seeing. 

In our case, the first editor that we open has an action in its toolbar which has tool tip e.g "Insert (Ctrl + Enter)" . Now you open the second editor for the same type of file and the key bindings disappear, e.g "Insert". This happens for pretty much all actions in the second editor's toolbar. Any subsequent editors have the same issue. Although, the commands execute fine in all editors if you use the associated key bindings. 

The only difference is that Isee this bug was found in 3.3.1 but we did not see this issue in 3.3.1. We just recently moved to 3.4.1 and this behavior started. 

I just want to make sure that this bug can cause the behavior described above. Can anybody please confirm?