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.CmsRemovedElementStatus;
031import org.opencms.gwt.client.CmsCoreProvider;
032import org.opencms.gwt.client.rpc.CmsRpcAction;
033import org.opencms.gwt.client.ui.CmsListItemWidget;
034import org.opencms.gwt.client.ui.CmsPopup;
035import org.opencms.gwt.client.ui.CmsPushButton;
036import org.opencms.gwt.client.ui.I_CmsButton.ButtonColor;
037import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle;
038import org.opencms.gwt.shared.CmsListInfoBean;
039
040import java.util.ArrayList;
041import java.util.List;
042
043import com.google.gwt.core.client.GWT;
044import com.google.gwt.event.dom.client.ClickEvent;
045import com.google.gwt.uibinder.client.UiBinder;
046import com.google.gwt.uibinder.client.UiField;
047import com.google.gwt.uibinder.client.UiHandler;
048import com.google.gwt.user.client.ui.Panel;
049
050/**
051 * Dialog for asking the user whether elements which were removed from the container page should be deleted.<p>
052 */
053public class CmsRemovedElementDeletionDialog extends CmsPopup {
054
055    /**
056     * Class with message accessors for the UiBinder.
057     */
058    public static class Messages {
059
060        /**
061         * Message accessor.<p>
062         *
063         * @return the message text
064         */
065        public static String messageCancel() {
066
067            return org.opencms.ade.containerpage.client.Messages.get().key(
068                org.opencms.ade.containerpage.client.Messages.GUI_KEEP_ELEMENT_0);
069
070        }
071
072        /**
073         * Message accessor.<p>
074         *
075         * @return the message text
076         */
077        public static String messageMainText() {
078
079            return org.opencms.ade.containerpage.client.Messages.get().key(
080                org.opencms.ade.containerpage.client.Messages.GUI_ASK_DELETE_REMOVED_ELEMENT_0);
081        }
082
083        /**
084         * Message accessor.<p>
085         *
086         * @return the message text
087         */
088        public static String messageOk() {
089
090            return org.opencms.gwt.client.Messages.get().key(org.opencms.gwt.client.Messages.GUI_DELETE_0);
091        }
092
093        /**
094         * Message accessor.<p>
095         *
096         * @return the message text
097         */
098        public static String messageTitle() {
099
100            return org.opencms.ade.containerpage.client.Messages.get().key(
101                org.opencms.ade.containerpage.client.Messages.GUI_ASK_DELETE_REMOVED_ELEMENT_TITLE_0);
102        }
103    }
104
105    /**
106     * UiBinder interface for this dialog.<p>
107     */
108    interface I_UiBinder extends UiBinder<Panel, CmsRemovedElementDeletionDialog> {
109        // empty uibinder interface
110    }
111
112    /** UiBinder instance for this dialog. */
113    private static I_UiBinder uibinder = GWT.create(I_UiBinder.class);
114
115    /** The cancel button. */
116    @UiField
117    protected CmsPushButton m_cancelButton;
118
119    /** The container for the file info box. */
120    @UiField
121    protected Panel m_infoBoxContainer;
122
123    /** The ok button. */
124    @UiField
125    protected CmsPushButton m_okButton;
126
127    /** The status of the removed element. */
128    CmsRemovedElementStatus m_status;
129
130    /**
131     * Creates a new dialog instance.<p>
132     *
133     * @param status the status of the removed element
134     */
135    public CmsRemovedElementDeletionDialog(CmsRemovedElementStatus status) {
136
137        super(
138            org.opencms.ade.containerpage.client.Messages.get().key(
139                org.opencms.ade.containerpage.client.Messages.GUI_ASK_DELETE_REMOVED_ELEMENT_TITLE_0));
140        setModal(true);
141        setGlassEnabled(true);
142        m_status = status;
143        CmsListInfoBean elementInfo = status.getElementInfo();
144        Panel panel = uibinder.createAndBindUi(this);
145        CmsListItemWidget infoBox = new CmsListItemWidget(elementInfo);
146        m_infoBoxContainer.add(infoBox);
147        setMainContent(panel);
148        m_okButton.setButtonStyle(ButtonStyle.TEXT, ButtonColor.RED);
149        for (CmsPushButton button : getDialogButtons()) {
150            addButton(button);
151        }
152    }
153
154    /**
155     * Click handler for the cancel button.<p>
156     *
157     * @param e the click event
158     */
159    @UiHandler("m_cancelButton")
160    protected void onClickCancel(ClickEvent e) {
161
162        hide();
163    }
164
165    /**
166     * Click handler for the ok button.<p>
167     *
168     * @param e the click event
169     */
170    @UiHandler("m_okButton")
171    protected void onClickOk(ClickEvent e) {
172
173        CmsRpcAction<Void> deleteAction = new CmsRpcAction<Void>() {
174
175            @Override
176            public void execute() {
177
178                start(200, true);
179                CmsCoreProvider.getVfsService().deleteResource(m_status.getStructureId(), this);
180            }
181
182            @Override
183            public void onResponse(Void result) {
184
185                stop(true);
186                hide();
187            }
188        };
189        deleteAction.execute();
190    }
191
192    /**
193     * Gets a list of the dialog buttons.<p>
194     *
195     * @return the list of dialog buttons
196     */
197    private List<CmsPushButton> getDialogButtons() {
198
199        List<CmsPushButton> result = new ArrayList<CmsPushButton>();
200        result.add(m_cancelButton);
201        result.add(m_okButton);
202        return result;
203    }
204
205}