Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] lazy loading for table

Lazy loading for large tables is not currently suported but it is on the 
plan for 3.0.  See:

http://bugs.eclipse.org/bugs/show_bug.cgi?id=37998




Cyril Araud <ca@xxxxxxxxxxxx> 
Sent by: platform-swt-dev-admin@xxxxxxxxxxx
10/29/2003 02:50 AM
Please respond to
platform-swt-dev


To
platform-swt-dev@xxxxxxxxxxx
cc

Subject
[platform-swt-dev] lazy loading for table






Hello,


I want to fill a table whith a lot of lines.


In order to increase performances, I was thinking of using a
LabelProvider.


I was hopping that the Label Provider would be called only
for visible lines.


But the label provider is called for each line, as you can see if you
run
the enclosed snippet, as soon as the Table.setInput() is called.


Is it possible that the label provider is called only for visible line
?(in
fact
I have a lot of calculations to do to compute the content of each cell
so i want to do them only if needed)


How can I turn on this feature if it exists ?


Thank for your help,


Cyril Araud




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.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
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 Test {

        public
static void main(String[] args){
                Display
display = new Display ();
                final
Shell shell = new Shell (display);
                GridLayout
layout = new GridLayout();
                layout.numColumns
= 1;
                shell.setLayout(layout);
                Table
t = new Table(shell, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
 
                String[]
headers = new String[]{"",""};
                for
(int i = 0; i < headers.length; i++) {
                        TableColumn
column = new TableColumn(t, SWT.NONE);
                        column.setText(headers[i]);
                        column.setWidth(90);
                }
                t.setLayoutData(new
GridData(GridData.FILL_BOTH));
 
                ITableLabelProvider
provider = new LabelProvider();
 
                TableViewer
tv = new TableViewer(t);
                tv.setLabelProvider(provider);
                tv.setContentProvider(new
ContentProvider());

                shell.setSize(250,250);
                shell.open
();
 
                String[]
iKs = new String[10000];
                for
(int i=0; i<10000; i++){
                        iKs[i]
= "line " + i;
                }
                tv.setInput(iKs);
 
                while
(!shell.isDisposed ()) {
                        if
(!display.readAndDispatch ()) display.sleep ();
                }
                display.dispose
();
        }

}


class LabelProvider implements ITableLabelProvider{

        public
Image getColumnImage(Object arg0, int arg1) {
                return
null;
        }

 
        public
String getColumnText(Object s, int arg1) {
                System.out.println("LabelProvider.
getColumnText(" + s+" )");
                return
s.toString();
        }
 
 
        public
void addListener(ILabelProviderListener arg0) {
        }

        public
void dispose() {
        }

        public
boolean isLabelProperty(Object arg0, String arg1) {
                return
false;
        }


        public
void removeListener(ILabelProviderListener arg0) {
        }

}
 
 
class ContentProvider implements IStructuredContentProvider{

        public
Object[] getElements(Object o) {
                if
(o instanceof String[]){
                        return
(String[])o;
                }
                return
null;
        }

 
        public
void dispose() {
 
        }

        public
void inputChanged(Viewer arg0, Object arg1, Object arg2) {
        }

}









Back to the top