Background:
Hello I am quite new to GWT and Java. I have an application which
helps students select courses. The application starts and the user
clicks on a department. When they click on the department the courses
offered by that department are shown with check boxes next to each
course.
Objective/Problem:
What I need to do is have a separate panel called the "summary panel"
that shows a summary of the users selections. I need to keep track of
the current selections in some variable that can be used to populate
the new widget.
Questions:
For my checkboxes, how do I call a method to set the check box as
checked or unchecked depending on its state when clicked and then show
the users selections when something is clicked? The summary panel
also needs to be updated on each change in the course selection. My
code is below, any help would be appreciated. Thanks
public class HW4_bleicherm implements EntryPoint {
private Widget selectedDepartmentRow;
private Department selectedDepartment;
private VerticalPanel coursesWidget;
private Widget summaryWidget;
public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get();
rootPanel.setSize("450", "300");
DockPanel mainPanel = new DockPanel();
mainPanel.setBorderWidth(5);
mainPanel.setSize("482px", "312px");
mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
Widget header = createHeaderWidget();
mainPanel.add(header, DockPanel.NORTH);
mainPanel.setCellHeight(header, "30px");
HorizontalSplitPanel departmentsAndCourses =
new HorizontalSplitPanel();
departmentsAndCourses.setSplitPosition("200px");
mainPanel.add(departmentsAndCourses, DockPanel.CENTER);
departmentsAndCourses.setSize("458px", "309px");
RootPanel.get().add(mainPanel, 0, 10);
Widget departments = createDepartmentsWidget();
departmentsAndCourses.setLeftWidget(departments);
Widget courses = createCoursesWidget();
departmentsAndCourses.setRightWidget(courses);
VerticalPanel summaryPanel = new VerticalPanel();
summaryPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
mainPanel.add(summaryPanel, DockPanel.SOUTH);
summaryPanel.setSize("100%", "46px");
Widget summary = createSummaryWidget();
mainPanel.add(summary);
}
private Widget createSummaryWidget(Widget summary) {
// TODO Auto-generated method stub
return null;
}
/**
* Creates the header part of the layout.
*/
protected Widget createHeaderWidget() {
return new Label("Computer Science Course Selection Guide");
}
/**
* Creates the widget that displays the list of
* departments on the left side of the screen
*/
protected Widget createDepartmentsWidget() {
VerticalPanel departmentList = new VerticalPanel();
departmentList.setWidth("100%");
List<Department> departments = getAllDepartments();
for (final Department ins : departments) {
Widget departmentRow = createDepartmentRow(ins);
departmentList.add(departmentRow);
}
return departmentList;
}
/**
* Creates the widget that displays the department
* in the department list
*/
protected Widget createDepartmentRow(final Department department) {
final Label row = new Label(department.getName());
row.setWordWrap(false);
row.setStyleName("departmentRow");
row.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent e) {
if (row.equals(selectedDepartmentRow)) {
return; // do nothing as it is already selected
}
markSelected(selectedDepartmentRow, false);
markSelected(row, true);
selectedDepartmentRow = row;
selectedDepartment = department;
updateCoursesList();
}
});
return row;
}
/**
* Marks the department row as selected/unselected
*/
protected void markSelected(Widget departmentRow, boolean selected) {
if (departmentRow == null) {
return;
}
if (selected) {
departmentRow.addStyleName("selectedDepartment");
departmentRow.removeStyleName("unselectedDepartment");
} else {
departmentRow.addStyleName("unselectedDepartment");
departmentRow.removeStyleName("selectedDepartment");
}
}
/**
* Updates the courses shown on the right side of the screen
* that are offered by the selected department.
*/
public void updateCoursesList() {
List<Course> courses = getCoursesForSelectedDepartment();
coursesWidget.clear();
for (Course c : courses) {
Widget courseRow = createCourseRow(c);
coursesWidget.add(courseRow);
}
}
/**
* Creates the widget that will display the list of courses
* on the right side of the screen
*/
public Widget createCoursesWidget() {
coursesWidget = new VerticalPanel();
coursesWidget.setWidth("100%");
return coursesWidget;
}
/**
* Creates the widget that displays courses in the courses list.
* Shows the name of the course along with a checkbox next to the
course.
*/
public Widget createCourseRow(Course course) {
HorizontalPanel row = new HorizontalPanel();
CheckBox checkbox = new CheckBox();
row.add(checkbox);
row.add(new Label(course.getCourseName()));
return row;
}
/**
* Returns a list of all available departments.
*/
public List<Department> getAllDepartments() {
List<Department> departmentList = new ArrayList<Department>();
departmentList.add(new Department("MET", "MET"));
departmentList.add(new Department("CAS", "CAS"));
return departmentList;
}
/**
* Returns a list of courses offered by the
* selected department.
*/
public List<Course> getCoursesForSelectedDepartment() {
List<Course> courses = new ArrayList<Course>();
if (selectedDepartment == null) {
return courses;
}
else if (selectedDepartment.getId().equals("MET")) {
courses.add(new Course("CS341", "Data
Structures","Maslanka","Wednesday"));
courses.add(new Course("CS702","Advanced Web Application
Development","Kalathur","Tuesday"));
return courses;
}
else if (selectedDepartment.getId().equals("CAS")) {
courses.add(new
Course("CS105","Databases","Sullivan","Monday"));
courses.add(new Course("CS455","Computer
Networks","Crovella","Thursday"));
return courses;
}
return courses;
}
}
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.