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 AttributeTypeAndValueValueEditor 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 AttributeTypeAndValueValueEditorRawValueWrapper ) 53 { 54 AttributeTypeAndValueValueEditorRawValueWrapper wrapper = ( AttributeTypeAndValueValueEditorRawValueWrapper ) value; 55 AttributeTypeAndValueDialog dialog = new AttributeTypeAndValueDialog( shell, wrapper.schema, 56 wrapper.attributeType, wrapper.value ); 57 if ( dialog.open() == TextDialog.OK && !EMPTY.equals( dialog.getAttributeType() ) 58 && !EMPTY.equals( dialog.getValue() ) ) 59 { 60 setValue( dialog.getAttributeType() + '=' + dialog.getValue() ); 61 return true; 62 } 63 } 64 return false; 65 } 66 67 68 73 public Object getRawValue( IValue value ) 74 { 75 return value != null ? getRawValue( value.getAttribute().getEntry().getConnection(), value.getStringValue() ) 76 : null; 77 } 78 79 80 85 public Object getRawValue( IConnection connection, Object value ) 86 { 87 Schema schema = null; 88 if ( connection != null ) 89 { 90 schema = connection.getSchema(); 91 } 92 if ( schema == null || value == null || !( value instanceof String ) ) 93 { 94 return null; 95 } 96 97 String atavValue = ( String ) value; 98 String [] atav = atavValue.split( "=", 2 ); String at = atav.length > 0 ? atav[0] : EMPTY; 100 String v = atav.length > 1 ? atav[1] : EMPTY; 101 AttributeTypeAndValueValueEditorRawValueWrapper wrapper = new AttributeTypeAndValueValueEditorRawValueWrapper( 102 schema, at, v ); 103 return wrapper; 104 } 105 106 113 private class AttributeTypeAndValueValueEditorRawValueWrapper 114 { 115 119 private Schema schema; 120 121 122 private String attributeType; 123 124 125 private String value; 126 127 128 135 private AttributeTypeAndValueValueEditorRawValueWrapper( Schema schema, String attributeType, String value ) 136 { 137 super(); 138 this.schema = schema; 139 this.attributeType = attributeType; 140 this.value = value; 141 } 142 } 143 144 } 145 | Popular Tags |