Complex composite

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

Complex composite

Postby Paul.Helster » Fri Apr 15, 2005 12:05 pm

I have a composite made of many buttons and labels that is used to select wind direction. I included the source code that is self contained and loads in SWT Desiger 4.0.0 trial. There are 3 issues when using it in SWT designer:

1- The layout is wrong when runninng in SWT Designer while when it runs in the main, it looks just right.

2- I want to be able to create all the embedded buttons using the form toolkit. Must I go through all the composite children and "adapt" them one by one? Or is there a way to tell SWT Designer to use a toolkit? If so, where does it get it?

3- How can I embed this complex composite into another composite? This is the part I am not getting right in SWT Designer. Do I have to manually add it to the source of the other composite?

I included the code that shows these issues. Maybe this will help identify a bug for #1.

Is #2 a limitation?

Thanks, and I am truly impressed with this plugin.


Code: Select all
package example.forms.swtdesigner;

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.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;

public class TestWinds extends Composite {

  public TestWinds(Composite parent, int style) {
    super(parent, style);

    FormLayout layout = new FormLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    this.setLayout(layout);

    int checkStyle = SWT.RADIO;
   
    Button bn = new Button(this, checkStyle);
    Button bne = new Button(this, checkStyle);
    Button be = new Button(this, checkStyle);
    Button bse = new Button(this, checkStyle);
    Button bs = new Button(this, checkStyle);
    Button bsw = new Button(this, checkStyle);
    Button bw = new Button(this, checkStyle);
    Button bnw = new Button(this, checkStyle);

    Label ln = new Label(this, SWT.NONE);
    ln.setText("N");
    Label le = new Label(this, SWT.NONE);
    le.setText("E");
    Label lw = new Label(this, SWT.NONE);
    lw.setText("W");
    Label ls = new Label(this, SWT.NONE);
    ls.setText("S");

    FormData data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.left = new FormAttachment(50, 100, -5);
    ln.setLayoutData(data);

    // n
    data = new FormData();
    data.top = new FormAttachment(ln, 0, SWT.BOTTOM);
    data.left = new FormAttachment(ln, 0, SWT.CENTER);
    bn.setLayoutData(data);

    // ne
    data = new FormData();
    data.top = new FormAttachment(bn, -6, SWT.BOTTOM);
    data.left = new FormAttachment(bn, 5, SWT.RIGHT);
    bne.setLayoutData(data);

    // nw
    data = new FormData();
    data.top = new FormAttachment(bne, 0, SWT.TOP);
    data.right = new FormAttachment(bn, -5, SWT.LEFT);
    bnw.setLayoutData(data);

    // e
    data = new FormData();
    data.top = new FormAttachment(bne, 2, SWT.BOTTOM);
    data.left = new FormAttachment(bne, -2, SWT.RIGHT);
    be.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(be, 0, SWT.CENTER);
    data.left = new FormAttachment(be, 5, SWT.RIGHT);
    le.setLayoutData(data);

    // w
    data = new FormData();
    data.top = new FormAttachment(be, 0, SWT.TOP);
    data.right = new FormAttachment(bnw, 2, SWT.LEFT);
    bw.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(bw, 0, SWT.CENTER);
    data.right = new FormAttachment(bw, -3, SWT.LEFT);
    lw.setLayoutData(data);

    // se
    data = new FormData();
    data.top = new FormAttachment(be, 2, SWT.BOTTOM);
    data.right = new FormAttachment(bne, 0, SWT.RIGHT);
    bse.setLayoutData(data);

    // sw

    data = new FormData();
    data.top = new FormAttachment(bse, 0, SWT.TOP);
    data.left = new FormAttachment(bnw, 0, SWT.LEFT);
    bsw.setLayoutData(data);

    // s
    data = new FormData();
    data.top = new FormAttachment(bse, -4, SWT.BOTTOM);
    data.left = new FormAttachment(bn, 0, SWT.LEFT);
    bs.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(bs, 0, SWT.BOTTOM);
    data.left = new FormAttachment(bs, 0, SWT.CENTER);
    ls.setLayoutData(data);   
    //
  }

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

  protected void checkSubclass() {
  }
  public static void main(String[] args) {
    Display display = new Display ();
    Shell shell = new Shell (display);
    shell.setSize(640, 480);
    shell.setLayout (new FillLayout ());
    boolean useForm = false;
    if (useForm){
      FormToolkit toolkit = new FormToolkit(shell.getDisplay());
      ScrolledForm form = toolkit.createScrolledForm(shell);
      form.getBody().setLayout(new FillLayout());
      form.setText("WindSelectorControl2");
      TestWinds control = new TestWinds(form.getBody(), SWT.NONE);
      toolkit.adapt(control);
    } else {
      new TestWinds(shell, SWT.NONE);
    }
    shell.pack ();
    shell.open ();
    while (!shell.isDisposed ()) {
      if (!display.readAndDispatch ()) display.sleep ();
    }
    display.dispose ();
  }   
}
Paul.Helster
 
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

Choose composite

Postby Paul.Helster » Fri Apr 15, 2005 12:45 pm

Ok, I found my answer to #3: How to embed my complex composite. I must use the "Choose Composite" button.
Paul.Helster
 
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

Re: Complex composite

Postby Eric Clayberg » Sun Apr 17, 2005 12:44 pm

Paul.Helster wrote:1- The layout is wrong when runninng in SWT Designer while when it runs in the main, it looks just right.

I assume that you did not create this composite with Designer. Is that correct? You are using a couple of constructs that we don't support in Designer, so we are investigating whether we can get your example to display correctly.

Paul.Helster wrote:2- I want to be able to create all the embedded buttons using the form toolkit. Must I go through all the composite children and "adapt" them one by one? Or is there a way to tell SWT Designer to use a toolkit? If so, where does it get it?

You should use the components from the Eclipse Forms palette rather than the generic SWT components from the SWT Controls palette. The components listed on the Eclipse Forms palette are already adapted. The Eclipse Forms palette is available for any window that defines a form toolkit. The following line at the top of your composite constructor would be enough...
    FormToolkit toolkit = new FormToolkit(Display.getCurrent());
Paul.Helster wrote:3- How can I embed this complex composite into another composite? This is the part I am not getting right in SWT Designer. Do I have to manually add it to the source of the other composite?

Use Choose Bean or Choose Composite. If you are going to use this composute a lot, you can add it to the Custom Controls palette.
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 » Sun Apr 17, 2005 5:45 pm

Yes, this is a composite I manually created as a prototype.

I will now redo it in SWT-Designer. I will be easier to modify later on.
Paul.Helster
 
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

Hm...

Postby Paul.Helster » Sun Apr 17, 2005 6:58 pm

I've been browsing around SWT-Designer app, web docs, and still cannot figure out how to add a composite to the Custom Control palette...


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

Re: Hm...

Postby Eric Clayberg » Mon Apr 18, 2005 8:54 am

Paul.Helster wrote:I've been browsing around SWT-Designer app, web docs, and still cannot figure out how to add a composite to the Custom Control palette...

See the Designer > SWT > Custom Controls preference page...

Image
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