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.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 41 public class ObjectClassEditorAttributesTableContentProvider implements IStructuredContentProvider 42 { 43 44 private SchemaPool schemaPool; 45 46 47 50 public ObjectClassEditorAttributesTableContentProvider() 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 [] attributes = ( String [] ) inputElement; 66 for ( String 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 Collections.sort( results, new Comparator <Object >() 81 { 82 public int compare( Object o1, Object 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 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 |