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;
}
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;
}
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;
}
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);
}
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);
}
}
Aggregations