1 20 package org.apache.directory.ldapstudio.schemas.view.editors.attributeType; 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.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 41 public class ATEUsedByOptionalTableContentProvider implements IStructuredContentProvider 42 { 43 46 public Object [] getElements( Object inputElement ) 47 { 48 if ( inputElement instanceof AttributeType ) 49 { 50 List <ObjectClass> results = new ArrayList <ObjectClass>(); 51 AttributeType inputAT = ( AttributeType ) inputElement; 52 SchemaPool schemaPool = SchemaPool.getInstance(); 53 54 List <String > names = new ArrayList <String >(); 55 for ( String name : inputAT.getNames() ) 56 { 57 names.add( name.toLowerCase() ); 58 } 59 60 List <ObjectClass> objectClasses = schemaPool.getObjectClasses(); 61 for ( ObjectClass oc : objectClasses ) 62 { 63 String [] mays = oc.getMay(); 64 for ( String may : mays ) 65 { 66 if ( names.contains( may.toLowerCase() ) ) 67 { 68 results.add( oc ); 69 } 70 } 71 } 72 73 Collections.sort( results, new Comparator <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 return null; 93 } 94 95 96 99 public void dispose() 100 { 101 } 102 103 104 107 public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) 108 { 109 } 110 } 111 | Popular Tags |