/*
- * Copyright 2000-2010 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import com.intellij.ui.AnActionButton;
import com.intellij.ui.AnActionButtonRunnable;
+import com.intellij.ui.TableUtil;
import com.intellij.ui.ToolbarDecorator;
import javax.swing.*;
component.requestFocus();
});
}
- }).setRemoveAction(new AnActionButtonRunnable() {
- @Override
- public void run(AnActionButton button) {
- final ListSelectionModel selectionModel = table.getSelectionModel();
- final int minIndex = selectionModel.getMinSelectionIndex();
- final int maxIndex = selectionModel.getMaxSelectionIndex();
- if (minIndex == -1 || maxIndex == -1) {
- return;
- }
- final ListWrappingTableModel tableModel = table.getModel();
- for (int i = minIndex; i <= maxIndex; i++) {
- if (selectionModel.isSelectedIndex(i)) {
- tableModel.removeRow(i);
- }
- }
- final int count = tableModel.getRowCount();
- if (count <= minIndex) {
- selectionModel.setSelectionInterval(count - 1,
- count - 1);
- }
- else if (minIndex <= 0) {
- if (count > 0) {
- selectionModel.setSelectionInterval(0, 0);
- }
- }
- else {
- selectionModel.setSelectionInterval(minIndex - 1,
- minIndex - 1);
- }
- }
- }).disableUpDownActions().createPanel();
+ })
+ .setRemoveAction(button -> TableUtil.removeSelectedItems(table))
+ .disableUpDownActions().createPanel();
}
public JComponent getContentPanel() {
/*
- * Copyright 2007-2013 Bas Leijdekkers
+ * Copyright 2007-2016 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package com.intellij.codeInspection.ui;
import com.intellij.util.containers.ContainerUtil;
+import com.intellij.util.ui.ItemRemovable;
import org.jetbrains.annotations.NotNull;
import javax.swing.table.AbstractTableModel;
import java.util.Arrays;
import java.util.List;
-public class ListWrappingTableModel extends AbstractTableModel {
+public class ListWrappingTableModel extends AbstractTableModel implements ItemRemovable {
private final List<List<String>> list;
private final List<String> columnNames = new ArrayList<>();
return true;
}
+ @Override
public void removeRow(int rowIndex) {
for (List<String> column : list) {
column.remove(rowIndex);
editTableCell(table, lastRowIndex, 0);
});
}
- }).setRemoveAction(new RemoveAction(table))
+ })
+ .setRemoveAction(button -> TableUtil.removeSelectedItems(table))
.disableUpDownActions().createPanel();
panel.setPreferredSize(JBUI.size(150, 100));
return panel;
}
editTableCell(table, rowIndex, table.getColumnCount() > 1 && project != null ? 1 : 0);
}
- }).setRemoveAction(new RemoveAction(table))
+ }).setRemoveAction(button -> TableUtil.removeSelectedItems(table))
.disableUpDownActions().createPanel();
panel.setPreferredSize(JBUI.size(150, 100));
return panel;
return optionsPanel;
}
- private static class RemoveAction implements AnActionButtonRunnable {
-
- private final ListTable table;
-
- public RemoveAction(ListTable table) {
- this.table = table;
- }
-
- @Override
- public void run(AnActionButton button) {
- EventQueue.invokeLater(() -> {
- final TableCellEditor editor = table.getCellEditor();
- if (editor != null) {
- editor.stopCellEditing();
- }
- final ListSelectionModel selectionModel = table.getSelectionModel();
- final int minIndex = selectionModel.getMinSelectionIndex();
- final int maxIndex = selectionModel.getMaxSelectionIndex();
- if (minIndex == -1 || maxIndex == -1) {
- return;
- }
- final ListWrappingTableModel tableModel = table.getModel();
- for (int i = minIndex; i <= maxIndex; i++) {
- tableModel.removeRow(minIndex);
- }
- final int count = tableModel.getRowCount();
- if (count <= minIndex) {
- selectionModel.setSelectionInterval(count - 1, count - 1);
- }
- else if (minIndex <= 0) {
- if (count > 0) {
- selectionModel.setSelectionInterval(0, 0);
- }
- }
- else {
- selectionModel.setSelectionInterval(minIndex - 1, minIndex - 1);
- }
- });
- }
- }
-
private static class SubclassFilter implements ClassFilter {
private final String[] ancestorClasses;