Search in sources :

Example 6 with JBTable

use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.

the class AutomaticRenamingDialog method createUIComponents.

private void createUIComponents() {
    myTable = new JBTable();
    myTable.setRowHeight(myTable.getFontMetrics(UIManager.getFont("Table.font").deriveFont(Font.BOLD)).getHeight() + 4);
}
Also used : JBTable(com.intellij.ui.table.JBTable)

Example 7 with JBTable

use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.

the class PerFileConfigurableBase method createComponent.

@NotNull
@Override
public JComponent createComponent() {
    //todo multi-editing, separate project/ide combos _if_ needed by specific configurable (SQL, no Web)
    myPanel = new JPanel(new BorderLayout());
    myTable = new JBTable(myModel = new MyModel<>(param(TARGET_TITLE), param(MAPPING_TITLE))) {

        @Override
        public String getToolTipText(@NotNull MouseEvent event) {
            Point point = event.getPoint();
            int row = rowAtPoint(point);
            int col = columnAtPoint(point);
            if (row != -1 && col == 1) {
                return getToolTipFor((T) getValueAt(convertRowIndexToModel(row), col));
            }
            return super.getToolTipText(event);
        }
    };
    setupPerFileTable();
    JPanel tablePanel = ToolbarDecorator.createDecorator(myTable).disableUpAction().disableDownAction().setAddAction(button -> doAddAction(button)).setRemoveAction(button -> doRemoveAction(button)).setEditAction(button -> doEditAction(button)).setEditActionUpdater(e -> myTable.getSelectedRows().length > 0).createPanel();
    myTable.getEmptyText().setText(param(EMPTY_TEXT).replace("$addShortcut", KeymapUtil.getFirstKeyboardShortcutText(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.ADD))));
    JBLabel label = new JBLabel(param(DESCRIPTION));
    label.setBorder(BorderFactory.createEmptyBorder(TITLED_BORDER_TOP_INSET, TITLED_BORDER_INDENT, TITLED_BORDER_BOTTOM_INSET, 0));
    label.setComponentStyle(UIUtil.ComponentStyle.SMALL);
    JComponent north = createDefaultMappingComponent();
    if (north != null) {
        myPanel.add(north, BorderLayout.NORTH);
    }
    myPanel.add(label, BorderLayout.SOUTH);
    myPanel.add(tablePanel, BorderLayout.CENTER);
    return myPanel;
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) UIUtil(com.intellij.util.ui.UIUtil) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) java.util(java.util) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) javax.swing.table(javax.swing.table) LanguagePerFileMappings(com.intellij.lang.LanguagePerFileMappings) PerFileMappingsBase(com.intellij.lang.PerFileMappingsBase) ContainerUtil(com.intellij.util.containers.ContainerUtil) JBLabel(com.intellij.ui.components.JBLabel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JBUI(com.intellij.util.ui.JBUI) Project(com.intellij.openapi.project.Project) SpeedSearchUtil(com.intellij.ui.speedSearch.SpeedSearchUtil) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) PerFileMappings(com.intellij.lang.PerFileMappings) FileUtil(com.intellij.openapi.util.io.FileUtil) ComboBoxAction(com.intellij.openapi.actionSystem.ex.ComboBoxAction) TIntArrayList(gnu.trove.TIntArrayList) CustomComponentAction(com.intellij.openapi.actionSystem.ex.CustomComponentAction) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) Configurable(com.intellij.openapi.options.Configurable) KeymapUtil(com.intellij.openapi.keymap.KeymapUtil) com.intellij.ui(com.intellij.ui) Collectors(java.util.stream.Collectors) JBPopup(com.intellij.openapi.ui.popup.JBPopup) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) JBTable(com.intellij.ui.table.JBTable) Nullable(org.jetbrains.annotations.Nullable) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) IdeBorderFactory(com.intellij.ui.IdeBorderFactory) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) ConfigurationException(com.intellij.openapi.options.ConfigurationException) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext) FileChooser(com.intellij.openapi.fileChooser.FileChooser) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) javax.swing(javax.swing) MouseEvent(java.awt.event.MouseEvent) JBLabel(com.intellij.ui.components.JBLabel) JBTable(com.intellij.ui.table.JBTable) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with JBTable

