Search in sources :

Example 1 with SearchCriterion

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());
        }
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) DatabaseSearchPanel(cbit.vcell.client.desktop.DatabaseSearchPanel) EventObject(java.util.EventObject) DataAccessException(org.vcell.util.DataAccessException) UserCancelException(org.vcell.util.UserCancelException) ProgressDialogListener(org.vcell.util.ProgressDialogListener) SearchCriterion(cbit.vcell.client.desktop.DatabaseSearchPanel.SearchCriterion) EventObject(java.util.EventObject)

Aggregations

DatabaseSearchPanel (cbit.vcell.client.desktop.DatabaseSearchPanel)1 SearchCriterion (cbit.vcell.client.desktop.DatabaseSearchPanel.SearchCriterion)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 ArrayList (java.util.ArrayList)1 EventObject (java.util.EventObject)1 Hashtable (java.util.Hashtable)1 DataAccessException (org.vcell.util.DataAccessException)1 ProgressDialogListener (org.vcell.util.ProgressDialogListener)1 UserCancelException (org.vcell.util.UserCancelException)1