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