Search in sources :

Example 1 with XDebuggerExpressionEditor

use of com.intellij.xdebugger.impl.ui.XDebuggerExpressionEditor in project intellij-community by JetBrains.

the class CompoundRendererConfigurable method createChildrenListEditor.

private JComponent createChildrenListEditor(JavaDebuggerEditorsProvider editorsProvider) {
    final MyTableModel tableModel = new MyTableModel();
    myTable = new JBTable(tableModel);
    myListChildrenEditor = new XDebuggerExpressionEditor(myProject, editorsProvider, "NamedChildrenConfigurable", null, XExpressionImpl.EMPTY_EXPRESSION, false, false, false);
    JComponent editorComponent = myListChildrenEditor.getComponent();
    AbstractTableCellEditor editor = new AbstractTableCellEditor() {

        @Override
        public Object getCellEditorValue() {
            return TextWithImportsImpl.fromXExpression(myListChildrenEditor.getExpression());
        }

        @Override
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
            myListChildrenEditor.setExpression(TextWithImportsImpl.toXExpression((TextWithImports) value));
            return editorComponent;
        }
    };
    editorComponent.registerKeyboardAction(e -> editor.stopCellEditing(), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    editorComponent.registerKeyboardAction(e -> editor.cancelCellEditing(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    TableColumn exprColumn = myTable.getColumnModel().getColumn(EXPRESSION_TABLE_COLUMN);
    exprColumn.setCellEditor(editor);
    exprColumn.setCellRenderer(new DefaultTableCellRenderer() {

        @NotNull
        @Override
        public Component getTableCellRendererComponent(@NotNull 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();
}
Also used : XDebuggerExpressionEditor(com.intellij.xdebugger.impl.ui.XDebuggerExpressionEditor) JBTable(com.intellij.ui.table.JBTable) TableColumn(javax.swing.table.TableColumn) NotNull(org.jetbrains.annotations.NotNull) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports)

Aggregations

TextWithImports (com.intellij.debugger.engine.evaluation.TextWithImports)1 JBTable (com.intellij.ui.table.JBTable)1 AbstractTableCellEditor (com.intellij.util.ui.AbstractTableCellEditor)1 XDebuggerExpressionEditor (com.intellij.xdebugger.impl.ui.XDebuggerExpressionEditor)1 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)1 TableColumn (javax.swing.table.TableColumn)1 NotNull (org.jetbrains.annotations.NotNull)1