2 * Copyright 2007 Bas Leijdekkers
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
.siyeh
.ig
.ui
;
18 import com
.siyeh
.InspectionGadgetsBundle
;
20 import javax
.swing
.AbstractAction
;
21 import javax
.swing
.ListSelectionModel
;
22 import javax
.swing
.table
.TableCellEditor
;
23 import java
.awt
.Component
;
24 import java
.awt
.EventQueue
;
25 import java
.awt
.Rectangle
;
26 import java
.awt
.event
.ActionEvent
;
28 public class AddAction
extends AbstractAction
{
32 public AddAction(IGTable table
) {
35 InspectionGadgetsBundle
.message("button.add"));
38 public void actionPerformed(ActionEvent e
) {
39 final ListWrappingTableModel tableModel
= table
.getModel();
41 EventQueue
.invokeLater(new Runnable() {
43 final int lastRowIndex
= tableModel
.getRowCount() - 1;
44 final Rectangle rect
=
45 table
.getCellRect(lastRowIndex
, 0, true);
46 table
.scrollRectToVisible(rect
);
47 table
.editCellAt(lastRowIndex
, 0);
48 final ListSelectionModel selectionModel
=
49 table
.getSelectionModel();
50 selectionModel
.setSelectionInterval(lastRowIndex
, lastRowIndex
);
51 final TableCellEditor editor
= table
.getCellEditor();
52 final Component component
=
53 editor
.getTableCellEditorComponent(table
,
54 null, true, lastRowIndex
, 0);
55 component
.requestFocus();