/** Persist the current instance of LaboratoireReference */
  @Override
  protected void save() {

    editor.validateFields();

    editorDriver.flush();

    // Check for errors on the client side
    if (editorDriver.hasErrors()) {
      // Window.alert("LaboratoireReference form not validated locally");
      return;
    }

    Request<Void> saveRequest = request.save(current, isNew);
    saveRequest.to(
        new Receiver<Void>() {
          @Override
          public void onSuccess(Void response) {
            requestFactory
                .getEventBus()
                .fireEvent(new SaveLaboratoireReferenceEvent(current, initField));
            closeForm();
          }

          @Override
          public void onConstraintViolation(Set<ConstraintViolation<?>> errors) {
            // Window.alert("LaboratoireReference form not validated on server");

            // TODO manage errors on client side when made available by GWT
            if (errors != null && errors.size() > 0) {
              // convert ConstraintViolation to get localized messages
              EpicamRenderer renderer = EpicamRenderer.get();
              Set<ConstraintViolation<?>> imogErrors = new HashSet<ConstraintViolation<?>>();
              for (ConstraintViolation<?> error : errors) {
                ImogConstraintViolation violation = new ImogConstraintViolation();
                violation.setLeafBean((BaseProxy) error.getLeafBean());
                violation.setPropertyPath(error.getPropertyPath());
                violation.setRootBean((BaseProxy) error.getRootBean());
                violation.setMessage(renderer.getI18nErrorMessage(error.getMessage()));
                imogErrors.add(violation);
              }
              editorDriver.setConstraintViolations(imogErrors);
            }
          }

          @Override
          public void onFailure(ServerFailure error) {
            Window.alert("Error updating the LaboratoireReference");
            super.onFailure(error);
          }
        });

    request.fire();
  }
  /** Create a new instance of LaboratoireReference */
  private void createNewLaboratoireReference() {

    request = requestFactory.laboratoireReferenceRequest();

    /* create a new intance of LaboratoireReference */
    LaboratoireReferenceProxy newLaboratoireReference =
        request.create(LaboratoireReferenceProxy.class);
    newLaboratoireReference.setId(ImogKeyGenerator.generateKeyId("LAB_REF"));
    LocalizedTextProxy newNom = request.create(LocalizedTextProxy.class);
    newLaboratoireReference.setNom(newNom);
    LocalizedTextProxy newDescription = request.create(LocalizedTextProxy.class);
    newLaboratoireReference.setDescription(newDescription);
    GeoFieldProxy newCoordonnees = request.create(GeoFieldProxy.class);
    newLaboratoireReference.setCoordonnees(newCoordonnees);

    /* push the instance to the editor */
    current = newLaboratoireReference;
    editorDriver.edit(current, request);

    /* set request context for list editor operations */
    editor.setRequestContextForListEditors(request);

    /* update field widgets in editor */
    editor.computeVisibility(null, true);
    // Field districtSante depends on the value of field region
    editor.getDistrictSanteFilteredByRegion(null);
    editor.setEdited(true);
  }
  /**
   * Display the current instance of LieuDit in editor
   *
   * @param entity the LieuDitProxy to be displayed
   */
  private void viewLieuDit(LieuDitProxy entity) {

    /* display instance information */
    setTitle(NLS.constants().lieuDit_name() + ": " + EpicamRenderer.get().getDisplayValue(entity));
    setMetaData((ImogBeanProxy) entity);

    /* push the instance to the editor in view mode */
    request = requestFactory.lieuDitRequest();
    current = request.edit(entity);
    if (current.getDescription() == null) {
      LocalizedTextProxy newDescription = request.create(LocalizedTextProxy.class);
      current.setDescription(newDescription);
    }
    if (current.getCoordonnees() == null) {
      GeoFieldProxy newCoordonnees = request.create(GeoFieldProxy.class);
      current.setCoordonnees(newCoordonnees);
    }

    editor.setEditedValue(current);

    /* set request context for list editor operations */
    editor.setRequestContextForListEditors(request);

    editorDriver.edit(current, request);
    editor.setEdited(false);

    /* update field widgets in editor */
    editor.computeVisibility(null, true);

    /* display edit button */
    if (AccessManager.canEditLieuDit()) setModifiable(true);

    showGlassPanel = false;
    EpicamEntryPoint.GP.hide();
  }
  /**
   * Display the current instance of TransfertReference in editor
   *
   * @param entity the TransfertReferenceProxy to be displayed
   */
  private void viewTransfertReference(TransfertReferenceProxy entity) {

    /* display instance information */
    setTitle(
        NLS.constants().transfertReference_name()
            + ": "
            + EpicamRenderer.get().getDisplayValue(entity));
    setMetaData((ImogBeanProxy) entity);

    /* push the instance to the editor in view mode */
    request = requestFactory.transfertReferenceRequest();
    current = request.edit(entity);

    editor.setEditedValue(current);

    /* set request context for list editor operations */
    editor.setRequestContextForListEditors(request);

    editorDriver.edit(current, request);
    editor.setEdited(false);

    /* update field widgets in editor */
    editor.computeVisibility(null, true);

    /* display edit button */
    if (AccessManager.canEditTransfertReference()) setModifiable(true);

    showGlassPanel = false;
    EpicamEntryPoint.GP.hide();
  }
  /** Create a new instance of TransfertReference */
  private void createNewTransfertReference() {

    request = requestFactory.transfertReferenceRequest();

    /* create a new intance of TransfertReference */
    TransfertReferenceProxy newTransfertReference = request.create(TransfertReferenceProxy.class);
    newTransfertReference.setId(ImogKeyGenerator.generateKeyId("TRANS_REF"));

    /* push the instance to the editor */
    current = newTransfertReference;
    editorDriver.edit(current, request);

    /* set request context for list editor operations */
    editor.setRequestContextForListEditors(request);

    /* update field widgets in editor */
    editor.computeVisibility(null, true);
    // Field districtSante depends on the value of field region
    editor.getDistrictSanteFilteredByRegion(null);
    // Field cDTDepart depends on the value of field districtSante
    editor.getCDTDepartFilteredByDistrictSante(null);
    // Field districtSanteArrivee depends on the value of field regionArrivee
    editor.getDistrictSanteArriveeFilteredByRegionArrivee(null);
    // Field cDTArrivee depends on the value of field districtSanteArrivee
    editor.getCDTArriveeFilteredByDistrictSanteArrivee(null);
    editor.getPatientFilteredByCDTDepart(null);
    editor.setEdited(true);
  }
  /** Create a new instance of LieuDit */
  private void createNewLieuDit() {

    request = requestFactory.lieuDitRequest();

    /* create a new intance of LieuDit */
    LieuDitProxy newLieuDit = request.create(LieuDitProxy.class);
    newLieuDit.setId(ImogKeyGenerator.generateKeyId("LD"));
    LocalizedTextProxy newDescription = request.create(LocalizedTextProxy.class);
    newLieuDit.setDescription(newDescription);
    GeoFieldProxy newCoordonnees = request.create(GeoFieldProxy.class);
    newLieuDit.setCoordonnees(newCoordonnees);

    /* push the instance to the editor */
    current = newLieuDit;
    editorDriver.edit(current, request);

    /* set request context for list editor operations */
    editor.setRequestContextForListEditors(request);

    /* update field widgets in editor */
    editor.computeVisibility(null, true);
    editor.setEdited(true);
  }
 /** Initialize the editor driver */
 private void createDriver() {
   if (editorDriver == null) {
     editorDriver = GWT.create(Driver.class);
     editorDriver.initialize(requestFactory, editor);
   }
 }