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.ui.client;
029
030import com.google.gwt.dom.client.Document;
031import com.google.gwt.dom.client.Element;
032import com.google.gwt.dom.client.Style.Unit;
033import com.google.gwt.user.client.Timer;
034import com.vaadin.client.ui.VPopupView;
035
036/**
037 * Extending the VAADIN popup view only to add a corner element pointing at the opening button.<p>
038 */
039public class CmsVPopupView extends VPopupView {
040
041    /** The drop down marker CSS class. */
042    private static final String DROP_DOWN_CLASS = "o-navigator-dropdown";
043
044    /** The pointy corner CSS class. */
045    private static final int OFFSET = -4;
046
047    /** The corner element. */
048    private Element m_corner;
049
050    /**
051     * @see com.vaadin.client.ui.VPopupView#center()
052     */
053    @Override
054    public void center() {
055
056        super.center();
057        if (getElement().hasClassName(DROP_DOWN_CLASS)) {
058            if (m_corner == null) {
059                m_corner = Document.get().createDivElement();
060                m_corner.setClassName("o-toolbar-menu-corner");
061                popup.getElement().appendChild(m_corner);
062            }
063            updateCornerLeft();
064
065            // wait to reposition the corner, as their may be an animation effecting the position
066            Timer timer = new Timer() {
067
068                @Override
069                public void run() {
070
071                    updateCornerLeft();
072                }
073            };
074            timer.schedule(100);
075        }
076    }
077
078    /**
079     * Updates the corner element left position.<p>
080     */
081    void updateCornerLeft() {
082
083        if (m_corner != null) {
084            int popupLeft = popup.getPopupLeft();
085            int dif = (getAbsoluteLeft() - popupLeft) + OFFSET;
086            m_corner.getStyle().setLeft(dif, Unit.PX);
087        }
088    }
089}