This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 193852 - BeanTreeView does not Maintain Cursor Position after deleting a node
Summary: BeanTreeView does not Maintain Cursor Position after deleting a node
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Explorer (show other bugs)
Version: 7.0
Hardware: PC Windows Vista
: P2 normal with 1 vote (vote)
Assignee: Jan Peska
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-27 21:02 UTC by bht
Modified: 2013-12-18 09:50 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Sample project (3.39 KB, application/octet-stream)
2012-05-24 14:42 UTC, Jaroslav Tulach
Details
Improves the behaviour, but I struggle writing test to ensure it (3.45 KB, patch)
2012-06-20 09:42 UTC, Jaroslav Tulach
Details | Diff
possible patch draft (3.57 KB, patch)
2013-12-13 14:42 UTC, Ondrej Vrabec
Details | Diff
fix and tests (10.44 KB, patch)
2013-12-17 15:04 UTC, Ondrej Vrabec
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description bht 2010-12-27 21:02:46 UTC
After deleting a Java source file from the project window, the cursor position is completely lost.

It would be good if the cursor position is on the member above or below the deleted member, on the same level, or if the deleted file was the last in the package, then the new cursor position is on the package node.

This is best reproduced by using only the keyboard not the mouse.

The fix would improve the handling substantially - I hope it is not too dificult to do.
Comment 1 Jaroslav Tulach 2011-02-18 20:16:44 UTC
Yes, it really is - but it shall not be this way, the file next to the one deleted shall remain selected.
Comment 2 Jaroslav Tulach 2011-03-03 11:17:16 UTC
My ergonomics#83a72132b938 fix is not ideal, but it will at least select a parent in these situations.
Comment 3 Quality Engineering 2011-03-04 05:47:07 UTC
Integrated into 'main-golden', will be available in build *201103040000* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/83a72132b938
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: #193852: Select parent when last child is removed
Comment 4 bht 2011-04-03 01:07:16 UTC
In RC1, in the project window, the cursor goes to the top, to the first project.
Comment 5 Jaroslav Tulach 2012-05-24 14:42:56 UTC
Created attachment 119828 [details]
Sample project

The selection in sample BeanTreeView with Children.Array behaves as expected (selects a sibling after delete), so the misbehaviour in favorites window must be cause by deeper problems.
Comment 6 Jaroslav Tulach 2012-06-20 09:42:15 UTC
Created attachment 121087 [details]
Improves the behaviour, but I struggle writing test to ensure it
Comment 7 Jaroslav Tulach 2012-11-05 14:57:39 UTC
Let's see if the following change helps: ergonomics#690b16f169be
Comment 8 Quality Engineering 2012-11-07 03:41:01 UTC
Integrated into 'main-golden', will be available in build *201211070001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/690b16f169be
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: #193852: Attempt to improve behavior of selection after BTW delete. Give it some testing please.
Comment 9 bht 2013-12-07 09:16:09 UTC
When I delete files, in the project window, then then the IDE locates at the top of the tree, at the first project.
Comment 10 Jaroslav Tulach 2013-12-09 09:24:51 UTC
Passing to default explorer owner.
Comment 11 Ondrej Vrabec 2013-12-10 15:23:07 UTC
ergonomics#690b16f169be made it even worse, i can reproduce in almost 100% cases. it seems simply deleting file results in events coming in different order (NodeDestroyed, NodeRemoved) instead of (NodeRemoved, NodeDestroyed).

bht: does it help if you delete a file not using Delete action (Delete key) but via Refactor -> Safely Delete (Alt+Del) ?
Comment 12 Ondrej Vrabec 2013-12-12 14:47:12 UTC
> bht: does it help if you delete a file not using Delete action (Delete key) but via Refactor -> Safely Delete (Alt+Del) ?
Besides that, what project type are you using?
Comment 13 bht 2013-12-13 08:58:09 UTC
I use a Maven project. Safely Delete (Alt+Del) works fine in case there is a dialog I must confirm. I haven't checked the case where (Alt+Del) does not pop up a dialog.
Comment 14 Ondrej Vrabec 2013-12-13 14:42:02 UTC
Created attachment 143159 [details]
possible patch draft
Comment 15 Ondrej Vrabec 2013-12-13 14:51:44 UTC
A bit of evaluation: it happens because DataSystems fire DataNode.fireNodeDestroyed() before it is removed from the node hierarchy via setKeys() method. ExplorerManager reacts on nodeDestroyed and if the destroyed node was a selected one it is deselected. Then the trick in TreeView cannot take place because there is no more any selection.
Potential fixes might be:
A) data systems do it in the right order - probably out of the question, who knows what regressions it could cause.
B) seems node.destroy() tries to remove nodes from hierarchy itself but Children.remove(node) is a noop in this case because children for file trees is lazy and simply skips the removal - is there a space for improvement???
C) explorer manager may be smarter and either move the selection to the parent (attached patch may do the trick but i am no Node/Explorer expert and i cannot see far enough to know all negative consequences). Or maybe it could be reviewed and the code removing the selection may be completely skipped? What is the motivation if the node is still visible in UI and can be selected by user again anyway?
Comment 16 Ondrej Vrabec 2013-12-17 15:04:55 UTC
Created attachment 143253 [details]
fix and tests
Comment 17 Ondrej Vrabec 2013-12-17 15:07:33 UTC
jardo, honzo, can you please take a look at my patch proposal? Contains a potential fix and unit tests. The fix is in ExplorerManager: the manager listens on nodeDestroyed and removes the selection only when the node is no more in parent's children. Does it make sense this way?
Comment 18 Jaroslav Tulach 2013-12-17 16:08:39 UTC
Seems OK. Possibly one may not listen to destroyed event at all - enough to verify the Node is still in the hierarchy.
Comment 19 Ondrej Vrabec 2013-12-17 17:00:35 UTC
> Possibly one may not listen to destroyed event at all - enough to verify the Node is still in the hierarchy.
Well, if i stop removing the selection in nodeDestroyed completely then ExplorerManager.testSetNodesSurviveChangeOfNodes starts failing.
Comment 20 Ondrej Vrabec 2013-12-18 09:50:31 UTC
fix: http://hg.netbeans.org/core-main/rev/54135b2ac379