/**
   * Adds different selection elements to the given form. Like radio buttons and checkboxes.
   *
   * @param formItemsFactory
   * @param form
   */
  private void addSelections(final FormItemContainer form) {
    // drop-down list
    uifactory.addDropdownSingleselect("guidemo.form.pulldown", form, keys, options, null);

    // vertical radio buttons
    verticalRadioButtons = uifactory.addRadiosVertical("guidemo.form.radio1", form, keys, options);
    // As an example on how to use the formInnerEvent method we'll catch events
    // on these radio buttons and therefore need to add the current controller
    // to their listeners.
    verticalRadioButtons.addActionListener(this, FormEvent.ONCLICK);

    // checkboxes
    final MultipleSelectionElement checkboxes =
        uifactory.addCheckboxesVertical(
            "checkboxes", "advanced_form.checkboxes", form, keys, options, null, 1);

    // Translate the keys to the yes and no option values
    final String[] yesOrNoOptions = new String[yesOrNoKeys.length];
    for (int i = 0; i < yesOrNoKeys.length; i++) {
      yesOrNoOptions[i] = translate(yesOrNoKeys[i]);
    }

    // Horizontal radio buttons. Choice between Yes or No.
    horizontalRadioButtons =
        uifactory.addRadiosHorizontal("guidemo.form.radio2", form, yesOrNoKeys, yesOrNoOptions);
    // A default value is needed for show/hide rules
    horizontalRadioButtons.select(yesOrNoKeys[0], true);
    horizontalRadioButtons.addActionListener(
        this, FormEvent.ONCLICK); // Radios/Checkboxes need onclick because of IE bug OLAT-5753
  }
Пример #2
0
  protected ModuleConfiguration getUpdatedConfig() {
    final String durationStr = durationSelection.getSelectedKey();
    config.set(InfoCourseNodeConfiguration.CONFIG_DURATION, durationStr);

    final String lengthStr = lengthSelection.getSelectedKey();
    config.set(InfoCourseNodeConfiguration.CONFIG_LENGTH, lengthStr);

    return config;
  }
  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);
    }
  }
 /**
  * Called if an element inside the form triggers an event. In this particular case clicks on the
  * vertical radio buttons are caught and the user gets notified by his choice.
  *
  * @param ureq
  * @param source
  * @param event
  */
 @Override
 @SuppressWarnings("unused")
 protected void formInnerEvent(
     final UserRequest ureq, final FormItem source, final FormEvent event) {
   if (source == verticalRadioButtons) {
     if (event.wasTriggerdBy(FormEvent.ONCLICK)) {
       final int selectedIndex = verticalRadioButtons.getSelected();
       final String selection = options[selectedIndex];
       showInfo("advanced_form.your_selection_is", selection);
     }
   } else if (source == richTextElement) {
     getWindowControl()
         .setInfo(
             "Wow, you just changed the html editor area. The new content is now: "
                 + richTextElement.getValue());
   }
 }
