use of cbit.vcell.client.desktop.DatabaseSearchPanel.SearchCriterion in project vcell by virtualcell.
the class VCDocumentDbTreePanel method search.
public void search(final boolean bShowAll) {
final Object[] status = new Object[] { null };
class SearchCancel implements ProgressDialogListener {
public void cancelButton_actionPerformed(EventObject newEvent) {
status[0] = UserCancelException.CANCEL_GENERIC;
}
}
final SearchCancel searchCancel = new SearchCancel();
final ArrayList<SearchCriterion> searchCriterionListFinal = new ArrayList<DatabaseSearchPanel.SearchCriterion>();
AsynchClientTask searchCriteriaTask = new AsynchClientTask("Creating search criteria...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING, true) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
if (bShowAll) {
return;
}
new Thread(new Runnable() {
public void run() {
try {
ArrayList<SearchCriterion> searchCriterionList = getDatabaseSearchPanel().getSearchCriterionList(getDocumentManager());
if (status[0] == null) {
// update status only if no one else has
if (searchCriterionList != null && searchCriterionList.size() > 0) {
searchCriterionListFinal.addAll(searchCriterionList);
}
status[0] = "OK";
return;
} else {
return;
}
} catch (Exception e) {
status[0] = e;
}
}
}).start();
long startTime = System.currentTimeMillis();
while ((System.currentTimeMillis() - startTime) < 60000) {
if (status[0] != null) {
if (status[0] instanceof Exception) {
// User cancelled or there was an exception in search criteria thread
throw (Exception) status[0];
}
// search criteria thread completed with 'OK'
return;
}
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
// ignore
}
}
throw new Exception("getSearchCriterionList timed out");
}
};
AsynchClientTask refreshTask = new AsynchClientTask("Refreshing tree...", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
if (searchCriterionListFinal.size() > 0) {
// show with search criteria
refresh(searchCriterionListFinal);
} else {
// show all
refresh(null);
}
}
};
Hashtable<String, Object> hashTable = new Hashtable<String, Object>();
if (!bShowAll && getDatabaseSearchPanel().hasRemoteDatabaseSearchDefined()) {
ClientTaskDispatcher.dispatch(this, hashTable, new AsynchClientTask[] { searchCriteriaTask, refreshTask }, true, false, true, searchCancel, true);
} else {
try {
searchCriteriaTask.run(hashTable);
refreshTask.run(hashTable);
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(this, e.getMessage());
}
}
}
Aggregations