Search in sources :

Example 6 with SingleSelection

use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project OpenOLAT by OpenOLAT.

the class ProjectEditDetailsFormController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    boolean projectChanged = false;
    if (!project.getTitle().equals(projectTitle.getValue())) {
        // title has been changed => change project-group name too
        String newProjectGroupName = translate("project.member.groupname", projectTitle.getValue());
        String newProjectGroupDescription = translate("project.member.groupdescription", projectTitle.getValue());
        OLATResource courseResource = courseEnv.getCourseGroupManager().getCourseResource();
        projectGroupManager.changeProjectGroupName(getIdentity(), project.getProjectGroup(), newProjectGroupName, newProjectGroupDescription, courseResource);
        projectGroupManager.sendGroupChangeEvent(project, courseEnv.getCourseResourceableId(), ureq.getIdentity());
        projectChanged = true;
    }
    if (!project.getTitle().equals(projectTitle.getValue())) {
        project.setTitle(projectTitle.getValue());
        projectChanged = true;
    }
    if (!project.getDescription().equals(projectDescription.getValue())) {
        project.setDescription(projectDescription.getValue());
        projectChanged = true;
    }
    if (project.getMaxMembers() != maxMembers.getIntValue()) {
        project.setMaxMembers(maxMembers.getIntValue());
        projectGroupManager.setProjectGroupMaxMembers(getIdentity(), project.getProjectGroup(), maxMembers.getIntValue());
        projectChanged = true;
    }
    if (StringHelper.containsNonWhitespace(attachmentFileName.getUploadFileName())) {
        // First call uploadFiles than setAttachedFileName because uploadFiles needs old attachment name
        uploadFiles(attachmentFileName);
        project.setAttachedFileName(attachmentFileName.getUploadFileName());
        projectChanged = true;
    } else if (StringHelper.containsNonWhitespace(project.getAttachmentFileName()) && attachmentFileName.getInitialFile() == null) {
        // Attachment file has been removed
        project.setAttachedFileName("");
        projectChanged = true;
    }
    // store customfields
    int index = 0;
    for (Iterator<FormItem> iterator = customfieldElementList.iterator(); iterator.hasNext(); ) {
        FormItem element = iterator.next();
        String value = "";
        if (element instanceof TextElement) {
            TextElement textElement = (TextElement) element;
            value = textElement.getValue();
        } else if (element instanceof SingleSelection) {
            SingleSelection selectionElement = (SingleSelection) element;
            if (!selectionElement.getSelectedKey().equals(DROPDOWN_NO_SELECETION)) {
                value = selectionElement.getValue(selectionElement.getSelected());
            } else {
                value = "";
            }
        }
        getLogger().debug("customfield index=" + index + " value=" + value + " project.getCustomFieldValue(index)=" + project.getCustomFieldValue(index));
        if (!project.getCustomFieldValue(index).equals(value)) {
            project.setCustomFieldValue(index, value);
            projectChanged = true;
        }
        index++;
    }
    // store events
    for (Project.EventType eventType : eventStartElementList.keySet()) {
        Date startDate = eventStartElementList.get(eventType).getDate();
        Date endDate = eventEndElementList.get(eventType).getDate();
        // First handle startdate
        if (hasBeenChanged(project.getProjectEvent(eventType).getStartDate(), startDate) || hasBeenChanged(project.getProjectEvent(eventType).getEndDate(), endDate)) {
            project.setProjectEvent(new ProjectEvent(eventType, startDate, endDate));
            projectChanged = true;
        }
    }
    if (mailNotification.isSelected(0) != project.isMailNotificationEnabled()) {
        project.setMailNotificationEnabled(mailNotification.isSelected(0));
        projectChanged = true;
    }
    if (projectChanged) {
        if (projectBrokerManager.existsProject(project.getKey())) {
            projectBrokerManager.updateProject(project);
            projectBrokerMailer.sendProjectChangedEmailToParticipants(ureq.getIdentity(), project, this.getTranslator());
        } else {
            showInfo("info.project.nolonger.exist", project.getTitle());
        }
    }
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormItem(org.olat.core.gui.components.form.flexible.FormItem) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date) ProjectEvent(org.olat.course.nodes.projectbroker.datamodel.ProjectEvent)

Example 7 with SingleSelection

use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project OpenOLAT by OpenOLAT.

the class RubricController method forgeDiscreteRadioButtons.

private SliderWrapper forgeDiscreteRadioButtons(Slider slider, Rubric element) {
    int start = element.getStart();
    int end = element.getEnd();
    int steps = element.getSteps();
    double[] theSteps = new double[steps];
    String[] theKeys = new String[steps];
    String[] theValues = new String[steps];
    double step = (end - start + 1) / (double) steps;
    for (int i = 0; i < steps; i++) {
        theSteps[i] = start + (i * step);
        theKeys[i] = Double.toString(theSteps[i]);
        theValues[i] = "";
    }
    SingleSelection radioEl = uifactory.addRadiosVertical("slider_" + (count++), null, flc, theKeys, theValues);
    radioEl.setDomReplacementWrapperRequired(false);
    radioEl.addActionListener(FormEvent.ONCHANGE);
    int widthInPercent = EvaluationFormElementWrapper.getWidthInPercent(element);
    radioEl.setWidthInPercent(widthInPercent, true);
    SliderWrapper sliderWrapper = new SliderWrapper(slider, radioEl);
    radioEl.setUserObject(sliderWrapper);
    return sliderWrapper;
}
Also used : SliderWrapper(org.olat.modules.forms.ui.model.SliderWrapper) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection)

