1 20 21 package org.apache.directory.ldapstudio.browser.common.widgets.entryeditor; 22 23 24 import org.apache.directory.ldapstudio.browser.core.model.IValue; 25 import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException; 26 import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaUtils; 27 import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager; 28 import org.eclipse.jface.dialogs.MessageDialog; 29 import org.eclipse.jface.viewers.ICellModifier; 30 import org.eclipse.swt.widgets.Display; 31 import org.eclipse.swt.widgets.Item; 32 33 34 41 public class EntryEditorWidgetCellModifier implements ICellModifier 42 { 43 44 45 private ValueEditorManager valueEditorManager; 46 47 48 53 public EntryEditorWidgetCellModifier( ValueEditorManager valueEditorManager ) 54 { 55 this.valueEditorManager = valueEditorManager; 56 } 57 58 59 62 public void dispose() 63 { 64 valueEditorManager = null; 65 } 66 67 68 71 public boolean canModify( Object element, String property ) 72 { 73 if ( element != null && element instanceof IValue && valueEditorManager != null ) 74 { 75 IValue attributeValue = ( IValue ) element; 76 77 if ( !SchemaUtils.isModifyable( attributeValue.getAttribute().getAttributeTypeDescription() ) ) 78 { 79 return false; 80 } 81 if ( attributeValue.isRdnPart() ) 82 { 83 return false; 84 } 85 if ( EntryEditorWidgetTableMetadata.KEY_COLUMN_NAME.equals( property ) ) 86 { 87 return false; 88 } 89 if ( EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME.equals( property ) ) 90 { 91 return this.valueEditorManager.getCurrentValueEditor( attributeValue ).getRawValue( attributeValue ) != null; 92 } 93 } 94 95 return false; 96 } 97 98 99 102 public Object getValue( Object element, String property ) 103 { 104 if ( element != null && element instanceof IValue && valueEditorManager != null ) 105 { 106 IValue attributeValue = ( IValue ) element; 107 Object returnValue; 108 if ( EntryEditorWidgetTableMetadata.KEY_COLUMN_NAME.equals( property ) ) 109 { 110 returnValue = attributeValue.getAttribute().getDescription(); 111 } 112 else if ( EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME.equals( property ) ) 113 { 114 returnValue = this.valueEditorManager.getCurrentValueEditor( attributeValue ).getRawValue( 115 attributeValue ); 116 } 117 else 118 { 119 returnValue = ""; 120 } 121 return returnValue; 122 } 123 else 124 { 125 return null; 126 } 127 } 128 129 130 135 public void modify( Object element, String property, Object newRawValue ) 136 { 137 if ( element != null && element instanceof Item ) 138 { 139 element = ( ( Item ) element ).getData(); 140 } 141 142 if ( element != null && element instanceof IValue && valueEditorManager != null ) 143 { 144 IValue attributeValue = ( IValue ) element; 145 146 if ( EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME.equals( property ) ) 147 { 148 try 149 { 150 this.valueEditorManager.getCurrentValueEditor( attributeValue ).modifyValue( attributeValue, 151 newRawValue ); 152 } 153 catch ( ModelModificationException mme ) 154 { 155 MessageDialog.openError( Display.getDefault().getActiveShell(), "Error While Modifying Value", mme 156 .getMessage() ); 157 } 158 } 159 } 160 } 161 162 } 163 | Popular Tags |