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.ui.components; 029 030import org.opencms.ui.CmsVaadinUtils; 031import org.opencms.ui.apps.Messages; 032import org.opencms.util.CmsPair; 033 034import java.util.ArrayList; 035import java.util.List; 036 037import com.vaadin.ui.ComboBox; 038 039/** 040 * Expired/unreleased resources selection component. 041 */ 042public class CmsAvailabilitySelector extends ComboBox<CmsPair<String, String>> { 043 044 /** Serial version id. */ 045 private static final long serialVersionUID = 1L; 046 047 /** The "all" option. */ 048 private static final String OPTION_ALL = "all"; 049 050 /** The "without" option. */ 051 private static final String OPTION_WITHOUT = "without"; 052 053 /** The "only" option. */ 054 private static final String OPTION_ONLY = "only"; 055 056 /** Option that selects all resources including the expired/unreleased resources. */ 057 public static CmsPair<String, String> m_optionAll; 058 059 /** Option that selects all resources without the expired/unreleased resources. */ 060 public static CmsPair<String, String> m_optionWithout; 061 062 /** Option that selects only the expired/unreleased resources. */ 063 public static CmsPair<String, String> m_optionOnly; 064 065 /** Option list. */ 066 private static List<CmsPair<String, String>> m_options; 067 068 /** 069 * Creates a new expired/unreleased resources selection component. 070 */ 071 public CmsAvailabilitySelector() { 072 073 setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_EXPIRED_SELECTOR_0)); 074 setDescription(CmsVaadinUtils.getMessageText(Messages.GUI_EXPIRED_SELECTOR_HELP_0)); 075 m_optionAll = CmsPair.create(OPTION_ALL, CmsVaadinUtils.getMessageText(Messages.GUI_EXPIRED_SELECTOR_ALL_0)); 076 m_optionWithout = CmsPair.create( 077 OPTION_WITHOUT, 078 CmsVaadinUtils.getMessageText(Messages.GUI_EXPIRED_SELECTOR_WITHOUT_0)); 079 m_optionOnly = CmsPair.create(OPTION_ONLY, CmsVaadinUtils.getMessageText(Messages.GUI_EXPIRED_SELECTOR_ONLY_0)); 080 m_options = new ArrayList<CmsPair<String, String>>(); 081 m_options.add(m_optionAll); 082 m_options.add(m_optionWithout); 083 m_options.add(m_optionOnly); 084 setItems(m_options); 085 setItemCaptionGenerator(CmsPair::getSecond); 086 setEmptySelectionAllowed(false); 087 setValue(m_optionAll); 088 setWidthFull(); 089 } 090 091 /** 092 * Returns an option for a given option string. 093 * @param option the option string 094 * @return the option 095 */ 096 public CmsPair<String, String> getOption(final String option) { 097 098 if (option == null) { 099 return m_optionAll; 100 } 101 switch (option) { 102 case OPTION_WITHOUT: 103 return m_optionWithout; 104 case OPTION_ONLY: 105 return m_optionOnly; 106 case OPTION_ALL: 107 default: 108 return m_optionAll; 109 } 110 } 111 112 /** 113 * Returns whether the "all" option is currently selected. 114 * @return whether the "all" option is currently selected 115 */ 116 public boolean isOptionAll() { 117 118 return getValue() == m_optionAll; 119 } 120 121 /** 122 * Returns the "without" option. 123 * @return the "without" option 124 */ 125 public boolean isOptionOnly() { 126 127 return getValue() == m_optionOnly; 128 } 129 130 /** 131 * Returns the "only" option. 132 * @return the "only" option 133 */ 134 public boolean isOptionWithout() { 135 136 return getValue() == m_optionWithout; 137 } 138 139 /** 140 * Resets this availability selector. 141 */ 142 public void reset() { 143 144 setValue(m_optionAll); 145 } 146}