KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > editors > schemabrowser > MatchingRuleUseDescriptionPage


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.schemabrowser;
22
23
24 import java.util.HashSet JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import org.apache.directory.ldapstudio.browser.core.model.schema.MatchingRuleUseDescription;
28 import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
29 import org.eclipse.jface.viewers.IStructuredContentProvider;
30 import org.eclipse.jface.viewers.ITableLabelProvider;
31 import org.eclipse.jface.viewers.LabelProvider;
32 import org.eclipse.jface.viewers.Viewer;
33 import org.eclipse.jface.viewers.ViewerFilter;
34 import org.eclipse.jface.viewers.ViewerSorter;
35 import org.eclipse.swt.graphics.Image;
36
37
38 /**
39  * The MatchingRuleUseDescriptionPage displays a list with all
40  * matching rule use descriptions and hosts the detail page.
41  *
42  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
43  * @version $Rev$, $Date$
44  */

45 public class MatchingRuleUseDescriptionPage extends SchemaPage
46 {
47
48     /**
49      *
50      * Creates a new instance of MatchingRuleUseDescriptionPage.
51      *
52      * @param schemaBrowser the schema browser
53      */

54     public MatchingRuleUseDescriptionPage( SchemaBrowser schemaBrowser )
55     {
56         super( schemaBrowser );
57     }
58
59
60     /**
61      * {@inheritDoc}
62      */

63     protected String JavaDoc getTitle()
64     {
65         return "Matching Rule Use";
66     }
67
68
69     /**
70      * {@inheritDoc}
71      */

72     protected String JavaDoc getFilterDescription()
73     {
74         return "Please select a matching rule. Enter a filter to restrict the list.";
75     }
76
77
78     /**
79      * {@inheritDoc}
80      */

81     protected IStructuredContentProvider getContentProvider()
82     {
83         return new MRUDContentProvider();
84     }
85
86
87     /**
88      * {@inheritDoc}
89      */

90     protected ITableLabelProvider getLabelProvider()
91     {
92         return new MRUDLabelProvider();
93     }
94
95
96     /**
97      * {@inheritDoc}
98      */

99     protected ViewerSorter getSorter()
100     {
101         return new MRUDViewerSorter();
102     }
103
104
105     /**
106      * {@inheritDoc}
107      */

108     protected ViewerFilter getFilter()
109     {
110         return new MRUDViewerFilter();
111     }
112
113
114     /**
115      * {@inheritDoc}
116      */

117     protected SchemaDetailsPage getDetailsPage()
118     {
119         return new MatchingRuleUseDescriptionDetailsPage( this, this.toolkit );
120     }
121
122     /**
123      * The content provider used by the viewer.
124      *
125      * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
126      * @version $Rev$, $Date$
127      */

128     class MRUDContentProvider implements IStructuredContentProvider
129     {
130         /**
131          * {@inheritDoc}
132          */

133         public Object JavaDoc[] getElements( Object JavaDoc inputElement )
134         {
135             if ( inputElement instanceof Schema )
136             {
137                 Schema schema = ( Schema ) inputElement;
138                 if ( schema != null && schema.getMrudMapByName() != null )
139                 {
140                     Set JavaDoc<Object JavaDoc> set = new HashSet JavaDoc<Object JavaDoc>( schema.getMrudMapByName().values() );
141                     return set.toArray();
142                 }
143             }
144             return new Object JavaDoc[0];
145         }
146
147
148         /**
149          * {@inheritDoc}
150          */

151         public void dispose()
152         {
153         }
154
155
156         /**
157          * {@inheritDoc}
158          */

159         public void inputChanged( Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput )
160         {
161         }
162     }
163
164     /**
165      * The label provider used by the viewer.
166      *
167      * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
168      * @version $Rev$, $Date$
169      */

170     class MRUDLabelProvider extends LabelProvider implements ITableLabelProvider
171     {
172         /**
173          * {@inheritDoc}
174          */

175         public String JavaDoc getColumnText( Object JavaDoc obj, int index )
176         {
177             return obj.toString();
178         }
179
180
181         /**
182          * {@inheritDoc}
183          */

184         public Image getColumnImage( Object JavaDoc obj, int index )
185         {
186             return null;
187         }
188     }
189
190     /**
191      * The sorter used by the viewer.
192      *
193      * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
194      * @version $Rev$, $Date$
195      */

196     class MRUDViewerSorter extends ViewerSorter
197     {
198         /**
199          * {@inheritDoc}
200          */

201         public int compare( Viewer viewer, Object JavaDoc e1, Object JavaDoc e2 )
202         {
203             return e1.toString().compareTo( e2.toString() );
204         }
205     }
206
207     /**
208      * The filter used by the viewer.
209      *
210      * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
211      * @version $Rev$, $Date$
212      */

213     class MRUDViewerFilter extends ViewerFilter
214     {
215         /**
216          * {@inheritDoc}
217          */

218         public boolean select( Viewer viewer, Object JavaDoc parentElement, Object JavaDoc element )
219         {
220             if ( element instanceof MatchingRuleUseDescription )
221             {
222                 MatchingRuleUseDescription mrud = ( MatchingRuleUseDescription ) element;
223                 boolean matched = false;
224
225                 if ( !matched )
226                     matched = mrud.toString().toLowerCase().indexOf( filterText.getText().toLowerCase() ) != -1;
227                 if ( !matched )
228                     matched = mrud.getNumericOID().toLowerCase().indexOf( filterText.getText().toLowerCase() ) != -1;
229
230                 return matched;
231             }
232             return false;
233         }
234     }
235
236 }
237
Popular Tags