001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (C) Alkacon Software (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.ui;
029
030import org.opencms.acacia.client.css.I_CmsLayoutBundle;
031import org.opencms.gwt.client.I_CmsHasResizeOnShow;
032import org.opencms.gwt.client.dnd.CmsDNDHandler.Orientation;
033import org.opencms.gwt.client.dnd.I_CmsDraggable;
034import org.opencms.gwt.client.dnd.I_CmsDropTarget;
035import org.opencms.gwt.client.ui.CmsHighlightingBorder;
036import org.opencms.gwt.client.util.CmsDomUtil;
037
038import com.google.gwt.dom.client.Element;
039import com.google.gwt.user.client.ui.FlowPanel;
040import com.google.gwt.user.client.ui.Widget;
041
042/**
043 * The attribute values panel.<p>
044 */
045public class CmsValuePanel extends FlowPanel implements I_CmsDropTarget, I_CmsHasResizeOnShow {
046
047    /** The current place holder. */
048    protected Element m_placeholder;
049
050    /** The placeholder position index. */
051    protected int m_placeholderIndex = -1;
052
053    /** The highlighting border. */
054    private CmsHighlightingBorder m_highlighting;
055
056    /**
057     * Constructor.<p>
058     */
059    public CmsValuePanel() {
060
061        setStyleName(I_CmsLayoutBundle.INSTANCE.form().attribute());
062    }
063
064    /**
065     * @see org.opencms.gwt.client.dnd.I_CmsDropTarget#checkPosition(int, int, org.opencms.gwt.client.dnd.CmsDNDHandler.Orientation)
066     */
067    public boolean checkPosition(int x, int y, Orientation orientation) {
068
069        return true;
070    }
071
072    /**
073     * @see org.opencms.gwt.client.dnd.I_CmsDropTarget#getPlaceholderIndex()
074     */
075    public int getPlaceholderIndex() {
076
077        return m_placeholderIndex;
078    }
079
080    /**
081     * Highlights the outline of this panel.<p>
082     */
083    public void highlightOutline() {
084
085        m_highlighting = new CmsHighlightingBorder(getElement(), CmsHighlightingBorder.BorderColor.red);
086        add(m_highlighting);
087    }
088
089    /**
090     * @see org.opencms.gwt.client.dnd.I_CmsDropTarget#insertPlaceholder(com.google.gwt.dom.client.Element, int, int, org.opencms.gwt.client.dnd.CmsDNDHandler.Orientation)
091     */
092    public void insertPlaceholder(Element placeholder, int x, int y, Orientation orientation) {
093
094        m_placeholder = placeholder;
095        repositionPlaceholder(x, y, orientation);
096    }
097
098    /**
099     * @see org.opencms.gwt.client.dnd.I_CmsDropTarget#onDrop(org.opencms.gwt.client.dnd.I_CmsDraggable)
100     */
101    public void onDrop(I_CmsDraggable draggable) {
102
103        // nothing to do
104    }
105
106    /**
107     * Removes the highlighting border.<p>
108     */
109    public void removeHighlighting() {
110
111        if (m_highlighting != null) {
112            m_highlighting.removeFromParent();
113            m_highlighting = null;
114        }
115    }
116
117    /**
118     * @see org.opencms.gwt.client.dnd.I_CmsDropTarget#removePlaceholder()
119     */
120    public void removePlaceholder() {
121
122        if (m_placeholder == null) {
123            return;
124        }
125        m_placeholder.removeFromParent();
126        m_placeholder = null;
127        m_placeholderIndex = -1;
128    }
129
130    /**
131     * @see org.opencms.gwt.client.dnd.I_CmsDropTarget#repositionPlaceholder(int, int, org.opencms.gwt.client.dnd.CmsDNDHandler.Orientation)
132     */
133    public void repositionPlaceholder(int x, int y, Orientation orientation) {
134
135        // handle vertical orientation only
136        m_placeholderIndex = CmsDomUtil.positionElementInside(m_placeholder, getElement(), m_placeholderIndex, -1, y);
137    }
138
139    /**
140     * @see org.opencms.gwt.client.I_CmsHasResizeOnShow#resizeOnShow()
141     */
142    public void resizeOnShow() {
143
144        for (Widget w : this) {
145            if (w instanceof I_CmsHasResizeOnShow) {
146                ((I_CmsHasResizeOnShow)w).resizeOnShow();
147            }
148        }
149    }
150
151    /**
152     * Updates the highlighting position if present.<p>
153     */
154    public void updateHighlightingPosition() {
155
156        if (m_highlighting != null) {
157            m_highlighting.resetPosition();
158        }
159    }
160}