/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS,
* <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/
package org.olat.test.guidemo;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.form.flexible.FormItem;
import org.olat.core.gui.components.form.flexible.FormItemContainer;
import org.olat.core.gui.components.form.flexible.elements.FormLink;
import org.olat.core.gui.components.form.flexible.elements.SingleSelection;
import org.olat.core.gui.components.form.flexible.elements.TextElement;
import org.olat.core.gui.components.form.flexible.impl.FormBasicController;
import org.olat.core.gui.components.form.flexible.impl.FormEvent;
import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer;
import org.olat.core.gui.components.form.flexible.impl.elements.FormSubmit;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.generic.closablewrapper.CloseableModalController;
/**
* Description:<br>
* TODO: patrickb Class Description for GuiDemoFlexiFormSubworkflow
* <P>
* Initial Date: 10.09.2007 <br>
*
* @author patrickb
*/
public class GuiDemoFlexiFormSubworkflow extends FormBasicController {
private GuiDemoFlexiFormPersonData personData;
private TextElement firstName;
private TextElement lastName;
private FormLayoutContainer horizontalLayout;
private TextElement institution;
private FormLink choose;
private FormSubmit submit;
private String[] values;
private GuiDemoFlexiFormSubworkflowTheChooser subworkflowTheChooser;
private CloseableModalController cmc;
public GuiDemoFlexiFormSubworkflow(UserRequest ureq, WindowControl wControl, GuiDemoFlexiFormPersonData data) {
super(ureq, wControl);
// first you may preprocess data to fit into the form items
// if all preprocessing is done, create the form items
//
// example for simple preprocessing - check for NULL
if (data != null) {
personData = data;
} else {
personData = new GuiDemoFlexiFormPersonData();
}
//
values = new String[]{"Faculty of Medicine","Vetsuisse Faculty","Faculty of Arts","Faculty of Science","All institutes and clinics of UZH"};
//
// calls our initForm(formlayout,listener,ureq) with default values.
initForm(ureq);
//
// after initialisation you may need to do some stuff
// but typically initForm(..) is the last call in the constructor.
}
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#doDispose(boolean)
*/
@Override
protected void doDispose() {
// nothing to dispose
}
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formOK(org.olat.core.gui.UserRequest)
*/
@Override
protected void formOK(UserRequest ureq) {
// nothing to do
}
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if(source == choose){
//choose link clicked
//show a subworkflow in a modal dialog without loosing fromdata
//
// work around to disable orange button and alert box of "unsubmitted form onscreen"
// this will change within the next release.
this.flc.getRootForm().setDirtyMarking(false);
//
//
subworkflowTheChooser = new GuiDemoFlexiFormSubworkflowTheChooser(ureq, getWindowControl(), values, institution.getValue());
// get informed if subworkflow has submitted =>
subworkflowTheChooser.addControllerListener(this);
cmc = new CloseableModalController(getWindowControl(), "close", subworkflowTheChooser.getInitialComponent());
// get informed if modal dialog is closed => this means canceling the workflow
cmc.addControllerListener(this);
cmc.activate();
return;
}
}
@Override
protected void event(UserRequest ureq, Controller source, org.olat.core.gui.control.Event event) {
if(source == cmc){
if(event == CloseableModalController.CLOSE_MODAL_EVENT){
// work around to re-enable orange button and alert box of "unsubmitted form onscreen"
// this will change within the next release.
this.flc.getRootForm().setDirtyMarking(true);
// modal dialog is closed
// modal dialog has already deactivated itself (you would get a redscreen otherwise)
subworkflowTheChooser.dispose();
}
}else if(source == subworkflowTheChooser){
//some value is choosen
//set the value and close dialog
institution.setValue(subworkflowTheChooser.getSelected());
cmc.deactivate();
subworkflowTheChooser.dispose();
// work around to re-enable orange button and alert box of "unsubmitted form onscreen"
// this will change within the next release.
this.flc.getRootForm().setDirtyMarking(true);
}
}
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
* org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
*/
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
/*
* create a form with a title and 4 input fields to enter some persons data
*/
// Example: set a form title and render within fieldsets
setFormTitle("guidemo_flexi_form_withchooser");
// Example2: Set a form description above the form
setFormDescription("guidemo_flexi_form_withchooser.desc");
// Example3: Set a context help link
setFormContextHelp("org.olat.core.commons.modules.bc", "bc-webdav.html", "guidemo_flexi_form_withchooser.helphover");
final int defaultDisplaySize = 32;
final boolean inputMode = !personData.isReadOnly();
firstName = uifactory.addTextElement("firstname", "guidemo.flexi.form.firstname", 256, personData.getFirstName(), formLayout);
firstName.setNotEmptyCheck("guidemo.flexi.form.mustbefilled");
firstName.setMandatory(true);
firstName.setEnabled(inputMode);
lastName = uifactory.addTextElement("lastname", "guidemo.flexi.form.lastname", 256, personData.getLastName(), formLayout);
lastName.setNotEmptyCheck("guidemo.flexi.form.mustbefilled");
lastName.setMandatory(true);
lastName.setEnabled(inputMode);
/*
* - create a composite element
* - text element and to the left a choose link
* - the label of the textelement is set as the label of the layouting
* container.
*/
horizontalLayout = FormLayoutContainer.createHorizontalFormLayout("chooser", getTranslator());
horizontalLayout. setLabel("guidemo.flexi.form.institution", null);
formLayout.add(horizontalLayout);
institution = uifactory.addTextElement("institution", null, 256, personData.getInstitution(), horizontalLayout);
institution.setEnabled(false);
choose = uifactory.addFormLink("choose", horizontalLayout,"b_form_genericchooser");
if (inputMode) {
// submit only if in input mode
submit = new FormSubmit("submit", "submit");
formLayout.add(submit);
}
}
//this innerclass represents the subworkflow
//but it could be any top level controller
private class GuiDemoFlexiFormSubworkflowTheChooser extends FormBasicController {
String[] entries;
private SingleSelection entrySelector;
private String selection;
public GuiDemoFlexiFormSubworkflowTheChooser(UserRequest ureq, WindowControl wControl, String[] values, String selection) {
super(ureq, wControl);
this.entries = values;
this.selection = selection;
initForm(ureq);
}
@Override
protected void doDispose() {
// TODO Auto-generated method stub
}
@Override
protected void formOK(UserRequest ureq) {
// TODO Auto-generated method stub
}
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
fireEvent(ureq, Event.DONE_EVENT);
}
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
//radio buttons
entrySelector = uifactory.addRadiosVertical("entries", null, formLayout, entries, entries);
//select one
if (selection != null && !selection.equals("")) {
entrySelector.select(selection, true);
}
//on click do something -> see the formInnerEvent method
entrySelector.addActionListener(this, FormEvent.ONCLICK);
}
String getSelected(){
return entrySelector.getSelectedKey();
}
}
}