Search in sources :

Example 1 with BooleanTableCellRenderer

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

the class OverridingMethodsDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createEmptyBorder(8, 0, 4, 0));
    final MyTableModel tableModel = new MyTableModel();
    myTable = new Table(tableModel);
    myTable.setShowGrid(false);
    TableColumnModel columnModel = myTable.getColumnModel();
    //    columnModel.getColumn(DISPLAY_NAME_COLUMN).setCellRenderer(new MemberSelectionTable.MyTableRenderer());
    TableColumn checkboxColumn = columnModel.getColumn(CHECK_COLUMN);
    TableUtil.setupCheckboxColumn(checkboxColumn);
    checkboxColumn.setCellRenderer(new BooleanTableCellRenderer());
    // make SPACE check/uncheck selected rows
    @NonNls InputMap inputMap = myTable.getInputMap();
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "enable_disable");
    @NonNls final 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 (!myChecked[row]) {
                        valueToBeSet = true;
                        break;
                    }
                }
                for (int row : rows) {
                    myChecked[row] = valueToBeSet;
                }
                tableModel.updateData();
            }
        }
    });
    /*Border titledBorder = IdeBorderFactory.createBoldTitledBorder("Select methods");
    Border emptyBorder = BorderFactory.createEmptyBorder(0, 5, 5, 5);
    Border border = BorderFactory.createCompoundBorder(titledBorder, emptyBorder);
    panel.setBorder(border);*/
    panel.setLayout(new BorderLayout());
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable);
    panel.add(scrollPane, BorderLayout.CENTER);
    ListSelectionListener selectionListener = new ListSelectionListener() {

        public void valueChanged(final ListSelectionEvent e) {
            int index = myTable.getSelectionModel().getLeadSelectionIndex();
            if (index != -1) {
                UsageInfo usageInfo = myOverridingMethods.get(index);
                myUsagePreviewPanel.updateLayout(Collections.singletonList(usageInfo));
            } else {
                myUsagePreviewPanel.updateLayout(null);
            }
        }
    };
    myTable.getSelectionModel().addListSelectionListener(selectionListener);
    final Splitter splitter = new Splitter(true, 0.3f);
    splitter.setFirstComponent(panel);
    splitter.setSecondComponent(myUsagePreviewPanel);
    myUsagePreviewPanel.updateLayout(null);
    Disposer.register(myDisposable, new Disposable() {

        public void dispose() {
            splitter.dispose();
        }
    });
    if (tableModel.getRowCount() != 0) {
        myTable.getSelectionModel().addSelectionInterval(0, 0);
    }
    return splitter;
}
Also used : Disposable(com.intellij.openapi.Disposable) NonNls(org.jetbrains.annotations.NonNls) Table(com.intellij.util.ui.Table) Splitter(com.intellij.openapi.ui.Splitter) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn) ListSelectionListener(javax.swing.event.ListSelectionListener) BooleanTableCellRenderer(com.intellij.ui.BooleanTableCellRenderer) UsageInfo(com.intellij.usageView.UsageInfo) SafeDeleteOverridingMethodUsageInfo(com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteOverridingMethodUsageInfo)

Example 2 with BooleanTableCellRenderer

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

the class AutomaticRenamingDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myTable.setModel(myTableModel);
    myTableModel.getSpaceAction().register();
    myTableModel.addTableModelListener(e -> handleChanges());
    myTable.addMouseListener(new PopupHandler() {

        @Override
        public void invokePopup(Component comp, int x, int y) {
            final int[] selectionRows = myTable.getSelectedRows();
            if (selectionRows != null) {
                compoundPopup().show(comp, x, y);
            }
        }
    });
    final TableColumnModel columnModel = myTable.getColumnModel();
    columnModel.getColumn(CHECK_COLUMN).setCellRenderer(new BooleanTableCellRenderer());
    TableUtil.setupCheckboxColumn(columnModel.getColumn(CHECK_COLUMN));
    columnModel.getColumn(NEW_NAME_COLUMN).setCellEditor(new StringTableCellEditor(myProject));
    mySelectAllButton.addActionListener(e -> {
        for (int i = 0; i < myShouldRename.length; i++) {
            myShouldRename[i] = true;
        }
        fireDataChanged();
    });
    myUnselectAllButton.addActionListener(e -> {
        for (int i = 0; i < myShouldRename.length; i++) {
            myShouldRename[i] = false;
        }
        fireDataChanged();
    });
    myListSelectionListener = e -> {
        myUsageFileLabel.setText("");
        int index = myTable.getSelectionModel().getLeadSelectionIndex();
        if (index != -1) {
            PsiNamedElement element = myRenames[index];
            UsageInfo usageInfo = new UsageInfo(element);
            myUsagePreviewPanel.updateLayout(Collections.singletonList(usageInfo));
            final PsiFile containingFile = element.getContainingFile();
            if (containingFile != null) {
                final VirtualFile virtualFile = containingFile.getVirtualFile();
                if (virtualFile != null) {
                    myUsageFileLabel.setText(virtualFile.getName());
                }
            }
        } else {
            myUsagePreviewPanel.updateLayout(null);
        }
    };
    myTable.getSelectionModel().addListSelectionListener(myListSelectionListener);
    myPanelForPreview.add(myUsagePreviewPanel, BorderLayout.CENTER);
    myUsagePreviewPanel.updateLayout(null);
    myPanelForPreview.add(myUsageFileLabel, BorderLayout.NORTH);
    mySplitPane.setDividerLocation(0.5);
    GuiUtils.replaceJSplitPaneWithIDEASplitter(myPanel);
    if (myTableModel.getRowCount() != 0) {
        myTable.getSelectionModel().addSelectionInterval(0, 0);
    }
    return myPanel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PopupHandler(com.intellij.ui.PopupHandler) PsiNamedElement(com.intellij.psi.PsiNamedElement) TableColumnModel(javax.swing.table.TableColumnModel) StringTableCellEditor(com.intellij.refactoring.ui.StringTableCellEditor) PsiFile(com.intellij.psi.PsiFile) BooleanTableCellRenderer(com.intellij.ui.BooleanTableCellRenderer) UsageInfo(com.intellij.usageView.UsageInfo)

