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.AttributeType; 28 import org.apache.directory.ldapstudio.schemas.model.SchemaPool; 29 import org.apache.directory.ldapstudio.schemas.view.editors.NonExistingAttributeType; 30 import org.eclipse.jface.viewers.IStructuredContentProvider; 31 import org.eclipse.jface.viewers.Viewer; 32 33 34 40 public class ATESuperiorComboContentProvider implements IStructuredContentProvider 41 { 42 43 private SchemaPool schemaPool; 44 45 46 49 public ATESuperiorComboContentProvider() 50 { 51 schemaPool = SchemaPool.getInstance(); 52 } 53 54 55 58 public Object [] getElements( Object inputElement ) 59 { 60 if ( inputElement instanceof ATESuperiorComboInput ) 61 { 62 ATESuperiorComboInput input = ( ATESuperiorComboInput ) inputElement; 63 64 if ( input.getChildren().isEmpty() ) 65 { 66 AttributeType editorAT = input.getAttributeType(); 67 68 input.addChild( new NonExistingAttributeType( NonExistingAttributeType.NONE ) ); 70 71 List <AttributeType> ats = schemaPool.getAttributeTypes(); 73 for ( AttributeType at : ats ) 74 { 75 if ( !isSubType( at, editorAT ) ) 76 { 77 input.addChild( at ); 78 } 79 } 80 } 81 82 List <Object > children = input.getChildren(); 84 85 Collections.sort( children, new Comparator <Object >() 87 { 88 public int compare( Object o1, Object o2 ) 89 { 90 if ( o1 instanceof AttributeType && o2 instanceof AttributeType ) 91 { 92 return ( ( AttributeType ) o1 ).getNames()[0].compareToIgnoreCase( ( ( AttributeType ) o2 ) 93 .getNames()[0] ); 94 } 95 else if ( o1 instanceof AttributeType && o2 instanceof NonExistingAttributeType ) 96 { 97 return ( ( AttributeType ) o1 ).getNames()[0] 98 .compareToIgnoreCase( ( ( NonExistingAttributeType ) o2 ).getName() ); 99 } 100 else if ( o1 instanceof NonExistingAttributeType && o2 instanceof AttributeType ) 101 { 102 return ( ( NonExistingAttributeType ) o1 ).getName().compareToIgnoreCase( 103 ( ( AttributeType ) o2 ).getNames()[0] ); 104 } 105 else if ( o1 instanceof NonExistingAttributeType && o2 instanceof NonExistingAttributeType ) 106 { 107 return ( ( NonExistingAttributeType ) o1 ).getName().compareToIgnoreCase( 108 ( ( NonExistingAttributeType ) o2 ).getName() ); 109 } 110 111 return 0; 112 } 113 } ); 114 115 return children.toArray(); 116 } 117 118 return new Object [0]; 120 } 121 122 123 126 public void dispose() 127 { 128 } 129 130 131 134 public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) 135 { 136 } 137 138 139 149 private boolean isSubType( AttributeType at1, AttributeType at2 ) 150 { 151 if ( at1.equals( at2 ) ) 152 { 153 return true; 154 } 155 else 156 { 157 String sup = at1.getSuperior(); 158 159 if ( sup == null ) 160 { 161 return false; 162 } 163 else 164 { 165 AttributeType supAT = schemaPool.getAttributeType( sup ); 166 if ( supAT == null ) 167 { 168 return false; 169 } 170 else 171 { 172 return isSubType( supAT, at2 ); 173 } 174 } 175 } 176 } 177 } 178 | Popular Tags |