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.gwt.client.ui.input;
029
030import org.opencms.gwt.client.ui.CmsPushButton;
031import org.opencms.gwt.client.ui.I_CmsButton;
032import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle;
033import org.opencms.gwt.client.ui.I_CmsButton.Size;
034
035import com.google.gwt.core.client.GWT;
036import com.google.gwt.dom.client.Style.Display;
037import com.google.gwt.event.dom.client.ClickEvent;
038import com.google.gwt.uibinder.client.UiBinder;
039import com.google.gwt.uibinder.client.UiField;
040import com.google.gwt.uibinder.client.UiHandler;
041import com.google.gwt.user.client.Command;
042import com.google.gwt.user.client.ui.Composite;
043import com.google.gwt.user.client.ui.Label;
044import com.google.gwt.user.client.ui.Widget;
045
046/**
047 * Text input field with value select opener button and value fader for overflowing values.<p>
048 */
049public class CmsSelectionInput extends Composite {
050
051    /**
052     * The UI Binder interface for this widget.<p>
053     */
054    interface I_CmsSelectionInputUiBinder extends UiBinder<Widget, CmsSelectionInput> {
055        // binder interface
056    }
057
058    /** The ui binder for this widget. */
059    private static I_CmsSelectionInputUiBinder uiBinder = GWT.create(I_CmsSelectionInputUiBinder.class);
060
061    /** The fader element. */
062    @UiField
063    Label m_fader;
064
065    /** The dialog opener. */
066    @UiField
067    CmsPushButton m_opener;
068
069    /** The text input field. */
070    @UiField
071    CmsSimpleTextBox m_textbox;
072
073    /** The command to open the value select dialog. */
074    private Command m_openCommand;
075
076    /**
077     * Constructor.<p>
078     *
079     * @param openerIcon the image icon class
080     */
081    public CmsSelectionInput(String openerIcon) {
082
083        initWidget(uiBinder.createAndBindUi(this));
084        if (openerIcon == null) {
085            m_opener.setImageClass(I_CmsButton.GALLERY);
086        } else {
087            m_opener.setImageClass(openerIcon);
088        }
089        m_opener.setButtonStyle(ButtonStyle.FONT_ICON, null);
090        m_opener.setSize(Size.small);
091    }
092
093    /**
094     * Returns the input box.<p>
095     *
096     * @return the input box
097     */
098    public CmsSimpleTextBox getTextBox() {
099
100        return m_textbox;
101    }
102
103    /**
104     * Hides the fader.<p>
105     */
106    public void hideFader() {
107
108        m_fader.getElement().getStyle().setDisplay(Display.NONE);
109    }
110
111    /**
112     * Sets the value select dialog open command.<p>
113     *
114     * @param openCommand the command
115     */
116    public void setOpenCommand(Command openCommand) {
117
118        m_openCommand = openCommand;
119    }
120
121    /**
122     * Shows the fader.<p>
123     */
124    public void showFader() {
125
126        m_fader.getElement().getStyle().clearDisplay();
127    }
128
129    /**
130     * Handles the opener clicks.<p>
131     *
132     * @param event the click event
133     */
134    @UiHandler("m_fader")
135    void onFaderClick(ClickEvent event) {
136
137        m_textbox.setFocus(true);
138    }
139
140    /**
141     * Handles the opener clicks.<p>
142     *
143     * @param event the click event
144     */
145    @UiHandler("m_opener")
146    void onOpen(ClickEvent event) {
147
148        if (m_openCommand != null) {
149            m_openCommand.execute();
150        }
151    }
152
153}