001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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.containerpage.client.ui; 029 030import org.opencms.ade.containerpage.client.Messages; 031import org.opencms.ade.containerpage.shared.CmsContainerElementData; 032import org.opencms.gwt.client.dnd.I_CmsDropTarget; 033import org.opencms.gwt.client.ui.CmsListItem; 034import org.opencms.gwt.client.ui.CmsListItemWidget; 035import org.opencms.gwt.client.ui.CmsPushButton; 036import org.opencms.gwt.client.ui.I_CmsButton; 037import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle; 038import org.opencms.gwt.client.util.CmsDomUtil; 039import org.opencms.gwt.shared.CmsAdditionalInfoBean; 040import org.opencms.gwt.shared.CmsListInfoBean; 041 042import com.google.gwt.event.dom.client.ClickEvent; 043import com.google.gwt.event.dom.client.ClickHandler; 044import com.google.gwt.event.shared.HandlerRegistration; 045 046/** 047 * Draggable menu element. Needed for favorite list.<p> 048 * 049 * @since 8.0.0 050 */ 051public class CmsMenuListItem extends CmsListItem { 052 053 /** The element edit button. */ 054 protected CmsPushButton m_editButton; 055 056 /** The edit click handler registration. */ 057 private HandlerRegistration m_editHandlerRegistration; 058 059 /** The element delete button. */ 060 private CmsPushButton m_removeButton; 061 062 /** 063 * Constructor.<p> 064 * 065 * @param element the element data 066 */ 067 public CmsMenuListItem(CmsContainerElementData element) { 068 069 super( 070 new CmsListItemWidget( 071 new CmsListInfoBean(element.getTitle(), element.getSitePath(), null).setBigIconClasses( 072 element.getBigIconClasses()))); 073 if (!m_listItemWidget.hasAdditionalInfo()) { 074 m_listItemWidget.addAdditionalInfo( 075 new CmsAdditionalInfoBean("", Messages.get().key(Messages.GUI_NO_SETTINGS_TITLE_0), null)); 076 } 077 setId(element.getClientId()); 078 getListItemWidget().setIcon(element.getBigIconClasses()); 079 080 m_removeButton = new CmsPushButton(); 081 m_removeButton.setImageClass(I_CmsButton.CUT_SMALL); 082 m_removeButton.setButtonStyle(ButtonStyle.FONT_ICON, null); 083 m_removeButton.setTitle(Messages.get().key(Messages.GUI_BUTTON_REMOVE_TEXT_0)); 084 m_removeButton.addClickHandler(new ClickHandler() { 085 086 /** 087 * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent) 088 */ 089 public void onClick(ClickEvent event) { 090 091 deleteElement(); 092 093 } 094 }); 095 m_editButton = new CmsPushButton(); 096 m_editButton.setImageClass(I_CmsButton.ButtonData.EDIT.getSmallIconClass()); 097 m_editButton.setButtonStyle(ButtonStyle.FONT_ICON, null); 098 m_editButton.setTitle( 099 org.opencms.gwt.client.Messages.get().key(org.opencms.gwt.client.Messages.GUI_BUTTON_ELEMENT_EDIT_0)); 100 m_editButton.setEnabled(false); 101 getListItemWidget().addButton(m_editButton); 102 } 103 104 /** 105 * Removes the element from it's parent widget.<p> 106 */ 107 public void deleteElement() { 108 109 removeFromParent(); 110 } 111 112 /** 113 * Disables the edit button with the given reason.<p> 114 * 115 * @param reason the disable reason 116 * @param locked <code>true</code> if the resource is locked 117 */ 118 public void disableEdit(String reason, boolean locked) { 119 120 m_editButton.disable(reason); 121 if (locked) { 122 m_editButton.setImageClass("opencms-icon-lock-20"); 123 } 124 } 125 126 /** 127 * Enables the edit button with the given click handler.<p> 128 * 129 * @param editClickHandler the edit click handler 130 */ 131 public void enableEdit(ClickHandler editClickHandler) { 132 133 if (m_editHandlerRegistration != null) { 134 m_editHandlerRegistration.removeHandler(); 135 } 136 m_editHandlerRegistration = m_editButton.addClickHandler(editClickHandler); 137 m_editButton.enable(); 138 } 139 140 /** 141 * Hides the edit button.<p> 142 */ 143 public void hideEditButton() { 144 145 if (m_editButton != null) { 146 getListItemWidget().removeButton(m_editButton); 147 } 148 } 149 150 /** 151 * Hides the element delete button.<p> 152 */ 153 public void hideRemoveButton() { 154 155 getListItemWidget().removeButton(m_removeButton); 156 } 157 158 /** 159 * @see org.opencms.gwt.client.dnd.I_CmsDraggable#onDragCancel() 160 */ 161 @Override 162 public void onDragCancel() { 163 164 super.onDragCancel(); 165 clearDrag(); 166 } 167 168 /** 169 * @see org.opencms.gwt.client.dnd.I_CmsDraggable#onDrop(org.opencms.gwt.client.dnd.I_CmsDropTarget) 170 */ 171 @Override 172 public void onDrop(I_CmsDropTarget target) { 173 174 super.onDrop(target); 175 clearDrag(); 176 } 177 178 /** 179 * @see org.opencms.gwt.client.dnd.I_CmsDraggable#onStartDrag(org.opencms.gwt.client.dnd.I_CmsDropTarget) 180 */ 181 @Override 182 public void onStartDrag(I_CmsDropTarget target) { 183 184 super.onStartDrag(target); 185 getElement().getStyle().setOpacity(0.7); 186 } 187 188 /** 189 * Shows the element edit button.<p> 190 */ 191 public void showEditButton() { 192 193 if (m_editButton != null) { 194 getListItemWidget().addButton(m_editButton); 195 } 196 } 197 198 /** 199 * Shows the element delete button.<p> 200 */ 201 public void showRemoveButton() { 202 203 getListItemWidget().addButton(m_removeButton); 204 } 205 206 /** 207 * Removes all styling done during drag and drop.<p> 208 */ 209 private void clearDrag() { 210 211 // using own implementation as GWT won't do it properly on IE7-8 212 CmsDomUtil.clearOpacity(getElement()); 213 214 getElement().getStyle().clearDisplay(); 215 } 216}