/**
* 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) 1999-2006 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/
package org.olat.core.gui.control.generic.wizard;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.Component;
import org.olat.core.gui.components.velocity.VelocityContainer;
import org.olat.core.gui.control.DefaultController;
import org.olat.core.gui.control.Event;
import org.olat.core.gui.render.StringOutput;
import org.olat.core.gui.translator.PackageTranslator;
import org.olat.core.gui.translator.Translator;
import org.olat.core.logging.AssertException;
import org.olat.core.util.Util;
/**
* enclosing_type Description: <br>
* this controller takes a component in its contructor and wraps a velocity
* container around it with a single link/button (with a userdefined
* displayname) which closes the dialog. <br>
* Important: the method getMainComponent is overridden and throws an Exception,
* since there is a different method to be used: activate(WindowController
* wControl). This reason is the this controller is intended to be used only as
* "a popup"/modal dialog (since it offers the 'close' button) and after
* clicking that button, it should disappear by itself. Therefore you can only
* use it in conjunction with a WindowsController.
*
* @author Felix Jost
*/
public class WizardInfoController extends DefaultController {
private static final String VELOCITY_ROOT = Util.getPackageVelocityRoot(WizardInfoController.class);
private static final String PACKAGE = Util.getPackageName(WizardInfoController.class);
private VelocityContainer myContent;
private int maxSteps;
/**
* @param ureq
* @param maxSteps
*/
public WizardInfoController(UserRequest ureq, int maxSteps) {
super(null);
this.maxSteps = maxSteps;
Translator trans = new PackageTranslator(PACKAGE, ureq.getLocale());
myContent = new VelocityContainer("genericwizard", VELOCITY_ROOT + "/wizard_steps.html", trans, null);
myContent.contextPut("max", String.valueOf(maxSteps));
myContent.contextPut("myself", this);
setCurStep(1);
setInitialComponent(myContent);
}
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
*/
public void event(UserRequest ureq, Component source, Event event) {
// nothing to listen to
}
/**
* @param i
*/
public void setCurStep(int i) {
if (i > maxSteps) throw new AssertException("Trying to set a step above max setps.");
myContent.contextPut("cur", String.valueOf(i));
}
/**
* @see org.olat.core.gui.control.DefaultController#doDispose(boolean)
*/
protected void doDispose() {
// nothing to do yet
}
/**
* [used by velocity!!]
* @param strStep
* @param strMaxStep
* @return
*/
public StringOutput renderWizardSteps(String strStep, String strMaxStep) {
int step = Integer.parseInt(strStep);
int maxStep = Integer.parseInt(strMaxStep);
StringOutput sb = new StringOutput(100);
renderWizardSteps(sb, maxStep, step);
return sb;
}
private void renderWizardSteps(StringOutput target, int totalSteps, int step) {
target.append("<div class=\"b_legacy_wizard_steps\">");
String activeImage = "";
String passiveImage = "";
for (int i = 1; i <= totalSteps; i++) {
activeImage = "<span class=\"b_small_icon b_legacy_wizard_step_a" + i + "\"></span>";
passiveImage = "<span class=\"b_small_icon b_legacy_wizard_step_p" + i + "\"></span>";
if (step == i) target.append(activeImage);
else target.append(passiveImage);
}
target.append("</div>");
}
}