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.ui.I_CmsButton.ButtonColor; 031import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle; 032 033import com.google.gwt.event.dom.client.ClickEvent; 034import com.google.gwt.event.dom.client.ClickHandler; 035 036/** 037 * Provides a confirmation dialog with yes, no and cancel button.<p> 038 * 039 * @since 8.0.0 040 */ 041public class CmsAcceptDeclineCancelDialog extends CmsAlertDialog { 042 043 /** The 'accept' button. */ 044 private CmsPushButton m_acceptButton; 045 046 /** The 'decline' button. */ 047 private CmsPushButton m_declineButton; 048 049 /** The dialog handler. */ 050 private I_CmsAcceptDeclineCancelHandler m_handler; 051 052 /** 053 * Constructor.<p> 054 * 055 * @param title the dialog title 056 * @param content the dialog content 057 */ 058 public CmsAcceptDeclineCancelDialog(String title, String content) { 059 060 super(title, content); 061 m_acceptButton = new CmsPushButton(); 062 m_acceptButton.setUseMinWidth(true); 063 m_acceptButton.setButtonStyle(ButtonStyle.TEXT, ButtonColor.GREEN); 064 m_acceptButton.addClickHandler(new ClickHandler() { 065 066 /** 067 * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent) 068 */ 069 public void onClick(ClickEvent event) { 070 071 onAccept(); 072 } 073 }); 074 m_declineButton = new CmsPushButton(); 075 m_declineButton.setUseMinWidth(true); 076 m_declineButton.setButtonStyle(ButtonStyle.TEXT, ButtonColor.RED); 077 m_declineButton.addClickHandler(new ClickHandler() { 078 079 /** 080 * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent) 081 */ 082 public void onClick(ClickEvent event) { 083 084 onDecline(); 085 } 086 }); 087 addButton(m_declineButton); 088 addButton(m_acceptButton); 089 } 090 091 /** 092 * @see org.opencms.gwt.client.ui.CmsAlertDialog#center() 093 */ 094 @Override 095 public void center() { 096 097 activateButtons(true); 098 super.center(); 099 } 100 101 /** 102 * Sets the accept button icon class.<p> 103 * 104 * @param iconClass the icon class 105 */ 106 public void setAcceptIconClass(String iconClass) { 107 108 m_acceptButton.setImageClass(iconClass); 109 } 110 111 /** 112 * Sets the accept button text.<p> 113 * 114 * @param text the button text 115 */ 116 public void setAcceptText(String text) { 117 118 m_acceptButton.setText(text); 119 } 120 121 /** 122 * Sets the decline button icon class.<p> 123 * 124 * @param iconClass the icon class 125 */ 126 public void setDeclineIconClass(String iconClass) { 127 128 m_declineButton.setImageClass(iconClass); 129 } 130 131 /** 132 * Sets the decline button text.<p> 133 * 134 * @param text the button text 135 */ 136 public void setDeclineText(String text) { 137 138 m_declineButton.setText(text); 139 } 140 141 /** 142 * Sets the dialog handler.<p> 143 * 144 * @param handler the handler to set 145 */ 146 public void setHandler(I_CmsAcceptDeclineCancelHandler handler) { 147 148 m_handler = handler; 149 super.setHandler(handler); 150 } 151 152 /** 153 * Sets the buttons enabled.<p> 154 * 155 * @param activate <code>true</code> to activate, <code>false</code> to deactivate 156 */ 157 protected void activateButtons(boolean activate) { 158 159 m_acceptButton.setEnabled(activate); 160 m_declineButton.setEnabled(activate); 161 getCloseButton().setEnabled(activate); 162 } 163 164 /** 165 * @see org.opencms.gwt.client.ui.CmsAlertDialog#getHandler() 166 */ 167 @Override 168 protected I_CmsAcceptDeclineCancelHandler getHandler() { 169 170 return m_handler; 171 } 172 173 /** 174 * Executed on accept click.<p> 175 */ 176 protected void onAccept() { 177 178 activateButtons(false); 179 if (getHandler() != null) { 180 getHandler().onAccept(); 181 } 182 hide(); 183 } 184 185 /** 186 * @see org.opencms.gwt.client.ui.CmsAlertDialog#onClose() 187 */ 188 @Override 189 protected void onClose() { 190 191 activateButtons(false); 192 if (getHandler() != null) { 193 getHandler().onClose(); 194 } 195 hide(); 196 } 197 198 /** 199 * Executed on decline click.<p> 200 */ 201 protected void onDecline() { 202 203 activateButtons(false); 204 if (getHandler() != null) { 205 getHandler().onDecline(); 206 } 207 hide(); 208 } 209}