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.ade.sitemap.client.edit;
029
030import org.opencms.ade.sitemap.client.CmsSitemapView;
031import org.opencms.ade.sitemap.client.Messages;
032import org.opencms.ade.sitemap.client.control.CmsSitemapController;
033import org.opencms.ade.sitemap.client.ui.css.I_CmsSitemapLayoutBundle;
034import org.opencms.ade.sitemap.shared.CmsClientSitemapEntry;
035import org.opencms.file.CmsResource;
036import org.opencms.gwt.client.property.CmsReloadMode;
037import org.opencms.gwt.shared.CmsListInfoBean;
038import org.opencms.gwt.shared.property.CmsClientProperty;
039import org.opencms.gwt.shared.property.CmsClientTemplateBean;
040import org.opencms.gwt.shared.property.CmsPropertyModification;
041import org.opencms.util.CmsUUID;
042
043import java.util.ArrayList;
044import java.util.Collections;
045import java.util.List;
046import java.util.Map;
047
048/**
049 * The mode handler for the 'edit entry' mode of the sitemap entry editor.<p>
050 *
051 * @since 8.0.0
052 */
053public class CmsEditEntryHandler extends A_CmsSitemapEntryEditorHandler {
054
055    /** True if the sitemap editor is in simple mode. */
056    private boolean m_isSimpleMode;
057
058    /** The page info bean. */
059    private CmsListInfoBean m_pageInfo;
060
061    /**
062     * Creates a new instance of this class.<p>
063     *
064     * @param controller the sitemap controller for this mode
065     * @param entry the sitemap entry for this mode
066     * @param isSimpleMode true if the sitemap entry editor is in simple mode
067     */
068    public CmsEditEntryHandler(CmsSitemapController controller, CmsClientSitemapEntry entry, boolean isSimpleMode) {
069
070        super(controller, entry);
071        m_isSimpleMode = isSimpleMode;
072
073    }
074
075    /**
076     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getAllPropertyNames()
077     */
078    public List<String> getAllPropertyNames() {
079
080        return CmsSitemapView.getInstance().getController().getData().getAllPropertyNames();
081    }
082
083    /**
084     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getDefaultFileId()
085     */
086    public CmsUUID getDefaultFileId() {
087
088        return m_entry.getDefaultFileId();
089    }
090
091    /**
092     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getDefaultFileProperties()
093     */
094    public Map<String, CmsClientProperty> getDefaultFileProperties() {
095
096        return m_entry.getDefaultFileProperties();
097    }
098
099    /**
100     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getDialogTitle()
101     */
102    public String getDialogTitle() {
103
104        return Messages.get().key(Messages.GUI_EDIT_ENTRY_TITLE_0);
105
106    }
107
108    /**
109     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getForbiddenUrlNames()
110     */
111    public List<String> getForbiddenUrlNames() {
112
113        if (m_entry.getSitePath().equals("/")) {
114            return Collections.<String> emptyList();
115        }
116
117        List<String> result = new ArrayList<String>();
118        String parentPath = CmsResource.getParentFolder(m_entry.getSitePath());
119        CmsClientSitemapEntry parent = m_controller.getEntry(parentPath);
120        if (parent == null) {
121            return result;
122        }
123        for (CmsClientSitemapEntry child : parent.getSubEntries()) {
124            if (child != m_entry) {
125                result.add(child.getName());
126            }
127        }
128        return result;
129    }
130
131    /**
132     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getId()
133     */
134    public CmsUUID getId() {
135
136        return m_entry.getId();
137    }
138
139    /**
140     * Gets the property object which would be inherited by a sitemap entry.<p>
141     *
142     * @param name the name of the property
143     * @return the property object which would be inherited
144     */
145    public CmsClientProperty getInheritedProperty(String name) {
146
147        return CmsSitemapView.getInstance().getController().getInheritedPropertyObject(m_entry, name);
148    }
149
150    /**
151     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getModeClass()
152     */
153    public String getModeClass() {
154
155        if (CmsSitemapView.getInstance().isNavigationMode()) {
156            return I_CmsSitemapLayoutBundle.INSTANCE.sitemapItemCss().navMode();
157        } else {
158            return I_CmsSitemapLayoutBundle.INSTANCE.sitemapItemCss().vfsMode();
159        }
160    }
161
162    /**
163     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getOwnProperties()
164     */
165    public Map<String, CmsClientProperty> getOwnProperties() {
166
167        return m_entry.getOwnProperties();
168    }
169
170    /**
171     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getPageInfo()
172     */
173    public CmsListInfoBean getPageInfo() {
174
175        return m_pageInfo;
176    }
177
178    /**
179     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getPath()
180     */
181    public String getPath() {
182
183        return m_entry.getSitePath();
184    }
185
186    /**
187     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getPossibleTemplates()
188     */
189    public Map<String, CmsClientTemplateBean> getPossibleTemplates() {
190
191        return CmsSitemapView.getInstance().getController().getData().getTemplates();
192    }
193
194    /**
195     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#handleSubmit(java.lang.String, java.lang.String, java.util.List, boolean, org.opencms.gwt.client.property.CmsReloadMode)
196     */
197    public void handleSubmit(
198        String newUrlName,
199        String vfsPath,
200        List<CmsPropertyModification> propertyChanges,
201        boolean editedName,
202        CmsReloadMode reloadStatus) {
203
204        if (editedName) {
205            m_controller.editAndChangeName(m_entry, newUrlName, propertyChanges, false, reloadStatus);
206        } else {
207            m_controller.edit(m_entry, propertyChanges, reloadStatus);
208        }
209
210    }
211
212    /**
213     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#hasEditableName()
214     */
215    public boolean hasEditableName() {
216
217        return !getEntry().isRoot();
218    }
219
220    /**
221     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#isFolder()
222     */
223    public boolean isFolder() {
224
225        return m_entry.isFolderType();
226    }
227
228    /**
229     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#isHiddenProperty(java.lang.String)
230     */
231    public boolean isHiddenProperty(String key) {
232
233        return CmsSitemapView.getInstance().getController().isHiddenProperty(key);
234    }
235
236    /**
237     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#isSimpleMode()
238     */
239    public boolean isSimpleMode() {
240
241        return m_isSimpleMode;
242    }
243
244    /**
245     * Sets the page info bean.<p>
246     *
247     * @param pageInfo the page info bean
248     */
249    public void setPageInfo(CmsListInfoBean pageInfo) {
250
251        m_pageInfo = pageInfo;
252    }
253
254    /**
255     * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#useAdeTemplates()
256     */
257    public boolean useAdeTemplates() {
258
259        return true;
260    }
261
262    /**
263     * Gets the edited sitemap entry.<p>
264     *
265     * @return the edited sitemap entry
266     */
267    protected CmsClientSitemapEntry getEntry() {
268
269        return m_entry;
270    }
271
272    /**
273     * Returns the path for the given URL name.<p>
274     *
275     * @param urlName the URL name to create the path for
276     *
277     * @return the new path for the given URL name
278     */
279    protected String getPath(String urlName) {
280
281        if (urlName.equals("")) {
282            return m_entry.getSitePath();
283        }
284        return CmsResource.getParentFolder(m_entry.getSitePath()) + urlName + "/";
285    }
286
287}