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.CmsPopup; 033import org.opencms.gwt.client.ui.CmsPushButton; 034import org.opencms.gwt.shared.CmsRestoreInfoBean; 035import org.opencms.util.CmsUUID; 036 037import java.util.List; 038 039/** 040 * A dialog used for undoing changes to a resource and restoring it to its last published state.<p> 041 */ 042public class CmsRestoreDialog extends CmsPopup { 043 044 /** The content widget for this dialog. */ 045 protected CmsRestoreView m_restoreView; 046 047 /** The structure id of the resource to undo changes for. */ 048 protected CmsUUID m_structureId; 049 050 /** The action executed after the changes have been undone. */ 051 Runnable m_afterRestoreAction; 052 053 /** 054 * Creates a new instance of this dialog.<p> 055 * 056 * @param structureId the structure id of the resource which should be restored 057 * @param afterRestoreAction the action which will be executed after the resource has been restored 058 */ 059 public CmsRestoreDialog(CmsUUID structureId, Runnable afterRestoreAction) { 060 061 super(CmsRestoreMessages.messageRestoreDialogTitle()); 062 setModal(true); 063 setGlassEnabled(true); 064 m_structureId = structureId; 065 m_afterRestoreAction = afterRestoreAction; 066 } 067 068 /** 069 * Loads the necessary data for the dialog from the server and shows the dialog.<p> 070 */ 071 public void loadAndShow() { 072 073 CmsRpcAction<CmsRestoreInfoBean> action = new CmsRpcAction<CmsRestoreInfoBean>() { 074 075 @Override 076 public void execute() { 077 078 start(0, true); 079 CmsCoreProvider.getVfsService().getRestoreInfo(m_structureId, this); 080 } 081 082 @Override 083 protected void onResponse(CmsRestoreInfoBean result) { 084 085 stop(false); 086 m_restoreView = new CmsRestoreView(result, m_afterRestoreAction); 087 m_restoreView.setPopup(CmsRestoreDialog.this); 088 setMainContent(m_restoreView); 089 List<CmsPushButton> buttons = m_restoreView.getDialogButtons(); 090 for (CmsPushButton button : buttons) { 091 addButton(button); 092 } 093 center(); 094 } 095 }; 096 action.execute(); 097 } 098 099}