Пример #5
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);
  }
 /**
  * org.olat.presentation.framework.components.form.flexible.FormItem,
  * org.olat.presentation.framework.components.form.flexible.impl.FormEvent)
  */
 @SuppressWarnings("unused")
 @Override
 protected void formInnerEvent(
     final UserRequest ureq, final FormItem source, final FormEvent event) {
   if (source instanceof FormLink) {
     final FormLink link = (FormLink) source;
     if (link.getName().startsWith(TAG_CMP_IDENTIFIER)) {
       // a tag-Link got clicked, find out which
       final String selectedTag = (String) link.getUserObject();
       if (!selectedTagsList.contains(selectedTag)) {
         selectedTagsList.add(selectedTag);
         tagAllBtn.toggleOff();
         tagNoneBtn.toggleOff();
       } else {
         selectedTagsList.remove(selectedTag);
         if (selectedTagsList.isEmpty()) {
           tagAllBtn.toggleOn();
         }
       }
       filterSettings.setTagFilter(selectedTagsList);
       fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
     } else if (link.getName().startsWith(HANDLER_PREFIX)) {
       // a type-link got clicked
       final String selectedType = (String) link.getUserObject();
       if (!selectedTypeList.contains(selectedType)) {
         selectedTypeList.add(selectedType);
         typeAllBtn.toggleOff();
       } else {
         selectedTypeList.remove(selectedType);
         if (selectedTypeList.isEmpty()) {
           typeAllBtn.toggleOn();
         }
       }
       filterSettings.setTypeFilter(selectedTypeList);
       fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
     }
   }
   if (source == tagAllBtn) {
     resetTagLinks();
     tagNoneBtn.toggleOff();
     filterSettings.setTagFilter(selectedTagsList);
     fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
   } else if (source == tagNoneBtn) {
     resetTagLinks();
     tagAllBtn.toggleOff();
     filterSettings.setNoTagFilter();
     fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
   } else if (source == typeAllBtn) {
     resetTypeLinks();
     filterSettings.setTypeFilter(selectedTypeList);
     fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
   } else if (source == dateStart || source == dateEnd) {
     if (validateFormLogic(ureq)) {
       final List<Date> dateList = new ArrayList<Date>();
       final Date selStartDate = dateStart.getDate();
       final Date selEndDate = dateEnd.getDate();
       dateList.add(selStartDate);
       dateList.add(selEndDate);
       filterSettings.setDateFilter(dateList);
       fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
     }
   } else if (source == typeEditBtn) {
     popupTypesCallout(ureq);
   } else if (source == tagEditBtn) {
     popupTagsCallout(ureq);
   } else if (source == searchFld) {
     final String searchText = searchFld.getValue();
     filterSettings.setTextFilter(searchText);
     fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
   } else if (source == filterSave) {
     if (StringHelper.containsNonWhitespace(filterName.getValue())) {
       final String oldFilterName = filterSettings.getFilterName();
       filterSettings.setFilterName(filterName.getValue());
       filterSettings.setTextFilter(searchFld.getValue());
       if (filterSave.getUserObject() != null && filterName.getValue().equals(oldFilterName)) {
         // fake update, delete before adding again
         final String filterID = (String) filterSave.getUserObject();
         ePFMgr.deleteFilterFromUsersList(getIdentity(), filterID);
       }
       if (!filterName.getValue().equals(oldFilterName) && oldFilterName != null) {
         // set another id, to distinguish from old
         filterSettings.setFilterIdToUniqueId();
       }
       final List<EPFilterSettings> filterList = ePFMgr.getSavedFilterSettings(getIdentity());
       // create a new or insert existing again
       filterList.add(filterSettings);
       ePFMgr.setSavedFilterSettings(getIdentity(), filterList);
       toggleSaveUpdateFilterButtons(true);
       showInfo("filter.saved", filterSettings.getFilterName());
       updateUI(ureq, filterSettings);
     }
   } else if (source == filterDel) {
     if (filterDel.getUserObject() != null) {
       ePFMgr.deleteFilterFromUsersList(getIdentity(), (String) filterDel.getUserObject());
       // refresh ui
       filterName.setValue("");
       toggleSaveUpdateFilterButtons(false);
       showInfo("filter.deleted");
       updateUI(ureq, new EPFilterSettings());
     }
   } else if (source == filterName) {
     final String oldFilterName = filterSettings.getFilterName();
     if (filterSave.getUserObject() != null && !filterName.getValue().equals(oldFilterName)) {
       toggleSaveUpdateFilterButtons(false);
     } else if (filterName.getValue().equals(oldFilterName)) {
       toggleSaveUpdateFilterButtons(true);
     }
   } else if (source == filterSel) {
     if (filterSel.isOneSelected()) {
       final int filterIndex = filterSel.getSelected();
       if (filterIndex == 0) {
         final EPFilterSettings newSettings = new EPFilterSettings();
         updateUI(ureq, newSettings);
         fireEvent(ureq, new PortfolioFilterChangeEvent(newSettings));
       } else if (filterIndex > 0 && filterIndex - 1 < nonEmptyFilters.size()) {
         final EPFilterSettings newSettings = nonEmptyFilters.get(filterIndex - 1);
         if (!filterSettings.getFilterId().equals(newSettings.getFilterId())) {
           updateUI(ureq, newSettings);
           fireEvent(ureq, new PortfolioFilterChangeEvent(newSettings));
         }
       }
     }
   }
 }