private void initFilterList(final FormItemContainer formLayout) {
    final List<EPFilterSettings> existingFilters = ePFMgr.getSavedFilterSettings(getIdentity());
    for (final Iterator<EPFilterSettings> existingFilterIt = existingFilters.iterator();
        existingFilterIt.hasNext(); ) {
      if (existingFilterIt.next().isFilterEmpty()) {
        existingFilterIt.remove();
      }
    }

    final int amount = existingFilters.size() + 1;
    nonEmptyFilters = new ArrayList<EPFilterSettings>(amount);
    final String[] theKeys = new String[amount];
    final String[] theValues = new String[amount];

    String presetFilterIndex = theKeys[0] = "0";
    theValues[0] = translate("filter.all");

    int i = 1;
    final String presetFilterID = filterSettings.getFilterId();
    for (final EPFilterSettings epFilterSettings : existingFilters) {
      theKeys[i] = epFilterSettings.getFilterId();
      theValues[i] = epFilterSettings.getFilterName();
      if (presetFilterID != null && presetFilterID.equals(epFilterSettings.getFilterId())) {
        presetFilterIndex = epFilterSettings.getFilterId();
      }
      nonEmptyFilters.add(epFilterSettings);
      i++;
    }
    // don't show anything if no filter exists
    if (!nonEmptyFilters.isEmpty()) {
      if (formLayout.getFormComponent("filter.select") == null) {
        filterSel =
            uifactory.addDropdownSingleselect(
                "filter.select", formLayout, theKeys, theValues, null);
        filterSel.addActionListener(this, FormEvent.ONCHANGE);
      } else {
        filterSel.setKeysAndValues(theKeys, theValues, null);
        filterSel.setVisible(true);
      }
      if (presetFilterIndex != null) {
        filterSel.select(presetFilterIndex, true);
      }
    } else if (formLayout.getFormComponent("filter.select") != null) {
      formLayout.getFormComponent("filter.select").setVisible(false);
    }
  }
  /**
   * org.olat.presentation.framework.control.Controller,
   * org.olat.presentation.framework.UserRequest)
   */
  @SuppressWarnings("unused")
  @Override
  protected void initForm(
      final FormItemContainer formLayout, final Controller listener, final UserRequest ureq) {
    searchQuery = uifactory.addTextElement("search", null, 250, null, formLayout);
    searchQuery.setDisplaySize(40);
    searchQuery.setExampleKey("navigation.create.article.example", null);

    // it doesn't seem to work
    // String regExp = "[a-zA-Z0-9]*";
    // searchQuery.setRegexMatchCheck(regExp, "navigation.create.article.validation.error");

    final FormSubmit submit = new FormSubmit("subm", "navigation.create.article");
    formLayout.add(submit);
  }
  /**
   * Adds a sublayout to the form. If the user selects no from the vertical radio buttons, the
   * sublayout shows up and the user is asked to provide more information.
   *
   * @param formItemsFactory
   * @param form
   */
  private void addSublayout(final FormItemContainer form) {
    // Default Sublayout
    final FormLayoutContainer subLayout =
        FormLayoutContainer.createDefaultFormLayout("why_not_form", getTranslator());
    // This doesn't work for some reason
    // subLayout.setVisible(false);
    form.add(subLayout);

    // Add a text element
    uifactory.addTextElement("why_not", "advanced_form.why_not?", 512, null, subLayout);

    // Let's try some show/hide rules. If 'No' is selected, the sublayout shows
    // up. Note: It's important to set the horizontal radio buttons to a default
    // value.
    RulesFactory.createHideRule(horizontalRadioButtons, yesOrNoKeys[0], subLayout, form);
    RulesFactory.createShowRule(horizontalRadioButtons, yesOrNoKeys[1], subLayout, form);
  }
