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

org.opencms.gwt.client.ui.A_CmsDirectEditButtons 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 (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.gwt.client.ui;

import org.opencms.gwt.client.CmsEditableDataJSO;
import org.opencms.gwt.client.util.CmsDomUtil;
import org.opencms.gwt.client.util.CmsPositionBean;
import org.opencms.util.CmsStringUtil;

import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
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.DOM;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Class to provide direct edit buttons.

* * @since 8.0.0 */ public abstract class A_CmsDirectEditButtons extends FlowPanel implements HasMouseOverHandlers, HasMouseOutHandlers { /** * Button handler for this class.

*/ private class MouseHandler extends A_CmsHoverHandler implements ClickHandler { /** * Constructor.

*/ protected MouseHandler() { // nothing to do } /** * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent) */ public void onClick(ClickEvent event) { Object source = event.getSource(); if (source == m_delete) { onClickDelete(); } if (source == m_edit) { onClickEdit(); } if (source == m_new) { onClickNew(); } } /** * @see org.opencms.gwt.client.ui.A_CmsHoverHandler#onHoverIn(com.google.gwt.event.dom.client.MouseOverEvent) */ @Override public void onHoverIn(MouseOverEvent event) { if (activeBar != null) { try { activeBar.removeHighlightingAndBar(); } catch (Throwable t) { // ignore } } activeBar = null; addHighlightingAndBar(); } /** * @see org.opencms.gwt.client.ui.A_CmsHoverHandler#onHoverOut(com.google.gwt.event.dom.client.MouseOutEvent) */ @Override public void onHoverOut(MouseOutEvent event) { timer = new Timer() { @Override public void run() { if (timer == this) { removeHighlightingAndBar(); } } }; timer.schedule(750); } } /** The currently active option bar. */ /*default */static A_CmsDirectEditButtons activeBar; /** The timer used for hiding the option bar. */ /*default */static Timer timer; /** The delete button. */ protected CmsPushButton m_delete; /** The edit button. */ protected CmsPushButton m_edit; /** The editable data. */ protected CmsEditableDataJSO m_editableData; /** The expired resources overlay element. */ protected Element m_expiredOverlay; /** Highlighting border for this element. */ protected CmsHighlightingBorder m_highlighting; /** The editable marker tag. */ protected Element m_markerTag; /** The new button. */ protected CmsPushButton m_new; /** The parent element id. */ protected String m_parentResourceId; /** The editable element position. */ protected CmsPositionBean m_position; /** * Constructor.

* * @param editable the editable marker tag * @param parentId the parent element id */ public A_CmsDirectEditButtons(Element editable, String parentId) { try { setStyleName(org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.directEditCss().directEditButtons()); addStyleName(org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.directEditCss().optionBar()); addStyleName(org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.generalCss().cornerAll()); m_markerTag = editable; m_parentResourceId = parentId; String jsonText = editable.getAttribute("rel"); m_editableData = CmsEditableDataJSO.parseEditableData(jsonText); MouseHandler handler = new MouseHandler(); addMouseOutHandler(handler); addMouseOverHandler(handler); if (m_editableData.hasDelete() && CmsStringUtil.isEmptyOrWhitespaceOnly(m_editableData.getNoEditReason())) { m_delete = new CmsPushButton(); m_delete.setImageClass(I_CmsButton.ButtonData.DELETE.getIconClass()); m_delete.addStyleName(I_CmsButton.ButtonData.DELETE.getIconClass()); m_delete.setTitle(I_CmsButton.ButtonData.DELETE.getTitle()); m_delete.setButtonStyle(I_CmsButton.ButtonStyle.TRANSPARENT, null); add(m_delete); m_delete.addClickHandler(handler); } if (m_editableData.hasNew()) { m_new = new CmsPushButton(); m_new.setImageClass(I_CmsButton.ButtonData.NEW.getIconClass()); m_new.addStyleName(I_CmsButton.ButtonData.NEW.getIconClass()); m_new.setTitle(I_CmsButton.ButtonData.NEW.getTitle()); m_new.setButtonStyle(I_CmsButton.ButtonStyle.TRANSPARENT, null); add(m_new); m_new.addClickHandler(handler); } if ((this.getWidgetCount() > 0) || m_editableData.hasEdit()) { m_edit = new CmsPushButton(); m_edit.setImageClass(I_CmsButton.ButtonData.SELECTION.getIconClass()); m_edit.addStyleName(I_CmsButton.ButtonData.SELECTION.getIconClass()); m_edit.setButtonStyle(I_CmsButton.ButtonStyle.TRANSPARENT, null); add(m_edit); if (m_editableData.hasEdit()) { m_edit.addStyleName(I_CmsButton.ButtonData.EDIT.getIconClass()); m_edit.setTitle(I_CmsButton.ButtonData.EDIT.getTitle()); m_edit.addClickHandler(handler); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_editableData.getNoEditReason())) { m_edit.disable(m_editableData.getNoEditReason()); } } } if (m_editableData.isUnreleasedOrExpired()) { m_expiredOverlay = DOM.createDiv(); m_expiredOverlay.setClassName(org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.directEditCss().expiredListElementOverlay()); m_markerTag.getParentElement().insertBefore(m_expiredOverlay, m_markerTag); } } catch (Exception e) { throw new UnsupportedOperationException("Error while parsing editable tag information: " + e.getMessage()); } } /** * @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()); } /** * Returns the marker tag.

* * @return the marker tag */ public Element getMarkerTag() { return m_markerTag; } /** * Puts a highlighting border around the element.

*/ public void highlightElement() { if (m_highlighting == null) { m_highlighting = new CmsHighlightingBorder(m_position, CmsHighlightingBorder.BorderColor.red); RootPanel.get().add(m_highlighting); } else { m_highlighting.setPosition(CmsPositionBean.getInnerDimensions(getElement())); } } /** * Returns if this edit button is still valid.

* * @return true if this edit button is valid */ public boolean isValid() { return RootPanel.getBodyElement().isOrHasChild(m_markerTag); } /** * @see com.google.gwt.user.client.ui.Widget#removeFromParent() */ @Override public void removeFromParent() { removeHighlighting(); super.removeFromParent(); } /** * Removes the highlighting border.

*/ public void removeHighlighting() { if (m_highlighting != null) { m_highlighting.removeFromParent(); m_highlighting = null; } } /** * Sets the position. Make sure the widget is attached to the DOM.

* * @param position the absolute position * @param containerElement the parent container element */ public void setPosition(CmsPositionBean position, Element containerElement) { m_position = position; Element parent = CmsDomUtil.getPositioningParent(getElement()); Style style = getElement().getStyle(); style.setRight( parent.getOffsetWidth() - ((m_position.getLeft() + m_position.getWidth()) - parent.getAbsoluteLeft()), Unit.PX); int top = m_position.getTop() - parent.getAbsoluteTop(); if (m_position.getHeight() < 24) { // if the highlighted area has a lesser height than the buttons, center vertically top -= (24 - m_position.getHeight()) / 2; } style.setTop(top, Unit.PX); updateExpiredOverlayPosition(parent); } /** * Adds the highlighting and option bar.

*/ protected void addHighlightingAndBar() { timer = null; highlightElement(); getElement().addClassName(org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.stateCss().cmsHovering()); activeBar = this; } /** * This method should be executed when the "delete" direct edit button is clicked.

*/ protected abstract void onClickDelete(); /** * This method should be executed when the "edit" direct edit button is clicked.

*/ protected abstract void onClickEdit(); /** * This method should be executed when the "new" direct edit button is clicked.

*/ protected abstract void onClickNew(); /** * Removes the highlighting and option bar.

*/ protected void removeHighlightingAndBar() { timer = null; if (activeBar == this) { activeBar = null; } removeHighlighting(); getElement().removeClassName(org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.stateCss().cmsHovering()); } /** * Updates the position of the expired resources overlay if present.

* * @param positioningParent the positioning parent element */ protected void updateExpiredOverlayPosition(Element positioningParent) { if (m_expiredOverlay != null) { Style expiredStyle = m_expiredOverlay.getStyle(); expiredStyle.setHeight(m_position.getHeight() + 4, Unit.PX); expiredStyle.setWidth(m_position.getWidth() + 4, Unit.PX); expiredStyle.setTop(m_position.getTop() - positioningParent.getAbsoluteTop() - 2, Unit.PX); expiredStyle.setLeft(m_position.getLeft() - positioningParent.getAbsoluteLeft() - 2, Unit.PX); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy