mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
getSelectedObjects — use the same approach as in TableUtil to collect selected items
This commit is contained in:
@@ -199,17 +199,21 @@ public class TableView<Item> extends BaseTableView implements ItemsProvider, Sel
|
||||
|
||||
@NotNull
|
||||
public List<Item> getSelectedObjects() {
|
||||
final int[] selectedRows = getSelectedRows();
|
||||
if (selectedRows == null || selectedRows.length == 0) {
|
||||
ListSelectionModel selectionModel = getSelectionModel();
|
||||
int minSelectionIndex = selectionModel.getMinSelectionIndex();
|
||||
int maxSelectionIndex = selectionModel.getMaxSelectionIndex();
|
||||
if (minSelectionIndex == -1 || maxSelectionIndex == -1) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<Item> result = new SmartList<Item>();
|
||||
ListTableModel<Item> model = getListTableModel();
|
||||
for (int selectedRow : selectedRows) {
|
||||
int modelIndex = convertRowIndexToModel(selectedRow);
|
||||
if (modelIndex >= 0 && modelIndex < model.getRowCount()) {
|
||||
result.add(model.getRowValue(modelIndex));
|
||||
for (int i = minSelectionIndex; i <= maxSelectionIndex; i++) {
|
||||
if (selectionModel.isSelectedIndex(i)) {
|
||||
int modelIndex = convertRowIndexToModel(i);
|
||||
if (modelIndex >= 0 && modelIndex < model.getRowCount()) {
|
||||
result.add(model.getRowValue(modelIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -105,14 +105,15 @@ public class TableUtil {
|
||||
}
|
||||
|
||||
ListSelectionModel selectionModel = table.getSelectionModel();
|
||||
if (selectionModel.isSelectionEmpty()) {
|
||||
int minSelectionIndex = selectionModel.getMinSelectionIndex();
|
||||
int maxSelectionIndex = selectionModel.getMaxSelectionIndex();
|
||||
if (minSelectionIndex == -1 || maxSelectionIndex == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int minSelectionIndex = selectionModel.getMinSelectionIndex();
|
||||
TableModel model = table.getModel();
|
||||
boolean removed = false;
|
||||
for (int index = table.getRowCount() - 1; index >= 0; index--) {
|
||||
for (int index = maxSelectionIndex; index >= 0; index--) {
|
||||
if (selectionModel.isSelectedIndex(index) && (applyable == null || applyable.isOperationApplyable(model, index))) {
|
||||
itemRemovable.removeRow(index);
|
||||
removed = true;
|
||||
@@ -127,7 +128,7 @@ public class TableUtil {
|
||||
if (count == 0) {
|
||||
table.clearSelection();
|
||||
}
|
||||
else if (table.getSelectedRow() == -1) {
|
||||
else if (selectionModel.getMinSelectionIndex() == -1) {
|
||||
if (minSelectionIndex >= model.getRowCount()) {
|
||||
selectionModel.setSelectionInterval(model.getRowCount() - 1, model.getRowCount() - 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user