Search in sources :

Example 6 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project intellij-community by JetBrains.

the class ImportLayoutPanel method moveRowUp.

private void moveRowUp() {
    int selected = myImportLayoutTable.getSelectedRow();
    if (selected < 1) {
        return;
    }
    TableUtil.stopEditing(myImportLayoutTable);
    PackageEntry entry = myImportLayoutList.getEntryAt(selected);
    PackageEntry previousEntry = myImportLayoutList.getEntryAt(selected - 1);
    myImportLayoutList.setEntryAt(previousEntry, selected);
    myImportLayoutList.setEntryAt(entry, selected - 1);
    AbstractTableModel model = (AbstractTableModel) myImportLayoutTable.getModel();
    model.fireTableRowsUpdated(selected - 1, selected);
    myImportLayoutTable.setRowSelectionInterval(selected - 1, selected - 1);
}
Also used : PackageEntry(com.intellij.psi.codeStyle.PackageEntry) AbstractTableModel(javax.swing.table.AbstractTableModel)

Example 7 with AbstractTableModel

use of javax.swing.table.AbstractTableModel 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 8 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project intellij-community by JetBrains.

the class PackagePanel method removeEntryFromPackages.

private static void removeEntryFromPackages(JBTable table, PackageEntryTable list) {
    int selected = table.getSelectedRow();
    if (selected < 0)
        return;
    TableUtil.stopEditing(table);
    list.removeEntryAt(selected);
    AbstractTableModel model = (AbstractTableModel) table.getModel();
    model.fireTableRowsDeleted(selected, selected);
    if (selected >= list.getEntryCount()) {
        selected--;
    }
    if (selected >= 0) {
        table.setRowSelectionInterval(selected, selected);
    }
}
Also used : AbstractTableModel(javax.swing.table.AbstractTableModel)

Example 9 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project intellij-community by JetBrains.

the class CodeStyleImportsPanelBase method refreshTable.

private void refreshTable(final JBTable table, final PackageEntryTable packageTable) {
    AbstractTableModel model = (AbstractTableModel) table.getModel();
    table.createDefaultColumnsFromModel();
    model.fireTableDataChanged();
    ImportLayoutPanel.resizeColumns(packageTable, table, myImportLayoutPanel.areStaticImportsEnabled());
}
Also used : AbstractTableModel(javax.swing.table.AbstractTableModel)

Example 10 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project intellij-community by JetBrains.

the class EditMigrationDialog method edit.

private void edit() {
    EditMigrationEntryDialog dialog = new EditMigrationEntryDialog(myProject);
    int selected = myTable.getSelectedRow();
    if (selected < 0)
        return;
    MigrationMapEntry entry = myMigrationMap.getEntryAt(selected);
    dialog.setEntry(entry);
    if (!dialog.showAndGet()) {
        return;
    }
    dialog.updateEntry(entry);
    AbstractTableModel model = (AbstractTableModel) myTable.getModel();
    model.fireTableRowsUpdated(selected, selected);
}
Also used : AbstractTableModel(javax.swing.table.AbstractTableModel)

Aggregations

AbstractTableModel (javax.swing.table.AbstractTableModel)24 TableModel (javax.swing.table.TableModel)6 PackageEntry (com.intellij.psi.codeStyle.PackageEntry)4 JBTable (com.intellij.ui.table.JBTable)3 JScrollPane (javax.swing.JScrollPane)3 JTable (javax.swing.JTable)3 JFrame (javax.swing.JFrame)2 TableModelEvent (javax.swing.event.TableModelEvent)2 TableRowSorter (javax.swing.table.TableRowSorter)2 FormBuilder (com.jgoodies.forms.builder.FormBuilder)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 MouseEvent (java.awt.event.MouseEvent)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 JButton (javax.swing.JButton)1 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)1