KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > editors > searchresult > FilterAndSortJob


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. 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,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.ui.editors.searchresult;
22
23
24 import org.apache.directory.ldapstudio.browser.core.jobs.AbstractEclipseJob;
25 import org.apache.directory.ldapstudio.browser.core.jobs.ExtendedProgressMonitor;
26 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
27
28
29 /**
30  * This job to filter and sort the search result editor asynchrously to avoid
31  * freezing the GUI.
32  *
33  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
34  * @version $Rev$, $Date$
35  */

36 public class FilterAndSortJob extends AbstractEclipseJob
37 {
38
39     /** The configuration. */
40     private SearchResultEditorConfiguration configuration;
41
42     /** The main widget. */
43     private SearchResultEditorWidget mainWidget;
44
45     /** All elements, unfiltered and unsorted. */
46     private Object JavaDoc[] elements;
47
48     /** The filtered and sorted elements. */
49     private Object JavaDoc[] filteredAndSortedElements;
50
51
52     /**
53      * Creates a new instance of FilterAndSortJob.
54      *
55      * @param configuration the configuration
56      * @param mainWidget the main widget
57      * @param elements the elements, unfiltered and unsorted
58      */

59     public FilterAndSortJob( SearchResultEditorConfiguration configuration, SearchResultEditorWidget mainWidget,
60         Object JavaDoc[] elements )
61     {
62         this.configuration = configuration;
63         this.mainWidget = mainWidget;
64         this.elements = elements;
65     }
66
67
68     /**
69      * {@inheritDoc}
70      */

71     protected Object JavaDoc[] getLockedObjects()
72     {
73         return new Object JavaDoc[0];
74     }
75
76
77     /**
78      * {@inheritDoc}
79      */

80     protected void executeAsyncJob( ExtendedProgressMonitor monitor ) throws Exception JavaDoc
81     {
82         monitor.beginTask( "Filter and Sort", 3 );
83         monitor.worked( 1 );
84
85         monitor.setTaskName( "Filter and Sort" );
86
87         monitor.reportProgress( "Filtering..." );
88         this.filteredAndSortedElements = this.configuration.getFilter().filter( this.mainWidget.getViewer(), "",
89             elements );
90         monitor.worked( 1 );
91
92         monitor.reportProgress( "Sorting..." );
93         this.configuration.getSorter().sort( this.mainWidget.getViewer(), this.filteredAndSortedElements );
94         monitor.worked( 1 );
95     }
96
97
98     /**
99      * {@inheritDoc}
100      */

101     protected IConnection[] getConnections()
102     {
103         return new IConnection[0];
104     }
105
106
107     /**
108      * Gets the filtered and sorted elements.
109      *
110      * @return the filtered and sorted elements
111      */

112     public Object JavaDoc[] getFilteredAndSortedElements()
113     {
114         return filteredAndSortedElements;
115     }
116
117 }
118
Popular Tags