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 * Gets the default file path, if available. 098 * 099 * @return the default file path 100 */ 101 @Override 102 public String getDefaultFilePath() { 103 104 return null; 105 } 106 107 /** 108 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getDefaultFileProperties() 109 */ 110 public Map<String, CmsClientProperty> getDefaultFileProperties() { 111 112 return null; 113 } 114 115 /** 116 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getDialogTitle() 117 */ 118 public String getDialogTitle() { 119 120 // remove this method, it isn't needed anymore 121 return "This is thedialog title."; 122 } 123 124 /** 125 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getForbiddenUrlNames() 126 */ 127 public List<String> getForbiddenUrlNames() { 128 129 return Collections.emptyList(); 130 } 131 132 /** 133 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getId() 134 */ 135 public CmsUUID getId() { 136 137 return m_propertiesBean.getStructureId(); 138 } 139 140 /** 141 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getInheritedProperty(java.lang.String) 142 */ 143 public CmsClientProperty getInheritedProperty(String name) { 144 145 return m_propertiesBean.getInheritedProperties().get(name); 146 } 147 148 /** 149 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getModeClass() 150 */ 151 public String getModeClass() { 152 153 return null; 154 } 155 156 /** 157 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getName() 158 */ 159 public String getName() { 160 161 String result = CmsResource.getName(m_propertiesBean.getSitePath()); 162 if (result.endsWith("/") && (result.length() > 0)) { 163 result = result.substring(0, result.length() - 1); 164 } 165 return result; 166 } 167 168 /** 169 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getOwnProperties() 170 */ 171 public Map<String, CmsClientProperty> getOwnProperties() { 172 173 return m_propertiesBean.getOwnProperties(); 174 175 } 176 177 /** 178 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getPageInfo() 179 */ 180 public CmsListInfoBean getPageInfo() { 181 182 return m_propertiesBean.getPageInfo(); 183 } 184 185 /** 186 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getPath() 187 */ 188 public String getPath() { 189 190 return m_propertiesBean.getSitePath(); 191 } 192 193 /** 194 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getPossibleTemplates() 195 */ 196 public Map<String, CmsClientTemplateBean> getPossibleTemplates() { 197 198 return m_propertiesBean.getTemplates(); 199 } 200 201 /** 202 * @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) 203 */ 204 public void handleSubmit( 205 final String newUrlName, 206 String vfsPath, 207 final List<CmsPropertyModification> propertyChanges, 208 final boolean editedName, 209 CmsReloadMode reloadMode) { 210 211 // ignore reloadMode; it's only relevant for the sitemap editor 212 213 CmsRpcAction<Void> saveAction = new CmsRpcAction<Void>() { 214 215 @Override 216 public void execute() { 217 218 start(300, false); 219 220 if (!CmsStringUtil.isEmptyOrWhitespaceOnly(newUrlName) && editedName) { 221 propertyChanges.add( 222 new CmsPropertyModification( 223 null, 224 CmsPropertyModification.FILE_NAME_PROPERTY, 225 newUrlName, 226 true)); 227 } 228 CmsPropertyChangeSet changeBean = new CmsPropertyChangeSet( 229 m_propertiesBean.getStructureId(), 230 propertyChanges); 231 saveProperties(changeBean, this); 232 } 233 234 @Override 235 protected void onResponse(Void result) { 236 237 stop(false); 238 onSubmitSuccess(); 239 } 240 241 }; 242 saveAction.execute(); 243 244 } 245 246 /** 247 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#hasEditableName() 248 */ 249 public boolean hasEditableName() { 250 251 return m_hasEditableName; 252 } 253 254 /** 255 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#isFolder() 256 */ 257 public boolean isFolder() { 258 259 return (m_propertiesBean != null) && m_propertiesBean.isFolder(); 260 } 261 262 /** 263 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#isHiddenProperty(java.lang.String) 264 */ 265 public boolean isHiddenProperty(String key) { 266 267 return false; 268 } 269 270 /** 271 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#isSimpleMode() 272 */ 273 public boolean isSimpleMode() { 274 275 return false; 276 } 277 278 /** 279 * Enables / disables editable file name.<p> 280 * 281 * @param editable true if the file name should be editable 282 */ 283 public void setEditableName(boolean editable) { 284 285 m_hasEditableName = editable; 286 } 287 288 /** 289 * Sets the data necessary to edit the properties.<p> 290 * 291 * @param propertiesBean the data which is used to edit the properties 292 */ 293 public void setPropertiesBean(CmsPropertiesBean propertiesBean) { 294 295 m_propertiesBean = propertiesBean; 296 } 297 298 /** 299 * Sets the property saver.<p> 300 * 301 * @param saver the property saver 302 */ 303 public void setPropertySaver(I_CmsPropertySaver saver) { 304 305 m_propertySaver = saver; 306 } 307 308 /** 309 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#useAdeTemplates() 310 */ 311 public boolean useAdeTemplates() { 312 313 return (m_propertiesBean != null) && (m_propertiesBean.isContainerPage() || m_propertiesBean.isFolder()); 314 } 315 316 /** 317 * Returns the context menu handler.<p> 318 * 319 * @return the context menu handler 320 */ 321 protected I_CmsContextMenuHandler getContextMenuHandler() { 322 323 return m_handler; 324 } 325 326 /** 327 * Called when the form is submitted successfully.<p> 328 */ 329 protected void onSubmitSuccess() { 330 331 if (getContextMenuHandler() != null) { 332 getContextMenuHandler().refreshResource(m_propertiesBean.getStructureId()); 333 } 334 } 335 336 /** 337 * Save properties.<p> 338 * 339 * @param changes the property changes 340 * @param callback the result callback 341 */ 342 protected void saveProperties(CmsPropertyChangeSet changes, AsyncCallback<Void> callback) { 343 344 if (m_propertySaver != null) { 345 m_propertySaver.saveProperties(changes, callback); 346 } else { 347 CmsCoreProvider.getVfsService().saveProperties(changes, false, callback); 348 } 349 } 350 351}