KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > editors > objectClass > ObjectClassEditorAttributesTableContentProvider


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.objectClass;
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.SchemaPool;
30 import org.apache.directory.ldapstudio.schemas.view.editors.NonExistingAttributeType;
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 Attributes Table of the Object Class Editor.
37  *
38  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
39  * @version $Rev$, $Date$
40  */

41 public class ObjectClassEditorAttributesTableContentProvider implements IStructuredContentProvider
42 {
43     /** The Schema Pool */
44     private SchemaPool schemaPool;
45
46
47     /**
48      * Creates a new instance of ObjectClassEditorAttributesTableContentProvider.
49      */

50     public ObjectClassEditorAttributesTableContentProvider()
51     {
52         schemaPool = SchemaPool.getInstance();
53     }
54
55
56     /* (non-Javadoc)
57      * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
58      */

59     public Object JavaDoc[] getElements( Object JavaDoc inputElement )
60     {
61         if ( inputElement instanceof String JavaDoc[] )
62         {
63             List JavaDoc<Object JavaDoc> results = new ArrayList JavaDoc<Object JavaDoc>();
64
65             String JavaDoc[] attributes = ( String JavaDoc[] ) inputElement;
66             for ( String JavaDoc attribute : attributes )
67             {
68                 AttributeType at = schemaPool.getAttributeType( attribute );
69                 if ( at != null )
70                 {
71                     results.add( at );
72                 }
73                 else
74                 {
75                     results.add( new NonExistingAttributeType( attribute ) );
76                 }
77             }
78
79             // Sorting Elements
80
Collections.sort( results, new Comparator JavaDoc<Object JavaDoc>()
81             {
82                 public int compare( Object JavaDoc o1, Object JavaDoc o2 )
83                 {
84                     if ( o1 instanceof AttributeType && o2 instanceof AttributeType )
85                     {
86                         return ( ( AttributeType ) o1 ).getNames()[0].compareToIgnoreCase( ( ( AttributeType ) o2 )
87                             .getNames()[0] );
88                     }
89                     else if ( o1 instanceof AttributeType && o2 instanceof NonExistingAttributeType )
90                     {
91                         return ( ( AttributeType ) o1 ).getNames()[0]
92                             .compareToIgnoreCase( ( ( NonExistingAttributeType ) o2 ).getName() );
93                     }
94                     else if ( o1 instanceof NonExistingAttributeType && o2 instanceof AttributeType )
95                     {
96                         return ( ( NonExistingAttributeType ) o1 ).getName().compareToIgnoreCase(
97                             ( ( AttributeType ) o2 ).getNames()[0] );
98                     }
99                     else if ( o1 instanceof NonExistingAttributeType && o2 instanceof NonExistingAttributeType )
100                     {
101                         return ( ( NonExistingAttributeType ) o1 ).getName().compareToIgnoreCase(
102                             ( ( NonExistingAttributeType ) o2 ).getName() );
103                     }
104
105                     return 0;
106                 }
107             } );
108
109             return results.toArray();
110         }
111
112         // Default
113
return null;
114     }
115
116
117     /* (non-Javadoc)
118      * @see org.eclipse.jface.viewers.IContentProvider#dispose()
119      */

120     public void dispose()
121     {
122     }
123
124
125     /* (non-Javadoc)
126      * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
127      */

128     public void inputChanged( Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput )
129     {
130     }
131 }
132
Popular Tags