Custom Widget with GridLayout

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

Custom Widget with GridLayout

Postby domfe » Tue Dec 07, 2010 7:02 am

Hi.
I'm using XWT.
I'm implementing a widget that has a GridLayout. I don't know how many columns it will contain.
In the constructor I've the code:

Code: Select all
      GridLayout layout = new GridLayout(1, false);
      layout.verticalSpacing = 1;
      layout.horizontalSpacing = 1;
      layout.marginHeight = 0;
      layout.marginWidth = 0;
      setLayout(layout);


I've also implemented the getter and setter pair for numColumns because the designer set this
value.

Code: Select all
   public void setNumColumns(int numcolumns) {
      GridLayout layout = (GridLayout) getLayout();
      layout.numColumns = numcolumns;
   }

   public int getNumColumns() {
      GridLayout layout = (GridLayout) getLayout();
      return layout.numColumns;
   }



When I add a widget to my component the object is added correctly only if I stay on the
first row. If I add a widget on the following rows, my component mess up and put all
the widgets already present using only one column. I've noticed that the XWT file doesn't
have the property numColumns set.

Any suggestion?

thank you.
domfe
 
Posts: 46
Joined: Mon Oct 04, 2010 6:42 am

Re: Custom Widget with GridLayout

Postby Eric Clayberg » Thu Dec 09, 2010 4:20 pm

We have made some improvements in the latest 8.1 build...

http://code.google.com/javadevtools/dow ... -beta.html

We have fixed problems with columns/rows management of implicit GridLayouts. You can't change the number of columns in such a GridLayout, but you can add new Controls in new rows, and you can move or delete new rows. You can"t delete or move (or move before) rows with inherited children.
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

Re: Custom Widget with GridLayout

Postby domfe » Fri Dec 10, 2010 1:37 am

Sorry to bother you but my widget with implicit GridLayout doesn't work as expected: I can't add any object to
it.

Code: Select all
   public Mycomposite(Composite parent, int style) {
      super(parent, style);
      setLayout(new GridLayout(1, false));
   }


You can't change the number of columns


Why not? I want to give my users a custom widget with GridLayout properties already setted (e.g. Margin,
Spacing, etc.) and work with any number of rows and columns like a GridLayout is expected to do.

I'm using the latest Designer 8.1.0.r36x201012090854 upgraded from a previous test build. Maybe
I should test the changes with a fresh Eclipse installation?

Thanks!
domfe
 
Posts: 46
Joined: Mon Oct 04, 2010 6:42 am

Re: Custom Widget with GridLayout

Postby Eric Clayberg » Tue Dec 14, 2010 3:52 pm

In the latest build, you can change the number of columns as long as there are no implicit children already added.
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

Re: Custom Widget with GridLayout

Postby domfe » Wed Dec 15, 2010 7:15 am

Hi Eric.
I'm using the latest build but, as stated in my previous post, I can't add any object to
it.
Would you be so kind to provide a simple example (java and wbp-component) of a
working component with implicit GridLayout? Maybe I'm missing some properties or
methods that I'm required to implement.
I'd like to use my custom SWT component within an XWT Application.

thank you for your time.
domfe
 
Posts: 46
Joined: Mon Oct 04, 2010 6:42 am

Re: Custom Widget with GridLayout

Postby Eric Clayberg » Thu Dec 16, 2010 8:23 pm

It would be much better if you would post a complete, working example illustrating what you are trying to do, so that we don't need to guess.
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

Re: Custom Widget with GridLayout

Postby domfe » Fri Dec 17, 2010 1:23 am

Hi Eric.
Here's my Example3.xwt and MyComponent.java.
I can't add any widget to MyComponent. I would like to use it
as a normal Composite with a GridLayout (add rows and columns)
and some property already setted.

Code: Select all
<Shell xmlns="http://www.eclipse.org/xwt/presentation" xmlns:x="http://www.eclipse.org/xwt" x:Class="test.Example3" text="XWT Application" xmlns:p1="clr-namespace:test">
   <Shell.layout>
      <FormLayout/>
   </Shell.layout>
   <p1:MyComponent background="COLOR_DARK_CYAN" x:Name="myComponent">
      <p1:MyComponent.layoutData>
         <FormData>
            <FormData.bottom>
               <FormAttachment control="{Binding ElementName=button}" offset="173" alignment="SWT.BOTTOM"/>
            </FormData.bottom>
            <FormData.right>
               <FormAttachment numerator="0" offset="286"/>
            </FormData.right>
            <FormData.top>
               <FormAttachment control="{Binding ElementName=button}" offset="43"/>
            </FormData.top>
            <FormData.left>
               <FormAttachment numerator="0" offset="81"/>
            </FormData.left>
         </FormData>
      </p1:MyComponent.layoutData>
   </p1:MyComponent>
   <Button text="Double click me!" x:Name="button">
      <Button.layoutData>
         <FormData>
            <FormData.top>
               <FormAttachment numerator="0" offset="3"/>
            </FormData.top>
            <FormData.left>
               <FormAttachment numerator="0" offset="3"/>
            </FormData.left>
         </FormData>
      </Button.layoutData>
   </Button>
</Shell>


Hope that helps. Thank you.
Attachments
MyComponent.java
(646 Bytes) Downloaded 15 times
domfe
 
Posts: 46
Joined: Mon Oct 04, 2010 6:42 am

Re: Custom Widget with GridLayout

Postby Eric Clayberg » Mon Dec 20, 2010 6:15 am

Here's an example that should work using the latest build...

Code: Select all
public class GridComposite extends Composite {
   private GridLayout layout;

   public GridComposite(Composite parent, int style) {
      super(parent, style);
      layout = new GridLayout(2, false);
      setLayout(layout);
      {
         Button btnButtonAaa = new Button(this, SWT.NONE);
         btnButtonAaa.setText("Button AAA");
      }
      {
         Button btnButtonBbb = new Button(this, SWT.NONE);
         btnButtonBbb.setText("Button BBB");
      }

   }
   public void setNumColumns(int numColumns) {
      gridLayout.numColumns = numColumns;
      layout();
   }
}

Code: Select all
<Composite xmlns="http://www.eclipse.org/xwt/presentation" xmlns:x="http://www.eclipse.org/xwt" x:Class="test.Composite_2" xmlns:p1="clr-namespace:test">
   <Composite.layout>
      <FillLayout/>
   </Composite.layout>
   <p1:GridComposite>
      <Label/>
      <Button text="New Button"/>
   </p1:GridComposite>
</Composite>
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

Re: Custom Widget with GridLayout

Postby domfe » Tue Dec 21, 2010 4:42 am

Thank you Eric. The latest build semms to solve this issue.
My component is now working!

Bye.
domfe
 
Posts: 46
Joined: Mon Oct 04, 2010 6:42 am

Re: Custom Widget with GridLayout

Postby Eric Clayberg » Tue Dec 21, 2010 5:18 am

Glad to hear it!
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: Bing [Bot] and 1 guest

cron