@Override
 protected void cancel() {
   if (parent != null) parent.hide();
   else {
     if (isNew) requestFactory.getEventBus().fireEvent(closeEvent);
     else
       requestFactory.getEventBus().fireEvent(new ViewLieuDitEvent(current.getId(), closeEvent));
   }
 }
  /**
   * 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();
  }
  private void setButtonHandlers() {

    final EventBus eventBus = requestFactory.getEventBus();

    // Handler for filterButton
    if (filterButton != null) {
      registrations.add(
          eventBus.addHandler(
              IsTableFilteredEvent.TYPE,
              new IsTableFilteredEvent.Handler() {
                @Override
                public void noticeFilteringChange(Boolean isFiltered, String message) {
                  if (isFiltered) {
                    filterButton.setButtonActivatedStyle();
                    wrapperPanel.setMessageLabel(message);
                  } else {
                    filterButton.removeButtonActivatedStyle();
                    wrapperPanel.clearMessageLabel();
                  }
                }
              }));
    }

    // Handler for plusButton
    if (plusButton != null) {
      registrations.add(
          eventBus.addHandler(
              SelectMenuItemEvent.TYPE,
              new SelectMenuItemEvent.Handler() {
                @Override
                public void selectMenuItem(SimpleMenuItem menuItem) {
                  plusButton.hidePopup();
                }
              }));
    }

    // Handler for listButton
    if (listButton != null) {
      registrations.add(
          eventBus.addHandler(
              SelectMenuItemEvent.TYPE,
              new SelectMenuItemEvent.Handler() {
                @Override
                public void selectMenuItem(SimpleMenuItem menuItem) {
                  listButton.hidePopup();
                }
              }));
    }

    // Handler for goHomeButton
    if (goHomeButton != null) {
      registrations.add(
          goHomeButton.addClickHandler(
              new ClickHandler() {
                public void onClick(ClickEvent event) {
                  History.newItem(TokenHelper.TK_CLASSIC, true);
                }
              }));
    }
  }
  /** 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);
  }
  /**
   * Get an existing instance of TransfertReference
   *
   * @param entityId the id of the TransfertReferenceProxy to be fetched
   */
  private void fetchTransfertReference(String entityId) {

    TransfertReferenceRequest request = requestFactory.transfertReferenceRequest();

    /* get the TransfertReference instance from database */
    Request<TransfertReferenceProxy> fetchRequest = request.findById(entityId);
    fetchRequest.with("region");
    fetchRequest.with("region.nom");
    fetchRequest.with("districtSante");
    fetchRequest.with("districtSante.nom");
    fetchRequest.with("CDTDepart");
    fetchRequest.with("patient");
    fetchRequest.with("regionArrivee");
    fetchRequest.with("regionArrivee.nom");
    fetchRequest.with("districtSanteArrivee");
    fetchRequest.with("districtSanteArrivee.nom");
    fetchRequest.with("CDTArrivee");

    fetchRequest
        .to(
            new Receiver<TransfertReferenceProxy>() {
              @Override
              public void onSuccess(TransfertReferenceProxy entity) {
                viewTransfertReference(entity);
              }
            })
        .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);
  }
  /**
   * Workflow constructor for the visualization and edition of an existing LaboratoireReference
   * instance
   *
   * @param factory the application request factory
   * @param entityId the id of the LaboratoireReference instance to be visualized and edited
   * @param titleContainer the label
   * @param parent the parent RelationPopupPanel when the workflow is opened from a relation field
   * @param initField the name of the field that initiated the opening of the workflow when the
   *     workflow is opened from a relation field
   */
  public LaboratoireReferenceEditorWorkflow(
      EpicamRequestFactory factory,
      String entityId,
      Label titleContainer,
      RelationPopupPanel parent,
      String initField) {

    super(factory.getEventBus(), titleContainer, parent);

    requestFactory = factory;
    if (parent != null) {
      editor = new LaboratoireReferenceEditor(factory, true);
      this.initField = initField;
    } else editor = new LaboratoireReferenceEditor(factory);

    setModifiable(false);
    isNew = false;
    setEditable(false);

    createDriver();
    fetchLaboratoireReference(entityId);

    this.setContent(editor);
    showGlassPanel = true;
  }
  /**
   * Get an existing instance of LaboratoireReference
   *
   * @param entityId the id of the LaboratoireReferenceProxy to be fetched
   */
  private void fetchLaboratoireReference(String entityId) {

    LaboratoireReferenceRequest request = requestFactory.laboratoireReferenceRequest();

    /* get the LaboratoireReference instance from database */
    Request<LaboratoireReferenceProxy> fetchRequest = request.findById(entityId);
    fetchRequest.with("nom");
    fetchRequest.with("description");
    fetchRequest.with("region");
    fetchRequest.with("region.nom");
    fetchRequest.with("districtSante");
    fetchRequest.with("districtSante.nom");
    fetchRequest.with("coordonnees");
    fetchRequest.with("lieuxDits");

    fetchRequest
        .to(
            new Receiver<LaboratoireReferenceProxy>() {
              @Override
              public void onSuccess(LaboratoireReferenceProxy entity) {
                viewLaboratoireReference(entity);
              }
            })
        .fire();
  }
  /**
   * 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();
  }
  /** Sets the properties of the fields */
  public void properties() {

    CDT.setLabel(NLS.constants().sortieLot_field_cDT());
    // the value of CDT affects the value of other fields
    CDT.notifyChanges(requestFactory.getEventBus());
    lot.setLabel(NLS.constants().sortieLot_field_lot());
    quantite.setLabel(NLS.constants().sortieLot_field_quantite());
  }
  /**
   * Adds create and export buttons to the wrapper panel
   *
   * @param createCommand
   * @param exportButton
   */
  private void setOtherActions(Command createCommand, Command exportCommand) {

    if (createCommand != null || exportCommand != null) {

      plusButton = new PopupButton(BaseNLS.constants().button_plus());

      if (createCommand != null) {
        SimpleMenuItem item =
            new SimpleMenuItem(
                requestFactory.getEventBus(), BaseNLS.constants().button_create(), createCommand);
        plusButton.addPopupPanelContent(item);
      }

      if (exportCommand != null) {
        SimpleMenuItem item =
            new SimpleMenuItem(
                requestFactory.getEventBus(), BaseNLS.constants().button_export(), exportCommand);
        plusButton.addPopupPanelContent(item);
      }

      wrapperPanel.addHeaderWidget(plusButton);
    }
  }
  /** Manages editor updates when a field value changes */
  private void setFieldValueChangeHandler() {

    registrations.add(
        requestFactory
            .getEventBus()
            .addHandler(
                FieldValueChangeEvent.TYPE,
                new FieldValueChangeEvent.Handler() {
                  @Override
                  public void onValueChange(ImogField<?> field) {

                    // field dependent visibility management
                    computeVisibility(field, false);
                  }
                }));
  }
  /**
   * Get an existing instance of LieuDit
   *
   * @param entityId the id of the LieuDitProxy to be fetched
   */
  private void fetchLieuDit(String entityId) {

    LieuDitRequest request = requestFactory.lieuDitRequest();

    /* get the LieuDit instance from database */
    Request<LieuDitProxy> fetchRequest = request.findById(entityId);
    fetchRequest.with("description");
    fetchRequest.with("coordonnees");

    fetchRequest
        .to(
            new Receiver<LieuDitProxy>() {
              @Override
              public void onSuccess(LieuDitProxy entity) {
                viewLieuDit(entity);
              }
            })
        .fire();
  }
  /** Manages editor updates when a field value changes */
  private void setFieldValueChangeHandler() {

    registrations.add(
        requestFactory
            .getEventBus()
            .addHandler(
                FieldValueChangeEvent.TYPE,
                new FieldValueChangeEvent.Handler() {
                  @Override
                  public void onValueChange(ImogField<?> field) {

                    // field dependent visibility management
                    computeVisibility(field, false);

                    /* Lot list content depends on the value of field CDT */
                    if (field.equals(CDT)) {
                      clearLotWidget();
                      getLotFilteredByCDT(CDT.getValue());
                    }
                  }
                }));
  }
  /** 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);
  }
  /**
   * Workflow constructor for the creation of a LaboratoireReference instance
   *
   * @param factory the application request factory
   * @param titleContainer the Label that will display the workflow title
   * @param parent the parent RelationPopupPanel when the workflow is opened from a relation field
   * @param initField the name of the field that initiated the opening of the workflow when the
   *     workflow is opened from a relation field
   */
  public LaboratoireReferenceEditorWorkflow(
      EpicamRequestFactory factory,
      Label titleContainer,
      RelationPopupPanel parent,
      String initField) {

    super(factory.getEventBus(), titleContainer, parent);

    requestFactory = factory;
    if (parent != null) {
      editor = new LaboratoireReferenceEditor(factory, true);
      this.initField = initField;
    } else editor = new LaboratoireReferenceEditor(factory);

    isNew = true;
    setEditable(true);

    setTitle(NLS.constants().laboratoireReference_create_title());
    createDriver();
    createNewLaboratoireReference();

    this.setContent(editor);
  }
  /** Configures the handlers of the widgets that manage relation fields */
  private void setRelationHandlers() {

    /* 'Information' button for field CDT */
    CDT.setViewClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            if (CDT.getValue() != null) {
              RelationPopupPanel relationPopup = new RelationPopupPanel();
              CentreDiagTraitFormPanel form =
                  new CentreDiagTraitFormPanel(
                      requestFactory, CDT.getValue().getId(), relationPopup, "CDT");
              relationPopup.addWidget(form);
              relationPopup.show();
            }
          }
        });

    /* 'Add' button for field CDT */
    CDT.setAddClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            RelationPopupPanel relationPopup = new RelationPopupPanel();
            CentreDiagTraitFormPanel form =
                new CentreDiagTraitFormPanel(requestFactory, null, relationPopup, "CDT");
            /* common fields */

            relationPopup.addWidget(form);
            relationPopup.show();
          }
        });

    /* SaveEvent handler when a CentreDiagTrait is created or updated from the relation field CDT */
    registrations.add(
        requestFactory
            .getEventBus()
            .addHandler(
                SaveCentreDiagTraitEvent.TYPE,
                new SaveCentreDiagTraitEvent.Handler() {
                  @Override
                  public void saveCentreDiagTrait(CentreDiagTraitProxy value) {
                    CDT.setValue(value);
                  }

                  @Override
                  public void saveCentreDiagTrait(CentreDiagTraitProxy value, String initField) {
                    if (initField.equals("CDT")) CDT.setValue(value, true);
                  }
                }));

    /* 'Information' button for field Lot */
    lot.setViewClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            if (lot.getValue() != null) {
              RelationPopupPanel relationPopup = new RelationPopupPanel();
              LotFormPanel form =
                  new LotFormPanel(requestFactory, lot.getValue().getId(), relationPopup, "lot");
              relationPopup.addWidget(form);
              relationPopup.show();
            }
          }
        });

    /* 'Add' button for field Lot */
    lot.setAddClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            RelationPopupPanel relationPopup = new RelationPopupPanel();
            LotFormPanel form = new LotFormPanel(requestFactory, null, relationPopup, "lot");
            /* common fields */

            relationPopup.addWidget(form);
            relationPopup.show();
          }
        });

    /* SaveEvent handler when a Lot is created or updated from the relation field Lot */
    registrations.add(
        requestFactory
            .getEventBus()
            .addHandler(
                SaveLotEvent.TYPE,
                new SaveLotEvent.Handler() {
                  @Override
                  public void saveLot(LotProxy value) {
                    lot.setValue(value);
                  }

                  @Override
                  public void saveLot(LotProxy value, String initField) {
                    if (initField.equals("lot")) lot.setValue(value, true);
                  }
                }));
  }
  /** @param eventBus */
  private void setListActions() {

    listButton = new PopupButton(BaseNLS.constants().button_list());

    if (AccessManager.canDirectAccessPatient() && AccessManager.canReadPatient()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/patient/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().patient_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessCasTuberculose() && AccessManager.canReadCasTuberculose()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/castuberculose/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().casTuberculose_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessTransfertReference()
        && AccessManager.canReadTransfertReference()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/transfertreference/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(),
              NLS.constants().transfertReference_name_plur(),
              command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessRegime() && AccessManager.canReadRegime()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/regime/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().regime_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessExamenATB() && AccessManager.canReadExamenATB()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/examenatb/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().examenATB_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessExamenBiologique()
        && AccessManager.canReadExamenBiologique()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/examenbiologique/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().examenBiologique_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessExamenMicroscopie()
        && AccessManager.canReadExamenMicroscopie()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/examenmicroscopie/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().examenMicroscopie_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessExamenSerologie() && AccessManager.canReadExamenSerologie()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/examenserologie/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().examenSerologie_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessLot() && AccessManager.canReadLot()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/lot/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().lot_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessCommande() && AccessManager.canReadCommande()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/commande/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().commande_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessReception() && AccessManager.canReadReception()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/reception/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().reception_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessRavitaillement() && AccessManager.canReadRavitaillement()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/ravitaillement/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().ravitaillement_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessInventaire() && AccessManager.canReadInventaire()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/inventaire/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().inventaire_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessHorsUsage() && AccessManager.canReadHorsUsage()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/horsusage/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().horsUsage_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessEntreeLot() && AccessManager.canReadEntreeLot()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/entreelot/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().entreeLot_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessSortieLot() && AccessManager.canReadSortieLot()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/sortielot/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().sortieLot_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessSmsPredefini() && AccessManager.canReadSmsPredefini()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/smspredefini/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().smsPredefini_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessOutBox() && AccessManager.canReadOutBox()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/outbox/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().outBox_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessFormation() && AccessManager.canReadFormation()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/formation/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().formation_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessTutoriel() && AccessManager.canReadTutoriel()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/tutoriel/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().tutoriel_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessRegion() && AccessManager.canReadRegion()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/region/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().region_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessDistrictSante() && AccessManager.canReadDistrictSante()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/districtsante/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().districtSante_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessCentreDiagTrait() && AccessManager.canReadCentreDiagTrait()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/centrediagtrait/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().centreDiagTrait_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessLaboratoireReference()
        && AccessManager.canReadLaboratoireReference()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/laboratoirereference/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(),
              NLS.constants().laboratoireReference_name_plur(),
              command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessLieuDit() && AccessManager.canReadLieuDit()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/lieudit/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().lieuDit_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessMedicament() && AccessManager.canReadMedicament()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/medicament/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().medicament_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessIntrant() && AccessManager.canReadIntrant()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/intrant/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().intrant_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessPersonnel() && AccessManager.canReadPersonnel()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/personnel/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().personnel_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessDepartPersonnel() && AccessManager.canReadDepartPersonnel()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/departpersonnel/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().departPersonnel_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessArriveePersonnel()
        && AccessManager.canReadArriveePersonnel()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/arriveepersonnel/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().arriveePersonnel_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessUtilisateur() && AccessManager.canReadUtilisateur()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/utilisateur/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().utilisateur_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    if (AccessManager.canDirectAccessQualification() && AccessManager.canReadQualification()) {

      Command command =
          new Command() {
            public void execute() {
              LocalSession.get().setSearchCriterions(null, null);
              History.newItem(TokenHelper.TK_LIST + "/qualification/", true);
            }
          };
      SimpleMenuItem item =
          new SimpleMenuItem(
              requestFactory.getEventBus(), NLS.constants().qualification_name_plur(), command);
      listButton.addPopupPanelContent(item);
    }

    wrapperPanel.addHeaderWidget(listButton);
  }
 @Override
 protected void returnToList() {
   requestFactory.getEventBus().fireEvent(new ListTransfertReferenceEvent());
 }
 @Override
 public RequestContext getEntityContext() {
   return requestFactory.priseMedicamentRegimeRequest();
 }
 @Override
 protected void returnToList() {
   requestFactory.getEventBus().fireEvent(new ListLaboratoireReferenceEvent());
 }
 @Override
 protected void returnToList() {
   requestFactory.getEventBus().fireEvent(new ListLieuDitEvent());
 }
 @Override
 public RequestContext getEntityContext() {
   return requestFactory.districtSanteRequest();
 }
 @Override
 public RequestContext getEntityContext() {
   return requestFactory.sortieLotRequest();
 }
  /** Configures the handlers of the widgets that manage relation fields */
  private void setRelationHandlers() {

    /* 'Information' button for field CDT */
    CDT.setViewClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            if (CDT.getValue() != null) {
              RelationPopupPanel relationPopup = new RelationPopupPanel();
              CentreDiagTraitFormPanel form =
                  new CentreDiagTraitFormPanel(
                      requestFactory, CDT.getValue().getId(), relationPopup, "CDT");
              relationPopup.addWidget(form);
              relationPopup.show();
            }
          }
        });

    /* 'Add' button for field CDT */
    CDT.setAddClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            RelationPopupPanel relationPopup = new RelationPopupPanel();
            CentreDiagTraitFormPanel form =
                new CentreDiagTraitFormPanel(requestFactory, null, relationPopup, "CDT");
            /* common fields */

            relationPopup.addWidget(form);
            relationPopup.show();
          }
        });

    /* SaveEvent handler when a CentreDiagTrait is created or updated from the relation field CDT */
    registrations.add(
        requestFactory
            .getEventBus()
            .addHandler(
                SaveCentreDiagTraitEvent.TYPE,
                new SaveCentreDiagTraitEvent.Handler() {
                  @Override
                  public void saveCentreDiagTrait(CentreDiagTraitProxy value) {
                    CDT.setValue(value);
                  }

                  @Override
                  public void saveCentreDiagTrait(CentreDiagTraitProxy value, String initField) {
                    if (initField.equals("CDT")) CDT.setValue(value, true);
                  }
                }));

    /* 'Information' button for field LaboratoireReference */
    laboratoireReference.setViewClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            if (laboratoireReference.getValue() != null) {
              RelationPopupPanel relationPopup = new RelationPopupPanel();
              LaboratoireReferenceFormPanel form =
                  new LaboratoireReferenceFormPanel(
                      requestFactory,
                      laboratoireReference.getValue().getId(),
                      relationPopup,
                      "laboratoireReference");
              relationPopup.addWidget(form);
              relationPopup.show();
            }
          }
        });

    /* 'Add' button for field LaboratoireReference */
    laboratoireReference.setAddClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            RelationPopupPanel relationPopup = new RelationPopupPanel();
            LaboratoireReferenceFormPanel form =
                new LaboratoireReferenceFormPanel(
                    requestFactory, null, relationPopup, "laboratoireReference");
            /* common fields */

            relationPopup.addWidget(form);
            relationPopup.show();
          }
        });

    /* SaveEvent handler when a LaboratoireReference is created or updated from the relation field LaboratoireReference */
    registrations.add(
        requestFactory
            .getEventBus()
            .addHandler(
                SaveLaboratoireReferenceEvent.TYPE,
                new SaveLaboratoireReferenceEvent.Handler() {
                  @Override
                  public void saveLaboratoireReference(LaboratoireReferenceProxy value) {
                    laboratoireReference.setValue(value);
                  }

                  @Override
                  public void saveLaboratoireReference(
                      LaboratoireReferenceProxy value, String initField) {
                    if (initField.equals("laboratoireReference"))
                      laboratoireReference.setValue(value, true);
                  }
                }));

    /* 'Information' button for field CasTb */
    casTb.setViewClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            if (casTb.getValue() != null) {
              RelationPopupPanel relationPopup = new RelationPopupPanel();
              CasTuberculoseFormPanel form =
                  new CasTuberculoseFormPanel(
                      requestFactory, casTb.getValue().getId(), relationPopup, "casTb");
              relationPopup.addWidget(form);
              relationPopup.show();
            }
          }
        });

    /* 'Add' button for field CasTb */
    casTb.setAddClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            RelationPopupPanel relationPopup = new RelationPopupPanel();
            CasTuberculoseFormPanel form =
                new CasTuberculoseFormPanel(requestFactory, null, relationPopup, "casTb");
            /* common fields */

            relationPopup.addWidget(form);
            relationPopup.show();
          }
        });

    /* SaveEvent handler when a CasTuberculose is created or updated from the relation field CasTb */
    registrations.add(
        requestFactory
            .getEventBus()
            .addHandler(
                SaveCasTuberculoseEvent.TYPE,
                new SaveCasTuberculoseEvent.Handler() {
                  @Override
                  public void saveCasTuberculose(CasTuberculoseProxy value) {
                    casTb.setValue(value);
                  }

                  @Override
                  public void saveCasTuberculose(CasTuberculoseProxy value, String initField) {
                    if (initField.equals("casTb")) casTb.setValue(value, true);
                  }
                }));
  }
  /** Configures the handlers of the widgets that manage relation fields */
  private void setRelationHandlers() {

    /* 'Information' button for field Patient */
    patient.setViewClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            if (patient.getValue() != null) {
              RelationPopupPanel relationPopup = new RelationPopupPanel();
              PatientFormPanel form =
                  new PatientFormPanel(
                      requestFactory, patient.getValue().getId(), relationPopup, "patient");
              relationPopup.addWidget(form);
              relationPopup.show();
            }
          }
        });

    /* 'Add' button for field Patient */
    patient.setAddClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            RelationPopupPanel relationPopup = new RelationPopupPanel();
            PatientFormPanel form =
                new PatientFormPanel(requestFactory, null, relationPopup, "patient");
            /* common fields */

            relationPopup.addWidget(form);
            relationPopup.show();
          }
        });

    /* SaveEvent handler when a Patient is created or updated from the relation field Patient */
    registrations.add(
        requestFactory
            .getEventBus()
            .addHandler(
                SavePatientEvent.TYPE,
                new SavePatientEvent.Handler() {
                  @Override
                  public void savePatient(PatientProxy value) {
                    patient.setValue(value);
                  }

                  @Override
                  public void savePatient(PatientProxy value, String initField) {
                    if (initField.equals("patient")) patient.setValue(value, true);
                  }
                }));

    /* 'Information' button for field PatientLie */
    patientLie.setViewClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            if (patientLie.getValue() != null) {
              RelationPopupPanel relationPopup = new RelationPopupPanel();
              PatientFormPanel form =
                  new PatientFormPanel(
                      requestFactory, patientLie.getValue().getId(), relationPopup, "patientLie");
              relationPopup.addWidget(form);
              relationPopup.show();
            }
          }
        });

    /* 'Add' button for field PatientLie */
    patientLie.setAddClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            RelationPopupPanel relationPopup = new RelationPopupPanel();
            PatientFormPanel form =
                new PatientFormPanel(requestFactory, null, relationPopup, "patientLie");
            /* common fields */

            relationPopup.addWidget(form);
            relationPopup.show();
          }
        });

    /* SaveEvent handler when a Patient is created or updated from the relation field PatientLie */
    registrations.add(
        requestFactory
            .getEventBus()
            .addHandler(
                SavePatientEvent.TYPE,
                new SavePatientEvent.Handler() {
                  @Override
                  public void savePatient(PatientProxy value) {
                    patientLie.setValue(value);
                  }

                  @Override
                  public void savePatient(PatientProxy value, String initField) {
                    if (initField.equals("patientLie")) patientLie.setValue(value, true);
                  }
                }));
  }