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; 033 034import com.google.gwt.event.dom.client.ClickEvent; 035import com.google.gwt.event.dom.client.ClickHandler; 036 037/** 038 * Provides a confirmation dialog with ok and cancel button.<p> 039 * 040 * @since 8.0.0 041 */ 042public class CmsConfirmDialog extends CmsAlertDialog { 043 044 /** The action handler. */ 045 private I_CmsConfirmDialogHandler m_handler; 046 047 /** The 'Ok' button. */ 048 private CmsPushButton m_okButton; 049 050 /** 051 * Constructor.<p> 052 * 053 * @param caption the title for this dialog 054 */ 055 public CmsConfirmDialog(String caption) { 056 057 this(caption, ""); 058 } 059 060 /** 061 * The constructor.<p> 062 * 063 * @param caption the title and heading of the dialog 064 * @param content the content text 065 */ 066 public CmsConfirmDialog(String caption, String content) { 067 068 super(caption, content, Messages.get().key(Messages.GUI_CANCEL_0), null); 069 m_okButton = new CmsPushButton(); 070 m_okButton.setText(Messages.get().key(Messages.GUI_OK_0)); 071 m_okButton.setUseMinWidth(true); 072 m_okButton.setButtonStyle(ButtonStyle.TEXT, ButtonColor.RED); 073 m_okButton.addClickHandler(new ClickHandler() { 074 075 /** 076 * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent) 077 */ 078 public void onClick(ClickEvent event) { 079 080 onOk(); 081 } 082 }); 083 addButton(m_okButton); 084 } 085 086 /** 087 * @see org.opencms.gwt.client.ui.CmsPopup#center() 088 */ 089 @Override 090 public void center() { 091 092 super.center(); 093 getOkButton().setEnabled(true); 094 } 095 096 /** 097 * Returns the 'OK' button widget.<p> 098 * 099 * @return the 'OK' button 100 */ 101 public CmsPushButton getOkButton() { 102 103 return m_okButton; 104 } 105 106 /** 107 * Sets the dialog handler.<p> 108 * 109 * @param handler the handler to set 110 */ 111 public void setHandler(I_CmsConfirmDialogHandler handler) { 112 113 m_handler = handler; 114 super.setHandler(handler); 115 } 116 117 /** 118 * Sets the accept button icon class.<p> 119 * 120 * @param iconClass the icon class 121 */ 122 public void setOkIconClass(String iconClass) { 123 124 m_okButton.setImageClass(iconClass); 125 } 126 127 /** 128 * Sets the accept button text.<p> 129 * 130 * @param text the button text 131 */ 132 public void setOkText(String text) { 133 134 m_okButton.setText(text); 135 } 136 137 /** 138 * @see org.opencms.gwt.client.ui.CmsPopup#show() 139 */ 140 @Override 141 public void show() { 142 143 super.show(); 144 getOkButton().setEnabled(true); 145 } 146 147 /** 148 * @see org.opencms.gwt.client.ui.CmsAlertDialog#getHandler() 149 */ 150 @Override 151 protected I_CmsConfirmDialogHandler getHandler() { 152 153 return m_handler; 154 } 155 156 /** 157 * Executed on 'ok' click.<p> 158 */ 159 protected void onOk() { 160 161 getOkButton().setEnabled(false); 162 if (getHandler() != null) { 163 getHandler().onOk(); 164 } 165 hide(); 166 } 167}