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.ui.components.extensions;
029
030import org.opencms.ui.I_CmsDialogContext;
031import org.opencms.ui.apps.CmsAppWorkplaceUi;
032import org.opencms.ui.shared.rpc.I_CmsJSPBrowserFrameRpc;
033import org.opencms.util.CmsUUID;
034
035import java.util.HashSet;
036import java.util.Set;
037
038import com.vaadin.server.AbstractExtension;
039import com.vaadin.server.ExternalResource;
040import com.vaadin.ui.BrowserFrame;
041import com.vaadin.ui.Window;
042
043/**
044 * Vaadin extension class for a BrowserFrame to display a JSP.<p>
045 *  From the client side, the extension allows to return an Array of UUIDs of changed resources over an Rpc-Interface.<p>
046 */
047public class CmsJSPBrowserFrameExtension extends AbstractExtension implements I_CmsJSPBrowserFrameRpc {
048
049    /**vaadin serial id.*/
050    private static final long serialVersionUID = -417339050505442749L;
051
052    /**Dialog context.*/
053    private I_CmsDialogContext m_context;
054
055    /**Vaadin window to where the iframe with the jsp gets shown.*/
056    private Window m_window;
057
058    /**
059     * Private constructor.<p>
060     * Only called from static method in this class.<p>
061     *
062     * @param link of jsp
063     * @param context Dialog Context
064     */
065    private CmsJSPBrowserFrameExtension(String link, I_CmsDialogContext context) {
066
067        m_context = context;
068        ExternalResource res = new ExternalResource(link);
069
070        BrowserFrame browser = new BrowserFrame("Browser", res);
071        browser.setSizeFull();
072        m_window = new Window();
073        m_window.setSizeFull();
074        m_window.addStyleName("o-jspwindow");
075        m_window.setContent(browser);
076        m_window.setClosable(false);
077        m_window.setDraggable(false);
078        CmsAppWorkplaceUi.get().addWindow(m_window);
079
080        super.extend(browser);
081        registerRpc(this);
082    }
083
084    /**
085     * Creates extended BrowserFrame displaying a JSP under given link.<p>
086     *
087     * @param jspLink of JSP file, absolute vfs-path
088     * @param context of the dialog to finish operation in the end
089     */
090    @SuppressWarnings("unused")
091    public static void showExtendedBrowserFrame(String jspLink, I_CmsDialogContext context) {
092
093        new CmsJSPBrowserFrameExtension(jspLink, context);
094    }
095
096    /**
097     * @see org.opencms.ui.shared.rpc.I_CmsJSPBrowserFrameRpc#cancelParentWindow(java.lang.String[])
098     */
099    public void cancelParentWindow(String[] uuids) {
100
101        m_window.close();
102        m_context.finish(getSetFromUUIDStrings(uuids));
103    }
104
105    /**
106     * Creates Set of type CmsUUID from String array.<p>
107     *
108     * @param uuids in array as string
109     * @return Set<CmsUUID> to use for finish method of I_CmsDialogContext
110     */
111    private Set<CmsUUID> getSetFromUUIDStrings(String[] uuids) {
112
113        Set<CmsUUID> res = new HashSet<CmsUUID>();
114        for (String uuid : uuids) {
115            res.add(new CmsUUID(uuid));
116        }
117        return res;
118    }
119}