Search in sources :

Example 11 with JBTable

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

the class InplaceAddEditRemovePanel method doAdd.

@Override
protected void doAdd() {
    super.doAdd();
    JBTable table = getTable();
    int selected = table.getSelectedRow();
    if (selected != -1) {
        table.editCellAt(selected, 0);
    }
}
Also used : JBTable(com.intellij.ui.table.JBTable)

Example 12 with JBTable

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

the class ImportLayoutPanel method createTableForPackageEntries.

public static JBTable createTableForPackageEntries(final PackageEntryTable packageTable, final ImportLayoutPanel panel) {
    final String[] names = { ApplicationBundle.message("listbox.import.package"), ApplicationBundle.message("listbox.import.with.subpackages") };
    // Create a model of the data.
    TableModel dataModel = new AbstractTableModel() {

        public int getColumnCount() {
            return names.length + (panel.areStaticImportsEnabled() ? 1 : 0);
        }

        public int getRowCount() {
            return packageTable.getEntryCount();
        }

        @Nullable
        public Object getValueAt(int row, int col) {
            PackageEntry entry = packageTable.getEntryAt(row);
            if (entry == null || !isCellEditable(row, col))
                return null;
            col += panel.areStaticImportsEnabled() ? 0 : 1;
            if (col == 0) {
                return entry.isStatic();
            }
            if (col == 1) {
                return entry.getPackageName();
            }
            if (col == 2) {
                return entry.isWithSubpackages();
            }
            throw new IllegalArgumentException(String.valueOf(col));
        }

        public String getColumnName(int column) {
            if (panel.areStaticImportsEnabled() && column == 0)
                return "Static";
            column -= panel.areStaticImportsEnabled() ? 1 : 0;
            return names[column];
        }

        public Class getColumnClass(int col) {
            col += panel.areStaticImportsEnabled() ? 0 : 1;
            if (col == 0) {
                return Boolean.class;
            }
            if (col == 1) {
                return String.class;
            }
            if (col == 2) {
                return Boolean.class;
            }
            throw new IllegalArgumentException(String.valueOf(col));
        }

        public boolean isCellEditable(int row, int col) {
            PackageEntry packageEntry = packageTable.getEntryAt(row);
            return !packageEntry.isSpecial();
        }

        public void setValueAt(Object aValue, int row, int col) {
            PackageEntry packageEntry = packageTable.getEntryAt(row);
            col += panel.areStaticImportsEnabled() ? 0 : 1;
            if (col == 0) {
                PackageEntry newPackageEntry = new PackageEntry((Boolean) aValue, packageEntry.getPackageName(), packageEntry.isWithSubpackages());
                packageTable.setEntryAt(newPackageEntry, row);
            } else if (col == 1) {
                PackageEntry newPackageEntry = new PackageEntry(packageEntry.isStatic(), ((String) aValue).trim(), packageEntry.isWithSubpackages());
                packageTable.setEntryAt(newPackageEntry, row);
            } else if (col == 2) {
                PackageEntry newPackageEntry = new PackageEntry(packageEntry.isStatic(), packageEntry.getPackageName(), ((Boolean) aValue).booleanValue());
                packageTable.setEntryAt(newPackageEntry, row);
            } else {
                throw new IllegalArgumentException(String.valueOf(col));
            }
        }
    };
    // Create the table
    final JBTable result = new JBTable(dataModel);
    result.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    resizeColumns(packageTable, result, panel.areStaticImportsEnabled());
    TableCellEditor editor = result.getDefaultEditor(String.class);
    if (editor instanceof DefaultCellEditor) {
        ((DefaultCellEditor) editor).setClickCountToStart(1);
    }
    TableCellEditor beditor = result.getDefaultEditor(Boolean.class);
    beditor.addCellEditorListener(new CellEditorListener() {

        public void editingStopped(ChangeEvent e) {
            if (panel.areStaticImportsEnabled()) {
                // add/remove static keyword
                result.repaint();
            }
        }

        public void editingCanceled(ChangeEvent e) {
        }
    });
    return result;
}
Also used : CellEditorListener(javax.swing.event.CellEditorListener) JBTable(com.intellij.ui.table.JBTable) ChangeEvent(javax.swing.event.ChangeEvent) PackageEntry(com.intellij.psi.codeStyle.PackageEntry) AbstractTableModel(javax.swing.table.AbstractTableModel) TableCellEditor(javax.swing.table.TableCellEditor) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Example 13 with JBTable

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

the class AutomaticUsageRenamingDialog method setupTable.

private void setupTable() {
    myTable = new JBTable();
    myTableModel = new MyTableModel();
    myTable.setModel(myTableModel);
    myTable.getSelectionModel().addListSelectionListener(e -> refreshValidatingComponent());
    myTable.setCellSelectionEnabled(false);
    myTable.setColumnSelectionAllowed(false);
    myTable.setRowSelectionAllowed(false);
    myTable.getTableHeader().setReorderingAllowed(false);
}
Also used : JBTable(com.intellij.ui.table.JBTable)

