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.gwt.client.property; 029 030import org.opencms.file.CmsResource; 031import org.opencms.gwt.client.CmsCoreProvider; 032import org.opencms.gwt.client.rpc.CmsRpcAction; 033import org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler; 034import org.opencms.gwt.shared.CmsListInfoBean; 035import org.opencms.gwt.shared.property.CmsClientProperty; 036import org.opencms.gwt.shared.property.CmsClientTemplateBean; 037import org.opencms.gwt.shared.property.CmsPropertiesBean; 038import org.opencms.gwt.shared.property.CmsPropertyChangeSet; 039import org.opencms.gwt.shared.property.CmsPropertyModification; 040import org.opencms.util.CmsStringUtil; 041import org.opencms.util.CmsUUID; 042 043import java.util.Collections; 044import java.util.List; 045import java.util.Map; 046 047import com.google.gwt.user.client.rpc.AsyncCallback; 048 049/** 050 * A simpler implementation of the property editor handler interface which only provides 051 * the data to edit a single file's properties (i.e. does not support combined folder/default file 052 * property editing.<p> 053 * 054 * @since 8.0.0 055 */ 056public class CmsSimplePropertyEditorHandler implements I_CmsPropertyEditorHandler { 057 058 /** The data necessary for editing the properties. */ 059 protected CmsPropertiesBean m_propertiesBean; 060 061 /** The context menu handler. */ 062 private I_CmsContextMenuHandler m_handler; 063 064 /** Flag controlling whether the file name is editable. */ 065 private boolean m_hasEditableName; 066 067 /** Object used to save the properties, i.e. send the changed properties to the server. */ 068 private I_CmsPropertySaver m_propertySaver; 069 070 /** 071 * Creates a new instance.<p> 072 * 073 * @param handler the context menu handler 074 */ 075 public CmsSimplePropertyEditorHandler(I_CmsContextMenuHandler handler) { 076 077 m_handler = handler; 078 } 079 080 /** 081 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getAllPropertyNames() 082 */ 083 public List<String> getAllPropertyNames() { 084 085 return m_propertiesBean.getAllProperties(); 086 } 087 088 /** 089 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getDefaultFileId() 090 */ 091 public CmsUUID getDefaultFileId() { 092 093 return null; 094 } 095 096 /** 097 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getDefaultFileProperties() 098 */ 099 public Map<String, CmsClientProperty> getDefaultFileProperties() { 100 101 return null; 102 } 103 104 /** 105 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getDialogTitle() 106 */ 107 public String getDialogTitle() { 108 109 // remove this method, it isn't needed anymore 110 return "This is thedialog title."; 111 } 112 113 /** 114 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getForbiddenUrlNames() 115 */ 116 public List<String> getForbiddenUrlNames() { 117 118 return Collections.emptyList(); 119 } 120 121 /** 122 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getId() 123 */ 124 public CmsUUID getId() { 125 126 return m_propertiesBean.getStructureId(); 127 } 128 129 /** 130 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getInheritedProperty(java.lang.String) 131 */ 132 public CmsClientProperty getInheritedProperty(String name) { 133 134 return m_propertiesBean.getInheritedProperties().get(name); 135 } 136 137 /** 138 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getModeClass() 139 */ 140 public String getModeClass() { 141 142 return null; 143 } 144 145 /** 146 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getName() 147 */ 148 public String getName() { 149 150 String result = CmsResource.getName(m_propertiesBean.getSitePath()); 151 if (result.endsWith("/") && (result.length() > 0)) { 152 result = result.substring(0, result.length() - 1); 153 } 154 return result; 155 } 156 157 /** 158 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getOwnProperties() 159 */ 160 public Map<String, CmsClientProperty> getOwnProperties() { 161 162 return m_propertiesBean.getOwnProperties(); 163 164 } 165 166 /** 167 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getPageInfo() 168 */ 169 public CmsListInfoBean getPageInfo() { 170 171 return m_propertiesBean.getPageInfo(); 172 } 173 174 /** 175 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getPath() 176 */ 177 public String getPath() { 178 179 return m_propertiesBean.getSitePath(); 180 } 181 182 /** 183 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getPossibleTemplates() 184 */ 185 public Map<String, CmsClientTemplateBean> getPossibleTemplates() { 186 187 return m_propertiesBean.getTemplates(); 188 } 189 190 /** 191 * @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) 192 */ 193 public void handleSubmit( 194 final String newUrlName, 195 String vfsPath, 196 final List<CmsPropertyModification> propertyChanges, 197 final boolean editedName, 198 CmsReloadMode reloadMode) { 199 200 // ignore reloadMode; it's only relevant for the sitemap editor 201 202 CmsRpcAction<Void> saveAction = new CmsRpcAction<Void>() { 203 204 @Override 205 public void execute() { 206 207 start(300, false); 208 209 if (!CmsStringUtil.isEmptyOrWhitespaceOnly(newUrlName) && editedName) { 210 propertyChanges.add( 211 new CmsPropertyModification( 212 null, 213 CmsPropertyModification.FILE_NAME_PROPERTY, 214 newUrlName, 215 true)); 216 } 217 CmsPropertyChangeSet changeBean = new CmsPropertyChangeSet( 218 m_propertiesBean.getStructureId(), 219 propertyChanges); 220 saveProperties(changeBean, this); 221 } 222 223 @Override 224 protected void onResponse(Void result) { 225 226 stop(false); 227 onSubmitSuccess(); 228 } 229 230 }; 231 saveAction.execute(); 232 233 } 234 235 /** 236 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#hasEditableName() 237 */ 238 public boolean hasEditableName() { 239 240 return m_hasEditableName; 241 } 242 243 /** 244 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#isFolder() 245 */ 246 public boolean isFolder() { 247 248 return (m_propertiesBean != null) && m_propertiesBean.isFolder(); 249 } 250 251 /** 252 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#isHiddenProperty(java.lang.String) 253 */ 254 public boolean isHiddenProperty(String key) { 255 256 return false; 257 } 258 259 /** 260 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#isSimpleMode() 261 */ 262 public boolean isSimpleMode() { 263 264 return false; 265 } 266 267 /** 268 * Enables / disables editable file name.<p> 269 * 270 * @param editable true if the file name should be editable 271 */ 272 public void setEditableName(boolean editable) { 273 274 m_hasEditableName = editable; 275 } 276 277 /** 278 * Sets the data necessary to edit the properties.<p> 279 * 280 * @param propertiesBean the data which is used to edit the properties 281 */ 282 public void setPropertiesBean(CmsPropertiesBean propertiesBean) { 283 284 m_propertiesBean = propertiesBean; 285 } 286 287 /** 288 * Sets the property saver.<p> 289 * 290 * @param saver the property saver 291 */ 292 public void setPropertySaver(I_CmsPropertySaver saver) { 293 294 m_propertySaver = saver; 295 } 296 297 /** 298 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#useAdeTemplates() 299 */ 300 public boolean useAdeTemplates() { 301 302 return (m_propertiesBean != null) && (m_propertiesBean.isContainerPage() || m_propertiesBean.isFolder()); 303 } 304 305 /** 306 * Returns the context menu handler.<p> 307 * 308 * @return the context menu handler 309 */ 310 protected I_CmsContextMenuHandler getContextMenuHandler() { 311 312 return m_handler; 313 } 314 315 /** 316 * Called when the form is submitted successfully.<p> 317 */ 318 protected void onSubmitSuccess() { 319 320 if (getContextMenuHandler() != null) { 321 getContextMenuHandler().refreshResource(m_propertiesBean.getStructureId()); 322 } 323 } 324 325 /** 326 * Save properties.<p> 327 * 328 * @param changes the property changes 329 * @param callback the result callback 330 */ 331 protected void saveProperties(CmsPropertyChangeSet changes, AsyncCallback<Void> callback) { 332 333 if (m_propertySaver != null) { 334 m_propertySaver.saveProperties(changes, callback); 335 } else { 336 CmsCoreProvider.getVfsService().saveProperties(changes, false, callback); 337 } 338 } 339 340}