1 20 21 package org.apache.directory.ldapstudio.aciitemeditor.valueeditors; 22 23 24 import org.apache.directory.ldapstudio.browser.common.dialogs.TextDialog; 25 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 26 import org.apache.directory.ldapstudio.browser.core.model.IValue; 27 import org.apache.directory.ldapstudio.browser.core.model.schema.Schema; 28 import org.apache.directory.ldapstudio.valueeditors.AbstractDialogStringValueEditor; 29 import org.eclipse.swt.widgets.Shell; 30 31 32 38 public class AttributeTypeValueEditor extends AbstractDialogStringValueEditor 39 { 40 41 private static final String EMPTY = ""; 43 44 49 public boolean openDialog( Shell shell ) 50 { 51 Object value = getValue(); 52 if ( value != null && value instanceof AttributeTypeValueEditorRawValueWrapper ) 53 { 54 AttributeTypeValueEditorRawValueWrapper wrapper = ( AttributeTypeValueEditorRawValueWrapper ) value; 55 AttributeTypeDialog dialog = new AttributeTypeDialog( shell, wrapper.schema, wrapper.attributeType ); 56 if ( dialog.open() == TextDialog.OK && !EMPTY.equals( dialog.getAttributeType() ) ) 57 { 58 setValue( dialog.getAttributeType() ); 59 return true; 60 } 61 } 62 return false; 63 } 64 65 66 71 public Object getRawValue( IValue value ) 72 { 73 return value != null ? getRawValue( value.getAttribute().getEntry().getConnection(), value.getStringValue() ) 74 : null; 75 } 76 77 78 83 public Object getRawValue( IConnection connection, Object value ) 84 { 85 Schema schema = null; 86 if ( connection != null ) 87 { 88 schema = connection.getSchema(); 89 } 90 if ( schema == null || value == null || !( value instanceof String ) ) 91 { 92 return null; 93 } 94 95 String atValue = ( String ) value; 96 AttributeTypeValueEditorRawValueWrapper wrapper = new AttributeTypeValueEditorRawValueWrapper( schema, atValue ); 97 return wrapper; 98 } 99 100 107 private class AttributeTypeValueEditorRawValueWrapper 108 { 109 113 private Schema schema; 114 115 116 private String attributeType; 117 118 119 125 private AttributeTypeValueEditorRawValueWrapper( Schema schema, String attributeType ) 126 { 127 super(); 128 this.schema = schema; 129 this.attributeType = attributeType; 130 } 131 } 132 133 } 134 | Popular Tags |