Example 14 with JBTable

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

the class JavadocEditor method createComponentImpl.

@Override
public JComponent createComponentImpl() {
    final DefaultTableModel tableModel = createModel();
    myTable = new JBTable(tableModel);
    myTable.setIntercellSpacing(new Dimension(0, 0));
    myTable.setDefaultRenderer(TableItem.class, new MyRenderer());
    myTable.setShowGrid(false);
    myTable.setDragEnabled(false);
    myTable.setShowHorizontalLines(false);
    myTable.setShowVerticalLines(false);
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    JPanel tablePanel = ToolbarDecorator.createDecorator(myTable).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            FileChooserDescriptor myDescriptor = FileChooserDescriptorFactory.createMultipleJavaPathDescriptor();
            myDescriptor.setTitle(ProjectBundle.message("module.javadoc.add.path.title"));
            myDescriptor.setDescription(ProjectBundle.message("module.javadoc.add.path.prompt"));
            VirtualFile[] files = FileChooser.chooseFiles(myDescriptor, myTable, myProject, null);
            final MyTableModel tableModel = (MyTableModel) myTable.getModel();
            boolean changes = false;
            for (final VirtualFile file : files) {
                if (file != null) {
                    tableModel.addTableItem(new TableItem(file));
                    changes = true;
                }
            }
            if (changes) {
                saveData();
                TableUtil.selectRows(myTable, new int[] { tableModel.getRowCount() - 1 });
            }
        }
    }).addExtraAction(new DumbAwareActionButton(ProjectBundle.message("module.javadoc.add.url.button"), IconUtil.getAddLinkIcon()) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            VirtualFile[] files = new VirtualFile[] { Util.showSpecifyJavadocUrlDialog(myTable) };
            final MyTableModel tableModel = (MyTableModel) myTable.getModel();
            boolean changes = false;
            for (final VirtualFile file : files) {
                if (file != null) {
                    tableModel.addTableItem(new TableItem(file));
                    changes = true;
                }
            }
            if (changes) {
                saveData();
                TableUtil.selectRows(myTable, new int[] { tableModel.getRowCount() - 1 });
            }
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            final List removedItems = TableUtil.removeSelectedItems(myTable);
            if (removedItems.size() > 0) {
                saveData();
            }
        }
    }).setButtonComparator("Add", ProjectBundle.message("module.javadoc.add.url.button"), "Remove").createPanel();
    final JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(tablePanel, BorderLayout.CENTER);
    mainPanel.add(new JBLabel(ProjectBundle.message("project.roots.javadoc.tab.description"), UIUtil.ComponentStyle.SMALL, UIUtil.FontColor.BRIGHTER), BorderLayout.NORTH);
    return mainPanel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) DefaultTableModel(javax.swing.table.DefaultTableModel) JBTable(com.intellij.ui.table.JBTable) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) JBLabel(com.intellij.ui.components.JBLabel) List(java.util.List)

Example 15 with JBTable

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

the class AnnotationsEditor method createComponentImpl.

@Override
public JComponent createComponentImpl() {
    final DefaultTableModel tableModel = createModel();
    myTable = new JBTable(tableModel);
    myTable.setIntercellSpacing(new Dimension(0, 0));
    myTable.setDefaultRenderer(TableItem.class, new MyRenderer());
    myTable.setShowGrid(false);
    myTable.setDragEnabled(false);
    myTable.setShowHorizontalLines(false);
    myTable.setShowVerticalLines(false);
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    JPanel tablePanel = ToolbarDecorator.createDecorator(myTable).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            FileChooserDescriptor myDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
            myDescriptor.setTitle(ProjectBundle.message("add.external.annotations.path.title"));
            myDescriptor.setDescription(ProjectBundle.message("add.external.annotations.path.description"));
            VirtualFile[] files = FileChooser.chooseFiles(myDescriptor, myTable, myProject, null);
            final MyTableModel tableModel = (MyTableModel) myTable.getModel();
            boolean changes = false;
            for (final VirtualFile file : files) {
                if (file != null) {
                    tableModel.addTableItem(new TableItem(file));
                    changes = true;
                }
            }
            if (changes) {
                saveData();
                TableUtil.selectRows(myTable, new int[] { tableModel.getRowCount() - 1 });
            }
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            final List removedItems = TableUtil.removeSelectedItems(myTable);
            if (removedItems.size() > 0) {
                saveData();
            }
        }
    }).createPanel();
    final JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(tablePanel, BorderLayout.CENTER);
    mainPanel.add(new JBLabel(ProjectBundle.message("project.roots.external.annotations.description"), UIUtil.ComponentStyle.SMALL, UIUtil.FontColor.BRIGHTER), BorderLayout.NORTH);
    return mainPanel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) DefaultTableModel(javax.swing.table.DefaultTableModel) JBTable(com.intellij.ui.table.JBTable) JBLabel(com.intellij.ui.components.JBLabel) List(java.util.List)

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