📄 tableview.java
字号:
Logger.log(new LogEvent(LOGID,
"Minor error adding a row to table " + sTableID, e));
}
}
try {
sortedRows_mon.enter();
if (sortedRows.size() > 0) {
// If we are >= to the last item, then just add it to the end
// instead of relying on binarySearch, which may return an item
// in the middle that also is equal.
TableRowCore lastRow = (TableRowCore) sortedRows.get(sortedRows
.size() - 1);
if (rowSorter.compare(row, lastRow) >= 0) {
sortedRows.add(row);
if (DEBUGADDREMOVE)
System.out.println("Adding new row to bottom");
} else {
int index = Collections.binarySearch(sortedRows, row,
rowSorter);
if (index < 0)
index = -1 * index - 1; // best guess
if (index > sortedRows.size())
index = sortedRows.size();
if (DEBUGADDREMOVE)
System.out.println("Adding new row at position " + index
+ " of " + (sortedRows.size() - 1));
sortedRows.add(index, row);
}
} else {
if (DEBUGADDREMOVE)
System.out.println("Adding new row to bottom (1st Entry)");
sortedRows.add(row);
}
if (!bTableVirtual) {
row.createSWTRow();
row.setIconSize(ptIconSize);
}
} catch (Exception e) {
Logger.log(new LogEvent(LOGID, "Error adding a row to table "
+ sTableID, e));
try {
if (!sortedRows.contains(row))
sortedRows.add(row);
} catch (Exception e2) {
Debug.out(e2);
}
} finally {
sortedRows_mon.exit();
}
} // for dataSources
if (bTableVirtual)
table.setItemCount(dataSourceToRow.size());
} finally {
dataSourceToRow_mon.exit();
}
fillRowGaps(false);
if (DEBUGADDREMOVE)
System.out.println("<<");
}
});
}
public void removeDataSource(final Object dataSource) {
removeDataSource(dataSource, false);
}
public void removeDataSource(final Object dataSource, boolean bImmediate) {
removeDataSources(new Object[] {dataSource}, bImmediate);
}
/** Remove the specified dataSource from the table.
*
* @param dataSources data sources to be removed
* @param bImmediate Remove immediately, or queue and remove at next refresh
*/
public void removeDataSources(final Object[] dataSources,
boolean bImmediate) {
if (!bImmediate) {
try{
dataSourceToRow_mon.enter();
if (dataSourcesToRemove == null)
dataSourcesToRemove = new ArrayList(4);
for (int i = 0; i < dataSources.length; i++)
dataSourcesToRemove.add(dataSources[i]);
}finally{
dataSourceToRow_mon.exit();
}
// .size() not modifying the structure of List, so sync not needed
if (dataSourcesToRemove.size() >= 20)
processDataSourceQueue();
return;
}
if (DEBUGADDREMOVE)
System.out.println(">>" + sTableID + " Remove rows");
boolean ok = Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if (DEBUGADDREMOVE)
System.out.println(">>>" + sTableID + " Remove rows. Start");
ArrayList itemsToRemove = new ArrayList();
for (int i = 0; i < dataSources.length; i++) {
if (dataSources[i] == null)
continue;
// Must remove from map before deleted from gui
TableRowCore item = (TableRowCore) dataSourceToRow.remove(dataSources[i]);
if (item != null) {
itemsToRemove.add(item);
sortedRows.remove(item);
}
}
if (bTableVirtual && !table.isDisposed()) {
//table.setItemCount(dataSourceToRow.size());
}
for (Iterator iter = itemsToRemove.iterator(); iter.hasNext();) {
TableRowCore item = (TableRowCore) iter.next();
item.delete();
}
if (DEBUGADDREMOVE)
System.out.println("<<" + sTableID + " Remove "
+ itemsToRemove.size() + " rows. now " + dataSourceToRow.size()
+ "ds; tc=" + table.getItemCount());
}
});
if (!ok) {
// execRunnable will only fail if we are closing
for (int i = 0; i < dataSources.length; i++) {
if (dataSources[i] == null)
continue;
TableRowCore item = (TableRowCore) dataSourceToRow.get(dataSources[i]);
dataSourceToRow.remove(dataSources[i]);
if (item != null) {
sortedRows.remove(item);
item.delete();
}
}
if (DEBUGADDREMOVE)
System.out.println("<<" + sTableID + " Remove 1 row, noswt");
}
}
/** Remove all the data sources (table rows) from the table.
*/
public void removeAllTableRows() {
long lTimeStart = System.currentTimeMillis();
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if (table != null && !table.isDisposed())
table.removeAll();
// Image Disposal handled by each cell
TableRowCore[] rows = getRows();
for (int i = 0; i < rows.length; i++)
rows[i].delete();
}
});
try {
dataSourceToRow_mon.enter();
sortedRows_mon.enter();
dataSourceToRow.clear();
sortedRows.clear();
if (dataSourcesToAdd != null)
dataSourcesToAdd.clear();
if (dataSourcesToRemove != null)
dataSourcesToRemove.clear();
if (DEBUGADDREMOVE)
System.out.println(sTableID + " removeAll");
} finally {
sortedRows_mon.exit();
dataSourceToRow_mon.exit();
}
if (DEBUGADDREMOVE) {
long lTimeDiff = (System.currentTimeMillis() - lTimeStart);
if (lTimeDiff > 10)
System.out.println("RemovaAll took " + lTimeDiff + "ms");
}
}
public Table getTable() {
return table;
}
public String getTableID() {
return sTableID;
}
/* ParameterListener Implementation */
public void parameterChanged(String parameterName) {
if (parameterName.equals("Graphics Update")) {
graphicsUpdate = configMan.getIntParameter("Graphics Update");
return;
}
if (parameterName.equals("ReOrder Delay")) {
reOrderDelay = configMan.getIntParameter("ReOrder Delay");
return;
}
if (parameterName.startsWith("Color")) {
tableInvalidate();
}
}
// ITableStructureModificationListener
public void tableStructureChanged() {
removeAllTableRows();
initializeTableColumns(table);
refreshTable(false);
}
// ITableStructureModificationListener
public void columnOrderChanged(int[] positions) {
try {
table.setColumnOrder(positions);
} catch (NoSuchMethodError e) {
// Pre SWT 3.1
// This shouldn't really happen, since this function only gets triggered
// from SWT >= 3.1
tableStructureChanged();
}
}
/**
* The Columns width changed
*/
// ITableStructureModificationListener
public void columnSizeChanged(TableColumnCore tableColumn) {
int newWidth = tableColumn.getWidth();
if (table == null || table.isDisposed())
return;
TableColumn column = null;
TableColumn[] tableColumnsSWT = table.getColumns();
for (int i = 0; i < tableColumnsSWT.length; i++) {
if (tableColumnsSWT[i].getData("TableColumnCore") == tableColumn) {
column = tableColumnsSWT[i];
break;
}
}
if (column == null || column.isDisposed() || (column.getWidth() == newWidth))
return;
column.setWidth(newWidth);
}
// ITableStructureModificationListener
public void columnInvalidate(TableColumnCore tableColumn) {
// We are being called from a plugin (probably), so we must refresh
columnInvalidate(tableColumn, true);
}
public void columnRefresh(TableColumnCore tableColumn) {
final String sColumnName = tableColumn.getName();
runForAllRows(new GroupTableRowRunner() {
public void run(TableRowCore row) {
TableCellCore cell = row.getTableCellCore(sColumnName);
if (cell != null)
cell.refresh();
}
});
}
/**
* Invalidate and refresh whole table
*/
public void tableInvalidate() {
runForAllRows(new GroupTableRowRunner() {
public void run(TableRowCore row) {
row.invalidate();
row.refresh(true);
}
});
}
/**
* Invalidate all the cells in a column
*
* @param sColumnName Name of column to invalidate
*/
public void columnInvalidate(final String sColumnName) {
TableColumnCore tc = TableColumnManager.getInstance().getTableColumnCore(
sTableID, sColumnName);
if (tc != null)
columnInvalidate(tc, tc.getType() == TableColumnCore.TYPE_TEXT_ONLY);
}
public void columnInvalidate(TableColumnCore tableColumn, final boolean bMustRefresh) {
final String sColumnName = tableColumn.getName();
runForAllRows(new GroupTableRowRunner() {
public void run(TableRowCore row) {
TableCellCore cell = row.getTableCellCore(sColumnName);
if (cell != null)
cell.invalidate(bMustRefresh);
}
});
}
/**
* Retrieve a list of <pre>TableCell</pre>s, in the last sorted order.
* The order will not be of the supplied cell's sort unless the table
* has been sorted by that column previously.
* <p>
* ie. You can sort on the 5th column, and retrieve the cells for the
* 3rd column, but they will be in order of the 5th columns sort.
*
* @param sColumnName Which column cell's to return. This does not sort
* the array on the column.
* @return array of cells
*/
public TableCellCore[] getColumnCells(String sColumnName) {
TableCellCore[] cells = new TableCellCore[sortedRows.size()];
try {
sortedRows_mon.enter();
int i = 0;
for (Iterator iter = sortedRows.iterator(); iter.hasNext();) {
TableRowCore row = (TableRowCore) iter.next();
cells[i++] = row.getTableCellCore(sColumnName);
}
} finally {
sortedRows_mon.exit();
}
return cells;
}
/** Get all the rows for this table, in the order they are displayed
*
* @return a list of TableRowCore objects in the order the user sees them
*/
public TableRowCore[] getRows() {
try {
sortedRows_mon.enter();
return (TableRowCore[]) sortedRows.toArray(new TableRowCore[0]);
} finally {
sortedRows_mon.exit();
}
}
/**
* Get the row associated with a datasource
* @param dataSource a reference to a core Datasource object
* (not a plugin datasource object)
* @return The row, or null
*/
public TableRowCore getRow(Object dataSource) {
return (TableRowCore)dataSourceToRow.get(dataSource);
}
public int getRowCount() {
// don't use sortedRows here, it's not always up to date
return dataSourceToRow.size();
}
/* various selected rows functions */
/***********************************/
public List getSelectedDataSourcesList() {
return getSelectedDataSourcesList(true);
}
/** Returns an array of all selected Data Sources. Null data sources are
* ommitted.
*
* @return an array containing the selected data sources
*
* @TODO TuxPaper: Virtual row not created when usint getSelecti
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -