📄 tableview.java
字号:
Object[] dataSourcesRemove = null;
try {
dataSourceToRow_mon.enter();
if (dataSourcesToAdd.size() > 0) {
dataSourcesAdd = dataSourcesToAdd.toArray();
dataSourcesToAdd.clear();
// remove the ones we are going to add then delete
if (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)
debug("Saved time by not adding a row that was removed");
}
}
}
if (dataSourcesToRemove.size() > 0) {
dataSourcesRemove = dataSourcesToRemove.toArray();
if (DEBUGADDREMOVE && dataSourcesRemove.length > 1)
debug("Streamlining removing " + dataSourcesRemove.length + " rows");
dataSourcesToRemove.clear();
}
} finally {
dataSourceToRow_mon.exit();
}
if (dataSourcesAdd != null && dataSourcesAdd.length > 0) {
reallyAddDataSources(dataSourcesAdd);
if (DEBUGADDREMOVE && dataSourcesAdd.length > 1)
debug("Streamlined adding " + dataSourcesAdd.length + " rows");
}
if (dataSourcesRemove != null && dataSourcesRemove.length > 0) {
reallyRemoveDataSources(dataSourcesRemove);
}
}
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, true);
}
});
}
/** 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);
if (timerProcessDataSources != null) {
timerProcessDataSources.destroy();
timerProcessDataSources = null;
}
//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) {
addDataSources(new Object[] { dataSource});
}
/**
* 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[]) {
if (dataSources == null)
return;
if (IMMEDIATE_ADDREMOVE_DELAY == 0) {
reallyAddDataSources(dataSources);
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
try {
dataSourceToRow_mon.enter();
int count = 0;
for (int i = 0; i < dataSources.length; i++) {
if (dataSources[i] != null && !dataSourcesToAdd.contains(dataSources[i])) {
count++;
dataSourcesToAdd.add(dataSources[i]);
}
}
if (DEBUGADDREMOVE)
debug("Queued " + count + " of " + dataSources.length
+ " dataSources to add. Total Queued: " + dataSourcesToAdd.size());
} finally {
dataSourceToRow_mon.exit();
}
refreshenProcessDataSourcesTimer();
}
private void refreshenProcessDataSourcesTimer() {
if (bReallyAddingDataSources || timerProcessDataSources == null) {
// when timerProcessDataSources is null, we are disposing
return;
}
synchronized (timerProcessDataSources) {
if (timerEventProcessDS != null && !timerEventProcessDS.hasRun()) {
// Push timer forward, unless we've pushed it forward for over x seconds
long now = SystemTime.getCurrentTime();
if (now - timerEventProcessDS.getCreatedTime() < IMMEDIATE_ADDREMOVE_MAXDELAY) {
long lNextTime = now + IMMEDIATE_ADDREMOVE_DELAY;
timerProcessDataSources.adjustAllBy(lNextTime
- timerEventProcessDS.getWhen());
} else {
timerEventProcessDS.cancel();
timerEventProcessDS = null;
if (DEBUGADDREMOVE) {
debug("Over immediate delay limit, processing queue now");
}
processDataSourceQueue();
}
} else {
timerEventProcessDS = timerProcessDataSources.addEvent(
SystemTime.getCurrentTime() + IMMEDIATE_ADDREMOVE_DELAY,
new TimerEventPerformer() {
public void perform(TimerEvent event) {
timerEventProcessDS = null;
processDataSourceQueue();
}
});
}
}
}
private void reallyAddDataSources(final Object dataSources[]) {
if (mainComposite == null || table == null || mainComposite.isDisposed()
|| table.isDisposed())
return;
bReallyAddingDataSources = true;
if (DEBUGADDREMOVE)
debug(">>" + " Add " + dataSources.length + " rows;");
Object[] remainingDataSources = null;
Object[] doneDataSources = dataSources;
// Create row, and add to map immediately
try {
dataSourceToRow_mon.enter();
long lStartTime = SystemTime.getCurrentTime();
for (int i = 0; i < dataSources.length; i++) {
if (dataSources[i] == null)
continue;
// Break off and add the rows to the UI if we've taken too long to
// create them
if (SystemTime.getCurrentTime() - lStartTime > BREAKOFF_ADDTOMAP) {
int iNewSize = dataSources.length - i;
if (DEBUGADDREMOVE) {
debug("Breaking off adding datasources to map after "
+ i + " took " + (SystemTime.getCurrentTime() - lStartTime)
+ "ms; # remaining: " + iNewSize);
}
remainingDataSources = new Object[iNewSize];
doneDataSources = new Object[i];
System.arraycopy(dataSources, i, remainingDataSources, 0, iNewSize);
System.arraycopy(dataSources, 0, doneDataSources, 0, i);
break;
}
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();
}
if (DEBUGADDREMOVE)
debug("--" + " Add " + doneDataSources.length + " rows;");
if (remainingDataSources == null) {
addDataSourcesToSWT(doneDataSources, true);
} else {
final Object[] fDoneDataSources = doneDataSources;
final Object[] fRemainingDataSources = remainingDataSources;
// wrap both calls in a SWT thread so that continuation of adding
// remaining datasources will be on SWT thread. OSX has horrible handling
// of switching to SWT thread.
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
addDataSourcesToSWT(fDoneDataSources, false);
reallyAddDataSources(fRemainingDataSources);
}
}, false);
}
}
private void addDataSourcesToSWT(final Object dataSources[], boolean async) {
try {
if (DEBUGADDREMOVE)
debug("--" + " Add " + dataSources.length + " rows to SWT " + (async ? " async " : " NOW"));
if (async) {
table.getDisplay().asyncExec(new AERunnable() {
public void runSupport() {
_addDataSourcesToSWT(dataSources);
}
});
} else {
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
_addDataSourcesToSWT(dataSources);
}
}, false);
}
} catch (Exception e) {
bReallyAddingDataSources = false;
e.printStackTrace();
}
}
private void _addDataSourcesToSWT(final Object dataSources[]) {
if (table == null || table.isDisposed()) {
bReallyAddingDataSources = false;
return;
}
boolean bBrokeEarly = false;
boolean bReplacedVisible = false;
try {
dataSourceToRow_mon.enter();
sortedRows_mon.enter();
if (DEBUGADDREMOVE)
debug("--" + " Add " + dataSources.length + " rows to SWT");
// purposefully not included in time check
table.setItemCount(sortedRows.size() + dataSources.length);
long lStartTime = SystemTime.getCurrentTime();
int iTopIndex = table.getTopIndex();
int iBottomIndex = Utils.getTableBottomIndex(table, iTopIndex);
// 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;
// If we've been processing on the SWT thread for too long,
// break off and allow SWT a breather to update.
if (SystemTime.getCurrentTime() - lStartTime > BREAKOFF_ADDROWSTOSWT) {
int iNewSize = dataSources.length - i;
if (DEBUGADDREMOVE) {
debug("Breaking off adding datasources to SWT after " + i
+ " took " + (SystemTime.getCurrentTime() - lStartTime)
+ "ms; # remaining: " + iNewSize);
}
Object[] remainingDataSources = new Object[iNewSize];
System.arraycopy(dataSources, i, remainingDataSources, 0, iNewSize);
addDataSourcesToSWT(remainingDataSources, true);
bBrokeEarly = true;
break;
}
TableRowImpl row = (TableRowImpl) dataSourceToRow.get(dataSource);
if (row == null || row.getIndex() >= 0)
continue;
if (sortColumn != null) {
TableCellCore cell = row.getTableCellCore(sortColumn.getName());
if (cell != null) {
try {
cell.invalidate();
cell.refresh(true);
} catch (Exception e) {
Logger.log(new LogEvent(LOGID,
"Minor error adding a row to table " + sTableID, e));
}
}
}
try {
int index = 0;
if (sortedRows.size() > 0) {
// If
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -