001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH (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.widgets.serialdate.CmsSerialDateController;
031import org.opencms.acacia.client.widgets.serialdate.I_CmsLayoutBundle;
032
033import com.google.gwt.dom.client.Element;
034import com.google.gwt.event.dom.client.FocusHandler;
035import com.google.gwt.event.logical.shared.ValueChangeEvent;
036import com.google.gwt.event.logical.shared.ValueChangeHandler;
037import com.google.gwt.event.shared.HandlerRegistration;
038import com.google.gwt.user.client.ui.Composite;
039
040/**
041 * Provides a DHTML calendar widget, for use on a widget dialog.<p>
042 *
043 * */
044public class CmsSerialDateWidget extends Composite implements I_CmsEditWidget {
045
046    /** Value of the activation. */
047    private boolean m_active = true;
048
049    /** The global select box. */
050    private CmsSerialDateController m_serialDate;
051
052    /**
053     * Constructs an CmsComboWidget with the in XSD schema declared configuration.<p>
054     */
055    public CmsSerialDateWidget() {
056
057        m_serialDate = new CmsSerialDateController();
058        // All composites must call initWidget() in their constructors.
059        initWidget(m_serialDate);
060
061        ValueChangeHandler<String> handler = new ValueChangeHandler<String>() {
062
063            public void onValueChange(ValueChangeEvent<String> arg0) {
064
065                fireChangeEvent();
066
067            }
068
069        };
070        I_CmsLayoutBundle.INSTANCE.widgetCss().ensureInjected();
071        m_serialDate.addStyleName(
072            org.opencms.ade.contenteditor.client.css.I_CmsLayoutBundle.INSTANCE.generalCss().cornerAll());
073        m_serialDate.addStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().serialDateWidget());
074        m_serialDate.addValueChangeHandler(handler);
075    }
076
077    /**
078     * @see com.google.gwt.event.dom.client.HasFocusHandlers#addFocusHandler(com.google.gwt.event.dom.client.FocusHandler)
079     */
080    public HandlerRegistration addFocusHandler(FocusHandler handler) {
081
082        return null;
083    }
084
085    /**
086     * @see com.google.gwt.event.logical.shared.HasValueChangeHandlers#addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler)
087     */
088    public HandlerRegistration addValueChangeHandler(ValueChangeHandler<String> handler) {
089
090        return addHandler(handler, ValueChangeEvent.getType());
091    }
092
093    /**
094     * Represents a value change event.<p>
095     *
096     */
097    public void fireChangeEvent() {
098
099        ValueChangeEvent.fire(this, getValue());
100
101    }
102
103    /**
104     * @see com.google.gwt.user.client.ui.HasValue#getValue()
105     */
106    public String getValue() {
107
108        return m_serialDate.getValue();
109    }
110
111    /**
112     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#isActive()
113     */
114    public boolean isActive() {
115
116        return m_active;
117    }
118
119    /**
120     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#onAttachWidget()
121     */
122    public void onAttachWidget() {
123
124        super.onAttach();
125    }
126
127    /**
128     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#owns(com.google.gwt.dom.client.Element)
129     */
130    public boolean owns(Element element) {
131
132        return getElement().isOrHasChild(element);
133    }
134
135    /**
136     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#setActive(boolean)
137     */
138    public void setActive(boolean active) {
139
140        if (active == m_active) {
141            return;
142        }
143        m_active = active;
144
145        if (m_active) {
146            getElement().removeClassName(org.opencms.acacia.client.css.I_CmsLayoutBundle.INSTANCE.form().inActive());
147            getElement().focus();
148        } else {
149            getElement().addClassName(org.opencms.acacia.client.css.I_CmsLayoutBundle.INSTANCE.form().inActive());
150        }
151        m_serialDate.setActive(m_active);
152        if (active) {
153            fireChangeEvent();
154        }
155    }
156
157    /**
158     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#setName(java.lang.String)
159     */
160    public void setName(String name) {
161
162        //not necessary to implement
163    }
164
165    /**
166     * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object)
167     */
168    public void setValue(String value) {
169
170        setValue(value, false);
171
172    }
173
174    /**
175     * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object, boolean)
176     */
177    public void setValue(String value, boolean fireEvents) {
178
179        m_serialDate.setValue(value);
180        if (fireEvents) {
181            fireChangeEvent();
182        }
183
184    }
185}