2 * Copyright 2000-2016 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.codeInspection.ui;
18 import com.intellij.ui.AnActionButton;
19 import com.intellij.ui.AnActionButtonRunnable;
20 import com.intellij.ui.TableUtil;
21 import com.intellij.ui.ToolbarDecorator;
24 import javax.swing.table.TableCellEditor;
26 import java.util.List;
28 public class ListEditForm {
32 public ListEditForm(String title, List<String> stringList) {
33 table = new ListTable(new ListWrappingTableModel(stringList, title));
35 contentPanel = ToolbarDecorator.createDecorator(table)
36 .setAddAction(new AnActionButtonRunnable() {
38 public void run(AnActionButton button) {
39 final ListWrappingTableModel tableModel = table.getModel();
41 EventQueue.invokeLater(() -> {
42 final int lastRowIndex = tableModel.getRowCount() - 1;
43 final Rectangle rectangle =
44 table.getCellRect(lastRowIndex, 0, true);
45 table.scrollRectToVisible(rectangle);
46 table.editCellAt(lastRowIndex, 0);
47 final ListSelectionModel selectionModel =
48 table.getSelectionModel();
49 selectionModel.setSelectionInterval(lastRowIndex, lastRowIndex);
50 final TableCellEditor editor = table.getCellEditor();
51 final Component component =
52 editor.getTableCellEditorComponent(table,
53 null, true, lastRowIndex, 0);
54 component.requestFocus();
58 .setRemoveAction(button -> TableUtil.removeSelectedItems(table))
59 .disableUpDownActions().createPanel();
62 public JComponent getContentPanel() {