KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > visualcontent > ui > nodetree > SearchJob


1 /**
2  * VC Browser - Visualizes the content of a JSR 170 compatible repository
3  * Copyright (C) 2006 Sandro Böhme
4  *
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.visualcontent.ui.nodetree;
19
20 import javax.jcr.RepositoryException;
21 import javax.jcr.query.Query;
22 import javax.jcr.query.QueryResult;
23
24 import org.eclipse.core.runtime.IProgressMonitor;
25 import org.eclipse.core.runtime.IStatus;
26 import org.eclipse.core.runtime.Status;
27 import org.eclipse.core.runtime.jobs.Job;
28 import org.eclipse.swt.widgets.Display;
29 import org.visualcontent.ui.UiPlugin;
30
31 /**
32  * @author Administrator
33  *
34  */

35 public class SearchJob extends Job {
36
37     private Query query;
38     private NodeTreeViewPart nodeTreeView;
39
40     public SearchJob(String JavaDoc name, Query aQuery, NodeTreeViewPart theNodeTreeView) {
41         super(name);
42         this.query = aQuery;
43         this.nodeTreeView = theNodeTreeView;
44     }
45
46     /* (non-Javadoc)
47      * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
48      */

49     protected IStatus run(IProgressMonitor monitor) {
50         monitor.beginTask("Search in the repository",IProgressMonitor.UNKNOWN);
51         Display display = nodeTreeView.getSite().getShell().getDisplay();
52         try {
53             final QueryResult result = query.execute();
54             //see: http://www.eclipse.org/swt/faq.php#uithread
55
display.syncExec(
56             new Runnable JavaDoc() {
57                 public void run(){
58                     nodeTreeView.setInput(result);
59                   }
60                 });
61             monitor.done();
62         }
63         catch (final RepositoryException e) {
64             display.syncExec(
65                     new Runnable JavaDoc() {
66                         public void run(){
67                             UiPlugin.getDefault().showError("Could not execute the query.",e);
68                           }
69                         });
70         }
71         return Status.OK_STATUS;
72     }
73 }
74
Popular Tags