/**
* 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.closablewrapper;
import java.util.ArrayList;
import java.util.List;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.Component;
import org.olat.core.gui.components.htmlheader.jscss.JSAndCSSComponent;
import org.olat.core.gui.components.link.Link;
import org.olat.core.gui.components.link.LinkFactory;
import org.olat.core.gui.components.panel.Panel;
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.control.WindowBackOffice;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.util.ZIndexWrapper;
import org.olat.core.gui.render.ValidationResult;
import org.olat.core.util.Util;
/**
* @author Felix Jost<br>
* Comment: 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.
*
* </pre>
*
* @deprecated don't use this anymore. Use BasicController methods or
* controllers from org.core.gui.control.modal package
*/
public class CloseableModalController extends DefaultController {
/**
* Comment for <code>CLOSE_MODAL_EVENT</code>
*/
public static final Event CLOSE_MODAL_EVENT = new Event("CLOSE_MODAL_EVENT");
private static final String VELOCITY_ROOT = Util.getPackageVelocityRoot(CloseableModalController.class);
private VelocityContainer myContent;
private Link backIcon;
private boolean displayAsOverlay;
/**
* @param wControl
* @param closeButtonText
* @param modalContent
*/
public CloseableModalController(WindowControl wControl, String closeButtonText, Component modalContent) {
this(wControl, closeButtonText, modalContent, true, null);
}
/**
* Additional constructor if display of content as overlay is not suitable.
* @param wControl
* @param closeButtonText
* @param modalContent
* @param showAsOverlay
*/
public CloseableModalController(WindowControl wControl, String closeButtonText, Component modalContent, boolean displayAsOverlay, String title) {
super(wControl);
final Panel guiMsgPlace = new Panel("guimessage_place");
myContent = new VelocityContainer("closeablewrapper", VELOCITY_ROOT + "/index.html", null, this) {
public void validate(UserRequest ureq, ValidationResult vr) {
super.validate(ureq, vr);
// just before rendering, we need to tell the windowbackoffice that we are a favorite for accepting gui-messages.
// the windowbackoffice doesn't know about guimessages, it is only a container that keeps them for one render cycle
WindowBackOffice wbo = getWindowControl().getWindowBackOffice();
List zindexed = (List) wbo.getData("guimessage");
if (zindexed == null) {
zindexed = new ArrayList(3);
wbo.putData("guimessage", zindexed);
}
zindexed.add(new ZIndexWrapper(guiMsgPlace, 20));
}
};
myContent.put("guimessage", guiMsgPlace);
backIcon = LinkFactory.createIconClose(closeButtonText, myContent, this);
if (title != null) myContent.contextPut("title", title);
myContent.put("modalContent", modalContent); // use our own name
this.displayAsOverlay = displayAsOverlay;
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) {
if (source == backIcon){
getWindowControl().pop();
fireEvent(ureq, CLOSE_MODAL_EVENT);
}
}
/**
* @see org.olat.core.gui.control.DefaultController#getInitialComponent()
*/
public Component getInitialComponent() {
throw new RuntimeException("please use activate() instead");
}
/**
*
*/
public void activate() {
if (displayAsOverlay) getWindowControl().pushAsModalDialog(myContent);
else getWindowControl().pushToMainArea(myContent);
}
/**
* deactivates the modal controller. please do use this method here instead of getWindowControl().pop() !
*
*/
public void deactivate() {
getWindowControl().pop();
}
/**
* insert css in HTML-header, wich overwrites default css
*/
public void insertHeaderCss() {
JSAndCSSComponent jac = new JSAndCSSComponent("cmc-css", this.getClass(), null, "olat-preview.css", true);
myContent.put("cmc-css", jac);
}
/**
* @see org.olat.core.gui.control.DefaultController#doDispose(boolean)
*/
protected void doDispose() {
// TODO Auto-generated method stub
}
}