@Override public void actionPerformed(AnActionEvent anActionEvent) { final ListWrappingTableModel tableModel = table.getModel(); tableModel.addRow(); EventQueue.invokeLater( new Runnable() { public void run() { final int lastRowIndex = tableModel.getRowCount() - 1; final Rectangle rectangle = table.getCellRect(lastRowIndex, 0, true); table.scrollRectToVisible(rectangle); table.editCellAt(lastRowIndex, 0); final ListSelectionModel selectionModel = table.getSelectionModel(); selectionModel.setSelectionInterval(lastRowIndex, lastRowIndex); final TableCellEditor editor = table.getCellEditor(); final Component component = editor.getTableCellEditorComponent(table, null, true, lastRowIndex, 0); component.requestFocus(); } }); }
@Override public void actionPerformed(AnActionEvent e) { final DataContext dataContext = e.getDataContext(); final Project project = DataKeys.PROJECT.getData(dataContext); if (project == null) { return; } final TreeClassChooserFactory chooserFactory = TreeClassChooserFactory.getInstance(project); final TreeClassChooser classChooser = chooserFactory.createWithInnerClassesScopeChooser( chooserTitle, GlobalSearchScope.allScope(project), myFilter, null); classChooser.showDialog(); final PsiClass selectedClass = classChooser.getSelected(); if (selectedClass == null) { return; } final String qualifiedName = selectedClass.getQualifiedName(); final ListWrappingTableModel tableModel = table.getModel(); final int index = tableModel.indexOf(qualifiedName, 0); final int rowIndex; if (index < 0) { tableModel.addRow(qualifiedName); rowIndex = tableModel.getRowCount() - 1; } else { rowIndex = index; } final ListSelectionModel selectionModel = table.getSelectionModel(); selectionModel.setSelectionInterval(rowIndex, rowIndex); EventQueue.invokeLater( new Runnable() { public void run() { final Rectangle rectangle = table.getCellRect(rowIndex, 0, true); table.scrollRectToVisible(rectangle); } }); }