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_CmsWidgetsLayoutBundle; 031import org.opencms.gwt.client.ui.input.CmsColorPicker; 032import org.opencms.gwt.client.util.CmsDomUtil; 033 034import com.google.gwt.dom.client.Element; 035import com.google.gwt.event.dom.client.FocusEvent; 036import com.google.gwt.event.dom.client.FocusHandler; 037import com.google.gwt.event.logical.shared.ValueChangeEvent; 038import com.google.gwt.event.logical.shared.ValueChangeHandler; 039import com.google.gwt.event.shared.HandlerRegistration; 040import com.google.gwt.user.client.ui.Composite; 041import com.google.gwt.user.client.ui.SimplePanel; 042 043/** 044 * Provides a DHTML calendar widget, for use on a widget dialog.<p> 045 * 046 * */ 047public class CmsColorpickerWidget extends Composite implements I_CmsEditWidget { 048 049 /** Value of the activation. */ 050 private boolean m_active = true; 051 052 /** The global select box. */ 053 private CmsColorPicker m_colorPicker = new CmsColorPicker(); 054 055 /**The main panel. */ 056 private SimplePanel m_panel = new SimplePanel(); 057 058 /** 059 * Constructs an CmsComboWidget with the in XSD schema declared configuration.<p> 060 * @param config The configuration string given from OpenCms XSD. 061 */ 062 public CmsColorpickerWidget(String config) { 063 064 // All composites must call initWidget() in their constructors. 065 m_panel.add(m_colorPicker); 066 initWidget(m_panel); 067 m_colorPicker.getColorfield().addStyleName(I_CmsWidgetsLayoutBundle.INSTANCE.widgetCss().colorPicker()); 068 m_colorPicker.getTextboxPanel().addStyleName(I_CmsWidgetsLayoutBundle.INSTANCE.widgetCss().colorPickerValue()); 069 m_colorPicker.addValueChangeHandler(new ValueChangeHandler<String>() { 070 071 public void onValueChange(ValueChangeEvent<String> event) { 072 073 fireChangeEvent(); 074 075 } 076 077 }); 078 m_colorPicker.getColorValueBox().addFocusHandler(new FocusHandler() { 079 080 public void onFocus(FocusEvent event) { 081 082 CmsDomUtil.fireFocusEvent(CmsColorpickerWidget.this); 083 } 084 }); 085 } 086 087 /** 088 * @see com.google.gwt.event.dom.client.HasFocusHandlers#addFocusHandler(com.google.gwt.event.dom.client.FocusHandler) 089 */ 090 public HandlerRegistration addFocusHandler(FocusHandler handler) { 091 092 return addDomHandler(handler, FocusEvent.getType()); 093 } 094 095 /** 096 * @see com.google.gwt.event.logical.shared.HasValueChangeHandlers#addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) 097 */ 098 public HandlerRegistration addValueChangeHandler(ValueChangeHandler<String> handler) { 099 100 return addHandler(handler, ValueChangeEvent.getType()); 101 } 102 103 /** 104 * Represents a value change event.<p> 105 * 106 */ 107 public void fireChangeEvent() { 108 109 if (m_colorPicker.getFormValueAsString() != null) { 110 ValueChangeEvent.fire(this, m_colorPicker.getFormValueAsString()); 111 } 112 113 } 114 115 /** 116 * @see com.google.gwt.user.client.ui.HasValue#getValue() 117 */ 118 public String getValue() { 119 120 return m_colorPicker.getFormValueAsString(); 121 } 122 123 /** 124 * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#isActive() 125 */ 126 public boolean isActive() { 127 128 return m_active; 129 } 130 131 /** 132 * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#onAttachWidget() 133 */ 134 public void onAttachWidget() { 135 136 super.onAttach(); 137 } 138 139 /** 140 * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#owns(com.google.gwt.dom.client.Element) 141 */ 142 public boolean owns(Element element) { 143 144 // TODO implement this in case we want the delete behavior for optional fields 145 return false; 146 147 } 148 149 /** 150 * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#setActive(boolean) 151 */ 152 public void setActive(boolean active) { 153 154 if (m_active == active) { 155 return; 156 } 157 158 m_active = active; 159 if (m_active) { 160 m_colorPicker.getElement().removeClassName( 161 org.opencms.acacia.client.css.I_CmsLayoutBundle.INSTANCE.form().inActive()); 162 } else { 163 m_colorPicker.getElement().addClassName( 164 org.opencms.acacia.client.css.I_CmsLayoutBundle.INSTANCE.form().inActive()); 165 m_colorPicker.getColorfield().getElement().getStyle().setBackgroundColor("#FFFFFF"); 166 } 167 if (active) { 168 fireChangeEvent(); 169 } 170 171 } 172 173 /** 174 * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#setName(java.lang.String) 175 */ 176 public void setName(String name) { 177 178 m_colorPicker.setName(name); 179 180 } 181 182 /** 183 * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object) 184 */ 185 public void setValue(String value) { 186 187 setValue(value, false); 188 189 } 190 191 /** 192 * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object, boolean) 193 */ 194 public void setValue(String value, boolean fireEvents) { 195 196 m_colorPicker.setFormValueAsString(value); 197 if (fireEvents) { 198 fireChangeEvent(); 199 } 200 201 } 202}