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.gwt.client.ui.restore;
029
030import org.opencms.gwt.client.CmsCoreProvider;
031import org.opencms.gwt.client.rpc.CmsRpcAction;
032import org.opencms.gwt.client.ui.CmsListItem;
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.input.CmsCheckBox;
037import org.opencms.gwt.shared.CmsListInfoBean;
038import org.opencms.gwt.shared.CmsRestoreInfoBean;
039import org.opencms.gwt.shared.rpc.I_CmsVfsServiceAsync;
040
041import java.util.ArrayList;
042import java.util.List;
043
044import com.google.gwt.core.client.GWT;
045import com.google.gwt.event.dom.client.ClickEvent;
046import com.google.gwt.uibinder.client.UiBinder;
047import com.google.gwt.uibinder.client.UiField;
048import com.google.gwt.uibinder.client.UiHandler;
049import com.google.gwt.user.client.ui.Composite;
050import com.google.gwt.user.client.ui.FlowPanel;
051import com.google.gwt.user.client.ui.Label;
052import com.google.gwt.user.client.ui.Panel;
053import com.google.gwt.user.client.ui.Widget;
054
055/**
056 * The content widget for the restore dialog.<p>
057 */
058public class CmsRestoreView extends Composite {
059
060    /** The UiBinder class for this widget. */
061    interface I_CmsRestoreViewUiBinder extends UiBinder<Widget, CmsRestoreView> {
062        //empty
063    }
064
065    /** The UiBinder instance for this widget. */
066    private static I_CmsRestoreViewUiBinder uiBinder = GWT.create(I_CmsRestoreViewUiBinder.class);
067
068    /** The cancel button. */
069    @UiField
070    protected CmsPushButton m_cancelButton;
071
072    /** The container for the file info box. */
073    @UiField
074    protected FlowPanel m_infoBoxContainer;
075
076    /** The label which informs the user that the resource has moved. */
077    @UiField
078    protected Label m_movedLabel;
079
080    /** The section which is displayed when the resource was moved. */
081    @UiField
082    protected Panel m_movedSection;
083
084    /** The OK button. */
085    @UiField
086    protected CmsPushButton m_okButton;
087
088    /** The popup in which this widget is contained. */
089    protected CmsPopup m_popup;
090
091    /** The bean containing information about the resource to restore. */
092    protected CmsRestoreInfoBean m_restoreInfo;
093
094    /** The check box used for selecting whether a move operation should be undone. */
095    @UiField
096    protected CmsCheckBox m_undoMoveCheckbox;
097
098    /** The action which is executed after undoing the changes for the resource. */
099    Runnable m_afterRestoreAction;
100
101    /**
102     * Creates a new widget instance.<p>
103     *
104     * @param restoreInfo a bean with information about the resource to restore
105     * @param afterRestoreAction the action to execute after restoring the resource
106     */
107    public CmsRestoreView(CmsRestoreInfoBean restoreInfo, Runnable afterRestoreAction) {
108
109        initWidget(uiBinder.createAndBindUi(this));
110        m_afterRestoreAction = afterRestoreAction;
111        CmsListInfoBean listInfo = restoreInfo.getListInfoBean();
112        listInfo.addAdditionalInfo(CmsRestoreMessages.messageDateModified(), restoreInfo.getOfflineDate());
113        listInfo.addAdditionalInfo(CmsRestoreMessages.messageDateModifiedOnline(), restoreInfo.getOnlineDate());
114        CmsListItemWidget liWidget = new CmsListItemWidget(restoreInfo.getListInfoBean());
115        CmsListItem li = new CmsListItem(liWidget);
116        m_infoBoxContainer.add(li);
117        if (restoreInfo.isMoved() && restoreInfo.canUndoMove()) {
118            m_movedLabel.setText(
119                CmsRestoreMessages.messageMoved(restoreInfo.getOnlinePath(), restoreInfo.getOfflinePath()));
120            m_movedSection.setVisible(true);
121        }
122        m_restoreInfo = restoreInfo;
123    }
124
125    /**
126     * Sets the popup in which this widget is displayed.<p>
127     *
128     * @param popup the popup in which this widget is displayed
129     */
130    public void setPopup(CmsPopup popup) {
131
132        m_popup = popup;
133    }
134
135    /**
136     * Handler for the cancel button.<p>
137     *
138     * @param e the click event
139     */
140    @UiHandler("m_cancelButton")
141    protected void onClickCancel(ClickEvent e) {
142
143        m_popup.hide();
144    }
145
146    /**
147     * Click handler for the OK button.<p>
148     *
149     * @param e the click event
150     */
151    @UiHandler("m_okButton")
152    protected void onClickOk(ClickEvent e) {
153
154        final boolean undoMove = m_undoMoveCheckbox.getFormValue().booleanValue();
155        m_popup.hide();
156        CmsRpcAction<Void> action = new CmsRpcAction<Void>() {
157
158            @Override
159            public void execute() {
160
161                start(200, true);
162                I_CmsVfsServiceAsync service = CmsCoreProvider.getVfsService();
163                service.undoChanges(m_restoreInfo.getStructureId(), undoMove, this);
164            }
165
166            @Override
167            protected void onResponse(Void result) {
168
169                stop(false);
170                if (m_afterRestoreAction != null) {
171                    m_afterRestoreAction.run();
172                }
173            }
174
175        };
176        action.execute();
177
178    }
179
180    /**
181     * Gets the list of buttons for the dialog.<p>
182     *
183     * @return the list of buttons for the dialog
184     */
185    List<CmsPushButton> getDialogButtons() {
186
187        List<CmsPushButton> result = new ArrayList<CmsPushButton>();
188        result.add(m_cancelButton);
189        result.add(m_okButton);
190        return result;
191    }
192
193}