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