
org.opencms.acacia.client.widgets.serialdate.CmsFocusAwareTextBox Maven / Gradle / Ivy
Show all versions of opencms-gwt Show documentation
/*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.acacia.client.widgets.serialdate;
import org.opencms.gwt.client.ui.input.CmsTextBox;
import org.opencms.gwt.client.ui.input.I_CmsFormWidget;
import org.opencms.gwt.client.ui.input.form.CmsWidgetFactoryRegistry;
import org.opencms.gwt.client.ui.input.form.I_CmsFormWidgetFactory;
import java.util.Map;
import com.google.common.base.Optional;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.FocusHandler;
/** An extension of {@link CmsTextBox} that keeps information about its focus state. */
public class CmsFocusAwareTextBox extends CmsTextBox {
/** Flag, indicating if the text box is currently focused. */
boolean m_hasFocus;
/** Default constructor. */
public CmsFocusAwareTextBox() {
super();
super.addFocusHandler(new FocusHandler() {
public void onFocus(FocusEvent event) {
m_hasFocus = true;
}
});
super.addBlurHandler(new BlurHandler() {
public void onBlur(BlurEvent event) {
m_hasFocus = false;
}
});
}
/**
* Initializes this class.
*/
public static void initClass() {
// registers a factory for creating new instances of this widget
CmsWidgetFactoryRegistry.instance().registerFactory(WIDGET_TYPE, new I_CmsFormWidgetFactory() {
/**
* @see org.opencms.gwt.client.ui.input.form.I_CmsFormWidgetFactory#createWidget(java.util.Map, com.google.common.base.Optional)
*/
public I_CmsFormWidget createWidget(Map widgetParams, Optional defaultValue) {
return new CmsFocusAwareTextBox().colorWhite();
}
});
}
/**
* Returns a flag, indicating if the text box is currently focused.
* @return a flag, indicating if the text box is currently focused.
*/
public boolean isFocused() {
return m_hasFocus;
}
}