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.gwt.client.ui; 029 030/** 031 * Abstract button class implementing common methods of {@link org.opencms.gwt.client.ui.I_CmsToolbarButton} 032 * for all container-page tool-bar menu buttons.<p> 033 * 034 * @param <HANDLER> the handler class for the menu button 035 * 036 * @since 8.0.0 037 */ 038public abstract class A_CmsToolbarMenu<HANDLER extends I_CmsToolbarHandler> extends CmsMenuButton 039implements I_CmsToolbarButton { 040 041 /** The handler instance. */ 042 private HANDLER m_handler; 043 044 /** 045 * Constructor.<p> 046 * 047 * @param buttonData the tool-bar button data 048 * @param handler the container-page handler 049 */ 050 public A_CmsToolbarMenu(I_CmsButton.ButtonData buttonData, HANDLER handler) { 051 052 super(null, buttonData.getIconClass()); 053 setToolbarMode(true); 054 setOpenRight(true); 055 m_handler = handler; 056 setTitle(buttonData.getTitle()); 057 } 058 059 /** 060 * @see org.opencms.gwt.client.ui.CmsMenuButton#hideMenu() 061 */ 062 @Override 063 public void hideMenu() { 064 065 super.hideMenu(); 066 } 067 068 /** 069 * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#isActive() 070 */ 071 public boolean isActive() { 072 073 return isOpen(); 074 } 075 076 /** 077 * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#onToolbarClick() 078 */ 079 public void onToolbarClick() { 080 081 boolean active = isActive(); 082 083 setActive(!active); 084 085 } 086 087 /** 088 * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#setActive(boolean) 089 */ 090 public void setActive(boolean active) { 091 092 if (active) { 093 m_handler.deactivateCurrentButton(); 094 m_handler.setActiveButton(this); 095 m_popup.catchNotifications(); 096 onToolbarActivate(); 097 openMenu(); 098 } else { 099 onToolbarDeactivate(); 100 closeMenu(); 101 m_handler.setActiveButton(null); 102 m_handler.activateSelection(); 103 } 104 } 105 106 /** 107 * @see org.opencms.gwt.client.ui.CmsMenuButton#autoClose() 108 */ 109 @Override 110 protected void autoClose() { 111 112 super.autoClose(); 113 onToolbarDeactivate(); 114 m_handler.setActiveButton(null); 115 m_handler.activateSelection(); 116 } 117 118 /** 119 * Returns the container-page handler.<p> 120 * 121 * @return the container-page handler 122 */ 123 protected HANDLER getHandler() { 124 125 return m_handler; 126 } 127 128 /** 129 * Sets the button handler.<p> 130 * 131 * @param handler the button handler 132 */ 133 protected void setHandler(HANDLER handler) { 134 135 m_handler = handler; 136 } 137}