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;
029
030import org.opencms.file.CmsProject;
031import org.opencms.file.CmsResource;
032import org.opencms.ui.A_CmsDialogContext;
033import org.opencms.ui.I_CmsEditPropertyContext;
034import org.opencms.ui.contextmenu.CmsContextMenuEditHandler;
035import org.opencms.util.CmsUUID;
036
037import java.util.Collection;
038import java.util.List;
039import java.util.stream.Collectors;
040
041import com.google.common.collect.Lists;
042
043/**
044 * The file table dialog context.<p>
045 */
046public class CmsFileTableDialogContext extends A_CmsDialogContext implements I_CmsEditPropertyContext {
047
048    /** The file table instance. */
049    private CmsFileTable m_fileTable;
050
051    /** The in line editable properties. */
052    private Collection<CmsResourceTableProperty> m_editableProperties;
053
054    /**
055     * Creates a new instance.<p>
056     *
057     * @param appId the app id
058     * @param contextType the context type
059     * @param fileTable the file table instance
060     * @param resources the list of selected resources
061     */
062    public CmsFileTableDialogContext(
063        String appId,
064        ContextType contextType,
065        CmsFileTable fileTable,
066        List<CmsResource> resources) {
067
068        super(appId, contextType, resources);
069        m_fileTable = fileTable;
070    }
071
072    /**
073     * @see org.opencms.ui.I_CmsEditPropertyContext#editProperty(java.lang.Object)
074     */
075    public void editProperty(Object propertyId) {
076
077        new CmsContextMenuEditHandler(
078            getResources().get(0).getStructureId(),
079            (CmsResourceTableProperty)propertyId,
080            m_fileTable,
081            this).start();
082    }
083
084    /**
085     * @see org.opencms.ui.A_CmsDialogContext#finish(org.opencms.file.CmsProject, java.lang.String)
086     */
087    @Override
088    public void finish(CmsProject project, String siteRoot) {
089
090        super.finish(null);
091        super.reload();
092    }
093
094    /**
095     * @see org.opencms.ui.I_CmsDialogContext#finish(java.util.Collection)
096     */
097    @Override
098    public void finish(Collection<CmsUUID> ids) {
099
100        super.finish(ids);
101        m_fileTable.clearSelection();
102        if (ids != null) {
103            if (ids.stream().anyMatch(CmsUUID::isNullUUID)) {
104                m_fileTable.update(m_fileTable.getAllIds(), false);
105            } else {
106                ids = ids.stream().filter(id -> m_fileTable.containsId(id)).collect(Collectors.toList());
107                m_fileTable.update(ids, false);
108            }
109        }
110    }
111
112    /**
113     * @see org.opencms.ui.I_CmsDialogContext#focus(org.opencms.util.CmsUUID)
114     */
115    public void focus(CmsUUID cmsUUID) {
116
117        // nothing to do
118    }
119
120    /**
121     * @see org.opencms.ui.I_CmsDialogContext#getAllStructureIdsInView()
122     */
123    public List<CmsUUID> getAllStructureIdsInView() {
124
125        return Lists.newArrayList(m_fileTable.getAllIds());
126    }
127
128    /**
129     * @see org.opencms.ui.I_CmsEditPropertyContext#isPropertyEditable(java.lang.Object)
130     */
131    public boolean isPropertyEditable(Object propertyId) {
132
133        return (getResources().size() == 1)
134            && (m_editableProperties != null)
135            && m_editableProperties.contains(propertyId)
136            && m_fileTable.isColumnVisible((CmsResourceTableProperty)propertyId);
137    }
138
139    /**
140     * Sets the in line editable properties.<p>
141     *
142     * @param editableProperties the in line editable properties
143     */
144    public void setEditableProperties(Collection<CmsResourceTableProperty> editableProperties) {
145
146        m_editableProperties = editableProperties;
147    }
148
149    /**
150     * @see org.opencms.ui.I_CmsDialogContext#updateUserInfo()
151     */
152    public void updateUserInfo() {
153
154        // not supported
155    }
156}