1 20 21 package org.apache.directory.ldapstudio.browser.ui.dialogs.properties; 22 23 24 import java.util.Arrays ; 25 26 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; 27 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 28 import org.apache.directory.ldapstudio.browser.core.model.IValue; 29 import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription; 30 import org.apache.directory.ldapstudio.browser.core.utils.Utils; 31 32 import org.eclipse.core.runtime.IAdaptable; 33 import org.eclipse.swt.events.SelectionAdapter; 34 import org.eclipse.swt.events.SelectionEvent; 35 import org.eclipse.swt.widgets.Button; 36 import org.eclipse.swt.widgets.Composite; 37 import org.eclipse.swt.widgets.Control; 38 import org.eclipse.swt.widgets.Group; 39 import org.eclipse.swt.widgets.Text; 40 import org.eclipse.ui.IWorkbenchPropertyPage; 41 import org.eclipse.ui.dialogs.PropertyPage; 42 43 44 public class AttributePropertyPage extends PropertyPage implements IWorkbenchPropertyPage 45 { 46 47 private Text attributeNameText; 48 49 private Text attributeTypeText; 50 51 private Text attributeValuesText; 52 53 private Text attributeSizeText; 54 55 private Text atdOidText; 56 57 private Text atdNamesText; 58 59 private Text atdDescText; 60 61 private Text atdUsageText; 62 63 private Button singleValuedFlag; 64 65 private Button collectiveFlag; 66 67 private Button obsoleteFlag; 68 69 private Button noUserModificationFlag; 70 71 private Text equalityMatchingRuleText; 72 73 private Text substringMatchingRuleText; 74 75 private Text orderingMatchingRuleText; 76 77 private Text syntaxOidText; 78 79 private Text syntaxDescText; 80 81 private Text syntaxLengthText; 82 83 84 public AttributePropertyPage() 85 { 86 super(); 87 super.noDefaultAndApplyButton(); 88 } 89 90 91 protected Control createContents( Composite parent ) 92 { 93 94 Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); 95 96 Composite mainGroup = BaseWidgetUtils.createColumnContainer( composite, 2, 1 ); 97 98 BaseWidgetUtils.createLabel( mainGroup, "Description:", 1 ); 99 attributeNameText = BaseWidgetUtils.createLabeledText( mainGroup, "", 1 ); 100 101 BaseWidgetUtils.createLabel( mainGroup, "Type:", 1 ); 102 attributeTypeText = BaseWidgetUtils.createLabeledText( mainGroup, "", 1 ); 103 104 BaseWidgetUtils.createLabel( mainGroup, "Number of Values:", 1 ); 105 attributeValuesText = BaseWidgetUtils.createLabeledText( mainGroup, "", 1 ); 106 107 BaseWidgetUtils.createLabel( mainGroup, "Attribute Size:", 1 ); 108 attributeSizeText = BaseWidgetUtils.createLabeledText( mainGroup, "", 1 ); 109 110 Group atdGroup = BaseWidgetUtils.createGroup( composite, "Attribute Type", 1 ); 111 Composite atdComposite = BaseWidgetUtils.createColumnContainer( atdGroup, 2, 1 ); 112 113 BaseWidgetUtils.createLabel( atdComposite, "Numeric OID:", 1 ); 114 atdOidText = BaseWidgetUtils.createLabeledText( atdComposite, "", 1 ); 115 116 BaseWidgetUtils.createLabel( atdComposite, "Alternative Names:", 1 ); 117 atdNamesText = BaseWidgetUtils.createLabeledText( atdComposite, "", 1 ); 118 119 BaseWidgetUtils.createLabel( atdComposite, "Description:", 1 ); 120 atdDescText = BaseWidgetUtils.createWrappedLabeledText( atdComposite, "", 1 ); 121 122 BaseWidgetUtils.createLabel( atdComposite, "Usage:", 1 ); 123 atdUsageText = BaseWidgetUtils.createLabeledText( atdComposite, "", 1 ); 124 125 Group flagsGroup = BaseWidgetUtils.createGroup( composite, "Flags", 1 ); 126 Composite flagsComposite = BaseWidgetUtils.createColumnContainer( flagsGroup, 4, 1 ); 127 128 singleValuedFlag = BaseWidgetUtils.createCheckbox( flagsComposite, "Single valued", 1 ); 129 singleValuedFlag.addSelectionListener( new SelectionAdapter() 130 { 131 public void widgetSelected( SelectionEvent e ) 132 { 133 singleValuedFlag.setSelection( !singleValuedFlag.getSelection() ); 134 } 135 } ); 136 137 noUserModificationFlag = BaseWidgetUtils.createCheckbox( flagsComposite, "Read only", 1 ); 138 noUserModificationFlag.addSelectionListener( new SelectionAdapter() 139 { 140 public void widgetSelected( SelectionEvent e ) 141 { 142 noUserModificationFlag.setSelection( !noUserModificationFlag.getSelection() ); 143 } 144 } ); 145 146 collectiveFlag = BaseWidgetUtils.createCheckbox( flagsComposite, "Collective", 1 ); 147 collectiveFlag.addSelectionListener( new SelectionAdapter() 148 { 149 public void widgetSelected( SelectionEvent e ) 150 { 151 collectiveFlag.setSelection( !collectiveFlag.getSelection() ); 152 } 153 } ); 154 155 obsoleteFlag = BaseWidgetUtils.createCheckbox( flagsComposite, "Obsolete", 1 ); 156 obsoleteFlag.addSelectionListener( new SelectionAdapter() 157 { 158 public void widgetSelected( SelectionEvent e ) 159 { 160 obsoleteFlag.setSelection( !obsoleteFlag.getSelection() ); 161 } 162 } ); 163 164 Group syntaxGroup = BaseWidgetUtils.createGroup( composite, "Syntax", 1 ); 165 Composite syntaxComposite = BaseWidgetUtils.createColumnContainer( syntaxGroup, 2, 1 ); 166 167 BaseWidgetUtils.createLabel( syntaxComposite, "Syntax OID:", 1 ); 168 syntaxOidText = BaseWidgetUtils.createLabeledText( syntaxComposite, "", 1 ); 169 170 BaseWidgetUtils.createLabel( syntaxComposite, "Syntax Description:", 1 ); 171 syntaxDescText = BaseWidgetUtils.createLabeledText( syntaxComposite, "", 1 ); 172 173 BaseWidgetUtils.createLabel( syntaxComposite, "Syntax Length:", 1 ); 174 syntaxLengthText = BaseWidgetUtils.createLabeledText( syntaxComposite, "", 1 ); 175 176 Group matchingGroup = BaseWidgetUtils.createGroup( composite, "Matching Rules", 1 ); 177 Composite matchingComposite = BaseWidgetUtils.createColumnContainer( matchingGroup, 2, 1 ); 178 179 BaseWidgetUtils.createLabel( matchingComposite, "Equality Match:", 1 ); 180 equalityMatchingRuleText = BaseWidgetUtils.createLabeledText( matchingComposite, "", 1 ); 181 182 BaseWidgetUtils.createLabel( matchingComposite, "Substring Match:", 1 ); 183 substringMatchingRuleText = BaseWidgetUtils.createLabeledText( matchingComposite, "", 1 ); 184 185 BaseWidgetUtils.createLabel( matchingComposite, "Ordering Match:", 1 ); 186 orderingMatchingRuleText = BaseWidgetUtils.createLabeledText( matchingComposite, "", 1 ); 187 188 IAttribute attribute = getAttribute( getElement() ); 189 if ( attribute != null ) 190 { 191 192 int bytes = 0; 193 int valCount = 0; 194 IValue[] allValues = attribute.getValues(); 195 for ( int valIndex = 0; valIndex < allValues.length; valIndex++ ) 196 { 197 if ( !allValues[valIndex].isEmpty() ) 198 { 199 valCount++; 200 bytes += allValues[valIndex].getBinaryValue().length; 201 } 202 } 203 204 this.setMessage( "Attribute " + attribute.getDescription() ); 205 attributeNameText.setText( attribute.getDescription() ); 206 attributeTypeText.setText( attribute.isString() ? "String" : "Binary" ); 207 attributeValuesText.setText( "" + valCount ); 208 attributeSizeText.setText( Utils.formatBytes( bytes ) ); 209 210 if ( attribute.getEntry().getConnection().getSchema().hasAttributeTypeDescription( 211 attribute.getDescription() ) ) 212 { 213 AttributeTypeDescription atd = attribute.getEntry().getConnection().getSchema() 214 .getAttributeTypeDescription( attribute.getDescription() ); 215 216 atdOidText.setText( atd.getNumericOID() ); 217 String atdNames = Arrays.asList( atd.getNames() ).toString(); 218 atdNamesText.setText( atdNames.substring( 1, atdNames.length() - 1 ) ); 219 atdDescText.setText( Utils.getNonNullString( atd.getDesc() ) ); 220 atdUsageText.setText( Utils.getNonNullString( atd.getUsage() ) ); 221 222 singleValuedFlag.setSelection( atd.isSingleValued() ); 223 noUserModificationFlag.setSelection( atd.isNoUserModification() ); 224 collectiveFlag.setSelection( atd.isCollective() ); 225 obsoleteFlag.setSelection( atd.isObsolete() ); 226 227 syntaxOidText.setText( Utils.getNonNullString( atd.getSyntaxDescriptionNumericOIDTransitive() ) ); 228 syntaxDescText.setText( Utils.getNonNullString( atd.getSyntaxDescription().getDesc() ) ); 229 syntaxLengthText.setText( Utils.getNonNullString( atd.getSyntaxDescriptionLengthTransitive() ) ); 230 231 equalityMatchingRuleText.setText( Utils.getNonNullString( atd 232 .getEqualityMatchingRuleDescriptionOIDTransitive() ) ); 233 substringMatchingRuleText.setText( Utils.getNonNullString( atd 234 .getSubstringMatchingRuleDescriptionOIDTransitive() ) ); 235 orderingMatchingRuleText.setText( Utils.getNonNullString( atd 236 .getOrderingMatchingRuleDescriptionOIDTransitive() ) ); 237 } 238 } 239 240 return parent; 241 } 242 243 244 private static IAttribute getAttribute( Object element ) 245 { 246 IAttribute attribute = null; 247 if ( element instanceof IAdaptable ) 248 { 249 attribute = ( IAttribute ) ( ( IAdaptable ) element ).getAdapter( IAttribute.class ); 250 } 251 return attribute; 252 } 253 254 } 255 | Popular Tags |