Widget with multiple constructors

GWT Designer allows you to quickly create the modules, composites, panels, remote services and other elements that comprise Google Web Tookit applications.

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

Widget with multiple constructors

Postby richfarrell » Wed Mar 07, 2007 2:06 pm

Hello,
I am experimenting with what I can do with widgets.
If I build a widget which has the default constructor it displays when I load it in the designer.
If I provide 2 constructors the designer shows unknown window type.
Is there anything I can do to avoid this (use the default constructor for instance)?

Below is an example (note the example is oversimplied, both versions are identical rather than the 2nd being dynamic based on the input parameters. The default constructor alone works, having 2 different constructors with the same code doesn't).
... Rich

Code: Select all
package com.uptodate.utdadmin.client.widget;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.uptodate.utdadmin.client.widget.HtmlWidget;

public class RfBlock extends Composite {


   
   public RfBlock() {
      final Grid grid = new Grid(2,1);
      initWidget(grid);
      grid.setBorderWidth(2);

      final HtmlWidget htmlWidget = new HtmlWidget();
      for (int i=0; i< 1; i++) {
         grid.setWidget(i, 0, htmlWidget);
      
      }      
   }

   public RfBlock(int row, int col) {
      final Grid grid = new Grid(2,1);
      initWidget(grid);
      grid.setBorderWidth(2);

      final HtmlWidget htmlWidget = new HtmlWidget();
      for (int i=0; i< 1; i++) {
         grid.setWidget(i, 0, htmlWidget);
      
      }      
   }
   
}
richfarrell
 
Posts: 3
Joined: Wed Mar 07, 2007 11:36 am
Location: waltham, ma

Re: Widget with multiple constructors

Postby Eric Clayberg » Mon Mar 12, 2007 4:32 am

You can use a code hiding tag to hide the second constructor...

Code: Select all
public class RfBlock extends Composite {
   public RfBlock() {
      final Grid grid = new Grid(2, 1);
      initWidget(grid);
      grid.setBorderWidth(2);
      final HtmlWidget htmlWidget = new HtmlWidget();
      for (int i = 0; i < 2; i++) {
         grid.setWidget(i, 0, htmlWidget);
      }
   }
   //$hide>>$
   public RfBlock(int row, int col) {
      final Grid grid = new Grid(2, 1);
      initWidget(grid);
      grid.setBorderWidth(2);
      final HtmlWidget htmlWidget = new HtmlWidget();
      for (int i = 0; i < 1; i++) {
         grid.setWidget(i, 0, htmlWidget);
      }
   }
   //$hide<<$
}

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 GWT Designer

Who is online

Users browsing this forum: No registered users and 3 guests