1 20 21 package org.apache.directory.ldapstudio.browser.common.dialogs.preferences; 22 23 24 import java.util.Iterator ; 25 import java.util.SortedMap ; 26 import java.util.TreeMap ; 27 28 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; 29 import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeValueProviderRelation; 30 import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager.ValueEditorExtension; 31 import org.eclipse.jface.dialogs.Dialog; 32 import org.eclipse.jface.dialogs.IDialogConstants; 33 import org.eclipse.swt.events.ModifyEvent; 34 import org.eclipse.swt.events.ModifyListener; 35 import org.eclipse.swt.widgets.Combo; 36 import org.eclipse.swt.widgets.Composite; 37 import org.eclipse.swt.widgets.Control; 38 import org.eclipse.swt.widgets.Shell; 39 40 41 public class AttributeValueEditorDialog extends Dialog 42 { 43 44 private AttributeValueProviderRelation relation; 45 46 private SortedMap <String , ValueEditorExtension> class2ValueEditorProxyMap; 47 48 private String [] attributeTypesAndOids; 49 50 private SortedMap <String , String > vpName2classMap; 51 52 private AttributeValueProviderRelation returnRelation; 53 54 private Combo typeOrOidCombo; 55 56 private Combo valueEditorCombo; 57 58 59 public AttributeValueEditorDialog( Shell parentShell, AttributeValueProviderRelation relation, 60 SortedMap <String , ValueEditorExtension> class2ValueEditorProxyMap, String [] attributeTypesAndOids ) 61 { 62 super( parentShell ); 63 this.relation = relation; 64 this.class2ValueEditorProxyMap = class2ValueEditorProxyMap; 65 this.attributeTypesAndOids = attributeTypesAndOids; 66 67 this.returnRelation = null; 68 69 this.vpName2classMap = new TreeMap <String , String >(); 70 for ( Iterator <ValueEditorExtension> it = this.class2ValueEditorProxyMap.values().iterator(); it.hasNext(); ) 71 { 72 ValueEditorExtension vp = it.next(); 73 vpName2classMap.put( vp.name, vp.className ); 74 } 75 } 76 77 78 protected void configureShell( Shell newShell ) 79 { 80 super.configureShell( newShell ); 81 newShell.setText( "Attribute Value Editor" ); 82 } 83 84 85 protected void okPressed() 86 { 87 this.returnRelation = new AttributeValueProviderRelation( this.typeOrOidCombo.getText(), this.vpName2classMap 88 .get( this.valueEditorCombo.getText() ) ); 89 super.okPressed(); 90 } 91 92 93 protected Control createDialogArea( Composite parent ) 94 { 95 96 Composite composite = ( Composite ) super.createDialogArea( parent ); 97 98 Composite c = BaseWidgetUtils.createColumnContainer( composite, 2, 1 ); 99 BaseWidgetUtils.createLabel( c, "Attribute Type or OID:", 1 ); 100 this.typeOrOidCombo = BaseWidgetUtils.createCombo( c, this.attributeTypesAndOids, -1, 1 ); 101 if ( this.relation != null && this.relation.getAttributeNumericOidOrType() != null ) 102 { 103 this.typeOrOidCombo.setText( this.relation.getAttributeNumericOidOrType() ); 104 } 105 this.typeOrOidCombo.addModifyListener( new ModifyListener() 106 { 107 public void modifyText( ModifyEvent e ) 108 { 109 validate(); 110 } 111 } ); 112 113 BaseWidgetUtils.createLabel( c, "Value Editor:", 1 ); 114 this.valueEditorCombo = BaseWidgetUtils.createReadonlyCombo( c, vpName2classMap.keySet() 115 .toArray( new String [0] ), -1, 1 ); 116 if ( this.relation != null && this.relation.getValueProviderClassname() != null 117 && this.class2ValueEditorProxyMap.containsKey( this.relation.getValueProviderClassname() ) ) 118 { 119 this.valueEditorCombo.setText( ( this.class2ValueEditorProxyMap.get( this.relation 120 .getValueProviderClassname() ) ).name ); 121 } 122 this.valueEditorCombo.addModifyListener( new ModifyListener() 123 { 124 public void modifyText( ModifyEvent e ) 125 { 126 validate(); 127 } 128 } ); 129 130 return composite; 131 } 132 133 134 private void validate() 135 { 136 super.getButton( IDialogConstants.OK_ID ).setEnabled( 137 !"".equals( this.valueEditorCombo.getText() ) && !"".equals( this.typeOrOidCombo.getText() ) ); 138 } 139 140 141 public AttributeValueProviderRelation getRelation() 142 { 143 return returnRelation; 144 } 145 146 } 147 | Popular Tags |