| Tableviewer with databinding and inline edit support for boolean [message #328226] | 
Mon, 19 May 2008 09:32   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: lukas.myslivec.com 
 
Hello, 
 
my tableviewer is bound to a collection (like in the jface databinding  
snippet). 
 
i want to add in line edit support. it works great for text ( i have done  
it like the example in Snippet013TableViewerEditing ). 
 
now i want to do the same with booleans. when the user clicks the cell it  
should change from true to false (an the other why). 
 
i tryed it the following way: 
 
public class InlineCheckboxEditingSupport extends  
ObservableValueEditingSupport 
{ 
  private CellEditor cellEditor; 
  private String propertyName; 
   
  /** 
   * @param viewer 
   * @param dbc 
   */ 
  public InlineCheckboxEditingSupport(ColumnViewer viewer,  
DataBindingContext dbc, String propertyName) 
  { 
    super(viewer, dbc); 
    cellEditor = new CheckboxCellEditor((Composite) viewer.getControl()); 
    this.propertyName = propertyName; 
  } 
 
  protected CellEditor getCellEditor(Object element) 
  { 
    return cellEditor; 
  } 
 
  protected IObservableValue doCreateCellEditorObservable(CellEditor  
cellEditor) 
  { 
    return SWTObservables.observeSelection(cellEditor.getControl()); 
  } 
 
  protected IObservableValue doCreateElementObservable(Object element,  
ViewerCell cell) 
  { 
    return BeansObservables.observeValue(element, propertyName); 
  } 
} 
 
But this fails because checkboxcelleditor doesnt provide a control. 
 
any suggestions? 
 
reagards 
lukas
 |  
 |  
  | 
 | 
 | 
 | 
| Re: Tableviewer with databinding and inline edit support for boolean [message #328251 is a reply to message #328250] | 
Tue, 20 May 2008 04:53   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Hi Lukas, 
 
Could you file a bug against this snippet under Platform/UI and CC me.  
I'll then take care that the bug is fixed. 
 
Tom 
 
lukas schrieb: 
> Hello, 
>  
> thank you very much (booth of you). 
>  
> the BooleanCellEditor works greate. i only had to modify the if  
> statement in deactivate method otherwise the cell gets empty if i am  
> changing the checkbox to the origin value (like from true to false to  
> true). 
>  
> regards 
> lukas 
>  
> public class BooleanCellEditor extends CellEditor 
> { 
>  private Button    button; 
>  private ViewerRow row; 
>  private int       index; 
>  private String    restoredText; 
>  private Image     restoredImage; 
>  private Boolean   oldValue; 
>  
>  /** 
>   * @param parent 
>   */ 
>  public BooleanCellEditor(Composite parent) 
>  { 
>    super(parent); 
>  } 
>  
>  /** 
>   * @param parent 
>   * @param style 
>   */ 
>  public BooleanCellEditor(Composite parent, int style) 
>  { 
>    super(parent, style); 
>  } 
>  
>  public LayoutData getLayoutData() 
>  { 
>    LayoutData data = super.getLayoutData(); 
>    data.horizontalAlignment = SWT.CENTER; 
>    data.grabHorizontal = false; 
>    return data; 
>  } 
>  
>  protected Control createControl(Composite parent) 
>  { 
>    Font font = parent.getFont(); 
>    Color bg = parent.getBackground(); 
>    button = new Button(parent, getStyle() | SWT.CHECK); 
>    button.setFont(font); 
>    button.setBackground(bg); 
>    button.addKeyListener(new KeyAdapter() 
>    { 
>      /* 
>       * (non-Javadoc) 
>       *       * @see  
>  org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.sw t.events.KeyEvent)  
>  
>       */ 
>      public void keyReleased(KeyEvent e) 
>      { 
>        if (e.character == SWT.ESC) 
>        { 
>          fireCancelEditor(); 
>        } 
>      } 
>    }); 
>    return button; 
>  } 
>  
>  protected Object doGetValue() 
>  { 
>    return new Boolean(button.getSelection()); 
>  } 
>  
>  protected void doSetValue(Object value) 
>  { 
>    boolean selection = Boolean.TRUE.equals(value); 
>    button.setSelection(selection); 
>  } 
>  
>  protected void doSetFocus() 
>  { 
>    if (button != null) 
>    { 
>      button.setFocus(); 
>    } 
>  } 
>  
>  protected void deactivate(ColumnViewerEditorDeactivationEvent event) 
>  { 
>    super.deactivate(event); 
>    if (event.eventType ==  
> ColumnViewerEditorDeactivationEvent.EDITOR_CANCELED 
>        || oldValue == button.getSelection())    { 
>      row.setImage(index, restoredImage); 
>      row.setText(index, restoredText); 
>    } 
>    row = null; 
>    restoredImage = null; 
>    restoredText = null; 
>  } 
>  
>  public void activate(ColumnViewerEditorActivationEvent activationEvent) 
>  { 
>    ViewerCell cell = (ViewerCell) activationEvent.getSource(); 
>    index = cell.getColumnIndex(); 
>    row = (ViewerRow) cell.getViewerRow().clone(); 
>    restoredImage = row.getImage(index); 
>    restoredText = row.getText(index); 
>    row.setImage(index, null); 
>    row.setText(index, ""); //$NON-NLS-1$ 
>    super.activate(activationEvent); 
>    oldValue = button.getSelection(); 
>  } 
>  
>  /* 
>   * (non-Javadoc) 
>   *   * @see  org.eclipse.jface.viewers.CellEditor#getDoubleClickTimeout() 
>   */ 
>  protected int getDoubleClickTimeout() 
>  { 
>    return 0; 
>  } 
> } 
>  
 
 
--  
B e s t S o l u t i o n . at 
 ------------------------------------------------------------ -------- 
Tom Schindl                                          JFace-Committer 
 ------------------------------------------------------------ --------
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.13541 seconds