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; 029 030import org.opencms.ade.sitemap.client.control.CmsSitemapController; 031import org.opencms.ade.sitemap.client.hoverbar.CmsEditModelPageMenuEntry; 032import org.opencms.ade.sitemap.client.ui.css.I_CmsSitemapLayoutBundle; 033import org.opencms.ade.sitemap.shared.CmsClientSitemapEntry; 034import org.opencms.ade.sitemap.shared.CmsModelPageEntry; 035import org.opencms.gwt.CmsIconUtil; 036import org.opencms.gwt.client.property.CmsReloadMode; 037import org.opencms.gwt.client.ui.CmsAlertDialog; 038import org.opencms.gwt.client.ui.CmsListItemWidget; 039import org.opencms.gwt.client.ui.css.I_CmsInputLayoutBundle; 040import org.opencms.gwt.client.ui.tree.CmsTreeItem; 041import org.opencms.gwt.shared.CmsListInfoBean; 042import org.opencms.gwt.shared.property.CmsClientProperty; 043import org.opencms.gwt.shared.property.CmsPropertyModification; 044import org.opencms.util.CmsStringUtil; 045import org.opencms.util.CmsUUID; 046 047import java.util.ArrayList; 048import java.util.List; 049 050import com.google.gwt.event.dom.client.ClickEvent; 051import com.google.gwt.event.dom.client.ClickHandler; 052import com.google.gwt.user.client.ui.Widget; 053 054/** 055 * Tree item for the model page editor mode.<p> 056 */ 057public class CmsModelPageTreeItem extends CmsTreeItem { 058 059 /** 060 * List item widget that displays additional infos dynamically.<p> 061 */ 062 protected class CmsModelPageListItemWidget extends CmsListItemWidget { 063 064 /** 065 * Constructor.<p> 066 * 067 * @param infoBean the data to display 068 */ 069 public CmsModelPageListItemWidget(CmsListInfoBean infoBean) { 070 071 super(infoBean); 072 ensureOpenCloseAdditionalInfo(); 073 } 074 075 } 076 077 /** The disabled flag. */ 078 private boolean m_disabled; 079 080 /** The folder entry id. */ 081 private CmsUUID m_entryId; 082 083 /** The model group flag. */ 084 private boolean m_isModelGroup; 085 086 /** The parent model flag. */ 087 private boolean m_isParentModel; 088 089 /** 090 * Creates the fake model page tree item used as a root for the tree view.<p> 091 * 092 * @param isModelGroup in case of a model group page 093 * @param title the title 094 * @param subTitle the sub title 095 */ 096 public CmsModelPageTreeItem(boolean isModelGroup, String title, String subTitle) { 097 098 super(true); 099 m_isModelGroup = isModelGroup; 100 CmsListInfoBean infoBean = new CmsListInfoBean(title, subTitle, null); 101 CmsListItemWidget content = new CmsListItemWidget(infoBean); 102 content.setIcon(isModelGroup ? CmsIconUtil.ICON_MODEL_GROUP_COPY_BIG : CmsIconUtil.ICON_MODEL_GROUP_BIG); 103 initContent(content); 104 } 105 106 /** 107 * Constructor.<p> 108 * 109 * @param modelpage the model page 110 * @param isModelGroup in case of a model group page 111 * @param isParentModel the parent model flag 112 */ 113 public CmsModelPageTreeItem(CmsModelPageEntry modelpage, boolean isModelGroup, boolean isParentModel) { 114 115 super(true); 116 m_isModelGroup = isModelGroup; 117 initContent(createListWidget(modelpage)); 118 m_entryId = modelpage.getStructureId(); 119 m_isParentModel = isParentModel; 120 setDisabled(modelpage.isDisabled()); 121 } 122 123 /** 124 * Creates the fake model page tree item used as a root for the tree view.<p> 125 * 126 * @param isModelGroup in case of a model group page 127 * @param title the title 128 * @param subTitle the sub title 129 * 130 * @return the root tree item 131 */ 132 public static CmsModelPageTreeItem createRootItem(boolean isModelGroup, String title, String subTitle) { 133 134 return new CmsModelPageTreeItem(isModelGroup, title, subTitle); 135 } 136 137 /** 138 * Returns the folder entry id.<p> 139 * 140 * @return the folder entry id 141 */ 142 public CmsUUID getEntryId() { 143 144 return m_entryId; 145 } 146 147 /** 148 * Returns the site path.<p> 149 * 150 * @return the site path 151 */ 152 public String getSitePath() { 153 154 // the site path is displayed as the sub title 155 return getListItemWidget().getSubtitleLabel(); 156 } 157 158 /** 159 * Returns if the model page entry is disabled.<p> 160 * 161 * @return <code>true</code> if the model page entry is disabled 162 */ 163 public boolean isDisabled() { 164 165 return m_disabled; 166 } 167 168 /** 169 * Returns whether the entry represents a model group page.<p> 170 * 171 * @return <code>true</code> if the entry represents a model group page 172 */ 173 public boolean isModelGroup() { 174 175 return m_isModelGroup; 176 } 177 178 /** 179 * Returns if this model page entry is inherited from the parent configuration.<p> 180 * 181 * @return <code>true</code> if this model page entry is inherited from the parent configuration 182 */ 183 public boolean isParentModel() { 184 185 return m_isParentModel; 186 } 187 188 /** 189 * Sets the model page entry disabled.<p> 190 * 191 * @param disabled <code>true</Code> to disable 192 */ 193 public void setDisabled(boolean disabled) { 194 195 m_disabled = disabled; 196 if (m_disabled) { 197 getListItemWidget().addStyleName(I_CmsSitemapLayoutBundle.INSTANCE.sitemapItemCss().hiddenNavEntry()); 198 } else { 199 getListItemWidget().removeStyleName(I_CmsSitemapLayoutBundle.INSTANCE.sitemapItemCss().hiddenNavEntry()); 200 } 201 } 202 203 /** 204 * Updates the site path info.<p> 205 * 206 * @param sitePath the new site path 207 */ 208 public void updateSitePath(String sitePath) { 209 210 getListItemWidget().setSubtitleLabel(sitePath); 211 } 212 213 /** 214 * Handles direct editing of the gallery title.<p> 215 * 216 * @param editEntry the edit entry 217 * @param newTitle the new title 218 */ 219 void handleEdit(CmsClientSitemapEntry editEntry, final String newTitle) { 220 221 if (CmsStringUtil.isEmpty(newTitle)) { 222 String dialogTitle = Messages.get().key(Messages.GUI_EDIT_TITLE_ERROR_DIALOG_TITLE_0); 223 String dialogText = Messages.get().key(Messages.GUI_TITLE_CANT_BE_EMPTY_0); 224 CmsAlertDialog alert = new CmsAlertDialog(dialogTitle, dialogText); 225 alert.center(); 226 return; 227 } 228 String oldTitle = editEntry.getPropertyValue(CmsClientProperty.PROPERTY_TITLE); 229 if (!oldTitle.equals(newTitle)) { 230 CmsPropertyModification propMod = new CmsPropertyModification( 231 getEntryId(), 232 CmsClientProperty.PROPERTY_TITLE, 233 newTitle, 234 true); 235 final List<CmsPropertyModification> propChanges = new ArrayList<CmsPropertyModification>(); 236 propChanges.add(propMod); 237 CmsSitemapController controller = CmsSitemapView.getInstance().getController(); 238 controller.edit(editEntry, propChanges, CmsReloadMode.reloadEntry); 239 } 240 } 241 242 /** 243 * Creates the list item widget for the given folder.<p> 244 * 245 * @param modelPage the model page bean 246 * 247 * @return the list item widget 248 */ 249 private CmsListItemWidget createListWidget(final CmsModelPageEntry modelPage) { 250 251 CmsListItemWidget result = new CmsModelPageListItemWidget(modelPage.getListInfoBean()); 252 if (modelPage.isDefault()) { 253 Widget label = result.getShortExtraInfoLabel(); 254 label.addStyleName(I_CmsInputLayoutBundle.INSTANCE.inputCss().subtitleSuffix()); 255 result.setExtraInfo("(*)"); 256 } 257 if (m_isModelGroup || CmsEditModelPageMenuEntry.checkVisible(modelPage.getStructureId())) { 258 result.addIconClickHandler(new ClickHandler() { 259 260 public void onClick(ClickEvent event) { 261 262 CmsEditModelPageMenuEntry.editModelPage(modelPage.getSitePath(), isModelGroup()); 263 } 264 }); 265 } 266 return result; 267 } 268}