susieq69 0 Newbie Poster

Hello I am quite new to GWT and Java. I am doing an assigment 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. This all works fine, however what I need to do is have a separate panel called the "summary panel" that shows a summary of the users selections. The summary panel also needs to be updated on each change in the course selection.

Question:

How do I code this "summary panel" to show the users selections. In other words when a user has checked a course how do I show the contents of what the user checked(course name, course id, instructor, and day) I need to have a separate panel to show the summary of the course that was checked? My Code is below: Thanks

package cs701.client;

import java.util.ArrayList;
import java.util.List;

import cs701.client.Course;
import cs701.client.Department;
import cs701.shared.FieldVerifier;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.HorizontalSplitPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.CaptionPanel;
import com.google.gwt.user.client.ui.VerticalSplitPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HTMLPanel;


/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class HW4_bleicherm implements EntryPoint {


        private Widget selectedDepartmentRow;
        private Department selectedDepartment;
        private VerticalPanel coursesWidget;


    public void onModuleLoad() {


            RootPanel rootPanel = RootPanel.get();
            rootPanel.setSize("450", "300");
            DockPanel mainPanel = new DockPanel();
            mainPanel.setBorderWidth(5);
            mainPanel.setSize("482px", "422px");
            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);



        }

    /**
     * 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 list of
     * checked courses
     * @param checkbox 
     * 
     */



/**
 * 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;
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.