KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > widgets > entryeditor > EntryEditorWidgetFilter


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.common.widgets.entryeditor;
22
23
24 import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
25 import org.apache.directory.ldapstudio.browser.core.model.IValue;
26 import org.eclipse.jface.viewers.TreeViewer;
27 import org.eclipse.jface.viewers.Viewer;
28 import org.eclipse.jface.viewers.ViewerFilter;
29
30
31 /**
32  * The EntryEditorWidgetFilter implements the filter for
33  * the entry editor widget.
34  *
35  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
36  * @version $Rev$, $Date$
37  */

38 public class EntryEditorWidgetFilter extends ViewerFilter
39 {
40
41     /** The viewer to filter. */
42     protected TreeViewer viewer;
43
44     /** The quick filter attribute. */
45     protected String JavaDoc quickFilterAttribute;
46
47     /** The quick filter value. */
48     protected String JavaDoc quickFilterValue;
49
50
51     /**
52      * Creates a new instance of EntryEditorWidgetFilter.
53      */

54     public EntryEditorWidgetFilter()
55     {
56         this.quickFilterAttribute = "";
57         this.quickFilterValue = "";
58     }
59
60
61     /**
62      * Connects this filter with the given viewer.
63      *
64      * @param viewer the viewer
65      */

66     public void connect( TreeViewer viewer )
67     {
68         this.viewer = viewer;
69         viewer.addFilter( this );
70     }
71
72
73     /**
74      * {@inheritDoc}
75      */

76     public boolean select( Viewer viewer, Object JavaDoc parentElement, Object JavaDoc element )
77     {
78         if ( element instanceof IAttribute )
79         {
80             IAttribute attribute = ( IAttribute ) element;
81
82             // check if one of the values goes through the quick filter
83
boolean oneGoesThrough = false;
84             IValue[] values = attribute.getValues();
85             for ( int i = 0; i < values.length; i++ )
86             {
87                 if ( goesThroughQuickFilter( values[i] ) )
88                 {
89                     oneGoesThrough = true;
90                     break;
91                 }
92             }
93             if ( !oneGoesThrough )
94             {
95                 return false;
96             }
97
98             return true;
99         }
100         else if ( element instanceof IValue )
101         {
102             IValue value = ( IValue ) element;
103
104             // check quick filter
105
if ( !goesThroughQuickFilter( value ) )
106             {
107                 return false;
108             }
109
110             // filter attribute types
111
if ( value.getAttribute().isObjectClassAttribute() )
112             {
113                 return isShowObjectClassAttribute();
114             }
115             else if ( value.getAttribute().isMustAttribute() )
116             {
117                 return isShowMustAttributes();
118             }
119             else if ( value.getAttribute().isMayAttribute() )
120             {
121                 return isShowMayAttributes();
122             }
123             else if ( value.getAttribute().isOperationalAttribute() )
124             {
125                 return isShowOperationalAttributes();
126             }
127             else
128             {
129                 return true;
130             }
131         }
132         else
133         {
134             return true;
135         }
136     }
137
138
139     /**
140      * Checks if the given value goes through quick filter.
141      *
142      * @param value the value
143      *
144      * @return true, if goes through quick filter
145      */

146     private boolean goesThroughQuickFilter( IValue value )
147     {
148         // filter attribute description
149
if ( quickFilterAttribute != null && !"".equals( quickFilterAttribute ) )
150         {
151             if ( value.getAttribute().getDescription().toUpperCase().indexOf( quickFilterAttribute.toUpperCase() ) == -1 )
152             {
153                 return false;
154             }
155         }
156
157         // fitler value
158
if ( quickFilterValue != null && !"".equals( quickFilterValue ) )
159         {
160             if ( value.isString()
161                 && value.getStringValue().toUpperCase().indexOf( quickFilterValue.toUpperCase() ) == -1 )
162             {
163                 return false;
164             }
165             else if ( value.isBinary() )
166             {
167                 return false;
168             }
169         }
170
171         return true;
172     }
173
174
175     /**
176      * Disposes this filter.
177      */

178     public void dispose()
179     {
180         viewer = null;
181     }
182
183
184     /**
185      * Gets the quick filter attribute.
186      *
187      * @return the quick filter attribute
188      */

189     public String JavaDoc getQuickFilterAttribute()
190     {
191         return quickFilterAttribute;
192     }
193
194
195     /**
196      * Sets the quick filter attribute.
197      *
198      * @param quickFilterAttribute the quick filter attribute
199      */

200     public void setQuickFilterAttribute( String JavaDoc quickFilterAttribute )
201     {
202         if ( !this.quickFilterAttribute.equals( quickFilterAttribute ) )
203         {
204             this.quickFilterAttribute = quickFilterAttribute;
205             if ( viewer != null )
206             {
207                 viewer.refresh();
208             }
209         }
210     }
211
212
213     /**
214      * Gets the quick filter value.
215      *
216      * @return the quick filter value
217      */

218     public String JavaDoc getQuickFilterValue()
219     {
220         return quickFilterValue;
221     }
222
223
224     /**
225      * Sets the quick filter value.
226      *
227      * @param quickFilterValue the quick filter value
228      */

229     public void setQuickFilterValue( String JavaDoc quickFilterValue )
230     {
231         if ( !this.quickFilterValue.equals( quickFilterValue ) )
232         {
233             this.quickFilterValue = quickFilterValue;
234             if ( viewer != null )
235             {
236                 viewer.refresh();
237             }
238         }
239     }
240
241
242     /**
243      * Checks if may attributes should be shown.
244      *
245      * @return true, if may attributes should be shown
246      */

247     public boolean isShowMayAttributes()
248     {
249         return true;
250     }
251
252
253     /**
254      * Checks if must attributes should be shown.
255      *
256      * @return true, if must attributes should be shown
257      */

258     public boolean isShowMustAttributes()
259     {
260         return true;
261     }
262
263
264     /**
265      * Checks if the objectClass attribute should be shown.
266      *
267      * @return true, if the objectClass attribute should be shown
268      */

269     public boolean isShowObjectClassAttribute()
270     {
271         return true;
272     }
273
274
275     /**
276      * Checks if operational attributes should be shown.
277      *
278      * @return true, if operational attributes should be shown
279      */

280     public boolean isShowOperationalAttributes()
281     {
282         return true;
283     }
284
285 }
286
Popular Tags