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;
032import org.opencms.gwt.shared.CmsListInfoBean;
033import org.opencms.gwt.shared.CmsResourceStatusBean;
034
035import com.google.gwt.dom.client.Style.Unit;
036import com.google.gwt.event.dom.client.ClickEvent;
037import com.google.gwt.event.dom.client.ClickHandler;
038import com.google.gwt.user.client.ui.FlowPanel;
039import com.google.gwt.user.client.ui.Label;
040
041/**
042 * Confirm dialog with a resource info box.<p>
043 */
044public class CmsResourceInfoConfirmDialog {
045
046    /** The cancel button. */
047    private CmsPushButton m_cancelButton;
048
049    /** Center panel. */
050    private FlowPanel m_centerPanel = new FlowPanel();
051
052    /** The dialog content. */
053    private FlowPanel m_content = new FlowPanel();
054
055    /** The dialog. */
056    private CmsPopup m_dialog;
057
058    /** The OK button. */
059    private CmsPushButton m_okButton;
060
061    /**
062     * Creates a new dialog instance for the given resource info.<p>
063     *
064     * @param resourceStatus the resource information
065     */
066    public CmsResourceInfoConfirmDialog(CmsResourceStatusBean resourceStatus) {
067
068        CmsListInfoBean info = resourceStatus.getListInfo();
069        CmsListItemWidget itemWidget = new CmsListItemWidget(info);
070        m_content.add(itemWidget);
071        m_centerPanel.add(new Label(getText()));
072        m_centerPanel.getElement().getStyle().setPadding(7, Unit.PX);
073
074        m_content.add(m_centerPanel);
075        m_okButton = createButton(getOkText());
076        m_okButton.addClickHandler(new ClickHandler() {
077
078            @SuppressWarnings("synthetic-access")
079            public void onClick(ClickEvent event) {
080
081                m_dialog.hide();
082                onConfirm();
083            }
084        });
085        m_cancelButton = createButton(getCancelText());
086        m_cancelButton.addClickHandler(new ClickHandler() {
087
088            @SuppressWarnings("synthetic-access")
089            public void onClick(ClickEvent event) {
090
091                m_dialog.hide();
092            }
093        });
094
095        m_dialog = new CmsPopup();
096        m_dialog.setModal(true);
097        m_dialog.setGlassEnabled(true);
098        m_dialog.setCaption(getCaption());
099
100        m_dialog.addButton(m_cancelButton);
101        m_dialog.addButton(m_okButton);
102        m_okButton.setButtonStyle(ButtonStyle.TEXT, ButtonColor.GREEN);
103
104        m_dialog.setMainContent(m_content);
105
106    }
107
108    /**
109     * Displays the dialog.<p>
110     */
111    public void display() {
112
113        m_dialog.center();
114    }
115
116    /**
117     * Gets the cancel button text.<p>
118     *
119     * @return the cancel button text
120     */
121    public String getCancelText() {
122
123        return "??? Cancel";
124    }
125
126    /**
127     * Gets the dialog title.<p>
128     *
129     * @return the dialog title
130     */
131    public String getCaption() {
132
133        return "??? Confirm";
134    }
135
136    /**
137     * Gets the OK button text.<p>
138     *
139     * @return the OK button text
140     */
141    public String getOkText() {
142
143        return "??? OK";
144    }
145
146    /**
147     * Gets the dialog text.<p>
148     *
149     * @return the dialog text
150     */
151    public String getText() {
152
153        return "??? Confirm";
154    }
155
156    /**
157     * Method to execute when the user confirms the action.<p>
158     */
159    public void onConfirm() {
160
161        // do nothing
162
163    }
164
165    /**
166     * Creates a button for the dialog.<p>
167     *
168     * @param text the button text
169     *
170     * @return the created button
171     */
172    private CmsPushButton createButton(String text) {
173
174        CmsPushButton result = new CmsPushButton();
175        result.setText(text);
176        result.setUseMinWidth(true);
177        return result;
178    }
179}