Bug 233161 - [CellEditors] [Snippets] Bug in BooleanCellEditor when changing value back to origin
Summary: [CellEditors] [Snippets] Bug in BooleanCellEditor when changing value back to...
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-21 04:21 EDT by lukas myslivec CLA
Modified: 2019-09-06 15:36 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lukas myslivec CLA 2008-05-21 04:21:22 EDT
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/BooleanCellEditor.java?view=markup

When using the booleanCellEditor in combination with a databinding the cell gets empty if i am changing the checkbox to the origin value (like from true to false to true).

here is my code for fixing this problem:

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.swt.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;
  }
}
Comment 1 Thomas Schindl CLA 2008-05-21 12:13:28 EDT
That's me and this part of the Snippets who hold this class. I think Databinding does the right thing ;-)
Comment 2 Thomas Schindl CLA 2010-01-28 17:12:15 EST
multi change because of intenion of stepping back as platform-ui committer
Comment 3 Eclipse Webmaster CLA 2019-09-06 15:36:48 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.