KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription;
25 import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
26 import org.eclipse.jface.viewers.IStructuredContentProvider;
27 import org.eclipse.jface.viewers.ITableLabelProvider;
28 import org.eclipse.jface.viewers.LabelProvider;
29 import org.eclipse.jface.viewers.Viewer;
30 import org.eclipse.jface.viewers.ViewerFilter;
31 import org.eclipse.jface.viewers.ViewerSorter;
32 import org.eclipse.swt.graphics.Image;
33
34
35 /**
36  * The ObjectClassDescriptionPage displays a list with all
37  * object class descriptions and hosts the detail page.
38  *
39  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
40  * @version $Rev$, $Date$
41  */

42 public class ObjectClassDescriptionPage extends SchemaPage
43 {
44
45     /**
46      * Creates a new instance of ObjectClassDescriptionPage.
47      *
48      * @param schemaBrowser the schema browser
49      */

50     public ObjectClassDescriptionPage( SchemaBrowser schemaBrowser )
51     {
52         super( schemaBrowser );
53     }
54
55
56     /**
57      * {@inheritDoc}
58      */

59     protected String JavaDoc getTitle()
60     {
61         return "Object Classes";
62     }
63
64
65     /**
66      * {@inheritDoc}
67      */

68     protected String JavaDoc getFilterDescription()
69     {
70         return "Please select an object class. Enter a filter to restrict the list.";
71     }
72
73
74     /**
75      * {@inheritDoc}
76      */

77     protected IStructuredContentProvider getContentProvider()
78     {
79         return new OCDContentProvider();
80     }
81
82
83     /**
84      * {@inheritDoc}
85      */

86     protected ITableLabelProvider getLabelProvider()
87     {
88         return new OCDLabelProvider();
89     }
90
91
92     /**
93      * {@inheritDoc}
94      */

95     protected ViewerSorter getSorter()
96     {
97         return new OCDViewerSorter();
98     }
99
100
101     /**
102      * {@inheritDoc}
103      */

104     protected ViewerFilter getFilter()
105     {
106         return new OCDViewerFilter();
107     }
108
109
110     /**
111      * {@inheritDoc}
112      */

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

124     class OCDContentProvider implements IStructuredContentProvider
125     {
126         /**
127          * {@inheritDoc}
128          */

129         public Object JavaDoc[] getElements( Object JavaDoc inputElement )
130         {
131             if ( inputElement instanceof Schema )
132             {
133                 Schema schema = ( Schema ) inputElement;
134                 if ( schema != null )
135                 {
136                     return schema.getObjectClassDescriptions();
137                 }
138             }
139             return new Object JavaDoc[0];
140         }
141
142
143         /**
144          * {@inheritDoc}
145          */

146         public void dispose()
147         {
148         }
149
150
151         /**
152          * {@inheritDoc}
153          */

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

165     class OCDLabelProvider extends LabelProvider implements ITableLabelProvider
166     {
167         /**
168          * {@inheritDoc}
169          */

170         public String JavaDoc getColumnText( Object JavaDoc obj, int index )
171         {
172             return obj.toString();
173         }
174
175
176         /**
177          * {@inheritDoc}
178          */

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

191     class OCDViewerSorter extends ViewerSorter
192     {
193         /**
194          * {@inheritDoc}
195          */

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

208     class OCDViewerFilter extends ViewerFilter
209     {
210         /**
211          * {@inheritDoc}
212          */

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