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.CmsVfsSelection;
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;
041
042/**
043 *
044 * */
045public class CmsVfsWidget extends Composite implements I_CmsEditWidget {
046
047    /** Value of the activation. */
048    private boolean m_active = true;
049
050    /***/
051    private String m_config = "";
052
053    /** The link selector. */
054    private CmsVfsSelection m_linkSelect;
055
056    /**
057     * Constructs an CmsComboWidget with the in XSD schema declared configuration.<p>
058     * @param config the configuration string given from OpenCms XSD
059     * @param type the mode in witch the widget should be started
060     * @param icon the icon image CSS class
061     */
062    public CmsVfsWidget(String config, String type, String icon) {
063
064        m_config = config;
065        m_linkSelect = new CmsVfsSelection(icon, type, m_config);
066        m_linkSelect.getTextAreaContainer().addStyleName(I_CmsWidgetsLayoutBundle.INSTANCE.widgetCss().vfsInputBox());
067        m_linkSelect.addValueChangeHandler(new ValueChangeHandler<String>() {
068
069            public void onValueChange(ValueChangeEvent<String> event) {
070
071                fireChangeEvent();
072
073            }
074        });
075        m_linkSelect.getTextAreaContainer().getTextBox().addFocusHandler(new FocusHandler() {
076
077            public void onFocus(FocusEvent event) {
078
079                CmsDomUtil.fireFocusEvent(CmsVfsWidget.this);
080            }
081        });
082        initWidget(m_linkSelect);
083
084    }
085
086    /**
087     * @see com.google.gwt.event.dom.client.HasFocusHandlers#addFocusHandler(com.google.gwt.event.dom.client.FocusHandler)
088     */
089    public HandlerRegistration addFocusHandler(FocusHandler handler) {
090
091        return addDomHandler(handler, FocusEvent.getType());
092    }
093
094    /**
095     * @see com.google.gwt.event.logical.shared.HasValueChangeHandlers#addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler)
096     */
097    public HandlerRegistration addValueChangeHandler(ValueChangeHandler<String> handler) {
098
099        return addHandler(handler, ValueChangeEvent.getType());
100    }
101
102    /**
103     * Represents a value change event.<p>
104     *
105     */
106    public void fireChangeEvent() {
107
108        ValueChangeEvent.fire(this, m_linkSelect.getFormValueAsString());
109    }
110
111    /**
112     * @see com.google.gwt.user.client.ui.HasValue#getValue()
113     */
114    public String getValue() {
115
116        return m_linkSelect.getFormValueAsString();
117    }
118
119    /**
120     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#isActive()
121     */
122    public boolean isActive() {
123
124        return m_active;
125    }
126
127    /**
128     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#onAttachWidget()
129     */
130    public void onAttachWidget() {
131
132        super.onAttach();
133    }
134
135    /**
136     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#owns(com.google.gwt.dom.client.Element)
137     */
138    public boolean owns(Element element) {
139
140        // TODO implement this in case we want the delete behavior for optional fields
141        return false;
142
143    }
144
145    /**
146     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#setActive(boolean)
147     */
148    public void setActive(boolean active) {
149
150        if (m_active == active) {
151            return;
152        }
153        m_active = active;
154        if (active) {
155            fireChangeEvent();
156        }
157
158    }
159
160    /**
161     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#setName(java.lang.String)
162     */
163    public void setName(String name) {
164
165        m_linkSelect.setName(name);
166
167    }
168
169    /**
170     * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object)
171     */
172    public void setValue(String value) {
173
174        setValue(value, false);
175    }
176
177    /**
178     * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object, boolean)
179     */
180    public void setValue(String value, boolean fireEvents) {
181
182        m_linkSelect.setFormValueAsString(value);
183        if (fireEvents) {
184            fireChangeEvent();
185        }
186
187    }
188}