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.gwt.client.I_CmsHasResizeOnShow;
031import org.opencms.gwt.client.ui.input.location.CmsLocationPicker;
032
033import com.google.gwt.dom.client.Element;
034import com.google.gwt.event.dom.client.FocusEvent;
035import com.google.gwt.event.dom.client.FocusHandler;
036import com.google.gwt.event.logical.shared.ValueChangeEvent;
037import com.google.gwt.event.logical.shared.ValueChangeHandler;
038import com.google.gwt.event.shared.HandlerRegistration;
039import com.google.gwt.user.client.ui.Composite;
040
041/**
042 * Provides a display only widget, for use on a widget dialog.<br>
043 * If there is no value in the content xml, the value<br>
044 * set in the configuration string of the xsd is shown.<p>
045 *
046 * */
047public class CmsLocationPickerWidget extends Composite implements I_CmsEditWidget, I_CmsHasResizeOnShow {
048
049    /** Value of the activation. */
050    private boolean m_active = true;
051
052    /** The disabled textbox to show the value. */
053    private CmsLocationPicker m_locationPicker;
054
055    /**
056     * Creates a new display widget.<p>
057     *
058     * @param config The configuration string given from OpenCms XSD.
059     */
060    public CmsLocationPickerWidget(String config) {
061
062        m_locationPicker = new CmsLocationPicker(config);
063        initWidget(m_locationPicker);
064    }
065
066    /**
067     * @see com.google.gwt.event.dom.client.HasFocusHandlers#addFocusHandler(com.google.gwt.event.dom.client.FocusHandler)
068     */
069    public HandlerRegistration addFocusHandler(FocusHandler handler) {
070
071        return addDomHandler(handler, FocusEvent.getType());
072    }
073
074    /**
075     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler)
076     */
077    public HandlerRegistration addValueChangeHandler(ValueChangeHandler<String> handler) {
078
079        return m_locationPicker.addHandler(handler, ValueChangeEvent.getType());
080    }
081
082    /**
083     * Represents a value change event.<p>
084     *
085     */
086    public void fireChangeEvent() {
087
088        ValueChangeEvent.fire(m_locationPicker, m_locationPicker.getStringValue());
089    }
090
091    /**
092     * @see com.google.gwt.user.client.ui.HasValue#getValue()
093     */
094    public String getValue() {
095
096        return m_locationPicker.getStringValue();
097    }
098
099    /**
100     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#isActive()
101     */
102    public boolean isActive() {
103
104        return m_active;
105    }
106
107    /**
108     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#onAttachWidget()
109     */
110    public void onAttachWidget() {
111
112        super.onAttach();
113    }
114
115    /**
116     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#owns(com.google.gwt.dom.client.Element)
117     */
118    public boolean owns(Element element) {
119
120        return getElement().isOrHasChild(element);
121
122    }
123
124    /**
125     * @see org.opencms.gwt.client.I_CmsHasResizeOnShow#resizeOnShow()
126     */
127    public void resizeOnShow() {
128
129        m_locationPicker.resizeOnShow();
130    }
131
132    /**
133     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#setActive(boolean)
134     */
135    public void setActive(boolean active) {
136
137        // check if the value has changed. If there is no change do nothing.
138        if (m_active == active) {
139            return;
140        }
141        m_active = active;
142        m_locationPicker.setEnabled(m_active);
143        if (active) {
144            fireChangeEvent();
145        }
146    }
147
148    /**
149     * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#setName(java.lang.String)
150     */
151    public void setName(String name) {
152
153        // no input field so nothing to do
154
155    }
156
157    /**
158     * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object)
159     */
160    public void setValue(String value) {
161
162        setValue(value, false);
163    }
164
165    /**
166     * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object, boolean)
167     */
168    public void setValue(String value, boolean fireEvents) {
169
170        m_locationPicker.setValue(value);
171        if (fireEvents) {
172            fireChangeEvent();
173        }
174    }
175
176}