Bug 201589 - [Contributions] visibleWhen has no effect on toolbar
Summary: [Contributions] visibleWhen has no effect on toolbar
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows 2000
: P3 normal with 35 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
: 297193 512790 (view as bug list)
Depends on:
Blocks: 144161 397765
  Show dependency tree
 
Reported: 2007-08-29 11:35 EDT by James Leotta CLA
Modified: 2020-03-15 12:25 EDT (History)
53 users (show)

See Also:


Attachments
Full Plugin XML showing the problem (3.44 KB, text/xml)
2007-08-29 12:23 EDT, James Leotta CLA
no flags Details
Current work for this defect (4.88 KB, patch)
2009-11-24 15:28 EST, Eric Moffatt CLA
no flags Details | Diff
Comment 38 diff (5.08 KB, patch)
2018-03-28 09:34 EDT, darrel karisch CLA
no flags Details | Diff
Example e4 RCP project with toolitems using core and imperative expressions (13.31 KB, application/zip)
2018-04-23 18:03 EDT, Lars Vogel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description James Leotta CLA 2007-08-29 11:35:54 EDT
I created a toolbar with three commands.  When I add an activeWhen extension to the toolbar using a 'with activePartId equals myView' it does not disable the commands when myView looses focus.  If I put the extension on each command individually it works fine.
Comment 1 Paul Webster CLA 2007-08-29 12:03:34 EDT
Please include your menuContribution definitions.

Thanx,
PW
Comment 2 James Leotta CLA 2007-08-29 12:23:18 EDT
Created attachment 77271 [details]
Full Plugin XML showing the problem
Comment 3 Paul Webster CLA 2007-09-26 13:49:35 EDT
By "does not disable the commands" I assume you mean does not make the toolbar invisible.

