Exemple #1
0
  /** Prepares the language form */
  private Tab setupLanguage(final ValuesManager vm) {
    Tab languageTab = new Tab();
    languageTab.setTitle(I18N.message(LANGUAGE));

    SelectItem languageItem = ItemFactory.newLanguageSelector(LANGUAGE, false, true);
    languageItem.setTitle(I18N.message("defaultlang"));
    languageItem.setRequired(true);
    languageItem.setValue(I18N.getLocale());

    final DynamicForm languageForm = new DynamicForm();
    languageForm.setID("languageForm");
    languageForm.setValuesManager(vm);
    languageForm.setFields(languageItem);
    languageForm.setDisabled(true);
    languageTab.setPane(languageForm);
    return languageTab;
  }
  public DuengungDetailsWindow(
      final DuengungRecord record, final boolean addNewRecord, AbstractListGrid grid) {
    super();
    SelectItem duengerartItem = new SelectItem(DuengungRecord.DUENGERART, "Düungerart");
    duengerartItem.setRequired(true);
    this.duengerartDataSource = new DuengerartDataSource(duengerartItem);

    this.stammdatenManager = new StammdatenManager();
    this.dataManager = new DataManager();

    this.grid = grid;
    setTitle("Düngung");
    setAutoSize(true);
    setCanDragResize(true);
    setIsModal(true);
    setShowModalMask(true);
    setAutoCenter(true);

    /* create the form */
    FloatItem flaecheItem =
        FormItemFactory.createFloatItem(DuengungRecord.FLAECHE, "Fläche", true);
    DateItem datumItem = FormItemFactory.createDateItem(DuengungRecord.DATUM, "Datum", true);
    FloatItem kgProHaItem =
        FormItemFactory.createFloatItem(DuengungRecord.KG_PRO_HA, "kg/ha", false);
    FloatItem ecItem = FormItemFactory.createFloatItem(DuengungRecord.EC, "EC", false);
    TextAreaItem bemItem =
        FormItemFactory.createTextAreaItem(DuengungRecord.BEMERKUNG, "Bemerkung", false);

    final DynamicForm form = new DynamicForm();
    form.setItems(datumItem, duengerartItem, flaecheItem, kgProHaItem, ecItem, bemItem);

    // display values form an existing entry
    if (!addNewRecord && record != null) {
      Duengung d = record.getDTO();

      bemItem.setValue(d.getBemerkung() != null ? d.getBemerkung() : "");
      flaecheItem.setValue(d.getFlaeche());
      datumItem.setValue(d.getDatum() != null ? d.getDatum() : new Date());
      ecItem.setValue(d.getEc() != null ? d.getEc() : Double.valueOf(0));
      kgProHaItem.setValue(d.getKgProHa() != null ? d.getKgProHa() : Double.valueOf(0));
      if (d.getDuengerartKey() != null) {
        duengerartDataSource.setSelectedValue(d.getDuengerartKey().getId());
      }
    }

    /* create the save & cancel buttons */
    com.smartgwt.client.widgets.Button saveBtn =
        new com.smartgwt.client.widgets.Button("Speichern");
    saveBtn.addClickHandler(
        new com.smartgwt.client.widgets.events.ClickHandler() {
          @Override
          public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
            if (form.validate()) {
              // save changes
              onSavePressed(record, form, addNewRecord);
              // close dialog window
              DuengungDetailsWindow.this.destroy();
            }
          }
        });

    com.smartgwt.client.widgets.Button cancelBtn =
        new com.smartgwt.client.widgets.Button("Abbrechen");
    cancelBtn.addClickHandler(
        new com.smartgwt.client.widgets.events.ClickHandler() {
          @Override
          public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
            // close dialog window
            DuengungDetailsWindow.this.destroy();
          }
        });

    /* create the layout */

    // panel for the buttons
    HLayout btnLayout = new HLayout();
    btnLayout.setMargin(10);
    // add the buttons
    btnLayout.addMember(saveBtn);
    btnLayout.addMember(cancelBtn);

    VLayout verticalPanel = new VLayout();
    verticalPanel.setMargin(10);
    verticalPanel.setPadding(5);

    // add the form
    verticalPanel.addMember(form);
    // and the buttons
    verticalPanel.addMember(btnLayout);

    // add panel to component
    addItem(verticalPanel);
  }