KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > editors > attributeType > ATEUsedByMandatoryTableContentProvider


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 package org.apache.directory.ldapstudio.schemas.view.editors.attributeType;
21
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.Comparator JavaDoc;
26 import java.util.List JavaDoc;
27
28 import org.apache.directory.ldapstudio.schemas.model.AttributeType;
29 import org.apache.directory.ldapstudio.schemas.model.ObjectClass;
30 import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
31 import org.eclipse.jface.viewers.IStructuredContentProvider;
32 import org.eclipse.jface.viewers.Viewer;
33
34
35 /**
36  * This class is the Content Provider for the Mandatory Table of the Attribute Type Editor (Used By Page).
37  *
38  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
39  * @version $Rev$, $Date$
40  */

41 public class ATEUsedByMandatoryTableContentProvider implements IStructuredContentProvider
42 {
43     /* (non-Javadoc)
44      * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
45      */

46     public Object JavaDoc[] getElements( Object JavaDoc inputElement )
47     {
48         if ( inputElement instanceof AttributeType )
49         {
50             List JavaDoc<ObjectClass> results = new ArrayList JavaDoc<ObjectClass>();
51             AttributeType inputAT = ( AttributeType ) inputElement;
52             SchemaPool schemaPool = SchemaPool.getInstance();
53
54             List JavaDoc<String JavaDoc> names = new ArrayList JavaDoc<String JavaDoc>();
55             for ( String JavaDoc name : inputAT.getNames() )
56             {
57                 names.add( name.toLowerCase() );
58             }
59
60             List JavaDoc<ObjectClass> objectClasses = schemaPool.getObjectClasses();
61             for ( ObjectClass oc : objectClasses )
62             {
63                 String JavaDoc[] musts = oc.getMust();
64                 for ( String JavaDoc must : musts )
65                 {
66                     if ( names.contains( must.toLowerCase() ) )
67                     {
68                         results.add( oc );
69                     }
70                 }
71             }
72
73             // Sorting Results
74
Collections.sort( results, new Comparator JavaDoc<ObjectClass>()
75             {
76                 public int compare( ObjectClass oc1, ObjectClass oc2 )
77                 {
78                     if ( oc1 instanceof ObjectClass && oc1 instanceof ObjectClass )
79                     {
80                         return ( ( ObjectClass ) oc1 ).getNames()[0].compareToIgnoreCase( ( ( ObjectClass ) oc2 )
81                             .getNames()[0] );
82                     }
83
84                     return 0;
85                 }
86             } );
87
88             return results.toArray();
89         }
90
91         // Default
92
return null;
93     }
94
95
96     /* (non-Javadoc)
97      * @see org.eclipse.jface.viewers.IContentProvider#dispose()
98      */

99     public void dispose()
100     {
101     }
102
103
104     /* (non-Javadoc)
105      * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
106      */

107     public void inputChanged( Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput )
108     {
109     }
110 }
111
Popular Tags