1 20 21 package org.apache.directory.ldapstudio.valueeditors; 22 23 24 import java.util.ArrayList ; 25 import java.util.Arrays ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 import org.apache.directory.ldapstudio.browser.common.dialogs.MultivaluedDialog; 30 import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy; 31 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 32 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 33 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 34 import org.apache.directory.ldapstudio.browser.core.model.IValue; 35 import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException; 36 import org.eclipse.jface.resource.ImageDescriptor; 37 import org.eclipse.jface.viewers.CellEditor; 38 import org.eclipse.swt.widgets.Composite; 39 import org.eclipse.swt.widgets.Control; 40 41 42 48 public class MultivaluedValueEditor extends CellEditor implements IValueEditor 49 { 50 51 52 private Object value; 53 54 55 private Composite parent; 56 57 58 private String name; 59 60 61 private ImageDescriptor imageDescriptor; 62 63 64 protected ValueEditorManager valueEditorManager; 65 66 67 74 public MultivaluedValueEditor( Composite parent, ValueEditorManager valueEditorManager ) 75 { 76 super( parent ); 77 this.parent = parent; 78 this.valueEditorManager = valueEditorManager; 79 } 80 81 82 87 protected Control createControl( Composite parent ) 88 { 89 return null; 90 } 91 92 93 98 protected final Object doGetValue() 99 { 100 return this.value; 101 } 102 103 104 109 protected void doSetFocus() 110 { 111 } 112 113 114 119 protected void doSetValue( Object value ) 120 { 121 this.value = value; 122 } 123 124 125 131 public void activate() 132 { 133 if ( this.getValue() != null && this.getValue() instanceof AttributeHierarchy ) 134 { 135 AttributeHierarchy ah = ( AttributeHierarchy ) this.getValue(); 136 if ( ah != null ) 137 { 138 MultivaluedDialog dialog = new MultivaluedDialog( this.parent.getShell(), ah ); 139 dialog.open(); 140 } 141 } 142 143 fireCancelEditor(); 144 } 145 146 147 152 public CellEditor getCellEditor() 153 { 154 return this; 155 } 156 157 158 164 public String getDisplayValue( AttributeHierarchy attributeHierarchy ) 165 { 166 167 List <IValue> valueList = new ArrayList <IValue>(); 168 for ( Iterator it = attributeHierarchy.iterator(); it.hasNext(); ) 169 { 170 IAttribute attribute = ( IAttribute ) it.next(); 171 valueList.addAll( Arrays.asList( attribute.getValues() ) ); 172 } 173 174 StringBuffer sb = new StringBuffer (); 175 if ( valueList.size() > 1 ) 176 sb.append( valueList.size() + " values: " ); 177 for ( Iterator it = valueList.iterator(); it.hasNext(); ) 178 { 179 IValue value = ( IValue ) it.next(); 180 IValueEditor vp = this.valueEditorManager.getCurrentValueEditor( value ); 181 sb.append( vp.getDisplayValue( value ) ); 182 if ( it.hasNext() ) 183 sb.append( ", " ); 184 } 185 return sb.toString(); 186 } 187 188 189 195 public String getDisplayValue( IValue value ) 196 { 197 return ""; 198 } 199 200 201 206 public Object getRawValue( AttributeHierarchy attributeHierarchy ) 207 { 208 return attributeHierarchy; 209 } 210 211 212 218 public Object getRawValue( IValue value ) 219 { 220 return null; 221 } 222 223 224 230 public Object getRawValue( IConnection connection, Object value ) 231 { 232 return null; 233 } 234 235 236 241 public void modifyValue( IValue oldValue, Object newRawValue ) throws ModelModificationException 242 { 243 } 244 245 246 251 public void createValue( IEntry entry, String attributeName, Object newRawValue ) throws ModelModificationException 252 { 253 } 254 255 256 261 public void deleteAttribute( AttributeHierarchy ah ) throws ModelModificationException 262 { 263 } 264 265 266 271 public void deleteValue( IValue oldValue ) throws ModelModificationException 272 { 273 } 274 275 276 282 public Object getStringOrBinaryValue( Object rawValue ) 283 { 284 return null; 285 } 286 287 288 291 public void setValueEditorName( String name ) 292 { 293 this.name = name; 294 } 295 296 297 300 public String getValueEditorName() 301 { 302 return name; 303 } 304 305 306 309 public void setValueEditorImageDescriptor( ImageDescriptor imageDescriptor ) 310 { 311 this.imageDescriptor = imageDescriptor; 312 } 313 314 315 318 public ImageDescriptor getValueEditorImageDescriptor() 319 { 320 return imageDescriptor; 321 } 322 323 } 324 | Popular Tags |