-
CSR
-
Resolution: Approved
-
P4
-
None
-
source
-
minimal
-
-
Java API
Summary
Add getSelectedIndices function to ListSelectionModel Interface as same function with duplicate implementation is being used in JList, JTable and DefaultTableColumnModel.
Problem
Currently, JList, JTable and DefaultTableColumnModel have there own implementation of getSelectedIndices function.
- JList has a method getSelectedIndices(), which gets the indices from its ListSelectionModel.
- JTable has a method getSelectedRows(), which gets the indices from its ListSelectionModel.
- DefaultTableColumnModel has a method getSelectedColumns(), which gets the indices from its ListSelectionModel.
These functions are same, which results in lot of duplicate code. It makes sense to add the getSelectedIndices function to ListSelectionModel interface.
Solution
Solution is to add the getSelectedIndices function to the ListSelectionModel and then call this function from JList, JTable and DefaultTableColumnModel . This can be done by using default functions in interfaces to maintain backwards compatibility.
The solution also changes getSelectedValuesList function in JList to use this function instead of duplicating the same code.
In addition to that, the getSelectedItemsCount function is also added to ListSelectionModel as similar function is implemented at different places. The getSelectedRowCount and getSelectedColumnCount functions in JTable and DefaultTableColumnModel respectively have also been changed to call getSelectedItemsCount. Webrev: http://cr.openjdk.java.net/~pbansal/8074286/webrev.03/
Specification
Providing the list of methods whose specification is being changed
1) src/java.desktop/share/classes/javax/swing/ListSelectionModel.java
/**
* Returns an array of all of the selected indices in the selection model,
* in increasing order.
*
* @return all of the selected indices, in increasing order,
* or an empty array if nothing is selected
* @see #removeSelectionInterval
* @see #addListSelectionListener
* @since 11
* @implSpec The default implementation iterates from minimum selected
* index {@link #getMinSelectionIndex()} to maximum selected index {@link
* #getMaxSelectionIndex()} and returns the selected indices {@link
* #isSelectedIndex(int)} in a newly allocated int array.
*/
default int[] getSelectedIndices() {}
/**
* Returns the number of selected items.
*
* @return the number of selected items, 0 if no items are selected
* @since 11
* @implSpec The default implementation iterates from minimum selected
* index {@link #getMinSelectionIndex()} to maximum selected index {@link
* #getMaxSelectionIndex()} and returns the number of selected indices
* {@link #isSelectedIndex(int)}
*/
default int getSelectedItemsCount() {}
Providing the public methods that are being affected here, but the specification is not being changed
1) src/java.desktop/share/classes/javax/swing/JList.java
public int[] getSelectedIndices() {}
public List<E> getSelectedValuesList() {}
2) src/java.desktop/share/classes/javax/swing/JTable.java
public int[] getSelectedRows() {}
public int getSelectedRowCount() {}
3) src/java.desktop/share/classes/javax/swing/table/DefaultTableColumnModel.java
public int[] getSelectedColumns() {}
public int getSelectedColumnCount() {}
- csr of
-
JDK-8074286 Add getSelectedIndices() to ListSelectionModel
-
- Resolved
-