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.toolbar; 029 030import org.opencms.ade.sitemap.client.CmsSitemapView; 031import org.opencms.ade.sitemap.client.Messages; 032import org.opencms.ade.sitemap.client.control.CmsSitemapChangeEvent; 033import org.opencms.ade.sitemap.client.control.CmsSitemapController; 034import org.opencms.ade.sitemap.client.control.I_CmsSitemapChangeHandler; 035import org.opencms.ade.sitemap.shared.CmsClientSitemapEntry; 036import org.opencms.ade.sitemap.shared.CmsSitemapClipboardData; 037import org.opencms.gwt.client.ui.CmsList; 038import org.opencms.gwt.client.ui.CmsListItem; 039import org.opencms.gwt.client.ui.CmsListItemWidget; 040import org.opencms.gwt.client.ui.CmsPushButton; 041import org.opencms.gwt.client.ui.I_CmsButton; 042import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle; 043import org.opencms.gwt.client.util.CmsDomUtil; 044import org.opencms.gwt.shared.CmsListInfoBean; 045import org.opencms.gwt.shared.CmsListInfoBean.StateIcon; 046import org.opencms.util.CmsStringUtil; 047 048import com.google.gwt.event.dom.client.ClickEvent; 049import com.google.gwt.event.dom.client.ClickHandler; 050 051/** 052 * Sitemap toolbar clipboard view.<p> 053 * 054 * @since 8.0.0 055 */ 056public class CmsToolbarClipboardView { 057 058 /** 059 * The deleted item widget.<p> 060 */ 061 public final class CmsClipboardDeletedItem extends CmsListItem { 062 063 /** The sitemap entry. */ 064 private final CmsClientSitemapEntry m_entry; 065 066 /** 067 * Constructor.<p> 068 * 069 * @param widget the widget 070 * @param entry the entry 071 */ 072 public CmsClipboardDeletedItem(CmsListItemWidget widget, CmsClientSitemapEntry entry) { 073 074 super(widget); 075 m_entry = entry; 076 setId(m_entry.getName()); 077 } 078 079 /** 080 * Returns the underlying sitemap entry.<p> 081 * 082 * @return the sitemap entry 083 */ 084 public CmsClientSitemapEntry getEntry() { 085 086 return m_entry; 087 } 088 } 089 090 /** The clipboard toolbar button. */ 091 protected CmsToolbarClipboardButton m_clipboardButton; 092 093 /** The deleted list. */ 094 private CmsList<CmsListItem> m_deleted; 095 096 /** The modified list. */ 097 private CmsList<CmsListItem> m_modified; 098 099 /** 100 * Constructor.<p> 101 * 102 * @param clipboardButton the clipboard button 103 * @param controller the sitemap controller 104 */ 105 public CmsToolbarClipboardView(CmsToolbarClipboardButton clipboardButton, final CmsSitemapController controller) { 106 107 m_clipboardButton = clipboardButton; 108 m_modified = new CmsList<CmsListItem>(); 109 m_deleted = new CmsList<CmsListItem>(); 110 updateContent(controller.getData().getClipboardData()); 111 controller.addChangeHandler(new I_CmsSitemapChangeHandler() { 112 113 /** 114 * @see org.opencms.ade.sitemap.client.control.I_CmsSitemapChangeHandler#onChange(org.opencms.ade.sitemap.client.control.CmsSitemapChangeEvent) 115 */ 116 public void onChange(CmsSitemapChangeEvent changeEvent) { 117 118 updateContent(changeEvent.getChange().getClipBoardData()); 119 } 120 }); 121 } 122 123 /** 124 * Adds an deleted entry.<p> 125 * 126 * @param entry the deleted entry 127 */ 128 public void addDeleted(CmsClientSitemapEntry entry) { 129 130 if (!(entry.isNew() && CmsStringUtil.isEmptyOrWhitespaceOnly(entry.getVfsPath()))) { 131 removeDeleted(entry.getId().toString()); 132 getDeleted().insertItem(createDeletedItem(entry), 0); 133 } 134 removeModified(entry.getId().toString()); 135 m_clipboardButton.enableClearDeleted(true); 136 } 137 138 /** 139 * Adds a modified entry.<p> 140 * 141 * @param entry the entry 142 * @param previousPath the previous path 143 */ 144 public void addModified(CmsClientSitemapEntry entry, String previousPath) { 145 146 removeDeleted(entry.getId().toString()); 147 removeModified(entry.getId().toString()); 148 getModified().insertItem(createModifiedItem(entry), 0); 149 m_clipboardButton.enableClearModified(true); 150 } 151 152 /** 153 * Clears the deleted list.<p> 154 */ 155 public void clearDeleted() { 156 157 m_deleted.clearList(); 158 m_clipboardButton.enableClearDeleted(false); 159 } 160 161 /** 162 * Clears the modified list.<p> 163 */ 164 public void clearModified() { 165 166 m_modified.clearList(); 167 m_clipboardButton.enableClearModified(false); 168 } 169 170 /** 171 * Creates a new deleted list item.<p> 172 * 173 * @param entry the sitemap entry 174 * 175 * @return the new created (still orphan) list item 176 */ 177 public CmsListItem createDeletedItem(final CmsClientSitemapEntry entry) { 178 179 CmsListInfoBean infoBean = new CmsListInfoBean(); 180 infoBean.setTitle(entry.getTitle()); 181 infoBean.setSubTitle(entry.getSitePath()); 182 infoBean.setResourceType( 183 CmsStringUtil.isNotEmptyOrWhitespaceOnly(entry.getDefaultFileType()) 184 ? entry.getDefaultFileType() 185 : entry.getResourceTypeName()); 186 infoBean.addAdditionalInfo(Messages.get().key(Messages.GUI_NAME_0), entry.getName()); 187 infoBean.addAdditionalInfo(Messages.get().key(Messages.GUI_VFS_PATH_0), entry.getVfsPath()); 188 infoBean.setBigIconClasses(entry.getNavModeIcon()); 189 final CmsListItemWidget itemWidget = new CmsListItemWidget(infoBean); 190 CmsListItem listItem = new CmsClipboardDeletedItem(itemWidget, entry); 191 CmsPushButton button = new CmsPushButton(); 192 button.setImageClass(I_CmsButton.RESET); 193 button.setTitle(Messages.get().key(Messages.GUI_HOVERBAR_UNDELETE_0)); 194 button.setButtonStyle(ButtonStyle.FONT_ICON, null); 195 button.addClickHandler(new ClickHandler() { 196 197 public void onClick(ClickEvent event) { 198 199 CmsDomUtil.ensureMouseOut(itemWidget.getElement()); 200 m_clipboardButton.closeMenu(); 201 CmsSitemapView.getInstance().getController().undelete(entry.getId(), entry.getSitePath()); 202 } 203 204 }); 205 itemWidget.addButton(button); 206 itemWidget.setStateIcon(StateIcon.standard); 207 listItem.setId(entry.getId().toString()); 208 return listItem; 209 } 210 211 /** 212 * Creates a new modified list item.<p> 213 * 214 * @param entry the sitemap entry 215 * 216 * @return the new created (still orphan) list item 217 */ 218 public CmsListItem createModifiedItem(final CmsClientSitemapEntry entry) { 219 220 CmsListInfoBean infoBean = new CmsListInfoBean(); 221 infoBean.setTitle(entry.getTitle()); 222 infoBean.setSubTitle(entry.getSitePath()); 223 infoBean.addAdditionalInfo(Messages.get().key(Messages.GUI_NAME_0), entry.getName()); 224 infoBean.addAdditionalInfo(Messages.get().key(Messages.GUI_VFS_PATH_0), entry.getVfsPath()); 225 infoBean.setResourceType( 226 CmsStringUtil.isNotEmptyOrWhitespaceOnly(entry.getDefaultFileType()) 227 ? entry.getDefaultFileType() 228 : entry.getResourceTypeName()); 229 infoBean.setBigIconClasses(entry.getNavModeIcon()); 230 CmsListItemWidget itemWidget = new CmsListItemWidget(infoBean); 231 232 final CmsListItem listItem = new CmsListItem(itemWidget); 233 234 CmsPushButton button = new CmsPushButton(); 235 button.setImageClass(I_CmsButton.PREVIEW_SMALL); 236 button.setTitle(Messages.get().key(Messages.GUI_HOVERBAR_GOTO_0)); 237 button.setButtonStyle(ButtonStyle.FONT_ICON, null); 238 button.addClickHandler(new ClickHandler() { 239 240 /** 241 * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent) 242 */ 243 public void onClick(ClickEvent event) { 244 245 // TODO: check if entry is intern or extern 246 boolean intern = true; 247 if (intern) { 248 CmsDomUtil.ensureMouseOut(listItem.getElement()); 249 m_clipboardButton.closeMenu(); 250 CmsSitemapView.getInstance().highlightPath(entry.getSitePath()); 251 } else { 252 // TODO: get the file to open 253 // TODO: jump to the right file with the right parameter 254 } 255 } 256 }); 257 itemWidget.addButton(button); 258 itemWidget.setStateIcon(StateIcon.standard); 259 listItem.setId(entry.getId().toString()); 260 return listItem; 261 } 262 263 /** 264 * Returns the deleted list.<p> 265 * 266 * @return the deleted list 267 */ 268 public CmsList<CmsListItem> getDeleted() { 269 270 return m_deleted; 271 } 272 273 /** 274 * Returns the modified list.<p> 275 * 276 * @return the modified list 277 */ 278 public CmsList<CmsListItem> getModified() { 279 280 return m_modified; 281 } 282 283 /** 284 * Removes an entry from the deleted list.<p> 285 * 286 * @param entryId the entry id 287 */ 288 public void removeDeleted(String entryId) { 289 290 CmsListItem item = getDeleted().getItem(entryId); 291 if (item != null) { 292 // remove 293 getDeleted().removeItem(item); 294 } 295 if (getDeleted().getWidgetCount() == 0) { 296 m_clipboardButton.enableClearDeleted(false); 297 } 298 } 299 300 /** 301 * Removes an entry from the modified list.<p> 302 * 303 * @param entryId the entry id 304 */ 305 public void removeModified(String entryId) { 306 307 CmsListItem item = getModified().getItem(entryId); 308 if (item != null) { 309 // remove 310 getModified().removeItem(item); 311 } 312 if (getModified().getWidgetCount() == 0) { 313 m_clipboardButton.enableClearModified(false); 314 } 315 } 316 317 /** 318 * Updates the clip board content.<p> 319 * 320 * @param data the clip board data 321 */ 322 protected void updateContent(CmsSitemapClipboardData data) { 323 324 if (data == null) { 325 return; 326 } 327 m_modified.clearList(); 328 boolean hasElements = false; 329 for (CmsClientSitemapEntry entry : data.getModifications().values()) { 330 m_modified.insertItem(createModifiedItem(entry), 0); 331 hasElements = true; 332 } 333 m_clipboardButton.enableClearModified(hasElements); 334 m_deleted.clearList(); 335 hasElements = false; 336 for (CmsClientSitemapEntry entry : data.getDeletions().values()) { 337 m_deleted.insertItem(createDeletedItem(entry), 0); 338 hasElements = true; 339 } 340 m_clipboardButton.enableClearDeleted(hasElements); 341 } 342}