/**
   * reads the data for the given document and instructor
   *
   * @param doc
   * @param instructor
   */
  public void synchronize(final CachedOpenWorkingCopyDocument doc, final InstructorGWT instructor) {
    this.openDocument = doc;
    instructor.verify();
    this.instructor = instructor;
    this.openDocument.forceSynchronize(
        new AsyncCallback<Void>() {

          @Override
          public void onSuccess(Void result) {

            if ((openDocument.getCourses().size() != 0)
                || (com.google.gwt.user.client.Window.confirm(
                    "The database doesn't contain any course right now. "
                        + "Do you want to proceed?"))) {
              InstructorPreferencesView.this.coursePrefs.setDataSources(doc, instructor);
              InstructorPreferencesView.this.timePrefs.setDataSources(doc, instructor);

              parent.show();
            } else {
              parent.hide();
            }
          }

          @Override
          public void onFailure(Throwable caught) {
            Window.alert("failed to synchronize document");
          }
        });
    parent.show();
  }
  /**
   * The constructor sets up the UI and passes the data fetching parameters to the sub widgets
   *
   * @param service
   * @param documentID
   * @param instructor
   * @param unsavedDocumentStrategy
   */
  public InstructorPreferencesView(
      CachedOpenWorkingCopyDocument openDocument, InstructorGWT instructor) {
    this.openDocument = openDocument;

    instructor.verify();

    this.instructor = instructor;

    HTML instructorName = new HTML("Instructor Time Preferences");
    instructorName.setStyleName("bigBold");
    DOM.setElementAttribute(instructorName.getElement(), "id", "instructorName");
    InstructorPreferencesView.this.add(instructorName);

    InstructorPreferencesView.this.timePrefs =
        new TimePrefsWidget(
            InstructorPreferencesView.this.openDocument, InstructorPreferencesView.this.instructor);

    InstructorPreferencesView.this.setSpacing(20);

    InstructorPreferencesView.this.add(timePrefs);
    InstructorPreferencesView.this.setStyleName("preferencesPanel");

    InstructorPreferencesView.this.coursePrefs =
        new CoursePrefsWidget(
            InstructorPreferencesView.this.openDocument, InstructorPreferencesView.this.instructor);
    InstructorPreferencesView.this.coursePrefs.setStyleName("otherCenterness");
    InstructorPreferencesView.this.coursePrefs.afterPush();

    HTML cprefs = new HTML("Instructor Course Preferences");
    cprefs.addStyleName("bigBold");
    InstructorPreferencesView.this.add(cprefs);

    InstructorPreferencesView.this.add(coursePrefs);

    closebutton =
        new Button(
            "Close",
            new ClickHandler() {
              public void onClick(ClickEvent event) {
                parent.hide();
              }
            });

    if (additionalCloseHandler != null) {
      closebutton.addClickHandler(additionalCloseHandler);
      additionalCloseHandler = null;
    }
    DOM.setElementAttribute(closebutton.getElement(), "id", "s_prefCloseBtn");
    InstructorPreferencesView.this.add(closebutton);
    InstructorPreferencesView.this.setCellHorizontalAlignment(closebutton, ALIGN_RIGHT);
  }