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.util; 029 030/** 031 * Container which contains at most one {@link org.opencms.gwt.client.util.I_CmsUniqueActiveItem}.<p> 032 * 033 * If a new value is set while this container already contains an item, the previous item is removed and notified of that removal.<p> 034 */ 035public class CmsUniqueActiveItemContainer { 036 037 /** The current item. */ 038 private I_CmsUniqueActiveItem m_activeItem; 039 040 /** 041 * Removes the current item. 042 */ 043 public void clear() { 044 045 if (m_activeItem != null) { 046 m_activeItem.onDeactivate(); 047 m_activeItem = null; 048 } 049 } 050 051 /** 052 * Removes the current item only if it is the same object as the given parameter.<p> 053 * 054 * @param item the item to match 055 */ 056 public void clearIfMatches(I_CmsUniqueActiveItem item) { 057 058 if (item == m_activeItem) { 059 clear(); 060 } 061 } 062 063 /** 064 * Sets the active item.<p> 065 * 066 * If this container already contains an item, it is replaced with the given item, and its onDeactivate() method is called.<p> 067 * 068 * @param item the new item 069 */ 070 public void setActiveItem(I_CmsUniqueActiveItem item) { 071 072 clear(); 073 if (item != null) { 074 m_activeItem = item; 075 } 076 } 077 078}