1 20 package org.apache.directory.ldapstudio.schemas.view.editors.objectClass; 21 22 23 import java.util.ArrayList ; 24 import java.util.Collections ; 25 import java.util.Comparator ; 26 import java.util.List ; 27 28 import org.apache.directory.ldapstudio.schemas.model.ObjectClass; 29 import org.apache.directory.ldapstudio.schemas.model.SchemaPool; 30 import org.apache.directory.ldapstudio.schemas.view.editors.NonExistingObjectClass; 31 import org.eclipse.jface.viewers.IStructuredContentProvider; 32 import org.eclipse.jface.viewers.Viewer; 33 34 35 41 public class ObjectClassEditorSuperiorsTableContentProvider implements IStructuredContentProvider 42 { 43 44 private SchemaPool schemaPool; 45 46 47 50 public ObjectClassEditorSuperiorsTableContentProvider() 51 { 52 schemaPool = SchemaPool.getInstance(); 53 } 54 55 56 59 public Object [] getElements( Object inputElement ) 60 { 61 if ( inputElement instanceof String [] ) 62 { 63 List <Object > results = new ArrayList <Object >(); 64 65 String [] superiors = ( String [] ) inputElement; 66 for ( String superior : superiors ) 67 { 68 ObjectClass oc = schemaPool.getObjectClass( superior ); 69 if ( oc != null ) 70 { 71 results.add( oc ); 72 } 73 else 74 { 75 results.add( new NonExistingObjectClass( superior ) ); 76 } 77 } 78 79 Collections.sort( results, new Comparator <Object >() 81 { 82 public int compare( Object o1, Object o2 ) 83 { 84 if ( o1 instanceof ObjectClass && o2 instanceof ObjectClass ) 85 { 86 return ( ( ObjectClass ) o1 ).getNames()[0].compareToIgnoreCase( ( ( ObjectClass ) o2 ) 87 .getNames()[0] ); 88 } 89 else if ( o1 instanceof ObjectClass && o2 instanceof NonExistingObjectClass ) 90 { 91 return ( ( ObjectClass ) o1 ).getNames()[0] 92 .compareToIgnoreCase( ( ( NonExistingObjectClass ) o2 ).getName() ); 93 } 94 else if ( o1 instanceof NonExistingObjectClass && o2 instanceof ObjectClass ) 95 { 96 return ( ( NonExistingObjectClass ) o1 ).getName().compareToIgnoreCase( 97 ( ( ObjectClass ) o2 ).getNames()[0] ); 98 } 99 else if ( o1 instanceof NonExistingObjectClass && o2 instanceof NonExistingObjectClass ) 100 { 101 return ( ( NonExistingObjectClass ) o1 ).getName().compareToIgnoreCase( 102 ( ( NonExistingObjectClass ) o2 ).getName() ); 103 } 104 105 return 0; 106 } 107 } ); 108 109 return results.toArray(); 110 } 111 112 return null; 114 } 115 116 117 120 public void dispose() 121 { 122 } 123 124 125 128 public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) 129 { 130 } 131 } 132 | Popular Tags |