Bug 271613 - [ActivityMgmt] Preference-pages and activities
Summary: [ActivityMgmt] Preference-pages and activities
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2009-04-08 09:10 EDT by Rudi Mising name CLA
Modified: 2019-11-27 07:44 EST (History)
4 users (show)

See Also:


Attachments
Includes a Eclipse-project redy to start an RCP-Application (24.02 KB, application/zip)
2009-04-08 09:10 EDT, Rudi Mising name CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rudi Mising name CLA 2009-04-08 09:10:33 EDT
Created attachment 131274 [details]
Includes a Eclipse-project redy to start an RCP-Application

Hello,

I discovered a strange behavior on preference pages and activities, which may be a bug.

I'm using activities to control which parts of the UI is visible for the user of my RCP-Application. Instead of dealing with the activities-API for enable/disable the activities, I wired my activities to extensions of the extensionpoint org.eclipse.core.expressions.definitions using enabledWhen - > reference.

The extensions of the extensionpoint org.eclipse.core.expressions.definitions are wired to a variable 'currentUserRoles' using with. 'currentUserRoles' is a List of Strings and is managed by an extension of the extensionpoint org.eclipse.ui.services -> sourceProvider. The sourceProvider is an instance of the class CurrentUserRolesSourceProvider.
In my programm, I get a reference to this sourceProvider by the following code:

IWorkbench workbench = PlatformUI.getWorkbench();
ISourceProviderService sourceService = (ISourceProviderService) workbench.getService(ISourceProviderService.class);
CurrentUserRolesSourceProvider sourceProvider = (CurrentUserRolesSourceProvider) sourceService.getSourceProvider(CurrentUserRolesSourceProvider.PROVIDEDSOURCE);

This instance is used, to change the roles of the current user through the method sourceProvider.activateRoles(roles), whenever the user changes.

Amongst others I want to hide/show preference pages which according to the docu should be possible (http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/workbench_advext_activities.htm).

I figured out, that it is possible to restrict the visibility of a preference page through the role of the current user but the visibility of the preference page is only managed accurate, if the activity which restricts the visibility of the preference-page is enabled when the preference-page is opened for the first time. When I open the preference page for the first time and the activity is not active, it is not shown. That's correnct. But when I afterwards activate the necessary activity, the preference page is still hidden and dosn't appear anymore as long as the application runs, independent of activities.

This may be sound confusing but if you start the enclosed RCP-Application in the attachment and follow this steps, you will immediately  understand:

- Start the application. It opens a window which shows all currently enabled activities, this list is empty when you start the application.
- There are two buttons: 'activate role1' and 'activate role2'. When you push this buttons ROLE_1 or ROLE_2 respectively are activated through the CurrentUserRolesSourceProvider as described above. This causes also the enablement of the according activities, as you can see in the label above the buttons.
- When you start the application and push immediately File > Preferences then the Preference-dialog opens and no page is shown. This is right so far. 
- Close the Preference-dialog and push the 'activate role2'-button. The enabled activities include now 'activity2' and from the activityPatternBindings you can see, that this activity is required for the SamplePreferencePage. So the SamplePreferencePage should be shown now. If you press File > Preferences you can see, that this is not the case.
- Note that you have opened the Preference-dialog for the first time, when the required activity for the SamplePreferencePage was not active.

- Now close the whole application and start it again.
- Push the 'activate role2'-button immediately.
- Push File > Preferences. The Preference-dialog opens and the 'Sample Preferences'-page is visible.
- Close the Preference-dialog and push the 'activate role1'-button.
- Push File > Preferences. The Preference-dialog opended and the 'Sample Preferences'-page is not visible.
- Close the Preference-dialog and push the the 'activate role2'-button.
- Push File > Preferences. The Preference-dialog is opended and the 'Sample Preferences'-page is  visible again. This means that the activities work as they should and the visibility of the SamplePreferencePage is managed correct.
- Note that this time you have opened the Preference-dialog for the first time, when the required activity for the SamplePreferencePage was active.


It seems very strange to me, that the behaviour of the activities and the visibility of the SamplePreferencePage is dependend on which activity is active, when you open the Preference-dialog for the first time.
Is this a bug? If not, what is wrong with my setup?