PW
Comment 4 James Leotta CLA 2007-09-29 13:18:46 EDT
(In reply to comment #3)
> By "does not disable the commands" I assume you mean does not make the toolbar
> invisible.
> 
> PW
> 

Your assumptions are correct.
Comment 5 William Davy CLA 2007-11-26 07:45:01 EST
I am unable to get the visibleWhen tag to work on a contribution to the trim.

I am trying to show a control only when a certain perspective is open and have created a property tester to enable this, however, the visibleWhen doesn't seem to be working. Below is an example of the xml, using a systemTest instead of a property test, and it seems to have no effect regardless of the permutations.

   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="toolbar:org.eclipse.ui.trim.status"
         <toolbar
               id="MyPlugin.CompanyWebLink">
            <control
                  class="org.view.CompanyWebLink"
                  id="MyPlugin.CompanyWebLink.Control">
            </control>
            <visibleWhen>
                <systemTest
                      property="os.name"
                      value="GobblyDeGook">
                </systemTest>
            </visibleWhen>
         </toolbar>
      </menuContribution>
   </extension>
Comment 6 Paul Webster CLA 2008-02-11 14:16:14 EST
Eric, this is one I was talking about earlier.

PW
Comment 7 Paul Webster CLA 2008-03-13 15:10:09 EDT
(In reply to comment #5)
> to be working. Below is an example of the xml, using a systemTest instead of a
> property test, and it seems to have no effect regardless of the permutations.

Does it work if you tie it to a known variable, like:
<with variable="activePartId">
  <equals value="org.eclipse.ui.views.ContentOutline"/>
</with>

System properties don't get re-evaluated when they change (and there was no way to do this for property testers before 3.4, either)


PW
Comment 8 craigoliveira CLA 2008-04-15 22:04:42 EDT
Since controls inside toolbars of the trim are not getting their visibility set properly from the visibleWhen tag, I am getting an issue which prevents any sort of lazy loading of a plugin which uses a control in the status bar.  Any ideas for a workaround until this behavior is fixed?
Comment 9 Paul Webster CLA 2008-04-16 07:58:42 EDT
(In reply to comment #8)
> Since controls inside toolbars of the trim are not getting their visibility set
> properly from the visibleWhen tag,

Pleases provide a simple plugin example.  AFAIK the control correctly has its visibility set.  This bug is about the toolbar itself not respecting visibleWhen.  Are you saying the control element does not honour visibleWhen?

As an aside, there is no lazy-loading implemented for a control contribution.  As soon as it is populated into a piece of trim (even if invisible) then it will load that plugin.

PW


Comment 10 craigoliveira CLA 2008-04-16 08:52:31 EDT
I think I mis-worded my original comment.  I'm setting visibility on the toolbar but the control is inside the toolbar so one would expect that the visibility applies to the control also.

I suspect that the second half of your reply means I am going to have to use a command here instead of a control if I want lazy-loading to work.


Here's my code:

<extension 
  point="org.eclipse.ui.menus">
  <menuContribution
    locationURI="toolbar:org.eclipse.ui.trim.status"
    <toolbar
       id="my.company.pluginName.ui.trimToolbar">
       <control
         class="my.company.pluginName.ui.MyWorkbenchWindowControlContribution"
         id="my.company.pluginName.ui.trimToolbarControl">
       </control>
       <visibleWhen>
         <reference
	   definitionId="my.company.pluginName.ui.myPerspectiveIsActive">
	 </reference>
       </visibleWhen>
    </toolbar>
  </menuContribution>
</extension>

<extension
  point="org.eclipse.core.expressions.definitions">
  <definition
    id="my.company.pluginName.ui.myPerspectiveIsActive">
    <with
      variable="activeContexts">
      <iterate
        operator="or">
        <equals
          value="my.company.pluginName.ui.SomeActionSetId">
        </equals>
      </iterate>
    </with>
  </definition>
</extension>
Comment 11 Paul Webster CLA 2008-04-16 08:58:45 EDT
(In reply to comment #10)
> I think I mis-worded my original comment.  I'm setting visibility on the
> toolbar but the control is inside the toolbar so one would expect that the
> visibility applies to the control also.

Right, so when this bug is fixed we'll make the toolbar disappear (which will make the control disappear).

> 
> I suspect that the second half of your reply means I am going to have to use a
> command here instead of a control if I want lazy-loading to work.


To show a control we had to instantiate it (there was no other way).  An optimization that could be added is that we proxy the control contribution so that we don't load the plugin as long as nothing ever calls fill(*).  That won't make it into 3.4, however, and would need to be requested in a new bug.

PW

Comment 12 Paul Webster CLA 2008-05-15 09:51:19 EDT
Equivalent partId definition:
<extension
  point="org.eclipse.core.expressions.definitions">
  <definition
    id="my.company.pluginName.ui.myPerspectiveIsActive">
    <with
      variable="activePartId">
        <equals
          value="org.eclipse.ui.views.ContentOutline"/>
    </with>
  </definition>
</extension>
Comment 13 Mike Wilson CLA 2008-06-09 14:52:51 EDT
Why is this still marked 3.4 RC2?

Comment 14 Paul Webster CLA 2008-06-09 15:15:20 EDT
Maybe we should consider for 3.4.1
PW
Comment 15 Eric Moffatt CLA 2008-06-10 15:25:42 EDT
+1 for me. I'd have done it now except I was concerned about introducing regressions (to me, this code is 'baroque...;-).
Comment 16 rehte CLA 2008-07-08 22:34:45 EDT
+1 for me. My case is to show a toolbar under the condition that a specific perspective is active. This bug still exists in the final release of 3.4.
Comment 17 Nitin Dahyabhai CLA 2008-07-23 21:51:13 EDT
+1 from me, assuming comment 9 also affects how dynamic menu contributions are handled.
Comment 18 Paul Webster CLA 2008-09-23 08:58:39 EDT
We should try and get this in early in 3.5

bug 246999 is for making the dynamic contribution proxied to delay plugin loading.

PW
Comment 19 Eric Moffatt CLA 2009-03-05 14:05:00 EST
Moving to triage (for now), this should be re-targeted to 3.6 when it becomes available...
Comment 20 Philipp Kursawe CLA 2009-03-13 12:57:18 EDT
+1 from me. Run into this problem again today.
Comment 21 Gerald Rosenberg CLA 2009-11-06 14:11:59 EST
Is there a viable workaround for this bug?  I can make the controls within the toolbar respond correctly to the visibleWhen property tester, but the toolbar itself remains visible, consuming space on the trim.  Any way to directly set the visibility of the toolbar from the property tester?
Comment 22 Eric Moffatt CLA 2009-11-24 15:28:55 EST
Created attachment 153008 [details]
Current work for this defect


This patch *almost* fixes the problems but there are still arifacts on the first startup (before the Welcome goes away) as well as some spurious issues. I'm capturing this for a second pass later.
Comment 23 Eric Moffatt CLA 2009-12-15 09:43:18 EST
*** Bug 297193 has been marked as a duplicate of this bug. ***
Comment 24 Eric Moffatt CLA 2010-05-21 14:10:03 EDT
Out of time...
Comment 25 Jan Krakora CLA 2011-10-04 06:15:48 EDT
(In reply to comment #24)
> Out of time...

Is it working in 3.6 or 3.7?
Comment 26 Igor Zapletnev CLA 2011-11-15 02:31:49 EST
Still reproducible on 3.7.
Comment 27 Andre Bergmann CLA 2012-05-10 10:22:48 EDT
I bet 4.x will net get it, due to new application model?
Comment 28 Sam Davis CLA 2012-06-08 18:44:58 EDT
(In reply to comment #21)
> Is there a viable workaround for this bug?  I can make the controls within the
> toolbar respond correctly to the visibleWhen property tester, but the toolbar
> itself remains visible, consuming space on the trim.  Any way to directly set
> the visibility of the toolbar from the property tester?

This creates a significant problem for anyone who wants to contribute trims that can be hidden on both 4.x and 3.x. You can contribute the trims using the extension point and setting visibleWhen on the controls, and this seems to work fine on 4.x (excepting that there seems to be no support for vertical trims anymore?), but on 3.x, when the controls are hidden, the empty toolbar remains, which makes hiding the trims a bit pointless. If the trim is the only toolbar on that side of the workbench, then it is quite annoying for the user to have a big empty bar when the controls are hidden.

Is there any workaround for this, or any plans to fix this issue? The only possible workaround I can see is to contribute the trims dynamically using ITrimManager on 3.x, and contribute them using the extension point on 4.x, but then I think you would need have the XML to contribute the extension in a separate bundle that is not installed on 3.x, otherwise 3.x users would get two copies of the trim.
Comment 29 Steffen Pingel CLA 2012-06-11 07:57:41 EDT
We used to have code in Mylyn which set visibility on the parent control directly and then forced a re-layout. I haven't checked if this works in combination with the <visibleWhen/> specification for contributions but we could try that as a work-around on 3.x.
Comment 30 Mario Marinato CLA 2012-06-18 13:08:03 EDT
+1 for me.  I'm adding visibleWhen to each and every item on my toolbars.
Comment 31 Sam Davis CLA 2012-06-21 15:57:48 EDT
(In reply to comment #29)
> We used to have code in Mylyn which set visibility on the parent control
> directly and then forced a re-layout. I haven't checked if this works in
> combination with the <visibleWhen/> specification for contributions but we could
> try that as a work-around on 3.x.

It looks like something like this will work.
Comment 32 Paul Fullbright CLA 2013-05-03 11:40:43 EDT
Any further word on this?  I'm seeing this problem now as well.
Comment 33 Paul Webster CLA 2013-05-03 12:19:50 EDT
(In reply to comment #32)
> Any further word on this?  I'm seeing this problem now as well.

No one is looking at this ATM.

PW
Comment 34 Kondal Kolipaka CLA 2014-09-17 05:11:25 EDT
By adding visibleWhen on each command, toolbar is automatically getting disappeared if there are no visible elements.

This works!
Comment 35 Eric Moffatt CLA 2015-08-17 15:41:09 EDT
Why is this one still open ? Is there work expected ?
Comment 36 Lars Vogel CLA 2016-04-20 12:19:18 EDT
Mass move to 4.7 as M7 is approaching. Please move back in case you are planning to fix it for Neon.
Comment 37 Ben Steffensmeier CLA 2016-05-11 13:34:22 EDT
In eclipse 4.5.1 a toolbar with no visible items is being rendered. It is just an empty space a few pixels wide but if there are several toolbars next to eachother it leads to a noticeable gap. Setting visibleWhen on all the items is no longer a good workaround in 4.5.1.
Comment 38 darrel karisch CLA 2018-03-27 16:11:47 EDT
This appears to be a design flaw or implementation oversight.

1. MenuAdditionCacheEntry
    a.processTrimChildren fails to add visibleWhen expressions to MToolBar model elements.
	i. item.setVisibleWhen(MenuHelper.getVisibleWhen(toolbar));
2. ToolBarContributionRecord fails to account for MToolBar visibleWhen attribute
    a. collectInfo 
	i. ContributionsAnalyzer.collectInfo(info, toolbarModel.getVisibleWhen());
    b. anyVisibleWhen 
	i. if (toolbarModel.getVisibleWhen() != null) return true;
    c. updateVisibility
	i. if (MCoreExpression.class.isInstance(toolbarModel.getVisibleWhen())) {
    boolean currentVisibility = ContributionsAnalyzer.isVisible((MCoreExpression)toolbarModel.getVisibleWhen(), exprContext);
    if (currentVisibility != toolbarModel.isVisible()) {
        toolbarModel.setVisible(currentVisibility);
    }
}
	ii. if (toolbarModel.getVisibleWhen() == null)
    Stream.of(managerForModel.getItems()).filter(i -> i.isVisible()).findFirst().ifPresent((i) -> toolbarModel.setVisible(true));


3. CoolBarToTrimManager unilaterally sets MToolBarElement parent MToolBar visible attribute
    a. fill(MToolBar container, IContributionManager manager)
	i. if (container.getVisibleWhen() == null) container.setVisible(true);
4. TrimBarLayout likewise unilaterally sets MToolBarElement parent MToolBar visible attribute
    a. hideManagedTB(MTrimElement te)
	i. boolean barVisible = te.getVisibleWhen() != null ? te.isVisible() : ((ToolBar) kids[0]).getItemCount() > 0;


Peculiarly, MToolBarContribution has a VisibleWhen attribute.  This is not congruent with the org.eclipse.ui.menus XML schema. I.e. menuContribution does not have an immediate visibleWhen child element whereas toolbar does.
Comment 39 darrel karisch CLA 2018-03-28 09:34:32 EDT
Created attachment 273345 [details]
Comment 38 diff

Comment 38 diff
Comment 40 Lars Vogel CLA 2018-03-28 10:19:45 EDT
Gerrit patches are welcome.
Comment 41 darrel karisch CLA 2018-03-28 10:25:25 EDT
(In reply to Lars Vogel from comment #40)
> Gerrit patches are welcome.

That's what I hear.  I submitted two early last month that are dying on the vine.
Comment 42 Lars Vogel CLA 2018-03-28 10:47:57 EDT
(In reply to darrel karisch from comment #41)
> That's what I hear.  I submitted two early last month that are dying on the
> vine.

In platform? Please provide the links.
Comment 43 darrel karisch CLA 2018-03-28 10:50:21 EDT
Bug 530628 - PartActivationHistory and EPartService.ACTIVE_ON_CLOSE_TAG
https://git.eclipse.org/r/116630

Bug 522450 Minimized views lost permanently in Detached Window
https://git.eclipse.org/r/116796
Comment 44 Lars Vogel CLA 2018-03-28 11:06:19 EDT
(In reply to darrel karisch from comment #43)
> Bug 530628 - PartActivationHistory and EPartService.ACTIVE_ON_CLOSE_TAG
> https://git.eclipse.org/r/116630
> 
> Bug 522450 Minimized views lost permanently in Detached Window
> https://git.eclipse.org/r/116796

Both had fast feedback, https://git.eclipse.org/r/#/c/116630/ still waiting for your feedback and in https://git.eclipse.org/r/#/c/116796/ it would have been helpful if you gave written feedback after my review, like "Done".
Comment 45 Eclipse Genie CLA 2018-03-28 14:52:46 EDT
New Gerrit change created: https://git.eclipse.org/r/120384
Comment 46 Lars Vogel CLA 2018-04-23 18:03:14 EDT
Created attachment 273739 [details]
Example e4 RCP project with toolitems using core and imperative expressions

(In reply to Eclipse Genie from comment #45)
> New Gerrit change created: https://git.eclipse.org/r/120384

I tested with an small e4 RCP application and this change did not hide the toolitem entries, neither with core expressions nor with imperative expressions.

Darrel, can you have a look? The "Not hidden by imperative expression" and the "Not hidden by core expressions" toolitems are the relevant ones. The same expressions work fine for menu items.
Comment 47 darrel karisch CLA 2018-04-24 13:16:28 EDT
(In reply to Lars Vogel from comment #46)

I neglected to test in an e4 app.

I used eclipse.platform ui org.eclipse.ui.examples.contributions plugin to test.

I moved org.eclipse.ui.examples.contributions.editor.toolbar visibleWhen from the command to the toolbar.

I also added the same visibleWhen to org.eclipse.ui.examples.contributions.group.file toolbar.

Appears this was not sufficient.  I will look at your suggestions from the CR.
Comment 48 Lars Vogel CLA 2018-04-24 13:26:59 EDT
(In reply to darrel karisch from comment #47)
> (In reply to Lars Vogel from comment #46)
> Appears this was not sufficient.  I will look at your suggestions from the
> CR.

They interesting part is that is already works for Toolbar Contributions. It only checks visibility in processAdditions (called only for contributions). I believe the correct fix is to move this check out into a method and after the additions are processed run this check on all contributions. I played around with it a bit today, see my notes here: https://git.eclipse.org/r/#/c/121658/
Comment 49 Rolf Theunissen CLA 2019-06-01 09:53:14 EDT
Darrel was on the right track, but might have missed some code paths.

I have been looking around into visibility of tool and menu items, and came to the following two observations:
1. In general, visibility attributes are not added and evaluated for 'root' elements. They are only added and evaluated for children. See also Bug 372508.
2. To correctly handle visibility, the following three attributes must resolve to true for an element to be visible:
  a. isVisible() attribute;
  b. getVisibleWhen() attribute; for core and imperative expressions
  c. getPersistedState().get(MenuManagerRenderer.VISIBILITY_IDENTIFIER) attribute; for activity based filtering, see Bug 407166.

Any place in code where a tool/menu (item) is created, that does not consider all attributes is incorrect. (For some cases, non of the attributes are considered.)
Any place in code that forwards model visibility to UI elements that does not consider all attributes is incorrect. (In some cases visibility is not considered at all.)
Note that there are (too) many code paths involved: e4, legacy contributions, factories, etc.

There are probably a dozen open bugs related to the two observations.
Comment 50 Lars Vogel CLA 2019-12-05 05:12:22 EST
Rolf, could you revive your work here for 4.15?
Comment 51 Rolf Theunissen CLA 2020-02-20 04:47:35 EST
(In reply to Lars Vogel from comment #50)
> Rolf, could you revive your work here for 4.15?

I have to really see how to balance the limited time I can spend on Eclipse platform. And some issues are way more time consuming than anticipated (e.g. removing of menu items). So I cannot commit that I will work on it for 4.15.
Comment 52 Lars Vogel CLA 2020-02-25 04:01:36 EST
*** Bug 512790 has been marked as a duplicate of this bug. ***