SWT Form questions

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

SWT Form questions

Postby Paul.Helster » Tue Apr 19, 2005 11:02 am

There are 3 issues I need help on when using forms. I list them here and if more details are needed, please let me know.

1- Form composites do not get adapted to the toolkit. If I create a composite, and then add a FormToolkit instance construction to the composite constructor, the composite itself is not adapted to the toolkit settings. In particular, the background is not white. Callint toolkit.adapt(this) has no effect.

2- I need to call toolkit.paintComponentBorders(this) in the composite so that children controls be drawn with borders.

3- If I "choose the composite" created with #1 and #2 workarounds, and add it to another composite, the borders of the embedded custom component do not get painted. The container composite is setup to use a FormToolkit, and I called here too paintComponentBorders.

I can provide sample code but it is very easy to replicate this:

- Create a SimpleCcomposite with a FormToolkit in its constructor, and adapt "this" composite.
* The background is grey, not white as it I would expect it to be.

- Add a Form Text control. The control has no border.

- Add toolkit.paintComponentBoorders(this) to the composite, and the borders will appear on the text control.

- Create another composite: WrappingComposite, and instantiate a FormToolkit in its constructor too.

- Add theSimpleComposite to this new composite: the text control will not display its borders.

Is this a know problem? Or am I missing a step?

Paul
Paul.Helster
 
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

Re: SWT Form questions

Postby Eric Clayberg » Wed Apr 20, 2005 6:13 am

Paul.Helster wrote:1- Form composites do not get adapted to the toolkit. If I create a composite, and then add a FormToolkit instance construction to the composite constructor, the composite itself is not adapted to the toolkit settings. In particular, the background is not white. Callint toolkit.adapt(this) has no effect.

A new v4.0.1 build is available that adds support for toolkit.adapt(this).

Paul.Helster wrote:2- I need to call toolkit.paintComponentBorders(this) in the composite so that children controls be drawn with borders.

Do you mean toolkit.paintBorders(this)? This is also supported by the latest build.

Paul.Helster wrote:3- If I "choose the composite" created with #1 and #2 workarounds, and add it to another composite, the borders of the embedded custom component do not get painted. The container composite is setup to use a FormToolkit, and I called here too paintComponentBorders.

This should now work fine in the latest build.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby Paul.Helster » Wed Apr 20, 2005 6:54 am

Thanks for the fast fix. It works.

But I had trouble with some of my custom controls: some of them were still not painted correctly: adapt and paintBordersFor calls had no effect. But I identified my problem: When there is a main method in a Custom Composite, the toolkit methods have no effect. If I remove the main method, they render correctly.

Is this a bug?

(PS: Interpreting source code like this this product does sounds complicated from the outside)
Paul.Helster
 
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

Postby Paul.Helster » Wed Apr 20, 2005 7:56 am

Still problems that I do not understand. The following simple custom Composite contains another composite. The Text in this embedded compositte does not display its border.

It looks likes the forms support is new and it has not been used/tested a lot.

Code: Select all
package test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;

public class TestCustom extends Composite {

  private Text text;
  public TestCustom(Composite parent, int style) {
    super(parent, style);
    setLayout(new FormLayout());
    FormToolkit toolkit = new FormToolkit(Display.getCurrent());
    toolkit.adapt(this);
    toolkit.paintBordersFor(this);

    final Composite composite = toolkit.createComposite(this, SWT.NONE);
    final FormData formData = new FormData();
    formData.bottom = new FormAttachment(0, 210);
    formData.right = new FormAttachment(0, 365);
    formData.top = new FormAttachment(0, 80);
    formData.left = new FormAttachment(0, 90);
    composite.setLayoutData(formData);
    composite.setLayout(new FormLayout());
    toolkit.paintBordersFor(composite);

    text = toolkit.createText(composite, null, SWT.NONE);
    final FormData formData_1 = new FormData();
    formData_1.bottom = new FormAttachment(0, 57);
    formData_1.right = new FormAttachment(0, 190);
    formData_1.top = new FormAttachment(0, 40);
    formData_1.left = new FormAttachment(0, 82);
    text.setLayoutData(formData_1);
    text.setText("New Forms Text");

    //
  }

