📄 tableview.java
字号:
}
new Clipboard(mainComposite.getDisplay()).setContents(new Object[] { sToClipboard },
new Transfer[] {TextTransfer.getInstance()});
}
});
// Add Plugin Context menus..
TableColumnCore tc = (TableColumnCore)tcColumn.getData("TableColumnCore");
TableContextMenuItem[] items = tc.getContextMenuItems();
if (items.length > 0) {
new MenuItem(menuThisColumn, SWT.SEPARATOR);
for (int i = 0; i < items.length; i++) {
final TableContextMenuItemImpl contextMenuItem = (TableContextMenuItemImpl)items[i];
final MenuItem menuItem = new MenuItem(menuThisColumn, SWT.PUSH);
Messages.setLanguageText(menuItem, contextMenuItem.getResourceKey());
menuItem.addListener(SWT.Selection, new SelectedTableRowsListener() {
public void run(TableRowCore row) {
contextMenuItem.invokeListeners(row);
}
});
}
}
}
/** Create a SubMenu for column specific tasks. Everytime the user opens
* the context menu, the "This Column" submenu is cleared, and this function
* is called to refill it.
*
* @param sColumnName The name of the column the user clicked on
* @param menuThisColumn the menu to fill with MenuItems
*/
public void addThisColumnSubMenu(String sColumnName, Menu menuThisColumn) {
/* // Template code
if (sColumnName.equals("xxx")) {
item = new MenuItem(menuThisColumn, SWT.PUSH);
Messages.setLanguageText(item, "xxx.menu.xxx");
item.setImage(ImageRepository.getImage("xxx"));
item.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
// Code here
}
});
*/
}
/** IView.getComposite()
* @return the composite for this TableView
*/
public Composite getComposite() {
return mainComposite;
}
public Composite getTableComposite() {
return tableComposite;
}
/** IView.refresh(), called when the GUI needs an update */
public final void refresh() {
refresh(false);
}
long count = 0;
public void refresh(boolean bForceSort) {
// don't refresh while there's no table
if (table == null)
return;
refreshTable(bForceSort);
if (bEnableTabViews && tabFolder != null && !tabFolder.isDisposed()
&& !tabFolder.getMinimized())
refreshSelectedSubView();
}
public void refreshSelectedSubView() {
if (!bEnableTabViews || tabFolder == null || tabFolder.isDisposed()
|| tabFolder.getMinimized())
return;
CTabItem item = tabFolder.getSelection();
if (item != null) {
IView view = (IView)item.getData("IView");
if (view != null)
view.refresh();
}
}
public void refreshTable(boolean bForceSort) {
// don't refresh while there's no table
if (table == null)
return;
try{
this_mon.enter();
if(getComposite() == null || getComposite().isDisposed())
return;
processDataSourceQueue();
if (checkColumnWidthsEvery != 0 &&
(loopFactor % checkColumnWidthsEvery) == 0) {
TableColumn[] tableColumnsSWT = table.getColumns();
for (int i = 0; i < tableColumnsSWT.length; i++) {
TableColumnCore tc = (TableColumnCore)tableColumnsSWT[i].getData("TableColumnCore");
if (tc != null && tc.getWidth() != tableColumnsSWT[i].getWidth()) {
tc.setWidth(tableColumnsSWT[i].getWidth());
int columnNumber = table.indexOf(tableColumnsSWT[i]);
locationChanged(columnNumber);
}
}
}
long lTimeStart = System.currentTimeMillis();
count = 0;
final boolean bDoGraphics = (loopFactor % graphicsUpdate) == 0;
final boolean bWillSort = bForceSort || (reOrderDelay != 0) && ((loopFactor % reOrderDelay) == 0);
//System.out.println("Refresh.. WillSort? " + bWillSort);
if (bWillSort)
sortColumn(true);
lTimeStart = System.currentTimeMillis();
//Refresh all visible items in table...
runForAllRows(new GroupTableRowRunner() {
public void run(TableRowCore row) {
row.refresh(bDoGraphics);
}
});
if (DEBUGADDREMOVE) {
long lTimeDiff = (System.currentTimeMillis() - lTimeStart);
if (lTimeDiff > 500)
System.out.println(sTableID + ": " + lTimeDiff + "ms to refresh rows");
}
loopFactor++;
}finally{
this_mon.exit();
}
}
/**
* Process the queue of datasources to be added and removed
*
*/
public void
processDataSourceQueue()
{
Object[] dataSourcesAdd = null;
Object[] dataSourcesRemove = null;
try{
dataSourceToRow_mon.enter();
if (dataSourcesToAdd != null) {
dataSourcesAdd = dataSourcesToAdd.toArray();
dataSourcesToAdd.clear();
// remove the ones we are going to add then delete
if (dataSourcesToRemove != null && dataSourcesToRemove.size() > 0) {
for (int i = 0; i < dataSourcesAdd.length; i++)
if (dataSourcesToRemove.contains(dataSourcesAdd[i])) {
dataSourcesToRemove.remove(dataSourcesAdd[i]);
dataSourcesAdd[i] = null;
if (DEBUGADDREMOVE)
System.out.println(sTableID
+ ": Saved time by not adding a row that was removed");
}
}
}
if (dataSourcesToRemove != null && dataSourcesToRemove.size() > 0) {
dataSourcesRemove = dataSourcesToRemove.toArray();
if (DEBUGADDREMOVE && dataSourcesRemove.length > 1)
System.out.println(sTableID + ": Streamlining removing "
+ dataSourcesRemove.length + " rows");
dataSourcesToRemove.clear();
}
}finally{
dataSourceToRow_mon.exit();
}
if ( dataSourcesAdd != null ){
addDataSources(dataSourcesAdd, true);
if (DEBUGADDREMOVE && dataSourcesAdd.length > 1)
System.out.println(sTableID + ": Streamlined adding "
+ dataSourcesAdd.length + " rows");
}
if ( dataSourcesRemove != null ){
removeDataSources(dataSourcesRemove, true);
}
}
private void locationChanged(final int iStartColumn) {
if (getComposite() == null || getComposite().isDisposed())
return;
runForAllRows(new GroupTableRowRunner() {
public void run(TableRowCore row) {
row.locationChanged(iStartColumn);
}
});
}
private void doPaint(final GC gc) {
if (getComposite() == null || getComposite().isDisposed())
return;
runForVisibleRows(new GroupTableRowRunner() {
public void run(TableRowCore row) {
row.doPaint(gc);
}
});
}
/** IView.delete: This method is called when the view is destroyed.
* Each color instanciated, images and such things should be disposed.
* The caller is the GUI thread.
*/
public void delete() {
if (tabViews != null && tabViews.size() > 0) {
for (int i = 0; i < tabViews.size(); i++) {
IView view = (IView)tabViews.get(i);
if (view != null)
view.delete();
}
}
TableStructureEventDispatcher.getInstance(sTableID).removeListener(this);
if (tableColumns != null)
for (int i = 0; i < tableColumns.length; i++)
tableColumns[i].saveSettings();
if (table != null && !table.isDisposed())
table.dispose();
removeAllTableRows();
configMan.removeParameterListener("ReOrder Delay", this);
configMan.removeParameterListener("Graphics Update", this);
Colors.getInstance().removeColorsChangedListener(this);
//oldSelectedItems = null;
super.delete();
}
/** IView.getData: Data 'could' store a key to a language file, in order to
* support multi-language titles
*
* @return a String which is the key of this view title.
*/
public String getData() {
return sPropertiesPrefix + ".title.short";
}
/** IView.getFullTitle:Called in order to set / update the title of this View
* @return the full title for the view
*/
public String getFullTitle() {
return MessageText.getString(sPropertiesPrefix + ".title.full");
}
/* (non-Javadoc)
* @see org.gudy.azureus2.ui.swt.views.AbstractIView#updateLanguage()
*/
public void updateLanguage() {
super.updateLanguage();
if (tabViews != null && tabViews.size() > 0) {
for (int i = 0; i < tabViews.size(); i++) {
IView view = (IView)tabViews.get(i);
if (view != null)
view.updateLanguage();
}
}
}
/** Adds a dataSource to the table as a new row. If the data source is
* already added, a new row will not be added. This function runs
* asynchronously, so the rows creation is not guaranteed directly after
* calling this function.
*
* You can't add datasources until the table is initialized
*
* @param dataSource data source to add to the table
* @param bImmediate Add immediately, or queue and add at next refresh
*/
public void addDataSource(Object dataSource, boolean bImmediate) {
addDataSources(new Object[] { dataSource}, bImmediate );
}
public void addDataSource(Object dataSource) {
addDataSources(new Object[] { dataSource}, false);
}
public void addDataSources(Object[] dataSources) {
addDataSources(dataSources, false);
}
/**
* Add a list of dataSources to the table. The array passed in may be
* modified, so make sure you don't need it afterwards.
*
* You can't add datasources until the table is initialized
*
* @param dataSources
* @param bImmediate Add immediately, or queue and add at next refresh
*/
public void addDataSources(final Object dataSources[],
boolean bImmediate) {
if (dataSources == null)
return;
// In order to save time, we cache entries to be added and process them
// in a refresh cycle. This is a huge benefit to tables that have
// many rows being added and removed in rapid succession
if (!bImmediate) {
if (DEBUGADDREMOVE)
System.out.println(sTableID + ": Queueing " + dataSources.length
+ " dataSources to add");
try{
dataSourceToRow_mon.enter();
if (dataSourcesToAdd == null)
dataSourcesToAdd = new ArrayList(4);
for (int i = 0; i < dataSources.length; i++)
dataSourcesToAdd.add(dataSources[i]);
return;
}finally{
dataSourceToRow_mon.exit();
}
}
if (mainComposite == null || table == null || mainComposite.isDisposed()
|| table.isDisposed())
return;
if (DEBUGADDREMOVE)
System.out.print(">>" + sTableID + " Add " + dataSources.length + " rows;");
// Create row, and add to map immediately
try {
dataSourceToRow_mon.enter();
for (int i = 0; i < dataSources.length; i++) {
if (dataSources[i] == null)
continue;
if (dataSourceToRow.containsKey(dataSources[i])) {
dataSources[i] = null;
} else {
TableRowImpl row = new TableRowImpl(table, sTableID, columnsOrdered,
dataSources[i], bSkipFirstColumn);
dataSourceToRow.put(dataSources[i], row);
}
}
} catch (Exception e) {
Logger.log(new LogEvent(LOGID, "Error while added row to Table "
+ sTableID, e));
} finally {
dataSourceToRow_mon.exit();
}
// Now, add to sortedRows which requires the SWT thread.
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if (table == null || table.isDisposed())
return;
try {
dataSourceToRow_mon.enter();
// add to sortedRows list in best position.
// We need to be in the SWT thread because the rowSorter may end up
// calling SWT objects.
for (int i = 0; i < dataSources.length; i++) {
Object dataSource = dataSources[i];
if (dataSource == null)
continue;
TableRowImpl row = (TableRowImpl) dataSourceToRow.get(dataSource);
if (row == null)
continue;
TableCellCore cell = row.getTableCellCore(rowSorter.sColumnName);
if (cell != null) {
try {
cell.invalidate();
cell.refresh(true);
} catch (Exception e) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -