I will admit this upfront, I am new to GWT programming. To outline the
overall application, I am trying to make a selection in the left
horizontal panel, which then populates a list of checkboxes on the
right. Upon selecting various items via checkboxes, the bottom panel
should summarize the information.

On the reverse, if something is unchecked, it should remove the item
from the summary panel.

Where I am having a problem, and where I can't find any documentation,
is how do you (or what is the best way) to:

-build an ArrayList or array or table (or anything else) that can be
used to search against to populate the checkboxes and then the summary
panel.

Here is my code:

**********************************************
//LJ_Test.java
package cs701.client;

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

import cs701.client.Course;
import cs701.client.Dept;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DockPanel;
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.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;



/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class LJ_Test implements EntryPoint {
        private Widget selectedDeptRow;
        private Dept selectedDept;
        private VerticalPanel coursesWidget;
        private VerticalPanel summaryWidget;

         /**
           * This is the entry point method.
           */

        public void onModuleLoad() {
                DockPanel mainPanel = new DockPanel();
                mainPanel.setBorderWidth(5);
                mainPanel.setSize("100%", "100%");
                mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
                Widget header = createHeaderWidget();
                mainPanel.add(header, DockPanel.NORTH);
                mainPanel.setCellHeight(header, "30px");
                Widget footer = createFooterWidget();
                mainPanel.add(footer, DockPanel.SOUTH);
                mainPanel.setCellHeight(footer, "25px");

                HorizontalSplitPanel deptsAndCourses =
                        new HorizontalSplitPanel();

                VerticalPanel submit = new VerticalPanel();

                deptsAndCourses.setSplitPosition("200px");
                deptsAndCourses.setHeight("50%");

                Widget depts = createDeptWidget();
                deptsAndCourses.setLeftWidget(depts);

                Widget courses = createCoursesWidget();
                deptsAndCourses.setRightWidget(courses);

                Widget summary = createSummaryWidget();
                submit.add(summary);

                mainPanel.add(deptsAndCourses, DockPanel.CENTER);
                mainPanel.add(submit, DockPanel.SOUTH);
                RootPanel.get().add(mainPanel);
        }
        /**
         * Creates the Summary part of the layout.
         */
        public Widget createSummaryWidget(){
                summaryWidget = new VerticalPanel();
                summaryWidget.setHeight("50%");
                return summaryWidget;
                //return new Label("Summary");
        }

        /**
         * Creates the header part of the layout.
         */
        protected Widget createHeaderWidget() {
                return new Label("LJ_Test");
        }

        /**
         * Creates the footer part of the layout.
         */
        protected Widget createFooterWidget() {
                HTML footer = new HTML("<em>Boston University</em>");
                footer.setStyleName("footer");
                return footer;
        }

        /**
         * Creates the widget that will display the list of
         * depts on the left side of the screen
         */
        protected Widget createDeptWidget() {
                VerticalPanel deptList = new VerticalPanel();
                deptList.setWidth("100%");
                List<Dept> depts = getAllDepts();
                for (final Dept ins : depts) {
                        Widget deptRow = createDeptRow(ins);
                        deptList.add(deptRow);
                }
                return deptList;
        }

        /**
         * Creates the widget that will display a dept
         * in the depts list
         */

        protected Widget createDeptRow(final Dept dept) {
                final Label row = new Label(dept.getName());
                row.setWordWrap(false);
                row.setStyleName("deptRow");
                row.addClickHandler(new ClickHandler() {
                        public void onClick(ClickEvent e) {
                                if (row.equals(selectedDeptRow)) {
                                        return; // do nothing as it is already 
selected
                                }
                                markSelected(selectedDeptRow, false);
                                markSelected(row, true);
                                selectedDeptRow = row;
                                selectedDept = dept;
                                updateCoursesList();
                        }
                });
                return row;
        }

        /**
         * Marks the given dept row as selected/unselected
         */
        protected void markSelected(Widget deptRow, boolean selected) {
                if (deptRow == null) {
                        return;
                }
                if (selected) {
                        deptRow.addStyleName("selectedDept");
                        deptRow.removeStyleName("unselectedDept");
                } else {
                        deptRow.addStyleName("unselectedDept");
                        deptRow.removeStyleName("selectedDept");
                }
        }


        /**
         * Updates the courses shown on the right side of the screen
         * to match the currently selected dept.
         */
        public void updateCoursesList() {
                List<Course> courses = getCoursesForSelectedDept();
                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 display a course in the courses list.
         * This widget shows the name of the course and a checkbox next to
it.
         */

        public Widget createCourseRow(final Course course) {
                HorizontalPanel row = new HorizontalPanel();
                final CheckBox checkbox = new CheckBox();
                checkbox.addClickHandler(new ClickHandler(){
                        public void onClick(ClickEvent event) {
                                if (checkbox.getValue()==true) {
                                        summaryWidget.add(new 
Label(course.getCourseName() + " " +
course.getCourseDay() +" Prof. " + course.getCourseIns() + " on "+
course.getCourseDay()));
                                }
                                else if (checkbox.getValue()==false){
                                        summaryWidget.clear();
                                        summaryCourseList();
                                }
                        }});
                row.add(checkbox);
                row.add(new Label(course.getCourseName()));
                return row;
        }

        public void summaryCourseList(){
                summaryWidget.add(new Label("Click Test 2"));
        }

        /**
         * Returns a list of all available depts.
         */
        public List<Dept> getAllDepts() {
                List<Dept> deptList = new ArrayList<Dept>();
                 deptList.add(new Dept("MET CS", "MET Computer Science"));
                 deptList.add(new Dept("CAS CS", "CAS Computer Science"));
         return deptList;
        }


        /**
         * Returns a list of courses for the currently
         * selected dept.
         */


        public List<Course> getCoursesForSelectedDept() {
                List<Course> courses = new ArrayList<Course>();
                if (selectedDept == null) {
                        return courses;
                }
                else if (selectedDept.getId().equals("MET CS")) {
                        courses.add(new Course("MET CS341",
                                "Data Structures", "Maslanka", "Wednesday"));
                        courses.add(new Course("MET CS701",
                                "Advanced Web Application Development", 
"Kalathur", "Tuesday"));
                        return courses;
                }
                else if (selectedDept.getId().equals("CAS CS")) {
                        courses.add(new Course("CAS CS105",
                                "Databases", "Sullivan", "Monday"));
                        courses.add(new Course("CAS CS455",
                                "Computer Language Theory", "Crovella", 
"Thursday"));
                        return courses;
                }
                else  if (selectedDept.getId().equals("kalathur")) {
                        courses.add(new Course("MET CS520",
                                "Information Structures", null, null));
                        courses.add(new Course("MET CS699", "Data Mining", 
null, null));
                        courses.add(new Course("MET CS701",
                                "Advanced Web Application Development", null, 
null));
                }
                return courses;

        }
}
**********************************************************
//Course.java

package cs701.client;

public class Course {

        //private String courseDept;
        private String courseId;
        private String courseName;
        private String courseIns;
        private String courseDay;

        public Course(/**String crsdpt,**/ String id, String name, String
ins, String day) {
                //this.courseDept = crsdpt;
                this.courseId = id;
                this.courseName = name;
                this.courseIns = ins;
                this.courseDay = day;
        }
        /**
        public String getCourseDept() {
                return courseDept;
        }
        public void setCourseDept(String courseDept) {
                this.courseDept = courseDept;
        }
        **/
        public String getCourseId() {
                return courseId;
        }
        public void setCourseId(String courseId) {
                this.courseId = courseId;
        }

        public String getCourseName() {
                return courseName;
        }
        public void setCourseName(String courseName) {
                this.courseName = courseName;
        }

        public String getCourseIns() {
                return courseIns;
        }
        public void setCourseIns(String courseIns){
                this.courseIns = courseIns;
        }
        public String getCourseDay() {
                return courseDay;
        }
        public void setCourseDay(String courseDay){
                this.courseDay = courseDay;
        }
}

Dept.java
package cs701.client;

public class Dept {

        private String id;
        private String name;

        public Dept(String id, String name) {
                this.id = id;
                this.name = name;
        }

        public String getId() {
                return id;
        }

        public void setId(String id) {
                this.id = id;
        }

        public String getName() {
                return name;
        }
        public void setName(String name) {
                this.name = name;
        }
}


Any help is greatly appreciated.

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

Reply via email to