5

I am using Nebula Grid widget in my RCP application. I have added a controlListener to my Grid which will resize the each of the Grid row heights whenever the Grid Control is resized. the code snippet is as follows:

@Override
public void controlResized(ControlEvent e) {
    GridColumn []cols = grid.getColumns();
    for (GridItem item : grid.getItems()) {
        GC gc = new GC(item.getDisplay());

        int max = 0;
        Point tb=null;
        for(GridColumn col : cols){
            tb = col.getCellRenderer().computeSize(gc, col.getWidth(), SWT.DEFAULT, item);
            max = Math.max(max, tb.y);
            if(max > hmax){
                break;
            }
        }

        if(hmax==-1){

        }else if(max > hmax){
            max=hmax;
        }

        gc.dispose();
        item.setHeight(max);
    }
}

This is working fine ie., the height is adjusted each time the user resizes any of the column. But whenever the number of grid rows is huge say few hundreds to thousands, the resizing is not smooth. The UI is not responsive for a few seconds. on doing some analysis, I could narrow down on the statement responsible for this delay. that is the below statement:

tb = col.getCellRenderer().computeSize(gc, col.getWidth(), SWT.DEFAULT, item);

I could understand the reason for this . This above statement is called for each row and a column and that seems to be the reason. for a Grid of 2000 rows and 5 columns, this statement is called 10000 times. how can I make this process performant ?

Jonah Graham
  • 7,890
  • 23
  • 55
ssdimmanuel
  • 448
  • 10
  • 29

0 Answers0