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).