1 20 21 package org.apache.directory.ldapstudio.browser.ui.dialogs.properties; 22 23 24 import org.apache.directory.ldapstudio.browser.common.jobs.RunnableContextJobAdapter; 25 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; 26 import org.apache.directory.ldapstudio.browser.core.events.EntryModificationEvent; 27 import org.apache.directory.ldapstudio.browser.core.jobs.InitializeAttributesJob; 28 import org.apache.directory.ldapstudio.browser.core.jobs.InitializeChildrenJob; 29 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 30 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 31 import org.apache.directory.ldapstudio.browser.core.model.IValue; 32 import org.apache.directory.ldapstudio.browser.core.utils.Utils; 33 34 import org.eclipse.core.runtime.IAdaptable; 35 import org.eclipse.swt.SWT; 36 import org.eclipse.swt.events.SelectionEvent; 37 import org.eclipse.swt.events.SelectionListener; 38 import org.eclipse.swt.layout.GridData; 39 import org.eclipse.swt.widgets.Button; 40 import org.eclipse.swt.widgets.Composite; 41 import org.eclipse.swt.widgets.Control; 42 import org.eclipse.swt.widgets.Group; 43 import org.eclipse.swt.widgets.Text; 44 import org.eclipse.ui.IWorkbenchPropertyPage; 45 import org.eclipse.ui.dialogs.PropertyPage; 46 47 48 public class EntryPropertyPage extends PropertyPage implements IWorkbenchPropertyPage 49 { 50 51 private Text dnText; 52 53 private Text urlText; 54 55 private Text ctText; 56 57 private Text cnText; 58 59 private Text mtText; 60 61 private Text mnText; 62 63 private Button reloadCmiButton; 64 65 private Text sizeText; 66 67 private Text childrenText; 68 69 private Text attributesText; 70 71 private Text valuesText; 72 73 private Button includeOperationalAttributesButton; 74 75 private Button reloadEntryButton; 76 77 78 public EntryPropertyPage() 79 { 80 super(); 81 super.noDefaultAndApplyButton(); 82 } 83 84 85 protected Control createContents( Composite parent ) 86 { 87 88 Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); 89 90 Composite mainGroup = BaseWidgetUtils.createColumnContainer( BaseWidgetUtils.createColumnContainer( composite, 91 1, 1 ), 2, 1 ); 92 BaseWidgetUtils.createLabel( mainGroup, "DN:", 1 ); 93 dnText = BaseWidgetUtils.createWrappedLabeledText( mainGroup, "", 1 ); 94 BaseWidgetUtils.createLabel( mainGroup, "URL:", 1 ); 95 urlText = BaseWidgetUtils.createWrappedLabeledText( mainGroup, "", 1 ); 96 97 Group cmiGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ), 98 "Create and Modify Information", 1 ); 99 Composite cmiComposite = BaseWidgetUtils.createColumnContainer( cmiGroup, 3, 1 ); 100 101 BaseWidgetUtils.createLabel( cmiComposite, "Create Timestamp:", 1 ); 102 ctText = BaseWidgetUtils.createLabeledText( cmiComposite, "", 2 ); 103 104 BaseWidgetUtils.createLabel( cmiComposite, "Creators Name:", 1 ); 105 cnText = BaseWidgetUtils.createLabeledText( cmiComposite, "", 2 ); 106 107 BaseWidgetUtils.createLabel( cmiComposite, "Modify Timestamp:", 1 ); 108 mtText = BaseWidgetUtils.createLabeledText( cmiComposite, "", 2 ); 109 110 BaseWidgetUtils.createLabel( cmiComposite, "Modifiers Name:", 1 ); 111 mnText = BaseWidgetUtils.createLabeledText( cmiComposite, "", 1 ); 112 113 reloadCmiButton = BaseWidgetUtils.createButton( cmiComposite, "", 1 ); 114 GridData gd = new GridData(); 115 gd.verticalAlignment = SWT.BOTTOM; 116 gd.horizontalAlignment = SWT.RIGHT; 117 reloadCmiButton.setLayoutData( gd ); 118 reloadCmiButton.addSelectionListener( new SelectionListener() 119 { 120 public void widgetSelected( SelectionEvent e ) 121 { 122 reloadOperationalAttributes(); 123 } 124 125 126 public void widgetDefaultSelected( SelectionEvent e ) 127 { 128 } 129 } ); 130 131 Group sizingGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ), 132 "Sizing Information", 1 ); 133 Composite sizingComposite = BaseWidgetUtils.createColumnContainer( sizingGroup, 3, 1 ); 134 135 BaseWidgetUtils.createLabel( sizingComposite, "Entry Size:", 1 ); 136 sizeText = BaseWidgetUtils.createLabeledText( sizingComposite, "", 2 ); 137 138 BaseWidgetUtils.createLabel( sizingComposite, "Number of Children:", 1 ); 139 childrenText = BaseWidgetUtils.createLabeledText( sizingComposite, "", 2 ); 140 141 BaseWidgetUtils.createLabel( sizingComposite, "Number of Attributes:", 1 ); 142 attributesText = BaseWidgetUtils.createLabeledText( sizingComposite, "", 2 ); 143 144 BaseWidgetUtils.createLabel( sizingComposite, "Number of Values:", 1 ); 145 valuesText = BaseWidgetUtils.createLabeledText( sizingComposite, "", 2 ); 146 147 includeOperationalAttributesButton = BaseWidgetUtils.createCheckbox( sizingComposite, 148 "Include operational attributes", 2 ); 149 includeOperationalAttributesButton.addSelectionListener( new SelectionListener() 150 { 151 public void widgetSelected( SelectionEvent e ) 152 { 153 entryUpdated( getEntry( getElement() ) ); 154 } 155 156 157 public void widgetDefaultSelected( SelectionEvent e ) 158 { 159 } 160 } ); 161 162 reloadEntryButton = BaseWidgetUtils.createButton( sizingComposite, "", 1 ); 163 gd = new GridData(); 164 gd.verticalAlignment = SWT.BOTTOM; 165 gd.horizontalAlignment = SWT.RIGHT; 166 reloadEntryButton.setLayoutData( gd ); 167 reloadEntryButton.addSelectionListener( new SelectionListener() 168 { 169 public void widgetSelected( SelectionEvent e ) 170 { 171 reloadEntry(); 172 } 173 174 175 public void widgetDefaultSelected( SelectionEvent e ) 176 { 177 } 178 } ); 179 180 this.entryUpdated( getEntry( getElement() ) ); 181 182 return composite; 183 } 184 185 186 private void reloadOperationalAttributes() 187 { 188 IEntry entry = EntryPropertyPage.getEntry( getElement() ); 189 InitializeAttributesJob job = new InitializeAttributesJob( new IEntry[] 190 { entry }, true ); 191 RunnableContextJobAdapter.execute( job ); 192 193 this.entryUpdated( entry ); 194 } 195 196 197 private void reloadEntry() 198 { 199 IEntry entry = EntryPropertyPage.getEntry( getElement() ); 200 InitializeChildrenJob job1 = new InitializeChildrenJob( new IEntry[] 201 { entry } ); 202 InitializeAttributesJob job2 = new InitializeAttributesJob( new IEntry[] 203 { entry }, true ); 204 RunnableContextJobAdapter.execute( job1 ); 205 RunnableContextJobAdapter.execute( job2 ); 206 this.entryUpdated( entry ); 207 } 208 209 210 static IEntry getEntry( Object element ) 211 { 212 IEntry entry = null; 213 if ( element instanceof IAdaptable ) 214 { 215 entry = ( IEntry ) ( ( IAdaptable ) element ).getAdapter( IEntry.class ); 216 } 217 return entry; 218 } 219 220 221 public boolean isDisposed() 222 { 223 return this.dnText.isDisposed(); 224 } 225 226 227 public void entryUpdated( EntryModificationEvent event ) 228 { 229 this.entryUpdated( event.getModifiedEntry() ); 230 } 231 232 233 private String getNonNullStringValue( IAttribute att ) 234 { 235 String value = null; 236 if ( att != null ) 237 { 238 value = att.getStringValue(); 239 } 240 return value != null ? value : "-"; 241 } 242 243 244 private void entryUpdated( IEntry entry ) 245 { 246 247 if ( !this.dnText.isDisposed() ) 248 { 249 250 this.setMessage( "Entry " + entry.getDn() ); 251 252 this.dnText.setText( entry.getDn().toString() ); 253 this.urlText.setText( entry.getUrl().toString() ); 254 this.ctText.setText( getNonNullStringValue( entry 255 .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ) ) ); 256 this.cnText.setText( getNonNullStringValue( entry 257 .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_CREATORS_NAME ) ) ); 258 this.mtText.setText( getNonNullStringValue( entry 259 .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ) ) ); 260 this.mnText.setText( getNonNullStringValue( entry 261 .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFIERS_NAME ) ) ); 262 this.reloadCmiButton.setText( "Refresh" ); 263 264 int attCount = 0; 265 int valCount = 0; 266 int bytes = 0; 267 268 IAttribute[] allAttributes = entry.getAttributes(); 269 if ( allAttributes != null ) 270 { 271 for ( int attIndex = 0; attIndex < allAttributes.length; attIndex++ ) 272 { 273 if ( !allAttributes[attIndex].isOperationalAttribute() 274 || this.includeOperationalAttributesButton.getSelection() ) 275 { 276 attCount++; 277 IValue[] allValues = allAttributes[attIndex].getValues(); 278 for ( int valIndex = 0; valIndex < allValues.length; valIndex++ ) 279 { 280 if ( !allValues[valIndex].isEmpty() ) 281 { 282 valCount++; 283 bytes += allValues[valIndex].getBinaryValue().length; 284 } 285 } 286 } 287 } 288 } 289 290 this.reloadEntryButton.setText( "Refresh" ); 291 if ( !entry.isChildrenInitialized() ) 292 { 293 this.childrenText.setText( "Not checked" ); 294 } 295 else 296 { 297 this.childrenText.setText( "" + entry.getChildrenCount() 298 + ( entry.hasMoreChildren() ? " fetched, may have more" : "" ) ); 299 } 300 this.attributesText.setText( "" + attCount ); 301 this.valuesText.setText( "" + valCount ); 302 this.sizeText.setText( Utils.formatBytes( bytes ) ); 303 } 304 } 305 306 } 307 | Popular Tags |