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