001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.gwt.client.ui; 029 030import org.opencms.gwt.client.Messages; 031import org.opencms.gwt.client.ui.I_CmsButton.ButtonColor; 032import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle; 033import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle; 034 035import com.google.gwt.dom.client.Style.Display; 036import com.google.gwt.event.dom.client.ClickEvent; 037import com.google.gwt.event.dom.client.ClickHandler; 038import com.google.gwt.user.client.Command; 039import com.google.gwt.user.client.ui.FlowPanel; 040import com.google.gwt.user.client.ui.Widget; 041 042/** 043 * Provides an alert dialog with a button.<p> 044 * 045 * @since 8.0.0 046 */ 047public class CmsAlertDialog extends CmsPopup { 048 049 /** The panel for the bottom widgets. */ 050 private FlowPanel m_bottomWidgets; 051 052 /** The 'close' button. */ 053 private CmsPushButton m_closeButton; 054 055 /** The content text. */ 056 private FlowPanel m_content; 057 058 /** The action handler. */ 059 private I_CmsCloseDialogHandler m_handler; 060 061 /** The panel for the top widgets. */ 062 private FlowPanel m_topWidgets; 063 064 /** The warning message. */ 065 private CmsMessageWidget m_warningMessage; 066 067 /** 068 * Constructor.<p> 069 */ 070 public CmsAlertDialog() { 071 072 this("", ""); 073 } 074 075 /** 076 * Constructor.<p> 077 * 078 * @param title the title and heading of the dialog 079 * @param content the content text 080 */ 081 public CmsAlertDialog(String title, String content) { 082 083 this(title, content, Messages.get().key(Messages.GUI_CLOSE_0)); 084 } 085 086 /** 087 * Constructor.<p> 088 * 089 * @param title the title and heading of the dialog 090 * @param content the content text 091 * @param buttonText the button text 092 */ 093 public CmsAlertDialog(String title, String content, String buttonText) { 094 095 this(title, content, buttonText, null); 096 } 097 098 /** 099 * Constructor.<p> 100 * 101 * @param title the title and heading of the dialog 102 * @param content the content text 103 * @param buttonText the button text 104 * @param buttonIconClass the button icon class 105 */ 106 public CmsAlertDialog(String title, String content, String buttonText, String buttonIconClass) { 107 108 super(title); 109 setAutoHideEnabled(false); 110 setModal(true); 111 setGlassEnabled(true); 112 113 // create the dialogs content panel 114 m_content = new FlowPanel(); 115 m_content.addStyleName(I_CmsLayoutBundle.INSTANCE.dialogCss().alertMainContent()); 116 117 // create the top widget panel 118 m_topWidgets = new FlowPanel(); 119 m_topWidgets.addStyleName(I_CmsLayoutBundle.INSTANCE.dialogCss().alertTopContent()); 120 m_topWidgets.getElement().getStyle().setDisplay(Display.NONE); 121 m_content.add(m_topWidgets); 122 123 // create the warning message 124 m_warningMessage = new CmsMessageWidget(); 125 m_warningMessage.addStyleName(I_CmsLayoutBundle.INSTANCE.generalCss().border()); 126 m_warningMessage.setMessageHtml(content); 127 128 m_content.add(m_warningMessage); 129 130 // create the bottom widget panel 131 m_bottomWidgets = new FlowPanel(); 132 m_bottomWidgets.addStyleName(I_CmsLayoutBundle.INSTANCE.dialogCss().alertBottomContent()); 133 m_bottomWidgets.getElement().getStyle().setDisplay(Display.NONE); 134 m_content.add(m_bottomWidgets); 135 136 // set the content to the popup 137 setMainContent(m_content); 138 139 // add the close button 140 m_closeButton = new CmsPushButton(); 141 m_closeButton.setText(buttonText); 142 m_closeButton.setImageClass(buttonIconClass); 143 m_closeButton.setUseMinWidth(true); 144 m_closeButton.setButtonStyle(ButtonStyle.TEXT, ButtonColor.BLUE); 145 m_closeButton.addClickHandler(new ClickHandler() { 146 147 /** 148 * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent) 149 */ 150 public void onClick(ClickEvent event) { 151 152 onClose(); 153 } 154 }); 155 addButton(m_closeButton); 156 addDialogClose(new Command() { 157 158 public void execute() { 159 160 onClose(); 161 } 162 }); 163 } 164 165 /** 166 * Adds a widget to this dialogs bottom content.<p> 167 * 168 * @param w the widget to add 169 */ 170 public void addBottomWidget(Widget w) { 171 172 m_content.removeStyleName(I_CmsLayoutBundle.INSTANCE.dialogCss().alertMainContent()); 173 m_bottomWidgets.getElement().getStyle().clearDisplay(); 174 m_bottomWidgets.add(w); 175 176 } 177 178 /** 179 * Adds a widget to this dialogs top content.<p> 180 * 181 * @param w the widget to add 182 */ 183 public void addTopWidget(Widget w) { 184 185 m_content.removeStyleName(I_CmsLayoutBundle.INSTANCE.dialogCss().alertMainContent()); 186 m_topWidgets.getElement().getStyle().clearDisplay(); 187 m_topWidgets.add(w); 188 } 189 190 /** 191 * @see org.opencms.gwt.client.ui.CmsPopup#center() 192 */ 193 @Override 194 public void center() { 195 196 super.center(); 197 onShow(); 198 } 199 200 /** 201 * Returns the button widget.<p> 202 * 203 * @return the button 204 */ 205 public CmsPushButton getCloseButton() { 206 207 return m_closeButton; 208 } 209 210 /** 211 * Sets the cancel/close button icon class.<p> 212 * 213 * @param iconClass the icon class 214 */ 215 public void setCloseIconClass(String iconClass) { 216 217 getCloseButton().setImageClass(iconClass); 218 } 219 220 /** 221 * Sets the close button text.<p> 222 * 223 * @param text the button text 224 */ 225 public void setCloseText(String text) { 226 227 m_closeButton.setText(text); 228 } 229 230 /** 231 * Sets the dialog handler.<p> 232 * 233 * @param handler the handler to set 234 */ 235 public void setHandler(I_CmsCloseDialogHandler handler) { 236 237 m_handler = handler; 238 } 239 240 /** 241 * Sets the warning text (HTML possible).<p> 242 * 243 * @param warningText the warning text to set 244 */ 245 public void setWarningMessage(String warningText) { 246 247 m_warningMessage.setMessageHtml(warningText); 248 } 249 250 /** 251 * @see org.opencms.gwt.client.ui.CmsPopup#show() 252 */ 253 @Override 254 public void show() { 255 256 super.show(); 257 onShow(); 258 } 259 260 /** 261 * Returns the dialog handler.<p> 262 * 263 * @return the dialog handler 264 */ 265 protected I_CmsCloseDialogHandler getHandler() { 266 267 return m_handler; 268 } 269 270 /** 271 * Returns the top widgets panel.<p> 272 * 273 * @return the top widgets panel 274 */ 275 protected FlowPanel getTopWidgets() { 276 277 return m_topWidgets; 278 } 279 280 /** 281 * Executed on 'close' click. <p> 282 */ 283 protected void onClose() { 284 285 getCloseButton().setEnabled(false); 286 if (getHandler() != null) { 287 getHandler().onClose(); 288 } 289 hide(); 290 } 291 292 /** 293 * Executed when the dialog is shown.<p> 294 */ 295 protected void onShow() { 296 297 getCloseButton().setEnabled(true); 298 } 299}