Bug 422314 - ColumnWeightData is wrong calculated for table in TitleAreaDialog
Summary: ColumnWeightData is wrong calculated for table in TitleAreaDialog
Status: ASSIGNED
Alias: None
Product: RAP
Classification: RT
Component: JFace (show other bugs)
Version: 2.1   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-22 03:38 EST by Yury CLA
Modified: 2014-01-09 06:13 EST (History)
1 user (show)

See Also:


Attachments
Wrong and good column wide calculation (13.84 KB, image/png)
2013-11-22 03:38 EST, Yury CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yury CLA 2013-11-22 03:38:04 EST
Created attachment 237640 [details]
Wrong and good column wide calculation

Snippet to reproduce:

public int createUI() {
    ServerPushSession pushSession = new ServerPushSession();
    Display display = PlatformUI.createDisplay();
    pushSession.start();
    Shell shell = new Shell(display);
    shell.setLayout( new GridLayout() );
    
    TitleAreaDialog dlg = new TitleAreaDialog(shell){
      @Override
      protected Control createDialogArea( Composite parent ) {
        Composite composite = (Composite)super.createDialogArea( parent );
        
        TableViewer viewer = new TableViewer(composite, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
        
        Table table = viewer.getTable();
        table.setHeaderVisible( true );
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.horizontalSpan = 2;
        gd.widthHint = 300;
        table.setLayoutData(gd);

        TableColumn column = new TableColumn(table, SWT.NONE);
        column.setText( "Check" );
        column = new TableColumn(table, SWT.NONE, 1);
        column.setText( "Name" );
        
        TableLayout layout = new TableLayout();
        layout.addColumnData(new ColumnWeightData(300, true));
        layout.addColumnData(new ColumnWeightData(130, true));
        table.setLayout(layout);

        return composite;
      }

      @Override
      protected Control createContents( Composite parent ) {
        Control content = super.createContents( parent );
        setErrorMessage( "Error" );
        return content;
      }
    };
    
    
    shell.setSize( 500, 400 );
    shell.open();
    dlg.open();
    while( !shell.isDisposed() ) {
      if( !display.readAndDispatch() ) {
        display.sleep();
      }
    }
    pushSession.stop();
    display.dispose();
    return 0;
  }

Executing setErrorMessage( "Error" ) in createContents method leads to wrong size calculation of table columns (see the attached picture).
Not a critical issue, but a root problem could be a cause of other bugs (seems to me a problem is with FormData layouting of TitleAreaDialog.workArea).
Comment 1 Ivan Furnadjiev CLA 2013-11-22 03:58:20 EST
I remember such a bug in RCP as well. Could you verify this? If I'm not mistaken the workaround was to use ColumnPixelData instead.
Comment 2 Yury CLA 2013-11-22 04:03:47 EST
This works fine in RCP. We use another workaround - setErrorMessage in PaintListener attached to the dialog. ColumnPixelData is not what we need.
Comment 3 Yury CLA 2013-11-22 04:09:58 EST
UPD: use ShellListener not a PaintListener.
Comment 4 Ivan Furnadjiev CLA 2014-01-09 06:13:49 EST
Hi Yury, I did some debugging today. TableLayout is original SWT class. TableLayout#layout is called *only* once (see internal TableLayout#firstTime and TableLayout line 133) by design. If you set an error message the first layout is triggered by setErrorMessage with bigger dimensions and the following ("correct") layout calls are ignored. Thus, table columns are never resized to correct column data. In RAP we always have multiple resizes because of text size determination. You can prove it by commenting the return statement in TableLayout line 133. I think your workaround is correct.