KickJava   Java API By Example, From Geeks To Geeks.

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


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.LdapSyntaxDescription;
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 LdapSyntaxDescriptionPage displays a list with all
40  * syntax 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 LdapSyntaxDescriptionPage extends SchemaPage
46 {
47
48     /**
49      * Creates a new instance of LdapSyntaxDescriptionPage.
50      *
51      * @param schemaBrowser the schema browser
52      */

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

62     protected String JavaDoc getTitle()
63     {
64         return "Syntaxes";
65     }
66
67
68     /**
69      * {@inheritDoc}
70      */

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

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

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

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

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

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

127     private class LSDContentProvider implements IStructuredContentProvider
128     {
129         /**
130          * {@inheritDoc}
131          */

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

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

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

169     private class LSDLabelProvider extends LabelProvider implements ITableLabelProvider
170     {
171         /**
172          * {@inheritDoc}
173          */

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

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

195     private class LSDViewerSorter extends ViewerSorter
196     {
197         /**
198          * {@inheritDoc}
199          */

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

212     private class LSDViewerFilter extends ViewerFilter
213     {
214         /**
215          * {@inheritDoc}
216          */

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