use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.

the class JavaChangeSignatureDialog method createAdditionalPanels.

@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, AllIcons.Hierarchy.Caller) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final Ref<JavaCallerChooser> chooser = new Ref<>();
            Consumer<Set<PsiMethod>> callback = 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());
    myExceptionsModel.addTableModelListener(mySignatureUpdater);
    final ArrayList<Pair<String, JPanel>> result = new ArrayList<>();
    final String message = RefactoringBundle.message("changeSignature.exceptions.panel.border.title");
    result.add(Pair.create(message, panel));
    return result;
}
Also used : JavaCallerChooser(com.intellij.refactoring.changeSignature.inCallers.JavaCallerChooser) ArrayList(java.util.ArrayList) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) JBTable(com.intellij.ui.table.JBTable) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) JavaCodeFragmentTableCellEditor(com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor) Ref(com.intellij.openapi.util.Ref) CodeFragmentTableCellRenderer(com.intellij.refactoring.ui.CodeFragmentTableCellRenderer) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with JBTable

use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.

the class EncapsulateFieldsDialog method createTable.

private JComponent createTable() {
    myTableModel = new MyTableModel();
    myTable = new JBTable(myTableModel);
    myTable.setSurrendersFocusOnKeystroke(true);
    MyTableRenderer renderer = new MyTableRenderer();
    TableColumnModel columnModel = myTable.getColumnModel();
    columnModel.getColumn(CHECKED_COLUMN).setCellRenderer(new BooleanTableCellRenderer());
    columnModel.getColumn(FIELD_COLUMN).setCellRenderer(renderer);
    columnModel.getColumn(GETTER_COLUMN).setCellRenderer(renderer);
    columnModel.getColumn(SETTER_COLUMN).setCellRenderer(renderer);
    TableUtil.setupCheckboxColumn(columnModel.getColumn(CHECKED_COLUMN));
    myTable.setPreferredScrollableViewportSize(new Dimension(550, myTable.getRowHeight() * 12));
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable);
    //    JLabel label = new JLabel("Fields to Encapsulate");
    //    CompTitledBorder titledBorder = new CompTitledBorder(label);
    JPanel panel = new JPanel(new BorderLayout());
    Border border = IdeBorderFactory.createTitledBorder(RefactoringBundle.message("encapsulate.fields.fields.to.encapsulate.border.title"), false);
    panel.setBorder(border);
    panel.add(scrollPane);
    // make ESC and ENTER work when focus is in the table
    myTable.registerKeyboardAction(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            TableCellEditor editor = myTable.getCellEditor();
            if (editor != null) {
                editor.cancelCellEditing();
            } else {
                doCancelAction();
            }
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    // make SPACE check/uncheck selected rows
    @NonNls InputMap inputMap = myTable.getInputMap();
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "enable_disable");
    @NonNls ActionMap actionMap = myTable.getActionMap();
    actionMap.put("enable_disable", new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            if (myTable.isEditing())
                return;
            int[] rows = myTable.getSelectedRows();
            if (rows.length > 0) {
                boolean valueToBeSet = false;
                for (int row : rows) {
                    if (!myCheckedMarks[row]) {
                        valueToBeSet = true;
                        break;
                    }
                }
                for (int row : rows) {
                    myCheckedMarks[row] = valueToBeSet;
                }
                myTableModel.fireTableRowsUpdated(rows[0], rows[rows.length - 1]);
                TableUtil.selectRows(myTable, rows);
            }
        }
    });
    // make ENTER work when the table has focus
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "invokeImpl");
    actionMap.put("invokeImpl", new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            TableCellEditor editor = myTable.getCellEditor();
            if (editor != null) {
                editor.stopCellEditing();
            } else {
                clickDefaultButton();
            }
        }
    });
    return panel;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) TableColumnModel(javax.swing.table.TableColumnModel) JBTable(com.intellij.ui.table.JBTable) TableCellEditor(javax.swing.table.TableCellEditor) Border(javax.swing.border.Border)

