Bug 213545 - [Contributions] IViewActionDelegate.init(IViewPart) can fail to be called on startup
Summary: [Contributions] IViewActionDelegate.init(IViewPart) can fail to be called on ...
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-19 20:21 EST by Mik Kersten CLA
Modified: 2019-09-06 16:13 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mik Kersten CLA 2007-12-19 20:21:32 EST
Mylyn has had a problematic bug where its Focus action would not get enabled on the Project Explorer or Navigator views if those views were visible on startup.  This bug does not manifest itself with the Package Explorer, or if the view is not visible on startup (e.g. start with a perspective that doesn't have it, toggle a perspective that does, or simply open the view).  The cause of this bug was that IViewActionDelegate.init(IViewPart) does not always get called when the view is created.  I'm not sure if this additional laziness is intentional or not, but the result is some inconsistency.

The problem appears to be in the following code in PartPluginAction, since the selection provider might not be around on start.  It seems to be around for the Package Explorer but not for the Project Explorer, so the action initialization that is triggered by the selectionChanged(..), which in turn calls PluginAction.createDelegate(), ends up never being called.

    protected void registerSelectionListener(IWorkbenchPart aPart) {
        ISelectionProvider selectionProvider = aPart.getSite()
                .getSelectionProvider();
        if (selectionProvider != null) {
            selectionProvider.addSelectionChangedListener(this);
            selectionChanged(selectionProvider.getSelection());
        }
    }
    
We don't currently have a better work-around than to do the following on the lazy start of the Context UI, which happens on first task activation, not on bundle activation.  Forcing the selection in this way will trigger the desired initialization of the view actions.  But it's a pretty weird thing for us to be doing, and will be invoked on views that do not have the Focus action added to them.  Others could also run into this problem if they expect init(IViewPart) to be called.

			for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
				if (window.getActivePage() != null) {
					IViewReference[] views = window.getActivePage().getViewReferences();
					for (IViewReference viewReference : views) {
						IViewPart viewPart = viewReference.getView(false);
						if (viewPart != null) {
							ISelectionProvider selectionProvider = viewPart.getSite().getSelectionProvider();
							if (selectionProvider != null) {
								selectionProvider.setSelection(selectionProvider.getSelection());
							}
						}
					}
				}
			}
Comment 1 Mik Kersten CLA 2007-12-20 13:10:30 EST
Adding Shawn to CC since he helped with the diagnosis.
Comment 2 Mik Kersten CLA 2007-12-20 13:13:46 EST
One more thing, in case anyone is possessed to replicate this pattern (hopefully not).  The inner-most code in the last snippet of the description has to check for null selections (noticed this with marker views when we tested this on Eclipse 3.3):

		ISelectionProvider selectionProvider = viewPart.getSite().getSelectionProvider();
       	if (selectionProvider != null) {
       		ISelection selection = selectionProvider.getSelection();
        	if (selection != null) {
         		selectionProvider.setSelection(selectionProvider.getSelection());
        	} else {
         		selectionProvider.setSelection(StructuredSelection.EMPTY);
        	}
       }
Comment 3 Paul Webster CLA 2009-03-02 11:41:33 EST
Updated as per http://wiki.eclipse.org/Platform_UI/Bug_Triage
PW
Comment 4 Eclipse Webmaster CLA 2019-09-06 16:13:19 EDT
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.