Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 353998 - Swing: Wrong row selection state in tables
Summary: Swing: Wrong row selection state in tables
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Scout (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-05 09:11 EDT by Beat Schwarzentrub CLA
Modified: 2021-08-19 11:25 EDT (History)
1 user (show)

See Also:
zimmermann: juno+
zimmermann: kepler+


Attachments
Proposed Patch (1009 bytes, patch)
2011-08-05 09:11 EDT, Beat Schwarzentrub CLA
zimmermann: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Beat Schwarzentrub CLA 2011-08-05 09:11:10 EDT
Build Identifier: 3.7.0.2011-Jun 2011

PROBLEM DESCRIPTION:
Assume a table with a bunch of rows and an existing set of selected rows. When the user presses the "up" or "down" key, the selection is cleared and the row above or below the last selected row is now selected. This does not work, when the selection was not made by the user (mouse / keyboard) but manually in the code by calling "table.selectRow(index)" (e.g. during the execution of a button action). The new selection _looks_ correct, but when the "up" or "down" key is pressed, the table behaves as if the old selection would was still present.

EVALUATION:
The problem is located in the class SwingScoutTable, presumably in the method setSelectionFromScout(). This method calculates which selection rows are new and which rows should be removed from the seleciton, and then calls the methods ListSelectionModel.addSelectionInterval() and ListSelectionModel.removeSelectionInterval(), respectively.  Those calls seem to leave the anchor and lead selection indexes untouched. Because those two values are consulted when the user presses the "up" or "down" key, the resulting selection is wrong.

PROPOSED SOLUTION:
Anchor and lead selection index have to be updated as well. The attached patch basically adds such a functionality (could probably be improved).

Reproducible: Always
Comment 1 Beat Schwarzentrub CLA 2011-08-05 09:11:32 EDT
Created attachment 200977 [details]
Proposed Patch
Comment 2 Stephan Leicht Vogt CLA 2012-12-13 10:52:50 EST
Thanks for the patch. But how do you think this could be improved? Do you have a hint?
Comment 3 Beat Schwarzentrub CLA 2012-12-18 03:25:48 EST
No, I just usually try to avoid variables that are considered "uninitialized" when being negative (because in fact, they _are_ initialized). For that particular method however, this seems to be the best solution.
Comment 4 Beat Schwarzentrub CLA 2013-02-15 02:51:34 EST
Applied patch to 3.8 branch. Will be merged with 3.9 Git repo.

Migration: none
Comment 5 Matthias Zimmermann CLA 2013-02-27 06:33:40 EST
fixed flags and target milestone
Comment 6 Judith Gull CLA 2013-03-13 03:25:24 EDT
to be verified.
Comment 7 Matthias Zimmermann CLA 2013-07-08 17:26:36 EDT
Bug closed, shipped with 3.9.0 (Kepler)