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.acacia.client.widgets; 029 030import org.opencms.acacia.client.css.I_CmsLayoutBundle; 031import org.opencms.ade.galleries.client.CmsGalleryConfigurationJSO; 032import org.opencms.ade.galleries.client.ui.CmsImageGalleryField; 033import org.opencms.gwt.client.util.CmsDomUtil; 034 035import com.google.gwt.dom.client.Element; 036import com.google.gwt.event.dom.client.FocusEvent; 037import com.google.gwt.event.dom.client.FocusHandler; 038import com.google.gwt.event.logical.shared.HasResizeHandlers; 039import com.google.gwt.event.logical.shared.ResizeHandler; 040import com.google.gwt.event.logical.shared.ValueChangeEvent; 041import com.google.gwt.event.logical.shared.ValueChangeHandler; 042import com.google.gwt.event.shared.HandlerRegistration; 043import com.google.gwt.user.client.ui.Composite; 044 045/** 046 * The VFS image gallery widget.<p> 047 **/ 048public class CmsImageGalleryWidget extends Composite implements I_CmsEditWidget, HasResizeHandlers { 049 050 /** Value of the activation. */ 051 private boolean m_active = true; 052 053 /** The link selector. */ 054 private CmsImageGalleryField m_linkSelect; 055 056 /** 057 * Constructs an CmsComboWidget with the in XSD schema declared configuration.<p> 058 * 059 * @param openerTitle the gallery opener title 060 * @param config the widget configuration string 061 */ 062 public CmsImageGalleryWidget(String openerTitle, String config) { 063 064 m_linkSelect = new CmsImageGalleryField(CmsGalleryConfigurationJSO.parseConfiguration(config), true); 065 m_linkSelect.setGalleryOpenerTitle(openerTitle); 066 m_linkSelect.addValueChangeHandler(new ValueChangeHandler<String>() { 067 068 public void onValueChange(ValueChangeEvent<String> event) { 069 070 fireChangeEvent(); 071 072 } 073 }); 074 // All composites must call initWidget() in their constructors. 075 initWidget(m_linkSelect); 076 m_linkSelect.addFocusHandler(new FocusHandler() { 077 078 public void onFocus(FocusEvent event) { 079 080 CmsDomUtil.fireFocusEvent(CmsImageGalleryWidget.this); 081 } 082 }); 083 } 084 085 /** 086 * @see com.google.gwt.event.dom.client.HasFocusHandlers#addFocusHandler(com.google.gwt.event.dom.client.FocusHandler) 087 */ 088 public HandlerRegistration addFocusHandler(FocusHandler handler) { 089 090 return addDomHandler(handler, FocusEvent.getType()); 091 } 092 093 /** 094 * @see com.google.gwt.event.logical.shared.HasResizeHandlers#addResizeHandler(com.google.gwt.event.logical.shared.ResizeHandler) 095 */ 096 public HandlerRegistration addResizeHandler(ResizeHandler handler) { 097 098 return m_linkSelect.addResizeHandler(handler); 099 } 100 101 /** 102 * @see com.google.gwt.event.logical.shared.HasValueChangeHandlers#addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) 103 */ 104 public HandlerRegistration addValueChangeHandler(ValueChangeHandler<String> handler) { 105 106 return addHandler(handler, ValueChangeEvent.getType()); 107 } 108 109 /** 110 * Represents a value change event.<p> 111 * 112 */ 113 public void fireChangeEvent() { 114 115 ValueChangeEvent.fire(this, m_linkSelect.getFormValueAsString()); 116 } 117 118 /** 119 * @see com.google.gwt.user.client.ui.HasValue#getValue() 120 */ 121 public String getValue() { 122 123 return m_linkSelect.getFormValueAsString(); 124 } 125 126 /** 127 * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#isActive() 128 */ 129 public boolean isActive() { 130 131 return m_active; 132 } 133 134 /** 135 * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#onAttachWidget() 136 */ 137 public void onAttachWidget() { 138 139 onAttach(); 140 } 141 142 /** 143 * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#owns(com.google.gwt.dom.client.Element) 144 */ 145 public boolean owns(Element element) { 146 147 return getElement().isOrHasChild(element); 148 } 149 150 /** 151 * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#setActive(boolean) 152 */ 153 public void setActive(boolean active) { 154 155 if (m_active == active) { 156 return; 157 } 158 m_active = active; 159 if (active) { 160 fireChangeEvent(); 161 } 162 163 } 164 165 /** 166 * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#setName(java.lang.String) 167 */ 168 public void setName(String name) { 169 170 m_linkSelect.setName(name); 171 172 } 173 174 /** 175 * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object) 176 */ 177 public void setValue(String value) { 178 179 setValue(value, false); 180 181 } 182 183 /** 184 * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object, boolean) 185 */ 186 public void setValue(String value, boolean fireEvents) { 187 188 m_linkSelect.setFormValueAsString(value); 189 if (fireEvents) { 190 fireChangeEvent(); 191 } 192 193 } 194 195 /** 196 * @see com.google.gwt.user.client.ui.Composite#onAttach() 197 */ 198 @Override 199 protected void onAttach() { 200 201 super.onAttach(); 202 // use the parent element with CSS class .widgetHolder as the upload drop zone to allow proper highlighting 203 Element dropZone = CmsDomUtil.getAncestor(getElement(), I_CmsLayoutBundle.INSTANCE.form().widgetHolder()); 204 if (dropZone != null) { 205 m_linkSelect.setDropZoneElement(dropZone); 206 } 207 } 208 209}