Example 3 with BooleanTableCellRenderer

use of com.intellij.ui.BooleanTableCellRenderer in project kotlin by JetBrains.

the class KotlinOverridingDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createEmptyBorder(8, 0, 4, 0));
    final MyTableModel tableModel = new MyTableModel();
    myTable = new JBTable(tableModel);
    myTable.setShowGrid(false);
    TableColumnModel columnModel = myTable.getColumnModel();
    int checkBoxWidth = new JCheckBox().getPreferredSize().width;
    columnModel.getColumn(CHECK_COLUMN).setCellRenderer(new BooleanTableCellRenderer());
    columnModel.getColumn(CHECK_COLUMN).setMaxWidth(checkBoxWidth);
    columnModel.getColumn(CHECK_COLUMN).setMinWidth(checkBoxWidth);
    // make SPACE check/uncheck selected rows
    InputMap inputMap = myTable.getInputMap();
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "enable_disable");
    ActionMap actionMap = myTable.getActionMap();
    actionMap.put("enable_disable", new AbstractAction() {

        @Override
        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 (!myChecked[row]) {
                        valueToBeSet = true;
                        break;
                    }
                }
                for (int row : rows) {
                    myChecked[row] = valueToBeSet;
                }
                tableModel.updateData();
            }
        }
    });
    panel.setLayout(new BorderLayout());
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable);
    panel.add(scrollPane, BorderLayout.CENTER);
    ListSelectionListener selectionListener = new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            int index = myTable.getSelectionModel().getLeadSelectionIndex();
            if (index != -1) {
                UsageInfo usageInfo = myOverridingMethods.get(index);
                myUsagePreviewPanel.updateLayout(Collections.singletonList(usageInfo));
            } else {
                myUsagePreviewPanel.updateLayout(null);
            }
        }
    };
    myTable.getSelectionModel().addListSelectionListener(selectionListener);
    final Splitter splitter = new Splitter(true, 0.3f);
    splitter.setFirstComponent(panel);
    splitter.setSecondComponent(myUsagePreviewPanel);
    myUsagePreviewPanel.updateLayout(null);
    Disposer.register(myDisposable, new Disposable() {

        @Override
        public void dispose() {
            splitter.dispose();
        }
    });
    if (tableModel.getRowCount() != 0) {
        myTable.getSelectionModel().addSelectionInterval(0, 0);
    }
    return splitter;
}
Also used : Disposable(com.intellij.openapi.Disposable) Splitter(com.intellij.openapi.ui.Splitter) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) TableColumnModel(javax.swing.table.TableColumnModel) JBTable(com.intellij.ui.table.JBTable) ListSelectionListener(javax.swing.event.ListSelectionListener) BooleanTableCellRenderer(com.intellij.ui.BooleanTableCellRenderer) UsageInfo(com.intellij.usageView.UsageInfo)

Example 4 with BooleanTableCellRenderer

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

the class CreateTestDialog method methodsSize.

public void methodsSize(int methods) {
    myTableModel = new DefaultTableModel(methods, 2);
    myMethodsTable.setModel(myTableModel);
    TableColumn checkColumn = myMethodsTable.getColumnModel().getColumn(0);
    TableUtil.setupCheckboxColumn(checkColumn);
    checkColumn.setCellRenderer(new BooleanTableCellRenderer());
    checkColumn.setCellEditor(new DefaultCellEditor(new JCheckBox()));
    myMethodsTable.getColumnModel().getColumn(1).setHeaderValue("Test method");
    checkColumn.setHeaderValue("");
    getOKAction().setEnabled(true);
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) TableColumn(javax.swing.table.TableColumn) BooleanTableCellRenderer(com.intellij.ui.BooleanTableCellRenderer)

Aggregations

BooleanTableCellRenderer (com.intellij.ui.BooleanTableCellRenderer)4 UsageInfo (com.intellij.usageView.UsageInfo)3 TableColumnModel (javax.swing.table.TableColumnModel)3 Disposable (com.intellij.openapi.Disposable)2 Splitter (com.intellij.openapi.ui.Splitter)2 ActionEvent (java.awt.event.ActionEvent)2 ListSelectionEvent (javax.swing.event.ListSelectionEvent)2 ListSelectionListener (javax.swing.event.ListSelectionListener)2 TableColumn (javax.swing.table.TableColumn)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 PsiNamedElement (com.intellij.psi.PsiNamedElement)1 SafeDeleteOverridingMethodUsageInfo (com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteOverridingMethodUsageInfo)1 StringTableCellEditor (com.intellij.refactoring.ui.StringTableCellEditor)1 PopupHandler (com.intellij.ui.PopupHandler)1 JBTable (com.intellij.ui.table.JBTable)1 Table (com.intellij.util.ui.Table)1 DefaultTableModel (javax.swing.table.DefaultTableModel)1 NonNls (org.jetbrains.annotations.NonNls)1