@NotNull protected List<Pair<String, JPanel>> createAdditionalPanels() { // this method is invoked before constructor body myExceptionsModel = new ExceptionsTableModel(myMethod.getMethod().getThrowsList()); myExceptionsModel.setTypeInfos(myMethod.getMethod()); final JBTable table = new JBTable(myExceptionsModel); table.setStriped(true); table.setRowHeight(20); table .getColumnModel() .getColumn(0) .setCellRenderer(new CodeFragmentTableCellRenderer(myProject)); final JavaCodeFragmentTableCellEditor cellEditor = new JavaCodeFragmentTableCellEditor(myProject); cellEditor.addDocumentListener( new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { final int row = table.getSelectedRow(); final int col = table.getSelectedColumn(); myExceptionsModel.setValueAt(cellEditor.getCellEditorValue(), row, col); updateSignature(); } }); table.getColumnModel().getColumn(0).setCellEditor(cellEditor); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().setSelectionInterval(0, 0); table.setSurrendersFocusOnKeystroke(true); myPropExceptionsButton = new AnActionButton( RefactoringBundle.message("changeSignature.propagate.exceptions.title"), null, PlatformIcons.NEW_EXCEPTION) { @Override public void actionPerformed(AnActionEvent e) { final Ref<JavaCallerChooser> chooser = new Ref<JavaCallerChooser>(); Consumer<Set<PsiMethod>> callback = new Consumer<Set<PsiMethod>>() { @Override public void consume(Set<PsiMethod> psiMethods) { myMethodsToPropagateExceptions = psiMethods; myExceptionPropagationTree = chooser.get().getTree(); } }; chooser.set( new JavaCallerChooser( myMethod.getMethod(), myProject, RefactoringBundle.message("changeSignature.exception.caller.chooser"), myExceptionPropagationTree, callback)); chooser.get().show(); } }; myPropExceptionsButton.setShortcut(CustomShortcutSet.fromString("alt X")); final JPanel panel = ToolbarDecorator.createDecorator(table) .addExtraAction(myPropExceptionsButton) .createPanel(); panel.setBorder(IdeBorderFactory.createEmptyBorder(0)); myExceptionsModel.addTableModelListener(mySignatureUpdater); final ArrayList<Pair<String, JPanel>> result = new ArrayList<Pair<String, JPanel>>(); final String message = RefactoringBundle.message("changeSignature.exceptions.panel.border.title"); result.add(Pair.create(message, panel)); return result; }
private JComponent createChildrenListEditor() { final MyTableModel tableModel = new MyTableModel(); myTable = new JBTable(tableModel); myListChildrenEditor = new DebuggerExpressionTextField(myProject, null, "NamedChildrenConfigurable"); final TableColumn exprColumn = myTable.getColumnModel().getColumn(EXPRESSION_TABLE_COLUMN); exprColumn.setCellEditor( new AbstractTableCellEditor() { public Object getCellEditorValue() { return myListChildrenEditor.getText(); } public Component getTableCellEditorComponent( JTable table, Object value, boolean isSelected, int row, int column) { myListChildrenEditor.setText((TextWithImports) value); return myListChildrenEditor; } }); exprColumn.setCellRenderer( new DefaultTableCellRenderer() { public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final TextWithImports textWithImports = (TextWithImports) value; final String text = (textWithImports != null) ? textWithImports.getText() : ""; return super.getTableCellRendererComponent( table, text, isSelected, hasFocus, row, column); } }); return ToolbarDecorator.createDecorator(myTable) .setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { tableModel.addRow("", DebuggerUtils.getInstance().createExpressionWithImports("")); } }) .setRemoveAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { int selectedRow = myTable.getSelectedRow(); if (selectedRow >= 0 && selectedRow < myTable.getRowCount()) { getTableModel().removeRow(selectedRow); } } }) .setMoveUpAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { TableUtil.moveSelectedItemsUp(myTable); } }) .setMoveDownAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { TableUtil.moveSelectedItemsDown(myTable); } }) .createPanel(); }