org.efaps.ui.wicket.pages.dialog.DialogPage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of efaps-webapp Show documentation
Show all versions of efaps-webapp Show documentation
eFaps WebApp provides a web interface as the User Interface for eFaps
which can be easily expanded and altered.
/*
* Copyright 2003 - 2012 The eFaps Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Revision: $Rev:1489 $
* Last Changed: $Date:2007-10-15 17:50:46 -0500 (Mon, 15 Oct 2007) $
* Last Changed By: $Author:jmox $
*/
package org.efaps.ui.wicket.pages.dialog;
import java.util.List;
import org.apache.wicket.Component;
import org.apache.wicket.PageReference;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.util.visit.IVisit;
import org.apache.wicket.util.visit.IVisitor;
import org.efaps.admin.dbproperty.DBProperties;
import org.efaps.admin.event.Parameter.ParameterValues;
import org.efaps.ui.wicket.components.LabelComponent;
import org.efaps.ui.wicket.components.button.Button;
import org.efaps.ui.wicket.components.footer.AjaxSubmitCloseBehavior;
import org.efaps.ui.wicket.components.modalwindow.ModalWindowContainer;
import org.efaps.ui.wicket.components.modalwindow.UpdateParentCallback;
import org.efaps.ui.wicket.models.objects.UIMenuItem;
import org.efaps.ui.wicket.pages.AbstractMergePage;
import org.efaps.ui.wicket.pages.content.AbstractContentPage;
import org.efaps.ui.wicket.pages.error.ErrorPage;
import org.efaps.ui.wicket.resources.AbstractEFapsHeaderItem;
import org.efaps.ui.wicket.resources.EFapsContentReference;
import org.efaps.util.EFapsException;
import org.efaps.util.cache.CacheReloadException;
/**
* This Page renders a Dialog for Userinterference.
* e.g. "Do you really want to...?"
*
* @author The eFaps Team
* @version $Id: DialogPage.java 8900 2013-02-20 18:50:19Z [email protected] $
*/
public class DialogPage
extends AbstractMergePage
{
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Reference to the StyleSheet of this Page stored in the eFaps-DataBase.
*/
private static final EFapsContentReference CSS = new EFapsContentReference(DialogPage.class, "DialogPage.css");
/**
* Reference to the page that opened this dialog.
*/
private final PageReference pageReference;
/**
* Constructor used for a DialogPage that renders a Question like: "Are you
* sure that??" with a Cancel and a SubmitButton.
*
* @param _pageReference Reference to the page that opened this dialog
* @param _model the MenuItem that called this DialogPage
* @param _oids oids which must be past on, in case of submit
*/
public DialogPage(final PageReference _pageReference,
final IModel _model,
final String[] _oids)
throws CacheReloadException
{
super(_model);
this.pageReference = _pageReference;
final UIMenuItem menuItem = _model.getObject();
final String cmdName = menuItem.getCommand().getName();
this.add(new Label("textLabel", DBProperties.getProperty(cmdName + ".Question")));
this.add(new Button("submitButton", new AjaxSubmitLink(Button.LINKID, _model, _oids),
DialogPage.getLabel(cmdName, "Submit"), Button.ICON.ACCEPT.getReference()));
this.add(new Button("closeButton", new AjaxCloseLink(Button.LINKID), DialogPage.getLabel(cmdName, "Cancel"),
Button.ICON.CANCEL.getReference()));
}
/**
* Constructor setting the ModalWindow.
*
* @param _pageReference Reference to the page that opened this dialog
* @param _value value is depending on parameter "_isSniplett" the key to a
* DBProperty or a snipplet
* @param _isSniplett is it a snipplet or not
* @param _goOn go on?
*/
public DialogPage(final PageReference _pageReference,
final String _value,
final boolean _isSniplett,
final boolean _goOn)
{
this.pageReference = _pageReference;
if (_isSniplett) {
this.add(new LabelComponent("textLabel", _value));
} else {
this.add(new Label("textLabel", DBProperties.getProperty(_value + ".Message")));
}
if (_goOn) {
final AjaxGoOnLink ajaxGoOnLink = new AjaxGoOnLink(Button.LINKID);
this.add(new Button("submitButton", ajaxGoOnLink, DialogPage.getLabel(_value, "Create"),
Button.ICON.ACCEPT.getReference()));
} else {
this.add(new WebMarkupContainer("submitButton").setVisible(false));
}
final AjaxCloseLink ajaxCloseLink = new AjaxCloseLink(Button.LINKID);
this.add(new Button("closeButton", ajaxCloseLink, DialogPage.getLabel(_value, "Close"),
Button.ICON.CANCEL.getReference()));
ajaxCloseLink.add(new KeyListenerBehavior());
}
@Override
public void renderHead(final IHeaderResponse _response)
{
super.renderHead(_response);
_response.render(AbstractEFapsHeaderItem.forCss(DialogPage.CSS));
}
/**
* Method that gets the Value for the Buttons from the DBProperties.
*
* @param _cmdName Name of the Command, that Label for the Button should be
* retrieved
* @param _keytype type of the key e.g. "Cancel", "Submit", "Close"
* @return Label
*/
private static String getLabel(final String _cmdName,
final String _keytype)
{
String ret;
if (DBProperties.hasProperty(_cmdName + ".Button." + _keytype)) {
ret = DBProperties.getProperty(_cmdName + ".Button." + _keytype);
} else {
ret = DBProperties.getProperty("default.Button." + _keytype);
}
return ret;
}
/**
* AjaxLink that closes the ModalWindow this Page was opened in.
*/
public class AjaxGoOnLink
extends AjaxLink