@ShowcaseSource
@Override
public Widget onInitialize() {
// Use a Grid to layout the content
Grid layout = new Grid(4, 2);
CellFormatter formatter = layout.getCellFormatter();
layout.setCellSpacing(5);
// Add a field to select the pattern
patternList = new ListBox();
patternList.setWidth("17em");
String[] patterns = constants.cwDateTimeFormatPatterns();
for (String pattern : patterns) {
patternList.addItem(pattern);
}
patternList.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
updatePattern();
}
});
layout.setHTML(0, 0, constants.cwDateTimeFormatPatternLabel());
layout.setWidget(0, 1, patternList);
// Add a field to display the pattern
patternBox = new TextBox();
patternBox.setWidth("17em");
patternBox.addKeyUpHandler(new KeyUpHandler() {
public void onKeyUp(KeyUpEvent event) {
updatePattern();
}
});
layout.setWidget(1, 1, patternBox);
// Add a field to set the value
valueBox = new TextBox();
valueBox.setWidth("17em");
valueBox.setText("13 September 1999 12:34:56");
valueBox.addKeyUpHandler(new KeyUpHandler() {
public void onKeyUp(KeyUpEvent event) {
updateFormattedValue();
}
});
layout.setHTML(2, 0, constants.cwDateTimeFormatValueLabel());
layout.setWidget(2, 1, valueBox);
// Add a field to display the formatted value
formattedBox = new Label();
formattedBox.setWidth("17em");
layout.setHTML(3, 0, constants.cwDateTimeFormatFormattedLabel());
layout.setWidget(3, 1, formattedBox);
formatter.setVerticalAlignment(3, 0, HasVerticalAlignment.ALIGN_TOP);
// Return the layout Widget
updatePattern();
return layout;
}