org.eclipse.rap icon indicating copy to clipboard operation
org.eclipse.rap copied to clipboard

GridEditor displayed at wrong offset for auto-height rows

Open ceisserer opened this issue 2 years ago • 6 comments

When using autoHeight / varialbe height grid rows, GridEditor Widgets are not properly positioned - but instead are positioned where they would belong with standard row height. My guess is, the problem originates from the height of the grid rows being computed client-side, but the GridEditor Widgets are layouted server-side.

public class BasicEntryPoint extends AbstractEntryPoint {

  protected void createContents(Composite parent) {
	parent.setLayout(null);
	
	Grid grid = new Grid(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
	grid.setData(RWT.MARKUP_ENABLED, true);
	grid.setAutoHeight(true);
	grid.setBounds(100, 100, 500, 500);
	
	GridColumn actionCol = new GridColumn(grid,SWT.NONE);
	actionCol.setText("Action");
	actionCol.setMinimumWidth(200);
	
	GridColumn textCol = new GridColumn(grid,SWT.NONE);
	textCol.setText("Textcolumn");
	textCol.setWidth(200);
	
	generateItem(grid, "multi <br/> line");
	generateItem(grid, "single line");
  }
  
  void generateItem(Grid grid, String txt) {
	    GridItem item = new GridItem(grid,SWT.NONE);
	    item.setText(1, txt);

		Button b = new Button(grid, SWT.PUSH);
		b.setText("button");
		
		GridEditor editor = new GridEditor(grid);
		editor.minimumWidth = 150;
		editor.minimumHeight = 10;
		editor.setEditor(b, item, 0);
  }
}

ceisserer avatar Nov 03 '22 07:11 ceisserer

Yes... the row height is calculated on the client and send to the server with the next request. I can only suggest a workaround here (re-layout the editor with timerExec):


  @Override
  protected void createContents( Composite parent ) {
    parent.setLayout( null );

    Grid grid = new Grid( parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL );
    grid.setData( RWT.MARKUP_ENABLED, true );
    grid.setAutoHeight( true );
    grid.setBounds( 100, 100, 500, 500 );

    GridColumn actionCol = new GridColumn( grid, SWT.NONE );
    actionCol.setText( "Action" );
    actionCol.setMinimumWidth( 200 );

    GridColumn textCol = new GridColumn( grid, SWT.NONE );
    textCol.setText( "Textcolumn" );
    textCol.setWidth( 200 );

    generateItem( grid, "multi <br/> line" );
    generateItem( grid, "single line" );

    parent.getDisplay().timerExec( 100, new Runnable() {
      @Override
      public void run() {
        for( GridItem item : grid.getItems() ) {
          ( ( GridEditor )( item.getData( "editor" ) ) ).layout();
        }
      }
    } );
  }

  void generateItem( Grid grid, String txt ) {
    GridItem item = new GridItem( grid, SWT.NONE );
    item.setText( 1, txt );

    Button b = new Button( grid, SWT.PUSH );
    b.setText( "button" );

    GridEditor editor = new GridEditor( grid );
    editor.minimumWidth = 150;
    editor.minimumHeight = 10;
    editor.setEditor( b, item, 0 );

    item.setData( "editor", editor );
  }

}```

ifurnadjiev avatar Nov 07 '22 09:11 ifurnadjiev

Thanks for the hint regarding the workaround.

This used to work when the row-hight was calculated immediatly on the client, but because height-calculation is now performed somehow asynchronous ( https://github.com/eclipse-rap/org.eclipse.rap/issues/75 ) sometimes the 100ms delay is enough and sometimes even 500ms is too short (large page, garbage collection hick-up, etc).

ceisserer avatar Nov 07 '22 09:11 ceisserer

I'm about to fix issue #75 today.

ifurnadjiev avatar Nov 07 '22 09:11 ifurnadjiev

The timerExec is only needed to start a server push request and trigger another UI request with updated item "height" property. The actual delay here is not important. Of course, this workaround will work after issue #75 is fixed (pull request is created).

ifurnadjiev avatar Nov 07 '22 09:11 ifurnadjiev

About the workaround: To eliminate editor flickering when resizing it, you can create the editors in timerExec instead of calling layout.

ifurnadjiev avatar Nov 07 '22 12:11 ifurnadjiev

Did you try the workaround? Can we close this issue as wontfix?

ifurnadjiev avatar Nov 25 '22 14:11 ifurnadjiev

sorry for being unresponsive - thanks for the suggested work-around, we already had it in-place before opening the report and we will simply continue to ship.

ceisserer avatar Aug 31 '24 07:08 ceisserer