issue: setting a property in the desiger

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

issue: setting a property in the desiger

Postby eyal » Mon Oct 16, 2006 1:57 pm

I am creating a composite that is made up of 4 labels. I added a method to the composite that takes in a data object that and then sets the labels according to the values of that object.

by default, the designer creates all objects as final and private to the constructor of the composite, so I changed that and made the labels global variables.

Code: Select all
public class ItemViewer extends Composite {
   
   final Label subjectLabel;
   final Label summaryLabel;
   final Label dateLabel;
   final Label contentLabel;

   public ItemViewer() {

      final Grid grid = new Grid(4, 1);
      initWidget(grid);

      subjectLabel = new Label();
      grid.setWidget(0, 0, subjectLabel);
      grid.getCellFormatter().setHeight(0, 0, "40");
      grid.getCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);

      summaryLabel = new Label();
      grid.setWidget(2, 0, summaryLabel);
      grid.getCellFormatter().setHeight(2, 0, "40");
      summaryLabel.setStyleName("shark-SummaryLabel");

      dateLabel = new Label();
      grid.setWidget(1, 0, dateLabel);
      grid.getCellFormatter().setHeight(1, 0, "40");

      contentLabel = new Label();
      grid.setWidget(3, 0, contentLabel);
      grid.getCellFormatter().setVerticalAlignment(3, 0, HasVerticalAlignment.ALIGN_TOP);
   }
   
   
   public void setItem(NewsItem item) {
      
      subjectLabel.setText(item.getSummary());
      summaryLabel.setText(item.getSummary());
      dateLabel.setText(item.getNewsDate().toLocaleString());
      contentLabel.setText(item.getText());
      
   }

}


now, if I go back to the designer and change the text property of subjectLabel, the app will actually overwrite my setText call in setItem().

let me know if more information is needed. A good solution for this might be to add your own init method that should not be touched by users (similar to what MS is doing in Visual Studio, and Borland does in JBuilder).
eyal
 
Posts: 2
Joined: Mon Oct 16, 2006 1:49 pm

Re: issue: setting a property in the desiger

Postby Eric Clayberg » Mon Oct 16, 2006 5:25 pm

eyal wrote:by default, the designer creates all objects as final and private to the constructor of the composite, so I changed that and made the labels global variables.

You can have widgets generated as local variables or fields depending on your code generation preferences.

You can either have every widget generated as a field by turning on the Create every component as a field by default preference, or you can control it on a type-by-type basis using the Type Specific preferences.

Image Image

You can also convert local variables to fields and back again using the Image Local to Field button.

eyal wrote:if I go back to the designer and change the text property of subjectLabel, the app will actually overwrite my setText call in setItem().

You can hide any code from the Designer parser by using code hiding tags like this...

Code: Select all
   public void setItem(NewsItem item) {
      //$hide>>$
      subjectLabel.setText(item.getSummary());
      summaryLabel.setText(item.getSummary());
      dateLabel.setText(item.getNewsDate().toLocaleString());
      contentLabel.setText(item.getText());
      //$hide<<$
   }


See the Designer > Code Generation > Code Parsing preferences...

Image

eyal wrote:A good solution for this might be to add your own init method that should not be touched by users (similar to what MS is doing in Visual Studio, and Borland does in JBuilder).

That would be far too restrictive for msot users. Designer is a true bi-directional code generation tool which allows the user to work equally well in the design view or source view.

One of its primary features is that is doesn't have any restricted code blocks that you can't touch.
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