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.apps;
029
030import org.opencms.file.CmsObject;
031import org.opencms.file.CmsProject;
032import org.opencms.file.CmsResource;
033import org.opencms.file.CmsResourceFilter;
034import org.opencms.main.CmsException;
035import org.opencms.main.OpenCms;
036import org.opencms.ui.A_CmsUI;
037import org.opencms.ui.components.CmsErrorDialog;
038import org.opencms.ui.components.CmsFileTable;
039import org.opencms.ui.components.CmsFileTableDialogContext;
040import org.opencms.util.CmsUUID;
041
042import java.util.Collection;
043import java.util.List;
044
045/**
046 * Dialog context for the explorer.<p>
047 */
048public class CmsExplorerDialogContext extends CmsFileTableDialogContext {
049
050    /** The explorer instance. */
051    private CmsFileExplorer m_explorer;
052
053    /**
054     * Creates a new instance.<p>
055     *
056     * @param contextType the context type
057     * @param fileTable the file table
058     * @param explorer the explorer app instance
059     * @param resources the list of selected resources
060     */
061    public CmsExplorerDialogContext(
062        ContextType contextType,
063        CmsFileTable fileTable,
064        CmsFileExplorer explorer,
065        List<CmsResource> resources) {
066
067        super(CmsFileExplorerConfiguration.APP_ID, contextType, fileTable, resources);
068        m_explorer = explorer;
069    }
070
071    /**
072     * @see org.opencms.ui.A_CmsDialogContext#finish(org.opencms.file.CmsProject, java.lang.String)
073     */
074    @Override
075    public void finish(CmsProject project, String siteRoot) {
076
077        finish(null);
078        m_explorer.onSiteOrProjectChange(project, siteRoot);
079    }
080
081    /**
082     * @see org.opencms.ui.I_CmsDialogContext#finish(java.util.Collection)
083     */
084    @Override
085    public void finish(Collection<CmsUUID> ids) {
086
087        closeWindow();
088        CmsAppWorkplaceUi.get().enableGlobalShortcuts();
089        if (ids != null) {
090            m_explorer.clearSelection();
091            for (CmsUUID id : ids) {
092                if (id.isNullUUID()) {
093                    m_explorer.updateAll(false);
094                    return;
095                }
096            }
097            m_explorer.update(ids);
098        }
099    }
100
101    /**
102     * @see org.opencms.ui.I_CmsDialogContext#focus(org.opencms.util.CmsUUID)
103     */
104    @Override
105    public void focus(CmsUUID cmsUUID) {
106
107        try {
108            CmsObject cms = A_CmsUI.getCmsObject();
109            CmsResource res = cms.readResource(cmsUUID, CmsResourceFilter.ALL);
110            String rootPath = res.getRootPath();
111            String siteRoot = OpenCms.getSiteManager().getSiteRoot(rootPath);
112            String sitePath = null;
113            if (siteRoot == null) {
114                if (OpenCms.getSiteManager().startsWithShared(rootPath)) {
115                    siteRoot = OpenCms.getSiteManager().getSharedFolder();
116                    sitePath = CmsResource.getParentFolder(
117                        rootPath.substring(OpenCms.getSiteManager().getSharedFolder().length()));
118                } else {
119                    sitePath = CmsResource.getParentFolder(rootPath);
120                    siteRoot = "";
121                }
122            } else {
123                CmsObject otherSiteCms = OpenCms.initCmsObject(cms);
124                otherSiteCms.getRequestContext().setSiteRoot(siteRoot);
125                sitePath = otherSiteCms.getRequestContext().removeSiteRoot(CmsResource.getParentFolder(rootPath));
126            }
127            m_explorer.changeSite(siteRoot, sitePath, true);
128        } catch (CmsException e) {
129            CmsErrorDialog.showErrorDialog(e);
130        }
131    }
132
133    /**
134     * @see org.opencms.ui.components.CmsFileTableDialogContext#updateUserInfo()
135     */
136    @Override
137    public void updateUserInfo() {
138
139        m_explorer.m_appContext.updateUserInfo();
140    }
141}