Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 34819 - [CellEditors] DialogCellEditor incorrectly displayed in TableViewer - RC2 bug
Summary: [CellEditors] DialogCellEditor incorrectly displayed in TableViewer - RC2 bug
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.1.1   Edit
Hardware: PC All
: P2 normal with 1 vote (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Tod Creasey CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 39517 55485 59040 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-03-12 10:34 EST by Mike Evans CLA
Modified: 2005-02-16 16:04 EST (History)
13 users (show)

See Also:


Attachments
Another ugly Workaround (3.28 KB, text/plain)
2003-07-05 08:12 EDT, Andreas Stubenrauch CLA
no flags Details
Add a FocusListener which disposes of the button on loss of focus (8.06 KB, patch)
2004-03-25 08:20 EST, Abeer Bagul CLA
no flags Details | Diff
Proposed patch for cell bug (863 bytes, patch)
2004-04-08 16:58 EDT, Ines Khelifi CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Evans CLA 2003-03-12 10:34:04 EST
Bug appeared on migration from M4 to RC2 - Linux GTK platform, JDK 1.3.1

Table has 2 columns, multiple rows
column 0 : text display with TextCellEditor (arbitary text)
column 1 : text display with subclass of DialogCellEditor - opens a FileDialog

Steps:
1 - all rows/column have data set 
2 - select column 1 - DialogCellEditor displayed as expected
3 - do not change anything but immediately select column 0 - TextCellEditor
displays as expected
4 - then select column 0 of any other row
BUG : the original column 0 now displays the DialogCellEditor for its row.

Need sample code?  Could strip out with a bit of work.
Comment 1 Veronika Irvine CLA 2003-03-12 11:45:18 EST
Please provide sample code.
Comment 2 Veronika Irvine CLA 2003-03-13 07:08:11 EST
Sample code provided by Mike:

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnLayoutData;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.DialogCellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;

/**
 * Bug demo : 
 * 1 : Add the following to plugin.xml
 *    <extension
         point="org.eclipse.ui.editors">
      <editor
            name="BugDemo"
            icon="dummy.gif"
            extensions="bugdemo"
            class="BugDemo"
            id="BugDemo">
      </editor>
      </extension>
     2: compile and deploy this class
     3 : in runtime workspace, create empty (actually any) file 
ending '.bugdemo'.
     4 : 'open' the file - i.e. this editor
     5 : follow three steps given in displayed text.
     Regards, MikeE
 * @author mikee
 */
public class BugDemo extends EditorPart {

 private static final String COLUMN0 = "Text Column";
 private static final String COLUMN1 = "File Dialog Column";
 
 private TableViewer viewer;
 
 public BugDemo() {
  super();
  viewer = null;
 }

 public void doSave(IProgressMonitor monitor) {}

 public void doSaveAs() {}

 public void gotoMarker(IMarker marker) {}

 public void init(IEditorSite site, IEditorInput input) throws 
PartInitException {
  setSite( site );
  setInput( input );
 }

 public boolean isDirty() {
  return false;
 }

 public boolean isSaveAsAllowed() {
  return false;
 }

 public void createPartControl(Composite parent) {
  
  viewer = new TableViewer( parent, SWT.MULTI   | SWT.FULL_SELECTION);
  
  // table gui setup
  Table table = viewer.getTable();
  
  TableColumn column0 = new TableColumn( table, SWT.LEFT );
  column0.setText( COLUMN0 );
  ColumnLayoutData column0Data = new ColumnWeightData( 1, true );

  TableColumn column1 = new TableColumn( table, SWT.LEFT );
  column1.setText( COLUMN1 );
  ColumnLayoutData column1Data = new ColumnWeightData ( 1, true );
               
  TableLayout layout = new TableLayout();
  layout.addColumnData( column0Data );
  layout.addColumnData( column1Data );  

  table.setLayout( layout );
  table.setLinesVisible( true );
  table.setHeaderVisible( true );  
  
  // viewer setup
  viewer.setColumnProperties( new String[] { COLUMN0, COLUMN1 } );
  viewer.setContentProvider( new BugDemoContentProvider() );
  viewer.setCellModifier( new BugDemoCellModifier() );
  viewer.setLabelProvider( new BugDemoLabelProvider() );
  
  // crucially for bug demo  - cell editors
  CellEditor editor0 = new TextCellEditor( table );
  CellEditor editor1 = new FileSelectCellEditor( table );
  viewer.setCellEditors( new CellEditor[]{ editor0, editor1 } );
  
  viewer.setInput( new Object() );
 }

 public void setFocus() {
  viewer.getTable().setFocus();
 }
 
 
 /* private subclass of DialogCellEditor - the one of interest in bug */
 private class FileSelectCellEditor extends DialogCellEditor {
  private FileSelectCellEditor(Composite parent) { super(parent); }
  protected Object openDialogBox(Control cellEditorWindow) { return null; }
 }


 /* private boilerplate classes */
 
 // content provider
 private class BugDemoContentProvider implements IStructuredContentProvider {
  public void dispose() {}
  public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
  public Object[] getElements(Object inputElement) {
   return new RowData[] { 
    new RowData( "click here second", "click here first"),
    new RowData( "click here third - when you do look at the value above", 
            "do not click here") };
  }
 }
 
 // model row
 private class RowData {
  public String column0Value;
  public String column1Value;
  RowData( String val0, String val1){
   column0Value = val0;
   column1Value = val1;
  }
 }
 
 // cell modifier
 private class BugDemoCellModifier implements ICellModifier {
  public boolean canModify(Object element, String property) { return true; }
  public void modify(Object element, String property, Object value) {}
  public Object getValue(Object element, String property) {
   if ( property.equals( COLUMN0) ){
    return ((RowData)element).column0Value;
   }
   else {
    return ((RowData)element).column1Value;
   }
  }
 }
 
 // label provider
 private class BugDemoLabelProvider extends LabelProvider
   implements ITableLabelProvider {
  public Image getColumnImage(Object element, int columnIndex) { return null; }
  public String getColumnText(Object element, int columnIndex) {
   if ( columnIndex == 0 ) {
    return ((RowData)element).column0Value;
   }
   else {
    return ((RowData)element).column1Value;
   }
  }
 }

}
Comment 3 Tobias Vogler CLA 2003-04-11 12:43:29 EDT
The same bug appears with Version 2.1 and Windows 2000
Comment 4 Emma Zhang CLA 2003-05-15 12:15:28 EDT
Same here!
The problem is not shown in 2.0.1 but shown in 2.1.
I traced it in debug mode and seems the actions are like this:
1. select a DialogCellEditor A, this fires the MouseDown event on A
2. leave A by selecting another table column B without doing anything on A, 
this will fire another MouseDown event on B
3. after MouseDown event on B finish, in TableViewerImpl, it begin to run those 
deferred event, which is FocusLost on A, here, it calls applyEditorValue which 
actually apply editor A's value to B!
Comment 5 Genady Beryozkin CLA 2003-06-05 12:04:56 EDT
I think I have a solution for this bug (or it may be a solution to another bug 
which annoys me).

In my dialog editor (a subclass of DialogCellEditor) I have added the 
following code:

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.CellEditor#createControl
(org.eclipse.swt.widgets.Composite)
	 */
	protected Control createControl(Composite parent) {
		Control cont = super.createControl(parent);
		cont.addListener(SWT.Deactivate, new Listener() {
			public void handleEvent(Event event) {
				MyDialogCellEditor.this.focusLost();
			}
		});
		return cont;
	}

Now the focus lost events are received correctly and the editor is properly 
deactivated.

Comment 6 Joan Haggarty CLA 2003-06-11 18:58:37 EDT
We've noticed the same behaviour and have observed that we get an 
activateCellEditor method call in TableViewerImpl before the previous cell
editor is deactivated.  The handleMouseDown method does not do an explicit 
deactivation of a cell editor that may still be active in the table.
Comment 7 Genady Beryozkin CLA 2003-06-14 04:35:17 EDT
My previous post had a problem.
Here is a code that really works:

Override the createButton() method:

	protected Button createButton(Composite parent) {
		Button dialogButton = super.createButton(parent);
		dialogButton.addListener(SWT.FocusOut, new Listener() {
			public void handleEvent(Event event) {
				if (!isDialogOpen) {
					System.out.println("focus lost");
					URLListCellEditor.this.focusLost();
				}
			}
		});
		return dialogButton;
	}

Now in the #openDialogBox() method i have the following code 

	protected Object openDialogBox(Control cellEditorWindow) {
                ..........
                ....
		isDialogOpen = true;
		int res = dlg.open();
		isDialogOpen = false; 
		if (res != Dialog.OK) {
                    ......
		}
                ....
                ..........
	}

This is a hack ... I hope to see it fixed in 2.1.1 ....
Comment 8 Andreas Stubenrauch CLA 2003-07-02 11:18:37 EDT
*** Bug 39517 has been marked as a duplicate of this bug. ***
Comment 9 Andreas Stubenrauch CLA 2003-07-05 08:12:29 EDT
Created attachment 5360 [details]
Another ugly Workaround

Bug still in 2.1.1 :(
Another Workaround seems to change the TableViewer so it activly deactivates
the CellEditor
if another cell is selected. See Attachment.
Only tested on linux-gtk and linux-motif
Comment 10 Narushima Hironori CLA 2003-10-28 13:05:48 EST
This bug is occasion in windows platform... :-(
Comment 11 John Arthorne CLA 2004-02-09 13:48:55 EST
Is this possibly a JFace cell editor bug? Note the same bug exists on both 
Windows and GTK.
Comment 12 Sebastian Davids CLA 2004-03-01 00:27:28 EST
This is quite annoying.

If one has a large table with lots of editors and clicks quite fast on lots of
different cells one ends up with several stale editors.

Code from comment 7 seems to work.
Comment 13 Veronika Irvine CLA 2004-03-01 09:37:24 EST
This seems to be a JFace bug - moving to the UI team.
Comment 14 Abeer Bagul CLA 2004-03-25 08:20:50 EST
Created attachment 8876 [details]
Add a FocusListener which disposes of the button on loss of focus

The focuslistener has been added to the button within the createontrol() method
Comment 15 Ines Khelifi CLA 2004-04-08 11:45:07 EDT
I believe the problem happens on the handleMouseDown method in the 
TableViewerImpl class. Its implementation changed between 2.0.1 and the 
following releases. The 2.0.1 implementation of that method used to deactivate 
the cell by calling the applyEditorValue. That method does not get called in 
the current implementation of handleMouseDown, which could be causing these 
activations problems.
Comment 16 Ines Khelifi CLA 2004-04-08 16:58:08 EDT
Created attachment 9342 [details]
Proposed patch for cell bug

Added a check to disable the cell is it's enaled.
Comment 17 Tod Creasey CLA 2004-04-12 11:24:39 EDT
Regression that occured due to other changes. The apply code for the mouseDown 
has been restored.

Fixed in build >20040412
Comment 18 Genady Beryozkin CLA 2004-04-12 11:29:53 EDT
Can we have it in the 2.1.x stream as well ?
Comment 19 Tod Creasey CLA 2004-04-12 11:36:20 EDT
We won't be patching the 2.1.x stream any more to the best of my knowledge.
Comment 20 Tod Creasey CLA 2004-04-14 15:34:26 EDT
*** Bug 55485 has been marked as a duplicate of this bug. ***
Comment 21 Ines Khelifi CLA 2004-04-19 13:51:52 EDT
*** Bug 59040 has been marked as a duplicate of this bug. ***
Comment 22 Dinko Ivanov CLA 2004-12-30 11:33:11 EST
Hi, is this patched in 3.0
Comment 23 Tod Creasey CLA 2005-01-04 09:35:12 EST
Marking to verify in 3.1 M5.
Comment 24 Tod Creasey CLA 2005-02-16 16:04:16 EST
Verified in 20050215-1200