Search in sources :

Example 1 with ItemRemovable

use of com.intellij.util.ui.ItemRemovable in project intellij-community by JetBrains.

the class TableUtil method removeSelectedItems.

@NotNull
public static List<Object[]> removeSelectedItems(@NotNull JTable table, @Nullable ItemChecker applyable) {
    final TableModel model = table.getModel();
    if (!(model instanceof ItemRemovable)) {
        throw new RuntimeException("model must be instance of ItemRemovable");
    }
    if (table.getSelectionModel().isSelectionEmpty()) {
        return new ArrayList<Object[]>(0);
    }
    final List<Object[]> removedItems = new SmartList<Object[]>();
    final ItemRemovable itemRemovable = (ItemRemovable) model;
    final int columnCount = model.getColumnCount();
    doRemoveSelectedItems(table, new ItemRemovable() {

        @Override
        public void removeRow(int index) {
            Object[] row = new Object[columnCount];
            for (int column = 0; column < columnCount; column++) {
                row[column] = model.getValueAt(index, column);
            }
            removedItems.add(row);
            itemRemovable.removeRow(index);
        }
    }, applyable);
    return ContainerUtil.reverse(removedItems);
}
Also used : ItemRemovable(com.intellij.util.ui.ItemRemovable) ArrayList(java.util.ArrayList) SmartList(com.intellij.util.SmartList) TableModel(javax.swing.table.TableModel) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SmartList (com.intellij.util.SmartList)1 ItemRemovable (com.intellij.util.ui.ItemRemovable)1 ArrayList (java.util.ArrayList)1 TableModel (javax.swing.table.TableModel)1 NotNull (org.jetbrains.annotations.NotNull)1