Java Reference
In-Depth Information
To track the date that the user selected in the addValueChangeHandler method above,
you'll need to add another private instance variable called startDate.
private Date startDate;
Your preceding addValueChangeHandler method also calls a renameColumns method.
To implement this method and its helper methods we need to have a quick
discussion regarding date classes. Unfortunately, GWT doesn't support
java.util.Calendar on the client and it doesn't appear that it will any time soon. Due
to the way that individual browsers deal with dates, using dates on the client side
with GWT is currently messy and involves using all of the deprecated methods of the
java.util.Date class. Here is your renameColumns method along with the helper
methods using the deprecated java.util.Date class methods.
private void renameColumns() {
flexEntryTable.setText(0, 3, formatDate(startDate));
flexEntryTable.setText(0, 4, formatDate(addDays(startDate,1)));
flexEntryTable.setText(0, 5, formatDate(addDays(startDate,2)));
flexEntryTable.setText(0, 6, formatDate(addDays(startDate,3)));
flexEntryTable.setText(0, 7, formatDate(addDays(startDate,4)));
flexEntryTable.setText(0, 8, formatDate(addDays(startDate,5)));
flexEntryTable.setText(0, 9, formatDate(addDays(startDate,6)));
}
private Date addDays(Date d, int numberOfDays) {
int day = d.getDate();
int month = d.getMonth();
int year = d.getYear();
return new Date(year, month, day+numberOfDays);
}
private String formatDate(Date d) {
return (d.getMonth()+1)+"/"+d.getDate()+"
("+d.toString().substring(0, 2)+")";
}
The last part of this chapter covers the FlexTable and how users enter their time.
Each row has a text box for each day of the week, and you'll need to implement
handlers and listeners to validate the data that the user enters. Add the following
110
 
Search WWH ::




Custom Search