tabular-data-column-widget/src/main/java/org/gcube/portlets/user/td/columnwidget/client/custom/ErrorMessageDialog.java

111 lines
3.0 KiB
Java

package org.gcube.portlets.user.td.columnwidget.client.custom;
import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.sencha.gxt.core.client.dom.XElement;
import com.sencha.gxt.widget.core.client.Dialog;
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutPack;
public class ErrorMessageDialog extends Dialog {
public interface ErrorMessageDialogAppearance {
XElement getMessageElement(XElement parent);
XElement getExtendedElement(XElement parent);
ImageResource getWindowIcon();
void render(SafeHtmlBuilder sb);
}
protected ImageResource icon;
protected ErrorMessageDialogAppearance contentAppearance;
public ErrorMessageDialog(String headingHtml, String messageHtml,
String extendedHtml) {
this(headingHtml, messageHtml, extendedHtml, (WindowAppearance) GWT
.create(WindowAppearance.class),
(ErrorMessageDialogAppearance) GWT
.create(DefaultErrorMessageDialogApperance.class));
}
/**
* Creates a message box with the specified heading HTML, message HTML and
* appearance. It is the caller's responsibility to ensure the HTML is CSS
* safe.
*
* @param headingHtml
* the HTML to display for the message box heading
* @param messageHtml
* the HTML to display in the message box
* @param extendedHtml
* the HTML to display in the extended box
* @param appearance
* the message box window appearance
* @param contentAppearance
* the message box content appearance
*/
public ErrorMessageDialog(String headingHtml, String messageHtml,
String extendedHtml, WindowAppearance appearance,
ErrorMessageDialogAppearance contentAppearance) {
super(appearance);
setWidth(650);
//setHeight(350);
getHeader().setIcon(contentAppearance.getWindowIcon());
setResizable(false);
this.contentAppearance = contentAppearance;
setHeadingHtml(headingHtml);
init();
SafeHtmlBuilder sb = new SafeHtmlBuilder();
contentAppearance.render(sb);
appearance.getContentElem(getElement()).setInnerHTML(
sb.toSafeHtml().asString());
contentAppearance.getMessageElement(getElement()).setId(
getId() + "-content");
if (messageHtml != null) {
contentAppearance.getMessageElement(getElement()).setInnerHTML(
messageHtml);
}
if (extendedHtml != null) {
contentAppearance.getExtendedElement(getElement()).setInnerHTML(
extendedHtml);
}
}
/**
* Sets the message.
*
* @param message
* the message
*/
public void setMessage(String message) {
contentAppearance.getMessageElement(getElement()).setInnerHTML(message);
}
private void init() {
setData("errorMessageDialog", true);
setResizable(false);
setConstrain(true);
setMinimizable(false);
setMaximizable(false);
setClosable(false);
setModal(true);
setButtonAlign(BoxLayoutPack.CENTER);
setPredefinedButtons(PredefinedButton.OK);
setHideOnButtonClick(true);
}
}