1 20 21 package org.apache.directory.ldapstudio.browser.common.widgets.entryeditor; 22 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator; 28 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants; 29 import org.apache.directory.ldapstudio.browser.core.jobs.InitializeAttributesJob; 30 import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy; 31 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 32 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 33 import org.apache.directory.ldapstudio.browser.core.model.IValue; 34 import org.eclipse.jface.viewers.ITreeContentProvider; 35 import org.eclipse.jface.viewers.Viewer; 36 37 38 46 public class EntryEditorWidgetContentProvider implements ITreeContentProvider 47 { 48 49 50 protected EntryEditorWidgetPreferences preferences; 51 52 53 protected EntryEditorWidget mainWidget; 54 55 56 62 public EntryEditorWidgetContentProvider( EntryEditorWidgetPreferences preferences, EntryEditorWidget mainWidget ) 63 { 64 this.preferences = preferences; 65 this.mainWidget = mainWidget; 66 } 67 68 69 74 public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) 75 { 76 if ( mainWidget != null ) 77 { 78 String dn = ""; 79 boolean enabled = true; 80 81 if ( newInput != null && newInput instanceof IEntry ) 82 { 83 IEntry entry = ( IEntry ) newInput; 84 dn = "DN: " + entry.getDn().toString(); 85 } 86 else if ( newInput != null && newInput instanceof AttributeHierarchy ) 87 { 88 AttributeHierarchy ah = ( AttributeHierarchy ) newInput; 89 dn = "DN: " + ah.getAttribute().getEntry().getDn().toString(); 90 } 91 else 92 { 93 dn = "No entry selected"; 94 enabled = false; 95 } 96 97 if ( mainWidget.getInfoText() != null && !mainWidget.getInfoText().isDisposed() ) 98 { 99 mainWidget.getInfoText().setText( dn ); 100 } 101 if ( mainWidget.getQuickFilterWidget() != null ) 102 { 103 mainWidget.getQuickFilterWidget().setEnabled( enabled ); 104 } 105 if ( mainWidget.getViewer() != null && !mainWidget.getViewer().getTree().isDisposed() ) 106 { 107 mainWidget.getViewer().getTree().setEnabled( enabled ); 108 } 109 } 110 } 111 112 113 116 public void dispose() 117 { 118 preferences = null; 119 mainWidget = null; 120 } 121 122 123 126 public Object [] getElements( Object inputElement ) 127 { 128 129 if ( inputElement != null && inputElement instanceof IEntry ) 130 { 131 IEntry entry = ( IEntry ) inputElement; 132 133 if ( !entry.isAttributesInitialized() && entry.isDirectoryEntry() ) 134 { 135 boolean soa = BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( 136 BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES ); 137 InitializeAttributesJob job = new InitializeAttributesJob( new IEntry[] 138 { entry }, soa ); 139 job.execute(); 140 return new Object [0]; 141 } 142 else 143 { 144 IAttribute[] attributes = entry.getAttributes(); 145 Object [] values = getValues( attributes ); 146 return values; 147 } 148 } 149 else if ( inputElement != null && inputElement instanceof AttributeHierarchy ) 150 { 151 AttributeHierarchy ah = ( AttributeHierarchy ) inputElement; 152 IAttribute[] attributes = ah.getAttributes(); 153 Object [] values = getValues( attributes ); 154 return values; 155 } 156 else 157 { 158 return new Object [0]; 159 } 160 } 161 162 163 170 private Object [] getValues( IAttribute[] attributes ) 171 { 172 List <Object > valueList = new ArrayList <Object >(); 173 for ( int i = 0; attributes != null && i < attributes.length; i++ ) 174 { 175 IValue[] values = attributes[i].getValues(); 176 if ( this.preferences == null || !this.preferences.isUseFolding() 177 || ( values.length <= this.preferences.getFoldingThreshold() ) ) 178 { 179 for ( int j = 0; j < values.length; j++ ) 180 { 181 valueList.add( values[j] ); 182 } 183 } 184 else 185 { 186 valueList.add( attributes[i] ); 188 } 189 } 190 return valueList.toArray(); 191 } 192 193 194 197 public Object [] getChildren( Object parentElement ) 198 { 199 if ( parentElement instanceof IAttribute ) 200 { 201 IAttribute attribute = ( IAttribute ) parentElement; 202 IValue[] values = attribute.getValues(); 203 return values; 204 } 205 return null; 206 } 207 208 209 212 public Object getParent( Object element ) 213 { 214 if ( element instanceof IValue ) 215 { 216 return ( ( IValue ) element ).getAttribute(); 217 } 218 return null; 219 } 220 221 222 225 public boolean hasChildren( Object element ) 226 { 227 return ( element instanceof IAttribute ); 228 } 229 230 } | Popular Tags |