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.file.types.A_CmsResourceTypeFolderBase; 031import org.opencms.file.types.CmsResourceTypeXmlContent; 032import org.opencms.file.types.I_CmsResourceType; 033import org.opencms.main.OpenCms; 034import org.opencms.ui.CmsVaadinUtils; 035import org.opencms.ui.CmsVaadinUtils.PropertyId; 036import org.opencms.ui.apps.Messages; 037import org.opencms.workplace.explorer.CmsExplorerTypeSettings; 038import org.opencms.workplace.explorer.CmsResourceUtil; 039 040import java.util.List; 041 042import com.vaadin.server.Resource; 043import com.vaadin.v7.data.Item; 044import com.vaadin.v7.data.util.IndexedContainer; 045import com.vaadin.v7.shared.ui.combobox.FilteringMode; 046import com.vaadin.v7.ui.ComboBox; 047 048/** 049 * Type selector component. 050 */ 051@SuppressWarnings("deprecation") 052public class CmsTypeSelector extends ComboBox { 053 054 /** Serial version id. */ 055 private static final long serialVersionUID = 1L; 056 057 /** 058 * Creates a new type selector component for given resource types. 059 */ 060 public CmsTypeSelector() { 061 062 setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_SOURCESEARCH_RESOURCE_TYPE_0)); 063 setDescription(CmsVaadinUtils.getMessageText(Messages.GUI_SOURCESEARCH_RESOURCE_TYPE_HELP_0)); 064 setWidthFull(); 065 } 066 067 /** 068 * Updates the resource types. 069 * @param resourceTypes the resource types 070 */ 071 public void updateTypes(List<I_CmsResourceType> resourceTypes) { 072 073 IndexedContainer types = generateResourceTypesContainer(resourceTypes); 074 types.addContainerFilter(CmsVaadinUtils.FILTER_NO_FOLDERS); 075 setContainerDataSource(types); 076 setItemCaptionPropertyId(PropertyId.caption); 077 setItemIconPropertyId(PropertyId.icon); 078 setFilteringMode(FilteringMode.CONTAINS); 079 } 080 081 /** 082 * Generates the resource types container. 083 * @param resourceTypes the resource types 084 * @return the resource types container 085 */ 086 private IndexedContainer generateResourceTypesContainer(List<I_CmsResourceType> resourceTypes) { 087 088 CmsVaadinUtils.sortResourceTypes(resourceTypes); 089 IndexedContainer types = new IndexedContainer(); 090 types.addContainerProperty(PropertyId.caption, String.class, null); 091 types.addContainerProperty(PropertyId.icon, Resource.class, null); 092 types.addContainerProperty(PropertyId.isFolder, Boolean.class, null); 093 types.addContainerProperty(PropertyId.isXmlContent, Boolean.class, null); 094 for (I_CmsResourceType type : resourceTypes) { 095 CmsExplorerTypeSettings typeSetting = OpenCms.getWorkplaceManager().getExplorerTypeSetting( 096 type.getTypeName()); 097 if (typeSetting != null) { 098 Item typeItem = types.addItem(type); 099 String caption = CmsVaadinUtils.getMessageText(typeSetting.getKey()) + " (" + type.getTypeName() + ")"; 100 typeItem.getItemProperty(PropertyId.caption).setValue(caption); 101 typeItem.getItemProperty(PropertyId.icon).setValue( 102 CmsResourceUtil.getSmallIconResource(typeSetting, null)); 103 typeItem.getItemProperty(PropertyId.isXmlContent).setValue( 104 Boolean.valueOf(type instanceof CmsResourceTypeXmlContent)); 105 typeItem.getItemProperty(PropertyId.isFolder).setValue( 106 Boolean.valueOf(type instanceof A_CmsResourceTypeFolderBase)); 107 } 108 } 109 return types; 110 } 111}