Example #4
0
  @Override
  protected void initForm(
      final FormItemContainer formLayout, final Controller listener, final UserRequest ureq) {
    setFormTitle("pane.tab.infos_config.title");
    setFormContextHelp(
        InfoConfigForm.class.getPackage().getName(),
        "ced-info-config.html",
        "help.hover.info.config");

    final String page = velocity_root + "/editShow.html";
    final FormLayoutContainer showLayout =
        FormLayoutContainer.createCustomFormLayout(
            "pane.tab.infos_config.shown", getTranslator(), page);
    showLayout.setLabel("pane.tab.infos_config.shown", null);
    formLayout.add(showLayout);

    durationSelection =
        uifactory.addDropdownSingleselect(
            "pane.tab.infos_config.max_duration",
            showLayout,
            maxDurationValues,
            maxDurationValues,
            null);
    durationSelection.setLabel("pane.tab.infos_config.max", null);
    final String durationStr = (String) config.get(InfoCourseNodeConfiguration.CONFIG_DURATION);
    if (StringHelper.containsNonWhitespace(durationStr)) {
      durationSelection.select(durationStr, true);
    } else {
      durationSelection.select("30", true);
    }

    lengthSelection =
        uifactory.addDropdownSingleselect(
            "pane.tab.infos_config.max_shown", showLayout, maxLengthValues, maxLengthValues, null);
    lengthSelection.setLabel("pane.tab.infos_config.max", null);
    final String lengthStr = (String) config.get(InfoCourseNodeConfiguration.CONFIG_LENGTH);
    if (StringHelper.containsNonWhitespace(lengthStr)) {
      lengthSelection.select(lengthStr, true);
    } else {
      lengthSelection.select("5", true);
    }

    uifactory.addFormSubmitButton("save", formLayout);
  }
  @SuppressWarnings("unused")
  protected void initOrUpdateForm(
      final FormItemContainer formLayout, final Controller listener, final UserRequest ureq) {
    // filter by tag
    if (formLayout.getFormComponent("tagLayout") == null) {
      tagFlc =
          FormLayoutContainer.createCustomFormLayout(
              "tagLayout", getTranslator(), this.velocity_root + "/filter-tags.html");
      formLayout.add(tagFlc);
      initTagFlc();
    } else {
      updateTagFlc();
    }

    // filter by type
    if (formLayout.getFormComponent("typeLayout") == null) {
      typeFlc =
          FormLayoutContainer.createCustomFormLayout(
              "typeLayout", getTranslator(), this.velocity_root + "/filter-types.html");
      formLayout.add(typeFlc);
      initOrUpdateTypeFlc(DEFAULT_TYPE_AMOUNT);
    } else {
      updateTypeFlc();
    }

    // filter by date
    if (formLayout.getFormComponent("dateLayout") == null) {
      final String page = this.velocity_root + "/filter_date.html";
      dateFlc = FormLayoutContainer.createCustomFormLayout("dateLayout", getTranslator(), page);
      formLayout.add(dateFlc);
      dateFlc.setLabel("filter.by.date", null);
      dateStart = uifactory.addDateChooser("filter.date.start", "", dateFlc);
      dateStart.addActionListener(this, FormEvent.ONCHANGE);
      dateEnd = uifactory.addDateChooser("filter.date.end", "", dateFlc);
      dateEnd.addActionListener(listener, FormEvent.ONCHANGE);
      dateStart.clearError();
      dateEnd.clearError();
    }

    if (filterSettings.getDateFilter().size() == 2) {
      dateStart.setDate(filterSettings.getDateFilter().get(0));
      dateEnd.setDate(filterSettings.getDateFilter().get(1));
    } else {
      dateStart.setDate(null);
      dateEnd.setDate(new Date());
    }

    // filter by fulltext
    final String searchText = filterSettings.getTextFilter();
    if (formLayout.getFormComponent("search") == null) {
      searchFld = uifactory.addTextElement("search", "filter.search", 20, searchText, formLayout);
      searchFld.addActionListener(listener, FormEvent.ONCHANGE);
    } else {
      searchFld.setValue(searchText);
    }

    // show filter list and save as new
    if (formLayout.getFormComponent("spacer") == null) {
      uifactory.addSpacerElement("spacer", formLayout, false);
    }

    // filter list
    initFilterList(formLayout);
    // filter save
    if (formLayout.getFormComponent("filterSaveLayout") == null) {
      filterFlc =
          FormLayoutContainer.createHorizontalFormLayout("filterSaveLayout", getTranslator());
      formLayout.add(filterFlc);
      filterFlc.setLabel("filter.save", null);
      filterName =
          uifactory.addTextElement(
              "filter.save.name", null, 30, filterSettings.getFilterName(), filterFlc);
      filterSave =
          uifactory.addFormLink(
              "filter.save.link", "filter.save.new", null, filterFlc, Link.BUTTON_XSMALL);
      filterDel =
          uifactory.addFormLink(
              "filter.del.link", "filter.del.link", null, filterFlc, Link.BUTTON_XSMALL);
    } else {
      filterName.setValue(filterSettings.getFilterName());
    }

    final boolean isExistingFilter = filterSettings.getFilterName() != null;
    toggleSaveUpdateFilterButtons(isExistingFilter);
  }
  /**
   * org.olat.presentation.framework.control.Controller,
   * org.olat.presentation.framework.UserRequest)
   */
  @Override
  @SuppressWarnings("unused")
  // listener is never used because listener == this!
  protected void initForm(
      final FormItemContainer formLayout, final Controller listener, final UserRequest ureq) {
    setFormTitle("guidemo_flexi_form_advanced");
    setFormDescription("advanced_form.description");
    // setFormContextHelp(this.getClass().getPackage().getName(),
    // "advancedFormHelp", "advanced_form.description");
    // Mandatory and read-only text fields

    this.addTextFields(formLayout);

    // More form items: Date, link and file selector
    this.addDateLinkAndFileItems(formLayout);

    // Separator with line
    uifactory.addSpacerElement("spacer", formLayout, false);

    // Single and multible selections (radio buttons and checkboxes)
    this.addSelections(formLayout);

    // Separator without line
    uifactory.addSpacerElement("spacernoline", formLayout, true);

    // Sublayout (shown if no is selected)
    this.addSublayout(formLayout);

    // Here's a text area
    uifactory.addTextAreaElement("guidemo.form.textarea", 0, 2, null, formLayout);

    // Add some rich text elements
    richTextElement =
        uifactory.addRichTextElementForStringData(
            "guidemo.form.richtext.simple",
            "guidemo.form.richtext.simple",
            "click <i>to</i> <b>edit</b>. This one has an event listener and an <b>external menu with auto hide</b>",
            -1,
            -1,
            true,
            false,
            null,
            null,
            formLayout,
            ureq.getUserSession(),
            getWindowControl());
    // richTextElement.addActionListener(this, FormEvent.ONCHANGE);

    richTextElement2 =
        uifactory.addRichTextElementForStringData(
            "guidemo.form.richtext.simple2",
            null,
            "one <i>with</i> <b>height</b> and <span style='color:red'>no</span> event listener and an <b>internal</b> menu",
            10,
            40,
            false,
            true,
            null,
            null,
            formLayout,
            ureq.getUserSession(),
            getWindowControl());

    disabledRichTextElement =
        uifactory.addRichTextElementForStringData(
            "guidemo.form.richtext.simple3",
            "guidemo.form.richtext.simple",
            "this <i>is</i> <b>disabled</b>",
            -1,
            -1,
            true,
            false,
            null,
            null,
            formLayout,
            ureq.getUserSession(),
            getWindowControl());
    disabledRichTextElement.setEnabled(false);

    // Button layout
    final FormLayoutContainer buttonLayout =
        FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
    formLayout.add(buttonLayout);

    // Submit and cancel buttons (without effect)
    uifactory.addFormSubmitButton("advanced_form.submit", buttonLayout);
    uifactory.addFormLink("advanced_form.cancel", buttonLayout, Link.BUTTON);
  }