Bug 251327 - [browsing] JavaBrowsingPart not clearing fPreveiousSelectionProvider
Summary: [browsing] JavaBrowsingPart not clearing fPreveiousSelectionProvider
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.5 M3   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords: needinfo
Depends on:
Blocks:
 
Reported: 2008-10-19 17:04 EDT by Wynne Crisman CLA
Modified: 2008-10-21 05:49 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 Wynne Crisman CLA 2008-10-19 17:04:35 EDT
Build ID: M20080911-1700

Steps To Reproduce:
1. Open two editors - one must be an ITextEditor (any java file) and the other must not be (extend EditorPart directly and only implement ISelectionProvider) 
2. Place a break point in JavaBrowsingPart.selectionChanged(IWorkbenchPart, ISelection)
2. Switch between the two editors in the java browsing perspective (so you can see the packages).
3. When you select the ITextEditor it shows the editor's package, when you select the non-ITextEditor it checks line 718 and determines that the same part last fired the selection event because when the ITextEditor's selection event is processed it doesn't set fPreviousSelectionProvider.

More information:
A simple fix would seem to be to set the fPreviousSelectionProvider in a finally block with the contents of selectionChanged inside the try portion.  It would be nice if this could make it into the next release as it really makes custom displays a pain to integrate.
Comment 1 Olivier Thomann CLA 2008-10-19 20:06:09 EDT
Moving to JDT/UI
Comment 2 Dani Megert CLA 2008-10-20 05:35:41 EDT
Just to clarify: you would like that the browsing views get cleared, right?
What kind of selection does your editor have?
Comment 3 Wynne Crisman CLA 2008-10-20 11:36:14 EDT
My editor edits a non-java file that exists in a package.  I would like the package to be selected when the file is the active editor.  I had to work around the problem by making my editor implement ITextEditor even though it isn't a text editor, because the JavaBrowsingPart base class for the packages view handles ITextEditor instances differently than other editor types.  Looking at the code for JavaBrowsingPart.selectionChanged(..), you notice that in some cases it sets the fPreviousSelectionProvider attribute, and in some cases it does not.  

The problem with my editor not being an ITextEditor is that when you change the selected editor between an ITextEditor and a non-ITextEditor, the selectionChanged(..) method sets fPreviousSelectionProvider for the non-ITextEditor and not for the ITextEditor.  

The attribute fPreviousSelectionProvider is used by the selectionChanged(..) method on line 718 to determine whether the selection has really changed if the firing part is not an ITextEditor.

So every time my editor is activated when alternating between my editor and an ITextEditor, the package view doesn't change its selection.

Simply placing all the code inside the selectionChanged(..) method inside a try block and adding an finally to set fPreviousSelectionProvider = part should solve the problem.
Comment 4 Dani Megert CLA 2008-10-20 12:09:19 EDT
Can you please tell me what kind of selection your editor sends out? Is it ITextSelection?
Comment 5 Wynne Crisman CLA 2008-10-20 12:22:49 EDT
Ah.. sorry.. I am currently using a StructuredSelection.
Comment 6 Wynne Crisman CLA 2008-10-20 12:24:25 EDT
setSelection(new StructuredSelection(((IFileEditorInput) getEditorInput()).getFile()));
Comment 7 Dani Megert CLA 2008-10-21 05:49:29 EDT
Fixed in HEAD.
Available in builds >= I20081021-0800.

Please try it out in I20081021-0800 or next milestone (3.5 M3) which due in less than two weeks.