001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (C) Alkacon Software (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.ade.containerpage.client.ui;
029
030import org.opencms.ade.containerpage.shared.CmsCntPageData.ElementDeleteMode;
031import org.opencms.gwt.client.ui.CmsPopup;
032import org.opencms.gwt.client.ui.CmsPushButton;
033import org.opencms.gwt.shared.CmsListInfoBean;
034
035import com.google.gwt.event.dom.client.KeyCodes;
036import com.google.gwt.user.client.Event;
037import com.google.gwt.user.client.Event.NativePreviewEvent;
038import com.google.gwt.user.client.rpc.AsyncCallback;
039
040/**
041 * Dialog used for confirming the removal of an element in the container page editor.<p>
042 */
043public class CmsConfirmRemoveDialog extends CmsPopup {
044
045    /** The widget with the dialog contents. */
046    private CmsConfirmRemoveWidget m_widget;
047
048    /**
049     * Creates a new instance.<p>
050     *
051     * @param elementInfo the data for the resource info box
052     * @param deleteCheckbox true if the checkbox for deleting the resource should be displayed
053     * @param deleteMode the element delete mode
054     * @param removeCallback the callback which should be called when the user has confirmed or cancelled the element removal
055     */
056    public CmsConfirmRemoveDialog(
057        CmsListInfoBean elementInfo,
058        boolean deleteCheckbox,
059        ElementDeleteMode deleteMode,
060        AsyncCallback<Boolean> removeCallback) {
061
062        m_widget = new CmsConfirmRemoveWidget(elementInfo, deleteCheckbox, removeCallback);
063        m_widget.setPopup(this);
064        switch (deleteMode) {
065            default:
066            case askDelete:
067                break;
068            case askKeep:
069                m_widget.m_checkBox.setChecked(false);
070                m_widget.m_deleteContent = false;
071                break;
072            case alwaysKeep:
073                m_widget.m_checkBox.setChecked(false);
074                m_widget.m_deleteContent = false;
075                //$FALL-THROUGH$
076            case alwaysDelete:
077                m_widget.m_checkBox.setVisible(false);
078                m_widget.m_noReferenceLabel.setVisible(false);
079                break;
080        }
081
082        setMainContent(m_widget);
083        setModal(true);
084        setGlassEnabled(true);
085        setCaption(CmsConfirmRemoveWidget.MessageStrings.caption());
086        for (CmsPushButton button : m_widget.getButtons()) {
087            addButton(button);
088        }
089    }
090
091    /**
092     * @see org.opencms.gwt.client.ui.CmsPopup#onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent)
093     */
094    @Override
095    protected void onPreviewNativeEvent(NativePreviewEvent event) {
096
097        super.onPreviewNativeEvent(event);
098        switch (event.getTypeInt()) {
099            case Event.ONKEYPRESS:
100                switch (event.getNativeEvent().getKeyCode()) {
101                    case KeyCodes.KEY_ENTER:
102                        event.cancel();
103                        m_widget.onClickCancel(null);
104                        break;
105                    case KeyCodes.KEY_ESCAPE:
106                        event.cancel();
107                        m_widget.onClickOk(null);
108                        break;
109                    default:
110                        break;
111                }
112                break;
113            default:
114                break;
115        }
116    }
117
118}