Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 399783

Summary: TreeModelIterator has TypeError on collapse if focus is not on the tree
Product: [ECD] Orion Reporter: Susan McCourt <susan>
Component: ClientAssignee: libing wang <libingw>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: antonm
Version: 1.0   
Target Milestone: 2.0 RC1   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Susan McCourt CLA 2013-02-02 15:00:28 EST
I was helping Anton with the project drive list, and noticed this problem.  I think it's probably always been there, but that the project page handles focus differently and so the problem appears.

1) open a project (create one if you don't have one).
2) on projectPage.html you should (hopefully) see a list of Drives that minimally includes "OrionContent"
3) note that focus is not on the drives tree
4) click on the expand twistie to open Orion Content *without* giving the tree focus.
5) You'll get this type error in treeModelIterator.js line 134
Uncaught Type Error: Cannot read property 'parent' of null

The problem is that
_inParentChain: function(model, compareTo)
expects a model in the first parameter.  

But in line 247 (TreeModelIterator.collapse) we pass this._cursor.
The _cursor is null.

My suspicion is that it's null because the tree has never had focused.  I didn't know whether to simply check null first, or set the cursor to some default, or if this was a symptom of something wrong in the explorer itself.  

Libing, can you have a look?  There is no problem with the tree apart from the error, it still works...
Comment 1 Susan McCourt CLA 2013-02-02 15:02:01 EST
I should add that once you give focus to the tree, everything is fine.
Comment 2 libing wang CLA 2013-02-04 09:57:10 EST
fixed with http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=b0f6813df1651bffac144fd3086fba9f9cbcbd2a.

The intention of that code was to check if the collapsing item is in the parent chain of the current selected item(or _cursor). If yes we have to move the _cursor up to the collapsing item, otherwise we are visually losing the current selected item(or _cursor). 

The code takes granted that the _cursor is always there otherwise you can't do collapse. But in reality it isn't. 
I safe guarded all the places where _cursor is used.If the explorer has never "initialized"/focused, the selection model just does nothing on _cursor and leave it uninitialized.
Comment 3 libing wang CLA 2013-02-04 10:03:36 EST
BTW, Susan, I know the explorer tree in project page is still in progress but I think it might be a reminder for you.
When you select the root and use right key to expand and down key to a child.
Then use right key, left key, right key again, you will see exception @line 395@extensionCommands.js.
commandService is not defined.

I bet it is just because of "working in progress" but I think it worth mentioning it.