1 20 21 package org.apache.directory.ldapstudio.schemas.view.views; 22 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import org.apache.directory.ldapstudio.schemas.Activator; 28 import org.apache.directory.ldapstudio.schemas.PluginConstants; 29 import org.apache.directory.ldapstudio.schemas.model.AttributeType; 30 import org.apache.directory.ldapstudio.schemas.model.LDAPModelEvent; 31 import org.apache.directory.ldapstudio.schemas.model.ObjectClass; 32 import org.apache.directory.ldapstudio.schemas.model.PoolListener; 33 import org.apache.directory.ldapstudio.schemas.model.SchemaPool; 34 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.AttributeTypeWrapper; 35 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.ITreeNode; 36 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.ObjectClassWrapper; 37 import org.eclipse.jface.viewers.IStructuredContentProvider; 38 import org.eclipse.jface.viewers.ITreeContentProvider; 39 import org.eclipse.jface.viewers.TreeViewer; 40 import org.eclipse.jface.viewers.Viewer; 41 42 43 49 public class HierarchyViewContentProvider implements IStructuredContentProvider, ITreeContentProvider, PoolListener 50 { 51 52 private SchemaPool schemaPool; 53 54 55 private TreeViewer viewer; 56 57 List <AttributeType> attributeTypes; 58 List <ObjectClass> objectClasses; 59 60 61 64 public HierarchyViewContentProvider( TreeViewer viewer ) 65 { 66 this.viewer = viewer; 67 schemaPool = SchemaPool.getInstance(); 68 schemaPool.addListener( this ); 69 attributeTypes = schemaPool.getAttributeTypes(); 70 objectClasses = schemaPool.getObjectClasses(); 71 } 72 73 74 77 public Object [] getElements( Object inputElement ) 78 { 79 return getChildren( inputElement ); 80 } 81 82 83 86 public Object [] getChildren( Object parentElement ) 87 { 88 int mode = Activator.getDefault().getDialogSettings().getInt( PluginConstants.PREFS_HIERARCHY_VIEW_MODE ); 89 List <ITreeNode> children = null; 90 91 if ( parentElement instanceof ObjectClass ) 92 { 93 ObjectClass oc = ( ObjectClass ) parentElement; 94 95 ObjectClassWrapper ocw = new ObjectClassWrapper( oc, null ); 96 children = new ArrayList <ITreeNode>(); 97 children.add( ocw ); 98 } 99 else if ( parentElement instanceof AttributeType ) 100 { 101 AttributeType at = ( AttributeType ) parentElement; 102 103 AttributeTypeWrapper atw = new AttributeTypeWrapper( at, null ); 104 children = new ArrayList <ITreeNode>(); 105 children.add( atw ); 106 } 107 else if ( parentElement instanceof ObjectClassWrapper ) 108 { 109 ObjectClassWrapper ocw = ( ObjectClassWrapper ) parentElement; 110 ObjectClass oc = ocw.getMyObjectClass(); 111 112 if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_SUPERTYPE ) 113 { 114 String [] superiors = oc.getSuperiors(); 115 for ( String superior : superiors ) 116 { 117 if ( superior != null || "".equals( superior ) ) { 119 ObjectClass supOC = schemaPool.getObjectClass( superior ); 120 if ( supOC != null ) 121 { 122 ObjectClassWrapper supOCW = new ObjectClassWrapper( supOC, ocw ); 123 ocw.addChild( supOCW ); 124 } 125 } 126 } 127 } 128 else if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_SUBTYPE ) 129 { 130 for ( ObjectClass objectClass : objectClasses ) 131 { 132 String [] superiors = objectClass.getSuperiors(); 133 for ( String superior : superiors ) 134 { 135 if ( superior != null || "".equals( superior ) ) { 137 ObjectClass supOC = schemaPool.getObjectClass( superior ); 138 if ( supOC != null && oc.equals( supOC ) ) 139 { 140 ObjectClassWrapper supOCW = new ObjectClassWrapper( objectClass, ocw ); 141 ocw.addChild( supOCW ); 142 } 143 } 144 } 145 } 146 } 147 148 children = ocw.getChildren(); 149 } 150 else if ( parentElement instanceof AttributeTypeWrapper ) 151 { 152 AttributeTypeWrapper atw = ( AttributeTypeWrapper ) parentElement; 153 AttributeType at = atw.getMyAttributeType(); 154 155 if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_SUPERTYPE ) 156 { 157 String superior = at.getSuperior(); 158 if ( superior != null || "".equals( superior ) ) { 160 AttributeType supAT = schemaPool.getAttributeType( superior ); 161 if ( supAT != null ) 162 { 163 AttributeTypeWrapper supATW = new AttributeTypeWrapper( supAT, atw ); 164 atw.addChild( supATW ); 165 } 166 } 167 } 168 else if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_SUBTYPE ) 169 { 170 for ( AttributeType attributeType : attributeTypes ) 171 { 172 String superior = attributeType.getSuperior(); 173 if ( superior != null && !"".equals( superior ) ) { 175 AttributeType supAT = schemaPool.getAttributeType( superior ); 176 if ( supAT != null && at.equals( supAT ) ) 177 { 178 AttributeTypeWrapper supATW = new AttributeTypeWrapper( attributeType, atw ); 179 atw.addChild( supATW ); 180 } 181 } 182 } 183 } 184 185 children = atw.getChildren(); 186 } 187 188 if ( children == null ) 189 { 190 return new Object [0]; 191 } 192 else 193 { 194 return children.toArray(); 195 } 196 } 197 198 199 202 public Object getParent( Object element ) 203 { 204 if ( element instanceof ITreeNode ) 205 { 206 return ( ( ITreeNode ) element ).getParent(); 207 } 208 209 return null; 211 } 212 213 214 217 public boolean hasChildren( Object element ) 218 { 219 if ( element instanceof ITreeNode ) 220 { 221 return getChildren( element ).length > 0; 222 } 223 224 return false; 226 } 227 228 229 232 public void dispose() 233 { 234 } 235 236 237 240 public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) 241 { 242 } 243 244 245 248 public void poolChanged( SchemaPool p, LDAPModelEvent e ) 249 { 250 viewer.refresh(); 251 viewer.expandAll(); 252 } 253 } 254 | Popular Tags |