Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 82990 - [Viewers] Suport for TableCursor in TableViewer
Summary: [Viewers] Suport for TableCursor in TableViewer
Status: RESOLVED DUPLICATE of bug 75557
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.0.1   Edit
Hardware: PC Windows XP
: P4 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Tod Creasey CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-17 12:14 EST by Andy Doddington CLA
Modified: 2005-05-19 11:35 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Doddington CLA 2005-01-17 12:14:31 EST
I am using a TableCursor in conjunction with a TableViewer. This is working fine
apart from one issue, which arises when the table 'model' is updated underneath
the cursor. When this occurs the rest of the table refreshes OK, but the content
selected by the cursor remains unchanged. The following snippet demonstrates the
problem:

CUT====================
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ControlEditor;
import org.eclipse.swt.custom.TableCursor;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;

public class TableCursorBug {
    private static int counter = 0;
    private static ArrayList data = new ArrayList();
    private static Table table;
    private static TableViewer viewer;

    public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());

table = new Table(shell, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
table.setLayoutData(new GridData(GridData.FILL_BOTH));
TableColumn column1 = new TableColumn(table, SWT.NONE);
column1.setWidth(200);
TableColumn column2 = new TableColumn(table, SWT.NONE);
column2.setWidth(100);
TableColumn column3 = new TableColumn(table, SWT.NONE);
column3.setWidth(200);

viewer = new TableViewer(table);

viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new ArrayLabelProvider());

populateTable();
viewer.setInput(data);

Button button = new Button(shell, SWT.PUSH);
button.setText("Update Model");
button.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                populateTable();
                viewer.refresh();
            }
});

TableCursor cursor = new TableCursor(table, SWT.NONE);

ControlEditor editor = new ControlEditor(cursor);
editor.grabHorizontal = true;
editor.grabVertical = true;

shell.pack();
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}

display.dispose();
}

    private static void populateTable() {
        counter++; // cause each redraw to be different
        Date now = new Date(); // different date too
                data.clear();
                for (int i = 0; i < 10; i++) {
            data.add(now.toString() + " #" + counter + '/' + i);
}
    }

    private static class ArrayContentProvider implements
IStructuredContentProvider {
        public ArrayContentProvider() {}
        public void dispose() {}
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}

        public Object[] getElements(Object inputElement) {
            return ((List)inputElement).toArray();
        }
    }

    private static class ArrayLabelProvider implements ITableLabelProvider {

        public ArrayLabelProvider() {}
        public boolean isLabelProperty(Object element, String property) { return
false; }
        public Image getColumnImage(Object element, int columnIndex) { return
null; }
        public void addListener(ILabelProviderListener listener) { }
        public void removeListener(ILabelProviderListener listener) { }
        public void dispose() {}

        public String getColumnText(Object element, int columnIndex) {
            return element.toString() + " col" + columnIndex;
        }
    }
}
CUT====================

The problem occurs both in the case when the model changes its content and when
a totally new model is specified, i.e. by calling viewer.setInput() with a new
input value.
Comment 1 Steve Northover CLA 2005-01-19 20:32:42 EST
I believe this is a dup but don't have the strength to find it.
Comment 2 Veronika Irvine CLA 2005-01-26 15:00:59 EST
1) TableCursor has no knowledge of TableViewer and its model.  The TableViewer 
is in JFace which is a layer on top of SWT and TableCursor is in SWT.
2) There is no event when the text in the table changes.  It is not SWT policy 
to send event notification for things that are changed programmatically (with 
some exceptions). So TableCursor can not update itself from a Table event.

I think this is not an SWT bug but rather a request for support in JFace for 
TableCursor in TableViewer.

Moving to the UI team.
Comment 3 Andy Doddington CLA 2005-01-27 04:47:15 EST
I understand your point about not adding events; all that is really required is
some way of being able to programmatically inform the cursor to 'reset itself'.
However, I have not been able to find any way of achieving this.
Comment 4 Tod Creasey CLA 2005-05-19 11:35:14 EDT

*** This bug has been marked as a duplicate of 75557 ***