Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 249442 - [Contributions] VisibleWhen with checkedEnabled expression on menuContribution
Summary: [Contributions] VisibleWhen with checkedEnabled expression on menuContribution
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M4   Edit
Assignee: Prakash Rangaraj CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 249445 252597 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-10-02 04:24 EDT by Adam Wehner CLA
Modified: 2009-06-03 13:42 EDT (History)
3 users (show)

See Also:


Attachments
RCP Application with the descriped behavior (23.74 KB, application/zip)
2008-10-02 04:24 EDT, Adam Wehner CLA
no flags Details
Patch v01 (1.33 KB, patch)
2008-11-11 06:41 EST, Prakash Rangaraj CLA
no flags Details | Diff
Patch v02 (1.91 KB, patch)
2008-11-26 05:48 EST, 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 Adam Wehner CLA 2008-10-02 04:24:06 EDT
Created attachment 114073 [details]
RCP Application with the descriped behavior

I tried to change the visibility of a menuContribution (menu and viewtoolbar) dynamically at runtime. Therefore I made a menuContribution which is visible when it is enabled (checkedEnabled on visibleWhen expression). But it seems to work only in one direction. When it is disabled (because the only handler is disabled) it disappears. Great! But when it is enabled it does not come back.
Comment 1 Prakash Rangaraj CLA 2008-11-11 06:41:19 EST
Created attachment 117527 [details]
Patch v01

If there is no need to show the command item in the tool bar, the widget is disposed. Any further changes on the command are processed only after widget==null check is performed. In this case, even if the command is enabled again, since the widget will be null, its not processed.

Fix: When processing the changes in command, when the widget == null && command is visible, recreate the widget. Patch attached.
Comment 2 Paul Webster CLA 2008-11-25 11:52:14 EST
(In reply to comment #1)
> Created an attachment (id=117527) [details]
> Patch v01

Given that we still have to protect ourselves from non-UI thread events, I would suggest:

1) let's get rid of the widget from the beginning of that call

Use org.eclipse.ui.internal.services.IWorkbenchLocationService.getWorkbench() to get the workbench and org.eclipse.ui.IWorkbench.getDisplay() to get the display.  You can do it in the constructor and cache it, I guess.

2) Then I guess in the Runnable we just swap the "if (commandEvent.isEnabledChanged() ..." block with the "if (commandEvent.getCommand().isDefined()) {..." block.

Would that keep the current code working and also allow the new usecase to work?

PW
Comment 3 Prakash Rangaraj CLA 2008-11-26 05:48:26 EST
Created attachment 118764 [details]
Patch v02

(In reply to comment #2)
> Would that keep the current code working and also allow the new usecase to
> work?

    Yes. Esp 1) sounds like a much better option. All the tests ran fine with the modifications. Attached the patch
Comment 4 Paul Webster CLA 2008-12-01 15:26:17 EST
Released to HEAD >20081201
PW
Comment 5 Paul Webster CLA 2008-12-04 11:31:37 EST
*** Bug 249445 has been marked as a duplicate of this bug. ***
Comment 6 Prakash Rangaraj CLA 2008-12-11 08:22:25 EST
Verified in I20081208-1800
Comment 7 Paul Webster CLA 2009-01-13 07:59:40 EST
*** Bug 252597 has been marked as a duplicate of this bug. ***