Example 8 with SingleSelection

use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project OpenOLAT by OpenOLAT.

the class ColorLA method getFormItem.

/**
 * @see org.olat.course.config.ui.courselayout.attribs.AbstractLayoutAttribute#getFormItem(java.lang.String, org.olat.core.gui.components.form.flexible.FormItemContainer)
 * get a dropdown and an input field wrapped in a FormLayoutContainer
 */
@Override
public FormItem getFormItem(String compName, FormItemContainer formLayout) {
    FormUIFactory uifact = FormUIFactory.getInstance();
    FormLayoutContainer colorFLC = FormLayoutContainer.createVerticalFormLayout(compName, formLayout.getTranslator());
    formLayout.add(compName, colorFLC);
    FormItem dropDown = super.getFormItem(compName + "sel", formLayout);
    dropDown.addActionListener(FormEvent.ONCHANGE);
    colorFLC.add(dropDown);
    String inputValue = "";
    if (getAttributeValue() != null && !((SingleSelection) dropDown).isOneSelected()) {
        inputValue = getAttributeValue();
    }
    TextElement inputEl = uifact.addTextElement(compName + "value", null, 7, inputValue, colorFLC);
    inputEl.setDisplaySize(7);
    colorFLC.setUserObject(new ColorSpecialHandler(colorFLC));
    return colorFLC;
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormUIFactory(org.olat.core.gui.components.form.flexible.FormUIFactory)

Example 9 with SingleSelection

use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project OpenOLAT by OpenOLAT.

the class ColorSpecialHandler method getValue.

@Override
public String getValue() {
    FormLayoutContainer innerFLC = (FormLayoutContainer) getFormItem();
    Map<String, FormItem> items = innerFLC.getFormComponents();
    String ddValue = "";
    String inputValue = "";
    FormItem inputItem = null;
    for (Entry<String, FormItem> fiEntry : items.entrySet()) {
        String compName = fiEntry.getKey();
        FormItem fi = fiEntry.getValue();
        if (compName.endsWith("sel") && fi instanceof SingleSelection) {
            ddValue = ((SingleSelection) fi).isOneSelected() ? ((SingleSelection) fi).getSelectedKey() : "";
        }
        if (compName.endsWith("value") && fi instanceof TextElement) {
            inputItem = fi;
            inputValue = ((TextElement) fi).getValue();
        }
    }
    if (ddValue.equals("") && StringHelper.containsNonWhitespace(inputValue)) {
        // use input-value if valid
        Pattern pattern = Pattern.compile(HEX_PATTERN);
        Matcher matcher = pattern.matcher(inputValue);
        if (matcher.matches()) {
            hasError = false;
            return inputValue;
        } else {
            hasError = true;
            inputItem.setErrorKey("color.hex.error", null);
            return "";
        }
    }
    if (!ddValue.equals("") && StringHelper.containsNonWhitespace(inputValue)) {
        inputItem.setErrorKey("color.double.error", null);
    }
    return ddValue;
}
Also used : Pattern(java.util.regex.Pattern) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) Matcher(java.util.regex.Matcher) FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 10 with SingleSelection

use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project OpenOLAT by OpenOLAT.

the class GenericSelectionPropertyHandler method isValid.

@Override
public boolean isValid(User user, FormItem formItem, Map<String, String> formContext) {
    if (formItem.isMandatory()) {
        if (isMultiselect) {
            MultipleSelectionElement msel = (MultipleSelectionElement) formItem;
            msel.setErrorKey("form.legende.mandatory", null);
            return msel.isAtLeastSelected(1);
        } else {
            SingleSelection ssel = (SingleSelection) formItem;
            if (ssel.getSelectedKey().equals(NO_SEL_KEY)) {
                ssel.setErrorKey("form.legende.mandatory", null);
                return false;
            }
        }
    }
    return true;
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection)

Aggregations

SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)88 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)34 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)26 FormItem (org.olat.core.gui.components.form.flexible.FormItem)18 ArrayList (java.util.ArrayList)14 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)12 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)12 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)12 SelectionEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)10 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)8 CollectRestriction (org.olat.portfolio.model.restriction.CollectRestriction)8 File (java.io.File)6 Map (java.util.Map)6 FormLinkImpl (org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)6 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)6 SliderWrapper (org.olat.modules.forms.ui.model.SliderWrapper)6 UserManager (org.olat.user.UserManager)6 HashMap (java.util.HashMap)4 List (java.util.List)4 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)4