Thank you in advance,
Rudi
Comment 1 Mike Wilson CLA 2009-05-05 14:27:20 EDT
Changing Version tag to something more believable.
Comment 2 Rudi Mising name CLA 2009-05-11 10:51:13 EDT
Could you please tell me if someone is tracking this? Is my description comprehensible? Is this a bug?
Comment 3 Paul Webster CLA 2009-05-11 11:01:09 EDT
This will be investigated in the 3.6 timeframe.

PW
Comment 4 Rudi Mising name CLA 2009-06-05 08:34:00 EDT
Hello Paul,

could you please tell me when this timeframe is or could you send me a link, where the timeframes are described?

I didn't think that it takes months, that someone takes a look at my bugreport. I can't wait so long with my app and have to find a workaround in the meantime.

Instead of preparing a demo app and describing this strange behaviour, next time I'll immediately look for a workaround. This is the second bug I reported, which nobody cares about :(
Comment 5 Paul Webster CLA 2009-06-05 09:41:17 EDT
(In reply to comment #4)
> Hello Paul,
> 
> could you please tell me when this timeframe is or could you send me a link,
> where the timeframes are described?

3.6 will be available in July 2010

> I didn't think that it takes months, that someone takes a look at my bugreport.
> I can't wait so long with my app and have to find a workaround in the meantime.

It does take months ... I'm good :-) but I'm sitting on >1000 bug reports.  This is a community based open source project.  If you need this fixed sooner than an existing committer can get to it, please contribute a fix.

http://wiki.eclipse.org/Platform_UI/How_to_Contribute contains instructions on setup, and I can point to hook points that are relevant 

PW
Comment 6 R. Oldenburg CLA 2012-03-14 06:53:51 EDT
Hi there,

any news concerning this issue?
It seems to me that this bug still exists in Indigo Build id: 20110615-0604

Prefs are hidden by an expression-controlled activity.
When expression state changes then toolbar entries appear but preference entries stay hidden...

Anybody working on that?

Regards,
R.O.
Comment 7 Paul Webster CLA 2012-03-14 07:02:17 EDT
unfortunately no, no one is looking at this at the moment.

PW
Comment 8 R. Oldenburg CLA 2012-03-14 07:08:48 EDT
:-)

well, any idea for a workaround?
Is it possible to programatically force the preference service/dialog to refresh its node list?

Or any other idea?

At least a hint for the right direction?
If I find a way, I will post my solution here...
Comment 9 R. Oldenburg CLA 2012-04-08 18:23:19 EDT
ok, I found one myself.

The following snippet works as a workaround for pages activated by activities during runtime.

Have fun!

public class MyPreferenceManager implements IActivityManagerListener {
		
		private PreferenceManager  pm = null;
        @SuppressWarnings("restriction")
		private PreferencePageRegistryReader 	registryReader = null;
		
		private List<String> hiddenPreferences = Arrays.asList(
				"org.eclipse.debug.ui.DebugPreferencePage", //$NON-NLS-1$
				"org.eclipse.team.ui.TeamPreferences", //$NON-NLS-1$
				"org.eclipse.ui.preferencePages.Workbench", //$NON-NLS-1$
		);

		@SuppressWarnings("restriction")
		public MyPreferenceManager(IWorkbench workbench) {
			pm = workbench.getPreferenceManager();
			registryReader = new PreferencePageRegistryReader(workbench);
	        registryReader.loadFromRegistry(Platform.getExtensionRegistry());
			
			for (String prefId : hiddenPreferences) {
				pm.remove(prefId);
			}
			
			workbench.getActivitySupport().getActivityManager().addActivityManagerListener(this);
		}
		
		@SuppressWarnings("restriction")
		@Override
		public void activityManagerChanged(ActivityManagerEvent activityManagerEvent) {
	        
	        Collection<Object> pageContributions = new LinkedList<Object>();
	        
	        for (Object element : registryReader.getTopLevelNodes()) {
				if (element instanceof WorkbenchPreferenceNode) {
					String id = ((WorkbenchPreferenceNode) element).getId();
					
					if (!hiddenPreferences.contains(id) && pm.find(id) == null) {
						pageContributions.add(element);
					}
				}
			}
	        
	        if (!pageContributions.isEmpty()) {
		        ((WorkbenchPreferenceManager)pm).addPages(pageContributions);
	        }
		}
	}
Comment 10 Lars Vogel CLA 2019-11-27 07:44:23 EST
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.

If the bug is still relevant, please remove the stalebug whiteboard tag.