1 20 21 package org.apache.directory.ldapstudio.valueeditors.dn; 22 23 24 import org.apache.directory.ldapstudio.browser.common.dialogs.TextDialog; 25 import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy; 26 import org.apache.directory.ldapstudio.browser.core.model.DN; 27 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 28 import org.apache.directory.ldapstudio.browser.core.model.IValue; 29 import org.apache.directory.ldapstudio.browser.core.model.NameException; 30 import org.apache.directory.ldapstudio.valueeditors.AbstractDialogStringValueEditor; 31 import org.eclipse.swt.widgets.Shell; 32 33 34 41 public class DnValueEditor extends AbstractDialogStringValueEditor 42 { 43 44 49 protected boolean openDialog( Shell shell ) 50 { 51 Object value = getValue(); 52 if ( value != null && value instanceof DnValueEditorRawValueWrapper ) 53 { 54 DnValueEditorRawValueWrapper wrapper = ( DnValueEditorRawValueWrapper ) value; 55 DN dn; 56 try 57 { 58 dn = new DN( wrapper.dn ); 59 } 60 catch ( NameException e ) 61 { 62 dn = null; 63 } 64 DnDialog dialog = new DnDialog( shell, wrapper.connection, dn ); 65 if ( dialog.open() == TextDialog.OK && dialog.getDn() != null ) 66 { 67 setValue( dialog.getDn().toString() ); 68 return true; 69 } 70 } 71 return false; 72 } 73 74 75 86 public Object getRawValue( AttributeHierarchy attributeHierarchy ) 87 { 88 if ( attributeHierarchy == null ) 89 { 90 return null; 91 } 92 else if ( attributeHierarchy.size() == 1 && attributeHierarchy.getAttribute().getValueSize() == 0 ) 93 { 94 IConnection connection = attributeHierarchy.getAttribute().getEntry().getConnection(); 95 return new DnValueEditorRawValueWrapper( connection, null ); 96 } 97 else if ( attributeHierarchy.size() == 1 && attributeHierarchy.getAttribute().getValueSize() == 1 ) 98 { 99 IConnection connection = attributeHierarchy.getAttribute().getEntry().getConnection(); 100 return new DnValueEditorRawValueWrapper( connection, getDisplayValue( attributeHierarchy ) ); 101 } 102 else 103 { 104 return null; 105 } 106 } 107 108 109 115 public Object getRawValue( IValue value ) 116 { 117 Object o = super.getRawValue( value ); 118 if ( o != null && o instanceof String ) 119 { 120 IConnection connection = value.getAttribute().getEntry().getConnection(); 121 return new DnValueEditorRawValueWrapper( connection, ( String ) o ); 122 } 123 124 return null; 125 } 126 127 128 134 public Object getRawValue( IConnection connection, Object value ) 135 { 136 Object o = super.getRawValue( connection, value ); 137 if ( o != null && o instanceof String ) 138 { 139 return new DnValueEditorRawValueWrapper( connection, ( String ) o ); 140 } 141 142 return null; 143 } 144 145 152 private class DnValueEditorRawValueWrapper 153 { 154 155 private IConnection connection; 156 157 158 private String dn; 159 160 161 167 private DnValueEditorRawValueWrapper( IConnection connection, String dn ) 168 { 169 this.connection = connection; 170 this.dn = dn; 171 } 172 173 174 177 public String toString() 178 { 179 return dn == null ? "" : dn; 180 } 181 182 } 183 184 } 185 | Popular Tags |