All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opencms.ade.containerpage.client.ui.CmsElementOptionBar Maven / Gradle / Ivy

Go to download

OpenCms is an enterprise-ready, easy to use website content management system based on Java and XML technology. Offering a complete set of features, OpenCms helps content managers worldwide to create and maintain beautiful websites fast and efficiently.

There is a newer version: 18.0
Show newest version
/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.ade.containerpage.client.ui;

import org.opencms.gwt.client.CmsCoreProvider;
import org.opencms.gwt.client.dnd.CmsDNDHandler;
import org.opencms.gwt.client.ui.A_CmsHoverHandler;
import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle;
import org.opencms.gwt.client.util.I_CmsUniqueActiveItem;

import java.util.Iterator;

import com.google.gwt.event.dom.client.HasMouseOutHandlers;
import com.google.gwt.event.dom.client.HasMouseOverHandlers;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * A panel to be displayed inside a container element to provide optional functions like edit, move, remove... 

* * @since 8.0.0 */ public class CmsElementOptionBar extends Composite implements HasMouseOverHandlers, HasMouseOutHandlers, I_CmsUniqueActiveItem { /** * Hover handler for option bar.

*/ protected class HoverHandler extends A_CmsHoverHandler { /** * @see org.opencms.gwt.client.ui.A_CmsHoverHandler#onHoverIn(com.google.gwt.event.dom.client.MouseOverEvent) */ @Override protected void onHoverIn(MouseOverEvent event) { timer = null; CmsCoreProvider.get().getFlyoutMenuContainer().setActiveItem(CmsElementOptionBar.this); addHighlighting(); } /** * @see org.opencms.gwt.client.ui.A_CmsHoverHandler#onHoverOut(com.google.gwt.event.dom.client.MouseOutEvent) */ @Override protected void onHoverOut(MouseOutEvent event) { timer = new Timer() { @Override public void run() { if (timer == this) { removeHighlighting(); } } }; timer.schedule(750); } } /** The timer used for hiding the option bar. */ /*default */static Timer timer; /** The CSS class to be assigned to each option-bar. */ public static String CSS_CLASS = org.opencms.ade.containerpage.client.ui.css.I_CmsLayoutBundle.INSTANCE.containerpageCss().optionBar(); /** The calculated panel width. */ private int m_calculatedWidth; /** The parent container element. */ private CmsContainerPageElementPanel m_containerElement; /** The panel. */ private FlowPanel m_panel; /** * Constructor.

* * @param containerElement the parent container element */ public CmsElementOptionBar(CmsContainerPageElementPanel containerElement) { m_panel = new FlowPanel(); m_containerElement = containerElement; initWidget(m_panel); HoverHandler handler = new HoverHandler(); addMouseOverHandler(handler); addMouseOutHandler(handler); setStyleName(CSS_CLASS); } /** * Creates an option-bar for the given drag element.

* * @param element the element to create the option-bar for * @param dndHandler the drag and drop handler * @param buttons the list of buttons to display * * @return the created option-bar */ public static CmsElementOptionBar createOptionBarForElement( CmsContainerPageElementPanel element, CmsDNDHandler dndHandler, A_CmsToolbarOptionButton... buttons) { CmsElementOptionBar optionBar = new CmsElementOptionBar(element); if (buttons != null) { // add buttons, last as first for (int i = buttons.length - 1; i >= 0; i--) { CmsElementOptionButton option = buttons[i].createOptionForElement(element); if (option == null) { continue; } optionBar.add(option); if (buttons[i] instanceof CmsToolbarMoveButton) { option.addMouseDownHandler(dndHandler); } } } return optionBar; } /** * Adds another option button.

* * @param w the button to add */ public void add(Widget w) { m_panel.add(w); } /** * @see com.google.gwt.event.dom.client.HasMouseOutHandlers#addMouseOutHandler(com.google.gwt.event.dom.client.MouseOutHandler) */ public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) { return addDomHandler(handler, MouseOutEvent.getType()); } /** * @see com.google.gwt.event.dom.client.HasMouseOverHandlers#addMouseOverHandler(com.google.gwt.event.dom.client.MouseOverHandler) */ public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) { return addDomHandler(handler, MouseOverEvent.getType()); } /** * Clears the bar.

*/ public void clear() { m_panel.clear(); m_calculatedWidth = 0; } /** * Returns the calculated width of the widget.

* * @return the calculated width */ public int getCalculatedWidth() { return m_calculatedWidth; } /** * Returns an iterator for the child widgets.

* * @return the iterator */ public Iterator iterator() { return m_panel.iterator(); } /** * @see org.opencms.gwt.client.util.I_CmsUniqueActiveItem#onDeactivate() */ public void onDeactivate() { try { internalRemoveHighlighting(); } catch (Exception e) { // ignore } } /** * Removes the highlighting and option bar.

*/ public void removeHighlighting() { timer = null; CmsCoreProvider.get().getFlyoutMenuContainer().clearIfMatches(this); internalRemoveHighlighting(); } /** * Adds the highlighting and option bar.

*/ protected void addHighlighting() { getElement().addClassName(I_CmsLayoutBundle.INSTANCE.stateCss().cmsHovering()); getContainerElement().highlightElement(); } /** * Returns the parent container element.

* * @return the parent container element */ protected CmsContainerPageElementPanel getContainerElement() { return m_containerElement; } /** * Removes the highlighting.

*/ protected void internalRemoveHighlighting() { getElement().removeClassName(I_CmsLayoutBundle.INSTANCE.stateCss().cmsHovering()); getContainerElement().removeHighlighting(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy