use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project OpenOLAT by OpenOLAT.
the class ProjectEditDetailsFormController method initForm.
/**
* Initialize form.
*/
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
// create form elements
projectTitle = uifactory.addTextElement("title", "detailsform.title.label", 100, project.getTitle(), formLayout);
// account-Managers
StringBuilder projectLeaderString = new StringBuilder();
for (Iterator<Identity> iterator = project.getProjectLeaders().iterator(); iterator.hasNext(); ) {
Identity identity = iterator.next();
String last = identity.getUser().getProperty(UserConstants.LASTNAME, getLocale());
String first = identity.getUser().getProperty(UserConstants.FIRSTNAME, getLocale());
if (projectLeaderString.length() > 0) {
projectLeaderString.append(",");
}
projectLeaderString.append(first);
projectLeaderString.append(" ");
projectLeaderString.append(last);
}
projectLeaders = uifactory.addTextElement("projectleaders", "detailsform.projectleaders.label", 100, projectLeaderString.toString(), formLayout);
projectLeaders.setEnabled(false);
// add the learning objectives rich text input element
projectDescription = uifactory.addRichTextElementForStringData("description", "detailsform.description.label", project.getDescription(), 10, -1, false, null, null, formLayout, ureq.getUserSession(), getWindowControl());
projectDescription.setMaxLength(2500);
stateLayout = FormLayoutContainer.createHorizontalFormLayout("stateLayout", getTranslator());
stateLayout.setLabel("detailsform.state.label", null);
formLayout.add(stateLayout);
String stateValue = getTranslator().translate(projectBrokerManager.getStateFor(project, ureq.getIdentity(), projectBrokerModuleConfiguration));
projectState = uifactory.addStaticTextElement("detailsform.state", stateValue + " ", stateLayout);
projectState.setLabel(null, null);
String keyDetailsformMax = null;
if (projectBrokerModuleConfiguration.isAcceptSelectionManually()) {
keyDetailsformMax = "detailsform.max.candidates.label";
} else {
keyDetailsformMax = "detailsform.max.members.label";
}
selectionMaxMembers = uifactory.addCheckboxesHorizontal(keyDetailsformMax, formLayout, keys, values);
maxMembers = uifactory.addIntegerElement("form.options.number.of.participants.per.topic_nbr", project.getMaxMembers(), formLayout);
maxMembers.setMinValueCheck(0, null);
maxMembers.setDisplaySize(3);
if (project.getMaxMembers() == Project.MAX_MEMBERS_UNLIMITED) {
maxMembers.setVisible(false);
selectionMaxMembers.select(keys[0], false);
} else {
selectionMaxMembers.select(keys[0], true);
}
selectionMaxMembers.addActionListener(FormEvent.ONCLICK);
String[] deselectValues = new String[] { translate("detailsform.allow.deselection.hint") };
allowDeselection = uifactory.addCheckboxesHorizontal("detailsform.allow.deselection", formLayout, keys, deselectValues);
allowDeselection.select(keys[0], projectGroupManager.isDeselectionAllowed(project));
allowDeselection.addActionListener(FormEvent.ONCLICK);
uifactory.addSpacerElement("spacer_1", formLayout, false);
// customfields
List<CustomField> customFields = projectBrokerModuleConfiguration.getCustomFields();
int customFieldIndex = 0;
for (Iterator<CustomField> iterator = customFields.iterator(); iterator.hasNext(); ) {
CustomField customField = iterator.next();
getLogger().debug("customField: " + customField.getName() + "=" + customField.getValue());
StringTokenizer tok = new StringTokenizer(customField.getValue(), ProjectBrokerManager.CUSTOMFIELD_LIST_DELIMITER);
if (customField.getValue() == null || customField.getValue().equals("") || !tok.hasMoreTokens()) {
// no value define => Text-input
// Add StaticTextElement as workaroung for non translated label
// null > no label
uifactory.addStaticTextElement("customField_label" + customFieldIndex, null, customField.getName(), formLayout);
TextElement textElement = uifactory.addTextElement("customField_" + customFieldIndex, "", 150, project.getCustomFieldValue(customFieldIndex), formLayout);
textElement.setDisplaySize(60);
// textElement.setTranslator(null);
// textElement.setLabel(customField.getName(), null);
textElement.showLabel(false);
customfieldElementList.add(textElement);
} else {
// values define => dropdown selection
List<String> valueList = new ArrayList<String>();
while (tok.hasMoreTokens()) {
String value = tok.nextToken();
valueList.add(value);
getLogger().debug("valueList add: " + value);
}
String[] theValues = new String[valueList.size() + 1];
String[] theKeys = new String[valueList.size() + 1];
int arrayIndex = 0;
theValues[arrayIndex] = translate(DROPDOWN_NO_SELECETION);
theKeys[arrayIndex] = DROPDOWN_NO_SELECETION;
arrayIndex++;
for (Iterator<String> iterator2 = valueList.iterator(); iterator2.hasNext(); ) {
String value = iterator2.next();
theValues[arrayIndex] = value;
theKeys[arrayIndex] = Integer.toString(arrayIndex);
arrayIndex++;
}
// Add StaticTextElement as workaround for non translated label
// null > no label
uifactory.addStaticTextElement("customField_label" + customFieldIndex, null, customField.getName(), formLayout);
SingleSelection selectionElement = uifactory.addDropdownSingleselect("customField_" + customFieldIndex, null, formLayout, theKeys, theValues, null);
if (project.getCustomFieldValue(customFieldIndex) != null && !project.getCustomFieldValue(customFieldIndex).equals("")) {
if (valueList.contains(project.getCustomFieldValue(customFieldIndex))) {
// '+1' because no-selection at the beginning
String key = Integer.toString(valueList.indexOf(project.getCustomFieldValue(customFieldIndex)) + 1);
selectionElement.select(key, true);
} else {
this.showInfo("warn.customfield.key.does.not.exist", project.getCustomFieldValue(customFieldIndex));
}
}
customfieldElementList.add(selectionElement);
}
uifactory.addSpacerElement("customField_spacer" + customFieldIndex, formLayout, false);
customFieldIndex++;
}
// Events
for (Project.EventType eventType : Project.EventType.values()) {
if (projectBrokerModuleConfiguration.isProjectEventEnabled(eventType)) {
ProjectEvent projectEvent = project.getProjectEvent(eventType);
DateChooser dateChooserStart = uifactory.addDateChooser(eventType + "start", eventType.getI18nKey() + ".start.label", null, formLayout);
dateChooserStart.setDateChooserTimeEnabled(true);
dateChooserStart.setDisplaySize(CUSTOM_DATE_FORMAT.length());
getLogger().info("Event=" + eventType + ", startDate=" + projectEvent.getStartDate());
dateChooserStart.setDate(projectEvent.getStartDate());
eventStartElementList.put(eventType, dateChooserStart);
DateChooser dateChooserEnd = uifactory.addDateChooser(eventType + "end", eventType.getI18nKey() + ".end.label", null, formLayout);
dateChooserEnd.setDateChooserTimeEnabled(true);
dateChooserEnd.setDisplaySize(CUSTOM_DATE_FORMAT.length());
getLogger().debug("Event=" + eventType + ", endDate=" + projectEvent.getEndDate());
dateChooserEnd.setDate(projectEvent.getEndDate());
eventEndElementList.put(eventType, dateChooserEnd);
uifactory.addSpacerElement(eventType + "spacer", formLayout, false);
}
}
attachmentFileName = uifactory.addFileElement(getWindowControl(), "detailsform.attachmentfilename.label", formLayout);
attachmentFileName.setLabel("detailsform.attachmentfilename.label", null);
if (project.getAttachmentFileName() != null && !project.getAttachmentFileName().equals("")) {
attachmentFileName.setInitialFile(new File(project.getAttachmentFileName()));
removeAttachmentLink = uifactory.addFormLink("detailsform.remove.attachment", formLayout, Link.BUTTON_XSMALL);
}
attachmentFileName.addActionListener(FormEvent.ONCHANGE);
mailNotification = uifactory.addCheckboxesHorizontal("detailsform.mail.notification.label", formLayout, keys, values);
mailNotification.select(keys[0], project.isMailNotificationEnabled());
FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
formLayout.add(buttonGroupLayout);
uifactory.addFormSubmitButton("save", buttonGroupLayout);
if (this.enableCancel) {
// TODO: Frage an PB: Warum flc hier noetig ???
uifactory.addFormCancelButton("cancel", buttonGroupLayout, ureq, getWindowControl());
}
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project OpenOLAT by OpenOLAT.
the class EvaluationFormController method formInnerEvent.
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (saveAsDoneButton == source) {
doConfirmDone(ureq);
} else if (source instanceof SingleSelection) {
SingleSelection radioEl = (SingleSelection) source;
Object uobject = radioEl.getUserObject();
if (uobject instanceof SliderWrapper) {
String selectedKey = radioEl.getSelectedKey();
SliderWrapper sliderWrapper = (SliderWrapper) uobject;
saveNumericalResponse(new BigDecimal(selectedKey), selectedKey, sliderWrapper.getId());
}
} else if (source instanceof SliderElement) {
SliderElement slider = (SliderElement) source;
Object uobject = slider.getUserObject();
if (uobject instanceof SliderWrapper) {
double value = slider.getValue();
SliderWrapper sliderWrapper = (SliderWrapper) uobject;
saveNumericalResponse(BigDecimal.valueOf(value), Double.toString(value), sliderWrapper.getId());
}
} else if (source instanceof FormLink) {
FormLink link = (FormLink) source;
Object uobject = link.getUserObject();
if (uobject instanceof TextInputWrapper) {
TextInputWrapper wrapper = (TextInputWrapper) uobject;
String value = wrapper.getTextEl().getValue();
saveNumericalResponse(null, value, wrapper.getId());
}
} else if (source instanceof FileElement) {
FileElement fileElement = (FileElement) source;
Object uobject = fileElement.getUserObject();
if (uobject instanceof FileUploadWrapper) {
FileUploadWrapper wrapper = (FileUploadWrapper) uobject;
if (event instanceof FileElementEvent) {
if (FileElementEvent.DELETE.equals(event.getCommand())) {
saveFileResponse(null, null, wrapper.getId());
fileElement.setInitialFile(null);
if (fileElement.getUploadFile() != null) {
fileElement.reset();
}
flc.setDirty(true);
}
} else if (fileElement.isUploadSuccess()) {
File file = fileElement.getUploadFile();
String filename = fileElement.getUploadFileName();
saveFileResponse(file, filename, wrapper.getId());
}
}
}
super.formInnerEvent(ureq, source, event);
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project OpenOLAT by OpenOLAT.
the class EvaluationFormController method forgeDiscreteRadioButtons.
private SliderWrapper forgeDiscreteRadioButtons(Slider slider, Rubric element, EvaluationFormResponse response) {
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);
radioEl.setEnabled(!readOnly);
radioEl.setAllowNoSelection(true);
int widthInPercent = EvaluationFormElementWrapper.getWidthInPercent(element);
radioEl.setWidthInPercent(widthInPercent, true);
if (response != null && response.getNumericalResponse() != null) {
double val = response.getNumericalResponse().doubleValue();
double error = step / 10.0d;
for (int i = 0; i < theSteps.length; i++) {
double theStep = theSteps[i];
double margin = Math.abs(theStep - val);
if (margin < error) {
radioEl.select(theKeys[i], true);
}
}
}
SliderWrapper sliderWrapper = new SliderWrapper(slider, radioEl);
radioEl.setUserObject(sliderWrapper);
return sliderWrapper;
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project OpenOLAT by OpenOLAT.
the class AbstractPageListController method forgeSectionRow.
protected PortfolioElementRow forgeSectionRow(Section section, AssessmentSection assessmentSection, List<Assignment> assignments, Map<OLATResourceable, List<Category>> categorizedElementMap) {
PortfolioElementRow row = new PortfolioElementRow(section, assessmentSection, config.isAssessable(), (assignments != null && assignments.size() > 0));
String openLinkId = "open_" + (++counter);
FormLink openLink = uifactory.addFormLink(openLinkId, "open.full", "open.full.page", null, flc, Link.BUTTON_SMALL);
openLink.setIconRightCSS("o_icon o_icon_start");
openLink.setPrimary(true);
row.setOpenFormLink(openLink);
openLink.setUserObject(row);
addCategoriesToRow(row, categorizedElementMap);
if (assignments != null && secCallback.canViewPendingAssignments(section) && secCallback.canInstantiateAssignment()) {
List<Assignment> startableAssignments = assignments.stream().filter(ass -> ass.getAssignmentStatus() == AssignmentStatus.notStarted).filter(ass -> ass.getPage() == null).collect(Collectors.toList());
if (!startableAssignments.isEmpty()) {
String[] keys = new String[startableAssignments.size() + 1];
String[] values = new String[startableAssignments.size() + 1];
keys[0] = "start.assignment.hint";
values[0] = translate("start.assignment.hint");
int count = 1;
for (Assignment assignment : startableAssignments) {
keys[count] = Long.toString(assignment.getKey());
values[count] = assignment.getTitle();
count++;
}
SingleSelection startEl = uifactory.addDropdownSingleselect("assignments_" + (++counter), "", flc, keys, values, null);
startEl.setDomReplacementWrapperRequired(false);
startEl.addActionListener(FormEvent.ONCHANGE);
row.setStartSelection(startEl);
}
}
return row;
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project OpenOLAT by OpenOLAT.
the class LicenseAdminConfigController method initHandlerConfigs.
private void initHandlerConfigs() {
List<FormLayoutContainer> handlerConfigs = new ArrayList<>(licenseHandlers.size());
for (LicenseHandler handler : licenseHandlers) {
boolean handlerEnabled = licenseModule.isEnabled(handler);
if (handlerEnabled) {
String handlerType = handler.getType();
FormLayoutContainer handlerCont = FormLayoutContainer.createDefaultFormLayout("handler-" + handlerType, getTranslator());
handlerCont.setRootForm(mainForm);
flc.add("handler-" + handlerType, handlerCont);
uifactory.addSpacerElement("spacer-" + handlerType, handlerCont, false);
SpacerElement handlerName = uifactory.addSpacerElement("name-" + handlerType, handlerCont, true);
handlerName.setLabel(handler.getTitle(getLocale()), null, false);
SingleSelection defaultLicenseTypeEl = uifactory.addDropdownSingleselect(DEFAULT_LICENSE_TYPE_PREFIX + handlerType, "admin.default.license.type", handlerCont, new String[0], new String[0], null);
defaultLicenseTypeEl.setUserObject(handler);
defaultLicenseTypeEl.addActionListener(FormEvent.ONCHANGE);
defaultLicenseTypeEls.put(handlerType, defaultLicenseTypeEl);
reloadDefaultLicenseTypeEl(handler);
String[] licensorCreatorKeys = licensorCreators.stream().map(LicensorCreator::getType).toArray(String[]::new);
String[] licensorCreatorValues = licensorCreators.stream().map(creator -> creator.getName(getLocale())).toArray(String[]::new);
SingleSelection licensorCreatorEl = uifactory.addDropdownSingleselect(LICENSOR_CREATOR_TYPE_PREFIX + handlerType, "admin.licensor.creator", handlerCont, licensorCreatorKeys, licensorCreatorValues, null);
licensorCreatorEl.setUserObject(handler);
String creatorType = licenseModule.getLicensorCreatorType(handler);
if (creatorType != null) {
licensorCreatorEl.select(creatorType, true);
}
licensorCreatorEl.addActionListener(FormEvent.ONCHANGE);
if (CONSTANT_CREATOR_TYPE.equals(creatorType)) {
String licensorConstant = licenseModule.getConstantLicensor(handler);
uifactory.addStaticTextElement("lgc-" + handlerType, "admin.licensor.constant", licensorConstant, handlerCont);
FormLink editLicensorConstantLink = uifactory.addFormLink("lgb-", "admin.licensor.constant.edit", "", handlerCont, Link.BUTTON);
editLicensorConstantLink.setUserObject(handler);
}
handlerConfigs.add(handlerCont);
}
}
flc.getFormItemComponent().contextPut("handlerConfigs", handlerConfigs);
}
Aggregations