1 20 21 package org.apache.directory.ldapstudio.browser.common.dialogs.preferences; 22 23 24 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; 25 import org.apache.directory.ldapstudio.browser.core.model.schema.BinaryAttribute; 26 27 import org.eclipse.jface.dialogs.Dialog; 28 import org.eclipse.jface.dialogs.IDialogConstants; 29 import org.eclipse.swt.events.ModifyEvent; 30 import org.eclipse.swt.events.ModifyListener; 31 import org.eclipse.swt.widgets.Combo; 32 import org.eclipse.swt.widgets.Composite; 33 import org.eclipse.swt.widgets.Control; 34 import org.eclipse.swt.widgets.Shell; 35 36 37 public class AttributeDialog extends Dialog 38 { 39 40 private BinaryAttribute currentAttribute; 41 42 private String [] attributeTypesAndOids; 43 44 private BinaryAttribute returnAttribute; 45 46 private Combo typeOrOidCombo; 47 48 49 public AttributeDialog( Shell parentShell, BinaryAttribute currentAttribute, String [] attributeNamesAndOids ) 50 { 51 super( parentShell ); 52 this.currentAttribute = currentAttribute; 53 this.attributeTypesAndOids = attributeNamesAndOids; 54 55 this.returnAttribute = null; 56 } 57 58 59 protected void configureShell( Shell newShell ) 60 { 61 super.configureShell( newShell ); 62 newShell.setText( "Select Attribute Type or OID" ); 63 } 64 65 66 protected void okPressed() 67 { 68 this.returnAttribute = new BinaryAttribute( typeOrOidCombo.getText() ); 69 super.okPressed(); 70 } 71 72 73 protected Control createDialogArea( Composite parent ) 74 { 75 76 Composite composite = ( Composite ) super.createDialogArea( parent ); 77 78 Composite c = BaseWidgetUtils.createColumnContainer( composite, 2, 1 ); 79 BaseWidgetUtils.createLabel( c, "Attribute Type or OID:", 1 ); 80 this.typeOrOidCombo = BaseWidgetUtils.createCombo( c, this.attributeTypesAndOids, -1, 1 ); 81 if ( this.currentAttribute != null ) 82 { 83 this.typeOrOidCombo.setText( currentAttribute.getAttributeNumericOidOrName() ); 84 } 85 this.typeOrOidCombo.addModifyListener( new ModifyListener() 86 { 87 public void modifyText( ModifyEvent e ) 88 { 89 validate(); 90 } 91 } ); 92 93 return composite; 94 } 95 96 97 private void validate() 98 { 99 super.getButton( IDialogConstants.OK_ID ).setEnabled( !"".equals( this.typeOrOidCombo.getText() ) ); 100 } 101 102 103 public BinaryAttribute getAttribute() 104 { 105 return returnAttribute; 106 } 107 108 } 109 | Popular Tags |