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.contextmenu; 029 030import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle; 031import org.opencms.gwt.client.ui.input.upload.CmsUploadButton; 032import org.opencms.gwt.client.ui.replace.CmsReplaceHandler; 033import org.opencms.gwt.shared.CmsContextMenuEntryBean; 034import org.opencms.util.CmsUUID; 035 036import com.google.gwt.event.dom.client.ClickEvent; 037import com.google.gwt.event.logical.shared.CloseEvent; 038import com.google.gwt.event.logical.shared.CloseHandler; 039import com.google.gwt.user.client.ui.PopupPanel; 040import com.google.gwt.user.client.ui.SimplePanel; 041 042/** 043 * The replace resource context menu entry.<p> 044 */ 045public class CmsReplace extends A_CmsContextMenuItem implements I_CmsHasContextMenuCommand { 046 047 /** The replace handler. */ 048 private CmsReplaceHandler m_replaceHandler; 049 050 /** 051 * Constructor.<p> 052 * 053 * @param structureId the structure id of the resource to replace 054 * @param handler the context menu handler 055 * @param bean the menu entry bean 056 */ 057 protected CmsReplace( 058 final CmsUUID structureId, 059 final I_CmsContextMenuHandler handler, 060 CmsContextMenuEntryBean bean) { 061 062 super(bean.getLabel()); 063 m_replaceHandler = new CmsReplaceHandler(structureId); 064 m_replaceHandler.setCloseHandler(new CloseHandler<PopupPanel>() { 065 066 public void onClose(CloseEvent<PopupPanel> arg0) { 067 068 handler.refreshResource(structureId); 069 } 070 }); 071 CmsUploadButton button = new CmsUploadButton(m_replaceHandler); 072 button.setText(getText()); 073 button.setStyleName(I_CmsLayoutBundle.INSTANCE.uploadButton().uploadButton()); 074 SimplePanel panel = new SimplePanel(); 075 panel.setWidget(button); 076 initWidget(panel); 077 setStyleName(I_CmsLayoutBundle.INSTANCE.contextmenuCss().cmsMenuItem()); 078 079 } 080 081 /** 082 * Returns the context menu command according to 083 * {@link org.opencms.gwt.client.ui.contextmenu.I_CmsHasContextMenuCommand}.<p> 084 * 085 * @return the context menu command 086 */ 087 public static I_CmsContextMenuCommand getContextMenuCommand() { 088 089 return new I_CmsContextMenuCommand() { 090 091 public void execute(CmsUUID structureId, I_CmsContextMenuHandler handler, CmsContextMenuEntryBean bean) { 092 093 // nothing to do, will be handled by the widget 094 } 095 096 public A_CmsContextMenuItem getItemWidget( 097 CmsUUID structureId, 098 I_CmsContextMenuHandler handler, 099 CmsContextMenuEntryBean bean) { 100 101 return new CmsReplace(structureId, handler, bean); 102 } 103 104 public boolean hasItemWidget() { 105 106 return true; 107 } 108 }; 109 } 110 111 /** 112 * @see org.opencms.gwt.client.ui.contextmenu.A_CmsContextMenuItem#onClick(com.google.gwt.event.dom.client.ClickEvent) 113 */ 114 @Override 115 public void onClick(ClickEvent event) { 116 117 m_replaceHandler.setMenuItem(this); 118 } 119 120}