Potential bug in TableViewer with associated VIRTUAL table [message #465369] |
Sun, 11 December 2005 16:29 |
Eclipse User |
|
|
|
Originally posted by: micasim.gmx.de
Hi,
I'm using jdk1.5.0_03; Eclipse 3.1.1; SWT
org.eclipse.swt.motif.linux.x86_3.1.1.jar
I set up a trivial sample to evaluate TableViewer with a VIRTUAL table
associated.
The content provider is a ILazyContentProvider (see also below).
Running the sample I noticed the following weird behaviour:
When started the first N instances were displayed (as esxpected).
Then I wanted to display the last ones so I pressed the CTRL+END keys.
Now ALL instances not loaded yet were loaded.
Examining a bit more I detected the TableViewer loads all elements
whenever I pressed the CTRL-key.
I guess this is a bug of the TableViewer at least on the motif platform.
Can anyone try my sample on his box to verify this, please?
I will try it on my Windows NT2K box tomorrow.
Please let me know whether this is a known bug.
Kind regards,
Michael
|
|
|
Re: Potential bug in TableViewer with associated VIRTUAL table [message #465370 is a reply to message #465369] |
Sun, 11 December 2005 16:41 |
Eclipse User |
|
|
|
Originally posted by: micasim.gmx.de
Sorry,
I've forgotten to attach the source, so here we go:
package de.micasim.vt;
import java.util.ArrayList;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.ILazyContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.ApplicationWindow;
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.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
/**
* @author michael
*
*/
public class Main extends ApplicationWindow {
private class Exit extends Action {
private ApplicationWindow parent;
public Exit (ApplicationWindow parent) {
super();
this.parent = parent;
setText ("E&xit@Ctrl+Q");
setToolTipText ("Quit the application.");
this.setAccelerator (SWT.CTRL|'Q');
//setImageDescriptor (ImageDescriptor.createFromFile (Main.class,
"exit.png"));
}
/**
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run () {
parent.close();
}
}
private class Element {
private String oid;
private String descript;
public Element (String id, String description){
super();
oid = id;
descript = description;
}
public String id() {return oid;}
public String description() {return descript;}
}
private class MyLabelProvider extends LabelProvider implements
ITableLabelProvider {
public Image getColumnImage (Object arg0, int arg1) {
return null;
}
public String getColumnText (Object element, int columnIndex) {
switch (columnIndex) {
case 0:
return ((Element)element).id();
case 1:
return ((Element)element).description();
}
return element.toString();
}
}
private class MyContentProvider implements ILazyContentProvider {
public final String[] properties = {"id","description"};
private ArrayList<Element> data;
private TableViewer connectedViewer;
public MyContentProvider (TableViewer viewer) {
super();
connectedViewer = viewer;
data = new ArrayList<Element> (107);
for (int i = 0; i < 100000; i++)
data.add (new Element (Integer.toString(i), "Element #"+i));
}
public void dispose () {}
public void inputChanged (Viewer viewer, Object input, Object oldInput)
{}
/**
* Called when a previously-blank item becomes visible in the
TableViewer.
* @see org.eclipse.jface.viewers.ILazyContentProvider#updateElement (int)
*/
public void updateElement (int index) {
System.out.println ("updateElement ("+index+")");
Element element = data.get (index);
if (element != null)
connectedViewer.replace (element, index);
}
public int contentSize() {
return data.size();
}
}
private Exit exit;
private TableViewer tableViewer;
private MyContentProvider contentProvider;
/**
* @param shell
*/
public Main (Shell shell) {
super (shell);
exit = new Exit (this);
this.addMenuBar();
}
/**
* @see org.eclipse.jface.window.ApplicationWindow#createMenuManager ()
*/
@Override
protected MenuManager createMenuManager () {
MenuManager menubar = new MenuManager();
MenuManager submenu = new MenuManager ("&File");
submenu.add (exit);
menubar.add (submenu);
return menubar;
}
/**
* @see
org.eclipse.jface.window.Window#createContents(org.eclipse.s wt.widgets.Composite)
*/
@Override
protected Control createContents (Composite parentComposite) {
Table table = new Table (parentComposite,
SWT.BORDER|SWT.H_SCROLL|SWT.V_SCROLL|SWT.MULTI|SWT.FULL_SELE CTION|SWT.VIRTUAL);
table.setHeaderVisible (true);
TableColumn column = new TableColumn (table, SWT.NONE);
column.setText ("Name");
column.setWidth (64);
column = new TableColumn (table, SWT.NONE);
column.setText ("Beschreibung");
column.setWidth (128);
tableViewer = new TableViewer (table);
tableViewer.setLabelProvider (new MyLabelProvider());
tableViewer.setContentProvider (contentProvider = new MyContentProvider
(tableViewer));
tableViewer.setColumnProperties (contentProvider.properties);
tableViewer.setItemCount (contentProvider.contentSize());
return table;
}
/**
* @see
org.eclipse.jface.window.ApplicationWindow#configureShell(or g.eclipse.swt.widgets.Shell)
*/
@Override
protected void configureShell (Shell shell) {
super.configureShell (shell);
shell.setSize (640, 480);
}
/**
* @param args
*/
public static void main (String[] args) {
try {
Main appWindow = new Main (null);
appWindow.setBlockOnOpen (true);
appWindow.open ();
} catch (Exception x) {
x.printStackTrace();
}
}
}
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03464 seconds