1 20 package org.apache.directory.ldapstudio.schemas.view.editors.attributeType; 21 22 23 import java.util.Collections ; 24 import java.util.Comparator ; 25 import java.util.List ; 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 39 public class ATESyntaxComboContentProvider implements IStructuredContentProvider 40 { 41 44 public Object [] getElements( Object inputElement ) 45 { 46 if ( inputElement instanceof ATESyntaxComboInput ) 47 { 48 ATESyntaxComboInput input = ( ATESyntaxComboInput ) inputElement; 49 50 if ( input.getChildren().isEmpty() ) 51 { 52 input.addChild( new NonExistingSyntax( NonExistingSyntax.NONE ) ); 54 55 List <Syntax> syntaxes = Syntaxes.getSyntaxes(); 57 for ( Syntax syntax : syntaxes ) 58 { 59 input.addChild( syntax ); 60 } 61 } 62 63 List <Object > children = input.getChildren(); 65 66 Collections.sort( children, new Comparator <Object >() 68 { 69 public int compare( Object o1, Object 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 return new Object [0]; 98 } 99 100 101 104 public void dispose() 105 { 106 } 107 108 109 112 public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) 113 { 114 } 115 } 116 | Popular Tags |