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.serialdate;
029
030import org.opencms.gwt.client.ui.input.CmsTextBox;
031import org.opencms.gwt.client.ui.input.I_CmsFormWidget;
032import org.opencms.gwt.client.ui.input.form.CmsWidgetFactoryRegistry;
033import org.opencms.gwt.client.ui.input.form.I_CmsFormWidgetFactory;
034
035import java.util.Map;
036
037import com.google.common.base.Optional;
038import com.google.gwt.event.dom.client.BlurEvent;
039import com.google.gwt.event.dom.client.BlurHandler;
040import com.google.gwt.event.dom.client.FocusEvent;
041import com.google.gwt.event.dom.client.FocusHandler;
042
043/** An extension of {@link CmsTextBox} that keeps information about its focus state. */
044public class CmsFocusAwareTextBox extends CmsTextBox {
045
046    /** Flag, indicating if the text box is currently focused. */
047    boolean m_hasFocus;
048
049    /** Default constructor. */
050    public CmsFocusAwareTextBox() {
051        super();
052        super.addFocusHandler(new FocusHandler() {
053
054            public void onFocus(FocusEvent event) {
055
056                m_hasFocus = true;
057
058            }
059        });
060        super.addBlurHandler(new BlurHandler() {
061
062            public void onBlur(BlurEvent event) {
063
064                m_hasFocus = false;
065
066            }
067        });
068    }
069
070    /**
071     * Initializes this class.<p>
072     */
073    public static void initClass() {
074
075        // registers a factory for creating new instances of this widget
076        CmsWidgetFactoryRegistry.instance().registerFactory(WIDGET_TYPE, new I_CmsFormWidgetFactory() {
077
078            /**
079             * @see org.opencms.gwt.client.ui.input.form.I_CmsFormWidgetFactory#createWidget(java.util.Map, com.google.common.base.Optional)
080             */
081            public I_CmsFormWidget createWidget(Map<String, String> widgetParams, Optional<String> defaultValue) {
082
083                return new CmsFocusAwareTextBox().colorWhite();
084            }
085        });
086    }
087
088    /**
089     * Returns a flag, indicating if the text box is currently focused.
090     * @return a flag, indicating if the text box is currently focused.
091     */
092    public boolean isFocused() {
093
094        return m_hasFocus;
095    }
096
097}