下面列出了javax.swing.table.TableColumn#getIdentifier ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected TableCellEditor getCellEditor(int row, int column) {
TableColumn tableColumn = impl.getColumnModel().getColumn(column);
if (tableColumn.getIdentifier() instanceof Column) {
Column columnConf = (Column) tableColumn.getIdentifier();
if (editableColumns != null
&& columnConf.getId() instanceof MetaPropertyPath
&& editableColumns.contains(columnConf.getId())) {
return tableFieldFactory.createEditComponent(row, columnConf);
}
}
return null;
}
protected TableCellEditor getColumnEditor(int column) {
TableColumn tableColumn = impl.getColumnModel().getColumn(column);
if (tableColumn.getIdentifier() instanceof Table.Column) {
Table.Column columnConf = (Table.Column) tableColumn.getIdentifier();
if (columnConf.getId() instanceof MetaPropertyPath
&& !(isEditable() && columnConf.isEditable())
&& !getTableModel().isGeneratedColumn(columnConf)) {
MetaPropertyPath propertyPath = (MetaPropertyPath) columnConf.getId();
final CellProvider cellProvider = getCustomCellEditor(propertyPath);
if (cellProvider != null) {
return new CellProviderEditor(cellProvider);
}
}
}
return null;
}
protected TableCellRenderer getColumnRenderer(int column) {
TableColumn tableColumn = impl.getColumnModel().getColumn(column);
if (tableColumn.getIdentifier() instanceof Table.Column) {
Table.Column columnConf = (Table.Column) tableColumn.getIdentifier();
if (columnConf.getId() instanceof MetaPropertyPath
&& !(isEditable() && columnConf.isEditable())
&& !getTableModel().isGeneratedColumn(columnConf)) {
MetaPropertyPath propertyPath = (MetaPropertyPath) columnConf.getId();
final CellProvider cellViewProvider = getCustomCellView(propertyPath);
if (cellViewProvider != null) {
return new CellProviderRenderer(cellViewProvider);
} else if (multiLineCells && String.class == columnConf.getType()) {
return new MultiLineTableCellRenderer();
}
}
}
return null;
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column) {
Entity item = getTableModel().getItem(row);
TableColumn tableColumn = impl.getColumnModel().getColumn(column);
Column columnConf = (Column) tableColumn.getIdentifier();
Component component = cellProvider.generateCell(item, (MetaPropertyPath) columnConf.getId());
if (component == null) {
return new JLabel("");
}
if (component instanceof JComponent) {
((JComponent) component).putClientProperty(DesktopTableCellEditor.CELL_EDITOR_TABLE, impl);
}
return component;
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Entity item = getTableModel().getItem(row);
TableColumn tableColumn = impl.getColumnModel().getColumn(column);
Column columnConf = (Column) tableColumn.getIdentifier();
Component component = cellViewProvider.generateCell(item, (MetaPropertyPath) columnConf.getId());
if (component == null) {
return new JLabel("");
}
if (component instanceof JComponent) {
((JComponent) component).putClientProperty(DesktopTableCellEditor.CELL_EDITOR_TABLE, impl);
}
String style = getStylename(table, row, column);
applyStylename(isSelected, hasFocus, component, style);
return component;
}
@Override
public void actionPerformed(ActionEvent actionEvent) {
List<String> colNames = columnLayout.getColumns();
LOGGER.debug(String.format("Retrieved %d col names: <<%s>>", colNames.size(), colNames.toString()));
List<TableColumns> visCols = new ArrayList<>();
Map<String, TableColumns> colNameToEnum = new HashMap<>();
for (TableColumns tcEnum : TableColumns.values()) {
colNameToEnum.put(tcEnum.getName(), tcEnum);
}
for (TableColumn tableColumn : table.getColumns()) {
Object o = tableColumn.getIdentifier();
if (!(o instanceof TableColumns)) {
LOGGER.error("TableColumn identifier of unexpected type: " + tableColumn.getIdentifier().getClass().getName());
return;
}
TableColumns tcs = (TableColumns) o;
table.getColumnExt(tcs).setVisible(false);
}
visCols.addAll(colNames.stream().map(colNameToEnum::get).collect(Collectors.toList()));
TablesUtils.showOnlyThisColumns(table, visCols.toArray(new TableColumns[visCols.size()]));
TablesUtils.sortColumnsInOrder(columnLayout, table);
LOGGER.debug("Column changes applied");
}
private void create() {
tableModel = new VersionHistoryTableModel(new Version[0]);
table = new GTable(tableModel);
JScrollPane sp = new JScrollPane(table);
table.setPreferredScrollableViewportSize(new Dimension(600, 120));
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
add(sp, BorderLayout.CENTER);
TableColumnModel columnModel = table.getColumnModel();
MyCellRenderer cellRenderer = new MyCellRenderer();
for (int i = 0; i < columnModel.getColumnCount(); i++) {
TableColumn column = columnModel.getColumn(i);
GTableHeaderRenderer headRenderer = new GTableHeaderRenderer();
column.setHeaderRenderer(headRenderer);
column.setCellRenderer(cellRenderer);
String name = (String) column.getIdentifier();
if (name.equals(VersionHistoryTableModel.VERSION)) {
column.setPreferredWidth(80);
}
else if (name.equals(VersionHistoryTableModel.DATE)) {
column.setPreferredWidth(210);
}
else if (name.equals(VersionHistoryTableModel.COMMENTS)) {
column.setPreferredWidth(250);
}
else if (name.equals(VersionHistoryTableModel.USER)) {
column.setPreferredWidth(125);
}
}
}
protected void setColumnIdentifiers() {
int i = 0;
for (TableColumn tableColumn : getAllColumns()) {
Column column = columnsOrder.get(i++);
if (!(tableColumn.getIdentifier() instanceof Column)) {
tableColumn.setIdentifier(column);
}
}
}
protected void setVisibleColumns(List<?> columnsOrder) {
for (TableColumn tableColumn : getAllColumns()) {
Column columnIdentifier = (Column) tableColumn.getIdentifier();
if (!columnsOrder.contains(columnIdentifier.getId())) {
impl.removeColumn(tableColumn);
}
}
}
protected boolean isCustomCellEditable(int row, int column) {
TableColumn tableColumn = impl.getColumnModel().getColumn(column);
if (tableColumn.getIdentifier() instanceof Table.Column) {
Table.Column columnConf = (Table.Column) tableColumn.getIdentifier();
if (columnConf.getId() instanceof MetaPropertyPath && !getTableModel().isGeneratedColumn(columnConf)) {
return isCustomCellEditable(tableModel.getItem(row), (MetaPropertyPath) columnConf.getId());
}
}
return false;
}
public void copyValues(TableColumn base) {
modelIndex = base.getModelIndex();
identifier = base.getIdentifier();
width = base.getWidth();
minWidth = base.getMinWidth();
setPreferredWidth(base.getPreferredWidth());
maxWidth = base.getMaxWidth();
headerRenderer = base.getHeaderRenderer();
headerValue = base.getHeaderValue();
cellRenderer = base.getCellRenderer();
cellEditor = base.getCellEditor();
isResizable = base.getResizable();
}
public void copyValues(TableColumn base) {
modelIndex = base.getModelIndex();
identifier = base.getIdentifier();
width = base.getWidth();
minWidth = base.getMinWidth();
setPreferredWidth(base.getPreferredWidth());
maxWidth = base.getMaxWidth();
headerRenderer = base.getHeaderRenderer();
headerValue = base.getHeaderValue();
cellRenderer = base.getCellRenderer();
cellEditor = base.getCellEditor();
isResizable = base.getResizable();
}
private void create() {
model = new FindCheckoutsTableModel(folder, plugin.getTool());
model.addInitialLoadListener(new ThreadedTableModelListener() {
@Override
public void loadPending() {
// don't care
}
@Override
public void loadingStarted() {
// don't care
}
@Override
public void loadingFinished(boolean wasCancelled) {
if (wasCancelled) {
setStatusText("Find Checkouts Cancelled");
return;
}
boolean hasData = model.getRowCount() > 0;
if (!hasData && showMessage) {
Msg.showInfo(getClass(), threadedTablePanel, "Find Checkouts",
"No checkouts were found.");
FindCheckoutsDialog.this.close();
}
}
});
threadedTablePanel = new GThreadedTablePanel<>(model);
table = threadedTablePanel.getTable();
TableColumnModel columnModel = table.getColumnModel();
MyCellRenderer cellRenderer = new MyCellRenderer();
for (int i = 0; i < columnModel.getColumnCount(); i++) {
TableColumn column = columnModel.getColumn(i);
column.setCellRenderer(cellRenderer);
String name = (String) column.getIdentifier();
if (name.equals(FindCheckoutsTableModel.CHECKOUT_DATE)) {
column.setPreferredWidth(180);
}
}
table.setPreferredScrollableViewportSize(
new Dimension(threadedTablePanel.getPreferredSize().width, 150));
addWorkPanel(threadedTablePanel);
addDismissButton();
}
private void create(java.util.List<LabelHistory> list) {
tableModel = new LabelHistoryTableModel(list, showAddresses);
// set up table sorter stuff
//sorter.sortByColumn(tableModel.getDefaultSortColumn());
historyTable = new GhidraTable(tableModel);
JScrollPane sp = new JScrollPane(historyTable);
Dimension d = new Dimension(showAddresses ? 600 : 520, 200);
historyTable.setPreferredScrollableViewportSize(d);
historyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
add(sp, BorderLayout.CENTER);
TableColumnModel columnModel = historyTable.getColumnModel();
for (int i = 0; i < columnModel.getColumnCount(); i++) {
TableColumn column = columnModel.getColumn(i);
String name = (String) column.getIdentifier();
if (name.equals(LabelHistoryTableModel.DATE)) {
column.setCellRenderer(new GenericDateCellRenderer());
column.setPreferredWidth(190);
}
else if (name.equals(LabelHistoryTableModel.LABEL)) {
column.setPreferredWidth(280);
column.setCellRenderer(new LabelCellRenderer());
}
else if (name.equals(LabelHistoryTableModel.ADDRESS)) {
column.setPreferredWidth(130);
}
else if (name.equals(LabelHistoryTableModel.USER)) {
column.setPreferredWidth(190);
}
}
historyTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (!e.isPopupTrigger()) {
handleMouseClicked();
}
}
});
}