Search in sources :

Example 6 with PackageEntry

use of com.intellij.psi.codeStyle.PackageEntry 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 7 with PackageEntry

use of com.intellij.psi.codeStyle.PackageEntry in project intellij-community by JetBrains.

the class ImportHelper method findEntryIndex.

private static int findEntryIndex(@NotNull String packageName, boolean isStatic, @NotNull PackageEntry[] entries) {
    PackageEntry bestEntry = null;
    int bestEntryIndex = -1;
    int allOtherStaticIndex = -1;
    int allOtherIndex = -1;
    for (int i = 0; i < entries.length; i++) {
        PackageEntry entry = entries[i];
        if (entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY) {
            allOtherStaticIndex = i;
        }
        if (entry == PackageEntry.ALL_OTHER_IMPORTS_ENTRY) {
            allOtherIndex = i;
        }
        if (entry.isBetterMatchForPackageThan(bestEntry, packageName, isStatic)) {
            bestEntry = entry;
            bestEntryIndex = i;
        }
    }
    if (bestEntryIndex == -1 && isStatic && allOtherStaticIndex == -1 && allOtherIndex != -1) {
        // if no layout for static imports specified, put them among all others
        bestEntryIndex = allOtherIndex;
    }
    return bestEntryIndex;
}
Also used : PackageEntry(com.intellij.psi.codeStyle.PackageEntry)

Example 8 with PackageEntry

use of com.intellij.psi.codeStyle.PackageEntry in project intellij-community by JetBrains.

the class CodeStyleImportsPanelBase method isModified.

private static boolean isModified(PackageEntryTable list, PackageEntryTable table) {
    if (list.getEntryCount() != table.getEntryCount()) {
        return true;
    }
    for (int i = 0; i < list.getEntryCount(); i++) {
        PackageEntry entry1 = list.getEntryAt(i);
        PackageEntry entry2 = table.getEntryAt(i);
        if (!entry1.equals(entry2)) {
            return true;
        }
    }
    return false;
}
Also used : PackageEntry(com.intellij.psi.codeStyle.PackageEntry)

Example 9 with PackageEntry

use of com.intellij.psi.codeStyle.PackageEntry in project intellij-community by JetBrains.

the class PackagePanel method addPackageToPackages.

private static void addPackageToPackages(JBTable table, PackageEntryTable list) {
    int selected = table.getSelectedRow() + 1;
    if (selected < 0) {
        selected = list.getEntryCount();
    }
    PackageEntry entry = new PackageEntry(false, "", true);
    list.insertEntryAt(entry, selected);
    ImportLayoutPanel.refreshTableModel(selected, table);
}
Also used : PackageEntry(com.intellij.psi.codeStyle.PackageEntry)

Example 10 with PackageEntry

use of com.intellij.psi.codeStyle.PackageEntry in project intellij-community by JetBrains.

the class ImportLayoutPanel method removeEntryFromImportLayouts.

private void removeEntryFromImportLayouts() {
    int selected = myImportLayoutTable.getSelectedRow();
    if (selected < 0) {
        return;
    }
    PackageEntry entry = myImportLayoutList.getEntryAt(selected);
    if (entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY || entry == PackageEntry.ALL_OTHER_IMPORTS_ENTRY) {
        return;
    }
    TableUtil.stopEditing(myImportLayoutTable);
    myImportLayoutList.removeEntryAt(selected);
    AbstractTableModel model = (AbstractTableModel) myImportLayoutTable.getModel();
    model.fireTableRowsDeleted(selected, selected);
    if (selected >= myImportLayoutList.getEntryCount()) {
        selected--;
    }
    if (selected >= 0) {
        myImportLayoutTable.setRowSelectionInterval(selected, selected);
    }
}
Also used : PackageEntry(com.intellij.psi.codeStyle.PackageEntry) AbstractTableModel(javax.swing.table.AbstractTableModel)

Aggregations

PackageEntry (com.intellij.psi.codeStyle.PackageEntry)14 PackageEntryTable (com.intellij.psi.codeStyle.PackageEntryTable)4 AbstractTableModel (javax.swing.table.AbstractTableModel)4 PsiElement (com.intellij.psi.PsiElement)3 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)3 ASTNode (com.intellij.lang.ASTNode)2 GrPackageDefinition (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition)2 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)1 JBTable (com.intellij.ui.table.JBTable)1 CellEditorListener (javax.swing.event.CellEditorListener)1 ChangeEvent (javax.swing.event.ChangeEvent)1 TableCellEditor (javax.swing.table.TableCellEditor)1 TableModel (javax.swing.table.TableModel)1 Nullable (org.jetbrains.annotations.Nullable)1 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)1