KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collections JavaDoc;
24 import java.util.Comparator JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.apache.directory.ldapstudio.schemas.model.Syntax;
28 import org.apache.directory.ldapstudio.schemas.model.Syntaxes;
29 import org.eclipse.jface.viewers.IStructuredContentProvider;
30 import org.eclipse.jface.viewers.Viewer;
31
32
33 /**
34  * This class implements the Content Provider for the Syntax Combo of the Attribute Type Editor.
35  *
36  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
37  * @version $Rev$, $Date$
38  */

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

44     public Object JavaDoc[] getElements( Object JavaDoc inputElement )
45     {
46         if ( inputElement instanceof ATESyntaxComboInput )
47         {
48             ATESyntaxComboInput input = ( ATESyntaxComboInput ) inputElement;
49
50             if ( input.getChildren().isEmpty() )
51             {
52                 // Creating the '(None)' item
53
input.addChild( new NonExistingSyntax( NonExistingSyntax.NONE ) );
54
55                 // Creating Children
56
List JavaDoc<Syntax> syntaxes = Syntaxes.getSyntaxes();
57                 for ( Syntax syntax : syntaxes )
58                 {
59                     input.addChild( syntax );
60                 }
61             }
62
63             // Getting Children
64
List JavaDoc<Object JavaDoc> children = input.getChildren();
65
66             // Sorting Children
67
Collections.sort( children, new Comparator JavaDoc<Object JavaDoc>()
68             {
69                 public int compare( Object JavaDoc o1, Object JavaDoc o2 )
70                 {
71                     if ( o1 instanceof Syntax && o2 instanceof Syntax )
72                     {
73                         return ( ( Syntax ) o1 ).getName().compareToIgnoreCase( ( ( Syntax ) o2 ).getName() );
74                     }
75                     else if ( o1 instanceof Syntax && o2 instanceof NonExistingSyntax )
76                     {
77                         return ( ( Syntax ) o1 ).getName().compareToIgnoreCase( ( ( NonExistingSyntax ) o2 ).getName() );
78                     }
79                     else if ( o1 instanceof NonExistingSyntax && o2 instanceof Syntax )
80                     {
81                         return ( ( NonExistingSyntax ) o1 ).getName().compareToIgnoreCase( ( ( Syntax ) o2 ).getName() );
82                     }
83                     else if ( o1 instanceof NonExistingSyntax && o2 instanceof NonExistingSyntax )
84                     {
85                         return ( ( NonExistingSyntax ) o1 ).getName().compareToIgnoreCase(
86                             ( ( NonExistingSyntax ) o2 ).getName() );
87                     }
88
89                     return 0;
90                 }
91             } );
92
93             return children.toArray();
94         }
95
96         // Default
97
return new Object JavaDoc[0];
98     }
99
100
101     /* (non-Javadoc)
102      * @see org.eclipse.jface.viewers.IContentProvider#dispose()
103      */

104     public void dispose()
105     {
106     }
107
108
109     /* (non-Javadoc)
110      * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
111      */

112     public void inputChanged( Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput )
113     {
114     }
115 }
116
Popular Tags