Example 10 with JBTable

use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.

the class ChangeClassSignatureDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    myTable = new JBTable(myTableModel);
    myTable.setStriped(true);
    TableColumn nameColumn = myTable.getColumnModel().getColumn(NAME_COLUMN);
    TableColumn boundColumn = myTable.getColumnModel().getColumn(BOUND_VALUE_COLUMN);
    TableColumn valueColumn = myTable.getColumnModel().getColumn(DEFAULT_VALUE_COLUMN);
    Project project = myClass.getProject();
    nameColumn.setCellRenderer(new MyCellRenderer());
    nameColumn.setCellEditor(new StringTableCellEditor(project));
    boundColumn.setCellRenderer(new MyCodeFragmentTableCellRenderer());
    boundColumn.setCellEditor(new JavaCodeFragmentTableCellEditor(project));
    valueColumn.setCellRenderer(new MyCodeFragmentTableCellRenderer());
    valueColumn.setCellEditor(new JavaCodeFragmentTableCellEditor(project));
    myTable.setPreferredScrollableViewportSize(new Dimension(210, myTable.getRowHeight() * 4));
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myTable.getSelectionModel().setSelectionInterval(0, 0);
    myTable.setSurrendersFocusOnKeystroke(true);
    myTable.setCellSelectionEnabled(true);
    myTable.setFocusCycleRoot(true);
    if (myHideDefaultValueColumn) {
        final TableColumn defaultValue = myTable.getColumnModel().getColumn(DEFAULT_VALUE_COLUMN);
        myTable.removeColumn(defaultValue);
        myTable.getModel().addTableModelListener(new TableModelListener() {

            @Override
            public void tableChanged(TableModelEvent e) {
                if (e.getType() == TableModelEvent.INSERT) {
                    myTable.getModel().removeTableModelListener(this);
                    final TableColumnAnimator animator = new TableColumnAnimator(myTable);
                    animator.setStep(20);
                    animator.addColumn(defaultValue, myTable.getWidth() / 2);
                    animator.startAndDoWhenDone(() -> myTable.editCellAt(myTable.getRowCount() - 1, 0));
                    animator.start();
                }
            }
        });
    }
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(SeparatorFactory.createSeparator(RefactoringBundle.message("changeClassSignature.parameters.panel.border.title"), myTable), BorderLayout.NORTH);
    panel.add(ToolbarDecorator.createDecorator(myTable).createPanel(), BorderLayout.CENTER);
    return panel;
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) JBTable(com.intellij.ui.table.JBTable) TableColumn(javax.swing.table.TableColumn) JavaCodeFragmentTableCellEditor(com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor) Project(com.intellij.openapi.project.Project) TableModelListener(javax.swing.event.TableModelListener) StringTableCellEditor(com.intellij.refactoring.ui.StringTableCellEditor)

Aggregations

JBTable (com.intellij.ui.table.JBTable)41 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)8 DefaultTableModel (javax.swing.table.DefaultTableModel)8 NotNull (org.jetbrains.annotations.NotNull)7 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)6 Nullable (org.jetbrains.annotations.Nullable)6 JBLabel (com.intellij.ui.components.JBLabel)5 ActionEvent (java.awt.event.ActionEvent)5 AbstractTableModel (javax.swing.table.AbstractTableModel)5 TableColumn (javax.swing.table.TableColumn)5 TableColumnModel (javax.swing.table.TableColumnModel)5 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)4 Project (com.intellij.openapi.project.Project)4 JBScrollPane (com.intellij.ui.components.JBScrollPane)4 MouseEvent (java.awt.event.MouseEvent)4 List (java.util.List)4 StringUtil (com.intellij.openapi.util.text.StringUtil)3 JavaCodeFragmentTableCellEditor (com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor)3 UsageInfo (com.intellij.usageView.UsageInfo)3