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.galleries.client.ui; 029 030import org.opencms.ade.galleries.client.Messages; 031import org.opencms.ade.galleries.client.ui.CmsResultItemWidget.ImageTile; 032import org.opencms.ade.galleries.client.ui.css.I_CmsLayoutBundle; 033import org.opencms.ade.galleries.shared.CmsResultItemBean; 034import org.opencms.gwt.client.dnd.CmsDNDHandler; 035import org.opencms.gwt.client.ui.CmsListItem; 036import org.opencms.gwt.client.ui.CmsPushButton; 037import org.opencms.gwt.client.ui.I_CmsButton; 038import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle; 039 040import com.google.gwt.event.dom.client.ClickHandler; 041import com.google.gwt.event.dom.client.DoubleClickEvent; 042import com.google.gwt.event.dom.client.DoubleClickHandler; 043import com.google.gwt.event.shared.HandlerRegistration; 044 045/** 046 * Provides the specific list item for the results list.<p> 047 * 048 * @since 8.0. 049 */ 050public class CmsResultListItem extends CmsListItem { 051 052 /** The name. */ 053 private String m_name; 054 055 /** The preview button. */ 056 private CmsPushButton m_previewButton; 057 058 /** The resource type name of the resource. */ 059 private String m_resourceType; 060 061 /** The search result bean. */ 062 private CmsResultItemBean m_result; 063 064 /** The select button. */ 065 private CmsPushButton m_selectButton; 066 067 /** 068 * Creates a new result list item with a main widget.<p> 069 * 070 * @param resultItem the result item 071 * @param hasPreview if the item has a preview option 072 * @param showPath <code>true</code> to show the resource path in sub title 073 * @param dndHandler the drag and drop handler 074 */ 075 public CmsResultListItem( 076 CmsResultItemBean resultItem, 077 boolean hasPreview, 078 boolean showPath, 079 CmsDNDHandler dndHandler) { 080 081 m_result = resultItem; 082 resultItem.addAdditionalInfo(Messages.get().key(Messages.GUI_PREVIEW_LABEL_PATH_0), resultItem.getPath()); 083 CmsResultItemWidget resultItemWidget = new CmsResultItemWidget(resultItem, showPath); 084 ImageTile imageTile = resultItemWidget.getImageTile(); 085 resultItemWidget.setUnselectable(); 086 initContent(resultItemWidget); 087 if (dndHandler != null) { 088 if (imageTile != null) { 089 imageTile.setDraggable(this); 090 imageTile.addMouseDownHandler(dndHandler); 091 } 092 setId(resultItem.getClientId()); 093 if (resultItem.getTitle() != null) { 094 setName(resultItem.getTitle().toLowerCase().replace("/", "-").replace(" ", "_")); 095 } else { 096 setName(resultItem.getClientId()); 097 } 098 if (!resultItem.isDeactivated()) { 099 initMoveHandle(dndHandler); 100 } 101 } 102 if (resultItemWidget.hasTileView()) { 103 addStyleName(I_CmsLayoutBundle.INSTANCE.galleryResultItemCss().tilingItem()); 104 } 105 106 // add preview button 107 if (hasPreview) { 108 m_previewButton = createButton( 109 I_CmsButton.PREVIEW_SMALL, 110 Messages.get().key(Messages.GUI_PREVIEW_BUTTON_SHOW_0)); 111 resultItemWidget.addButton(m_previewButton); 112 } 113 m_selectButton = createButton( 114 I_CmsButton.CHECK_SMALL, 115 Messages.get().key(Messages.GUI_PREVIEW_BUTTON_SELECT_0)); 116 m_selectButton.setVisible(false); 117 resultItemWidget.addButton(m_selectButton); 118 119 if (!resultItem.isReleasedAndNotExpired() || resultItem.isDeactivated()) { 120 addStyleName(I_CmsLayoutBundle.INSTANCE.galleryResultItemCss().expired()); 121 } 122 } 123 124 /** 125 * Creates the delete button for this item.<p> 126 * 127 * @return the delete button 128 */ 129 public static CmsPushButton createDeleteButton() { 130 131 return createButton(I_CmsButton.TRASH_SMALL, Messages.get().key(Messages.GUI_RESULT_BUTTON_DELETE_0)); 132 } 133 134 /** 135 * Creates a button for the list item.<p> 136 * 137 * @param imageClass the icon image class 138 * @param title the button title 139 * 140 * @return the button 141 */ 142 private static CmsPushButton createButton(String imageClass, String title) { 143 144 CmsPushButton result = new CmsPushButton(); 145 result.setImageClass(imageClass); 146 result.setButtonStyle(ButtonStyle.FONT_ICON, null); 147 result.setTitle(title); 148 return result; 149 } 150 151 /** 152 * Adds a double click event handler.<p> 153 * 154 * @param handler the event handler to add 155 * 156 * @return the handler registration for removing the event handler 157 */ 158 public HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler) { 159 160 return addDomHandler(handler, DoubleClickEvent.getType()); 161 } 162 163 /** 164 * Adds the preview button click handler.<p> 165 * 166 * @param handler the click handler 167 */ 168 public void addPreviewClickHandler(ClickHandler handler) { 169 170 if (m_previewButton != null) { 171 m_previewButton.addClickHandler(handler); 172 } 173 } 174 175 /** 176 * Adds the select button click handler.<p> 177 * 178 * @param handler the click handler 179 */ 180 public void addSelectClickHandler(ClickHandler handler) { 181 182 m_selectButton.setVisible(true); 183 m_selectButton.addClickHandler(handler); 184 } 185 186 /** 187 * Returns the name.<p> 188 * 189 * @return the name 190 */ 191 public String getName() { 192 193 return m_name; 194 } 195 196 /** 197 * Returns the resource type name.<p> 198 * 199 * @return the resource type name 200 */ 201 public String getResourceType() { 202 203 return m_resourceType; 204 } 205 206 /** 207 * Gets the search result bean.<p> 208 * 209 * @return the search result bean 210 */ 211 public CmsResultItemBean getResult() { 212 213 return m_result; 214 } 215 216 /** 217 * Sets the name.<p> 218 * 219 * @param name the name to set 220 */ 221 public void setName(String name) { 222 223 m_name = name; 224 } 225 226 /** 227 * Sets the resource type name.<p> 228 * 229 * @param resourceType the resource type name to set 230 */ 231 public void setResourceType(String resourceType) { 232 233 m_resourceType = resourceType; 234 } 235}