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.upload.client.ui; 029 030import org.opencms.gwt.client.CmsCoreProvider; 031import org.opencms.gwt.client.ui.CmsFrameDialog; 032import org.opencms.gwt.client.ui.CmsPopup; 033import org.opencms.gwt.client.ui.contextmenu.I_CmsActionHandler; 034import org.opencms.gwt.client.util.CmsEmbeddedDialogHandler; 035import org.opencms.gwt.shared.CmsGwtConstants; 036import org.opencms.gwt.shared.I_CmsUploadConstants; 037import org.opencms.util.CmsUUID; 038 039import java.util.ArrayList; 040import java.util.HashMap; 041import java.util.List; 042import java.util.Map; 043 044import com.google.common.base.Joiner; 045import com.google.gwt.event.logical.shared.CloseHandler; 046import com.google.gwt.user.client.ui.PopupPanel; 047 048/** 049 * A opens a dialog which contains an IFRAME for displaying the upload hook JSP page.<p> 050 */ 051public final class CmsUploadHookDialog { 052 053 /** The dialog height. */ 054 public static final int DIALOG_HEIGHT = 300; 055 056 /** 057 * Hide public constructor.<p> 058 */ 059 private CmsUploadHookDialog() { 060 061 // noop 062 } 063 064 /** 065 * Opens a new upload property dialog.<p> 066 * 067 * @param title the title for the dialog popup 068 * @param hookUri the URI of the upload hook page 069 * @param uploadedFiles the uploaded files 070 * @param closeHandler the dialog close handler 071 */ 072 public static void openDialog( 073 String title, 074 String hookUri, 075 List<String> uploadedFiles, 076 final CloseHandler<PopupPanel> closeHandler) { 077 078 if (hookUri.startsWith("#")) { 079 List<CmsUUID> resourceIds = new ArrayList<CmsUUID>(); 080 if (uploadedFiles != null) { 081 for (String id : uploadedFiles) { 082 resourceIds.add(new CmsUUID(id)); 083 } 084 085 } 086 CmsEmbeddedDialogHandler handler = new CmsEmbeddedDialogHandler(new I_CmsActionHandler() { 087 088 public void leavePage(String targetUri) { 089 090 // TODO Auto-generated method stub 091 092 } 093 094 public void onSiteOrProjectChange(String sitePath, String serverLink) { 095 096 // TODO Auto-generated method stub 097 098 } 099 100 public void refreshResource(CmsUUID structureId) { 101 102 closeHandler.onClose(null); 103 } 104 }); 105 String dialogId = hookUri.substring(1); 106 handler.openDialog(dialogId, CmsGwtConstants.CONTEXT_TYPE_FILE_TABLE, resourceIds); 107 108 } else { 109 Map<String, String> parameters = new HashMap<String, String>(); 110 parameters.put(I_CmsUploadConstants.PARAM_RESOURCES, Joiner.on(",").join(uploadedFiles)); 111 CmsPopup popup = CmsFrameDialog.showFrameDialog( 112 title, 113 CmsCoreProvider.get().link(hookUri), 114 parameters, 115 closeHandler); 116 popup.setHeight(DIALOG_HEIGHT); 117 popup.setWidth(CmsPopup.DEFAULT_WIDTH); 118 popup.center(); 119 } 120 } 121}