[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.platform.swt] Re: Problem in using virtual table
|
Does anybody have solution for it?
Here is the code snippet, hope it is usefull for you to identify the
problem.
=====================================================================
/**
* Created on 2006-12-6
*
* Copyright (c) Sybase, Inc. 2004-2006. All rights reserved.
*/
package scripts;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
/**
*
* @author Shi-feng Yu
*/
public class TestVirtualTable
{
static final int COUNT = 1000000;
public static void main(String[] args)
{
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new RowLayout(SWT.VERTICAL));
final Table table = new Table(shell, SWT.VIRTUAL | SWT.BORDER);
final Label label_loader = new Label(shell, SWT.NONE);
label_loader.setText("Loaded: 0 ");
final int loadedNum[] = new int[1];
loadedNum[0]=0;
table.addListener(SWT.SetData, new Listener()
{
public void handleEvent(Event event)
{
TableItem item = (TableItem) event.item;
int index = table.indexOf(item);
item.setText("Item " + index);
loadedNum[0]=loadedNum[0]+1;
label_loader.setText(loadedNum[0] +" Loaded ");
}
});
table.setLayoutData(new RowData(200, 200));
Button button = new Button(shell, SWT.PUSH);
button.setText("Add Items");
final Label label = new Label(shell, SWT.NONE);
button.addListener(SWT.Selection, new Listener()
{
public void handleEvent(Event event)
{
long t1 = System.currentTimeMillis();
table.setItemCount(COUNT);
long t2 = System.currentTimeMillis();
label.setText("Items: " + COUNT + ", Time: " + (t2 - t1) + "
(ms)");
shell.layout();
}
});
final Color backgroundColor = new Color(display, 238, 237, 224);
final Color foregroundColor = new Color(display, 128, 128, 128);
Button button2 = new Button(shell, SWT.PUSH);
button2.setText("refresh");
button2.addListener(SWT.Selection, new Listener()
{
public void handleEvent(Event event)
{
//first clear all cached table items
table.clearAll();
loadedNum[0]= 0;
label_loader.setText(loadedNum[0] +" Loaded ");
//then set some background/foreground color for some table
items
for(int i = 50; i<55;i++)
{
table.getItem(i).setBackground(backgroundColor);
table.getItem(i).setForeground(foregroundColor);
}
for(int i = 3; i<8;i++)
{
table.getItem(i).setBackground(backgroundColor);
table.getItem(i).setForeground(foregroundColor);
}
}
});
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
"Stephen" <shi-feng.yu@xxxxxxxxxx> wrote in message
news:ekjbgs$2gm$1@xxxxxxxxxxxxxxxxxxxx
> Hi,
>
> I wrote a customized tableviewer based on virtual table, but I meet some
> problems:
> In my table viewer,after user inserts new row, all the existing rows
> become blank except the row which is inserted. By debugging, I found that
> when a new row is inserted to the table, ,my code will do
> 1)refresh the viewer
> 2)set the background color for those rows which are read-only
>
> Ok, problems come. When my code call xxxViewer.refresh(), it will call
> [private void internalVirtualRefreshAll()] (I implemented this method just
> like the org.eclipse.jface.viewers.TableViewer has done, so you can find
> this method in the org.eclipse.jface.viewers.TableViewer)
> this method will call getTable().clearAll(); this method will clean each
> table item if it is cashed.
> Ok, after refresh, all items in table are cleaned with attribute cached =
> false.
>
> After the refresh operation, my code sets the background color for those
> rows which are read-only, but I found that once [public void setBackground
> (Color color) ]in TableItem is called, the attribue:cached is set to true
> regardless of whether the data (I mean other attributes like:
> strings,checked and etc) is really loaded.
>
> Therefore, after refresh and set background color operations, the table
> items in my table have following states:
> cached =true;
> background=xxx;
> strings=null;
> image=null;
> .......
>
> Seeing from the state above, cached is true but strings is null,this state
> causes the blank displaying.
>
> For now, I don't how to fix this problem. I try to judget whether the
> table item is cached before I set the color, but the there is no API to
> access the "cashed" attribute of table item.
>
> Does anybody meet similar problem? Or you have solution for me?
>
>
> Thanks a lot.
>