This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 410426 - [Contributions] [Compatibility] VisibleWhen from contribution factories not handled in toolbars
Summary: [Contributions] [Compatibility] VisibleWhen from contribution factories not h...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3   Edit
Hardware: PC All
: P3 major (vote)
Target Milestone: 4.4 M6   Edit
Assignee: Paul Webster CLA
QA Contact: Daniel Rolka CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 428322
  Show dependency tree
 
Reported: 2013-06-11 05:14 EDT by Maxime Porhel CLA
Modified: 2014-03-04 12:32 EST (History)
5 users (show)

See Also:


Attachments
anyVisibleWhen draft patch to handle Factory case in toolbar (3.38 KB, patch)
2013-06-11 05:14 EDT, Maxime Porhel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Maxime Porhel CLA 2013-06-11 05:14:33 EDT
Created attachment 232212 [details]
anyVisibleWhen draft patch to handle Factory case in toolbar

Hi,

VisibleWhen expression of IContributionItems created by a toolbar contribution factory are never evaluated on Kepler RC2.

We have a toolbar populated through IMenuService#populateContributionManager(*). All our menu contributions (org.eclipse.ui.menus extension point) inherit from org.eclipse.ui.menus.ExtensionContributionFactory.  Their createContributionItems methods are called when we use IMenuService#populateContributionManager(*) and some org.eclipse.e4.ui.model.application.ui.menu.impl.OpaqueMenuItemImpl are created. 

Our contribution factories create IContributionItem  with visible when expressions. These visibleWhen expressions are never evaluated, but they seems to be well added to the application model as MCoreExpression of the MUIElement(MOpaqueToolITem) created from our IContributionItem. ToolBarContributionRecord.mergeIntoModel() detects the use of a factory and call mergeFactoryIntoModel(), otherwise it directly call MToolBarContribution.getChildren().

However, during the next phase, ToolbarContributionRecord does not handle the factory case and always return false for our contributions. I discovered a linked issue when I tried to handle the factory case, a ClassCastException occurs in ToolBarManagerRenderer.toBeRenderedUpdater EventHandler (l 162): the 'ici' IContributionItem is directly casted into a ContributionItem to get its parent, but there are other possible IContributionItems with or without getParent() method. In our case, we have some org.eclipse.jface.action.MenuManager, but other types like IToolbarContributionManager (with the use of getToolbarManager instead of getParent) might require to be added too.

You attach a draft patch which allow to handle the factory case in ToolBarContributionRecord.anyVisibleWhen() and to correct the ClassCastException I could observe with our contributions.
Comment 1 Maxime Porhel CLA 2013-06-12 09:50:55 EDT
The provided draft patch allows to look into toolbarModel.getChildren() in the FACTORY case in order to avoid to re-createContribution by calling mergeIntoModel.  The old behavior was to check only the toolbarContribution.getChildren(), but the returned list is empty when a contribution factory is used.
Comment 2 Maxime Porhel CLA 2013-06-18 05:58:42 EDT
IContributionItem without visibleWhen might require a specific treatment (as mentionned in https://bugs.eclipse.org/bugs/show_bug.cgi?id=410432). 

In the draft attached patch, I just reused  child.getPersistedState().get(MenuManagerRenderer.VISIBILITY_IDENTIFIER) != null but it might not be sufficient.
Comment 3 Pierre-Charles David CLA 2014-01-31 09:35:24 EST
Any news on this? From a quick test using Luna M5 it seems we get the same behavior as we had for Kepler: all the contributions are always visible, whatever the selection is.

For Sirius we had to create a "degraded mode" enabled when we run under 4.x, but we would have like to be able to disable the workaround for Luna.
Comment 4 Paul Webster CLA 2014-01-31 09:42:48 EST
No one is looking at this at the moment, but we would accept a patch.  https://wiki.eclipse.org/Platform_UI/How_to_Contribute

PW
Comment 5 Maxime Porhel CLA 2014-02-06 05:22:11 EST
Hi, 

I submitted a review on Gerrit: https://git.eclipse.org/r/21602

Could you give me some tips to find an existing test to modify to checks the behavior of toolbar populated from factories with contributions with visibleWhen ? or a path too an existing test on toolbars (in order to start on a good base and in the right place).
Comment 6 Paul Webster CLA 2014-02-06 05:43:46 EST
Thanks Maxime for that contribution.  The menu contribution related tests are in /org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/menus/MenusTestSuite.java

They should be runnable as Plug-in Tests.  There are failures now related to the MenuPopulationTests for various factory contributions.  That's probably a good place to add a factory test with visibleWhen.

PW
Comment 7 Maxime Porhel CLA 2014-02-06 06:10:22 EST
Thanks Paul, but I am not looking for menu contributions tests: MenuManagerRenderer and ContributionRecord are not impacted by this bug, only ToolbarManagerRenderer and ToolBarContributionRecord. So I am looking for toolbar contribution tests.
Comment 8 Maxime Porhel CLA 2014-02-06 06:13:32 EST
I missed Bug231304Test.java and which is a toolbar test andis ine the MenusTestSuite.

Thanks for the tip.

Maxime
Comment 9 Maxime Porhel CLA 2014-02-10 04:23:56 EST
I have updated the patch set, it now contains the corrections (ClassCastException and visibleWhen inspection) and a test class.

Regards

Maxime
Comment 11 Paul Webster CLA 2014-03-04 12:32:10 EST
In 4.4.0.I20140303-2000

PW