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