  public void dispose() {
    super.dispose();
  }

  protected void checkSubclass() {
  }
}
Paul.Helster
 
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

Postby Paul.Helster » Wed Apr 20, 2005 9:17 am

Hm... my previous TestCustom example is now working fine.

But when I add this TestCustom composite into another composite, the text borders are not drawn. Here is the Composite that embeds this TestCustom:

Code: Select all
package test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.FormToolkit;

public class Test extends Composite {

  public Test(Composite parent, int style) {
    super(parent, style);
    FormToolkit toolkit = new FormToolkit(parent.getDisplay());
    toolkit.adapt(this);
    toolkit.paintBordersFor(this);
    setLayout(new FormLayout());

    final TestCustom testCustom = new TestCustom(this, SWT.NONE);
    final FormData formData = new FormData();
    formData.top = new FormAttachment(0, 40);
    formData.left = new FormAttachment(0, 35);
    testCustom.setLayoutData(formData);

  }

  public void dispose() {
    super.dispose();
  }

  protected void checkSubclass() {
  } 
}
Paul.Helster
 
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

A simpler way to reproduce it

Postby Paul.Helster » Thu Apr 21, 2005 5:18 am

I noticed that it is easier to reproduce this problem than what I suggested above.

1- Create a new Composite.
2- Add the FormToolkit instantiation.
3- Add a composite inside.
4- Add a Text to this embedded composite.

The text will not have borders.
Paul.Helster
 
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

Re: A simpler way to reproduce it

Postby Eric Clayberg » Thu Apr 21, 2005 10:21 am

Paul.Helster wrote:I noticed that it is easier to reproduce this problem than what I suggested above.

1- Create a new Composite.
2- Add the FormToolkit instantiation.
3- Add a composite inside.
4- Add a Text to this embedded composite.

The text will not have borders.

This problem and the prior one have been fixed in the latest v4.0.1 update.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby Paul.Helster » Thu Apr 21, 2005 5:21 pm

I closed eclipse, ran deletexxx.bat, re-installed the latest plugin and there is still something wrong. Is there some cache somewhere else I should delete?

The last problem I described just above is fixed: If I add a composite, and a text field inside this composite, it will draw the borders.

But the sad part is when I embed it as a Custom Control: Borders do not get drawn, and the background problem is back (i.e. the background of the custom composite is now grey.) This was fixed in the last build but the problem is back.

This is very easy to reproduce. The problems always surface when embedding a composite with text fields in a form-based composite with 2 scenarios. I test it with either embedding the composite dirtecly in the class, or embedding it as a custom control. The 2 scenarios generate different results at each build.
Paul.Helster
 
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

Postby Paul.Helster » Thu Apr 21, 2005 5:38 pm

If it can help you with testing, I can email you a zipped plugin that contains some UI prototypes I have created with SWT-Designer. They are all form-based. They currently only depend on Eclipse.
Paul.Helster
 
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

Postby Eric Clayberg » Fri Apr 22, 2005 5:25 am

Paul.Helster wrote:But the sad part is when I embed it as a Custom Control: Borders do not get drawn, and the background problem is back (i.e. the background of the custom composite is now grey.) This was fixed in the last build but the problem is back.

OK. It should now be working for all of the test cases you have sent us in the latest v4.0.1 build.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby Paul.Helster » Fri Apr 22, 2005 7:34 am

Yippie!

This build fixes all the issues from this thread. Thank you for the quick reponse.

The next issue I have is regarding inheritance... I will submit a new topic for that next :)
Paul.Helster
 
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

Postby Paul.Helster » Fri Apr 22, 2005 11:09 am

One minor issue: the fix is complete for the designer view, but the problems are still present in the "Quick preview".
Paul.Helster
 
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

Postby Eric Clayberg » Sat Apr 23, 2005 11:42 am

Paul.Helster wrote:One minor issue: the fix is complete for the designer view, but the problems are still present in the "Quick preview".

Fixed in the latest v4.0.1 build.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest