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 addStyleName(OpenCmsTheme.TYPE_SELECT); 066 } 067 068 /** 069 * Updates the resource types. 070 * @param resourceTypes the resource types 071 */ 072 public void updateTypes(List<I_CmsResourceType> resourceTypes) { 073 074 IndexedContainer types = generateResourceTypesContainer(resourceTypes); 075 types.addContainerFilter(CmsVaadinUtils.FILTER_NO_FOLDERS); 076 setContainerDataSource(types); 077 setItemCaptionPropertyId(PropertyId.caption); 078 setItemIconPropertyId(PropertyId.icon); 079 setFilteringMode(FilteringMode.CONTAINS); 080 } 081 082 /** 083 * Generates the resource types container. 084 * @param resourceTypes the resource types 085 * @return the resource types container 086 */ 087 private IndexedContainer generateResourceTypesContainer(List<I_CmsResourceType> resourceTypes) { 088 089 CmsVaadinUtils.sortResourceTypes(resourceTypes); 090 IndexedContainer types = new IndexedContainer(); 091 types.addContainerProperty(PropertyId.caption, String.class, null); 092 types.addContainerProperty(PropertyId.icon, Resource.class, null); 093 types.addContainerProperty(PropertyId.isFolder, Boolean.class, null); 094 types.addContainerProperty(PropertyId.isXmlContent, Boolean.class, null); 095 for (I_CmsResourceType type : resourceTypes) { 096 CmsExplorerTypeSettings typeSetting = OpenCms.getWorkplaceManager().getExplorerTypeSetting( 097 type.getTypeName()); 098 if (typeSetting != null) { 099 Item typeItem = types.addItem(type); 100 String caption = CmsVaadinUtils.getMessageText(typeSetting.getKey()) + " (" + type.getTypeName() + ")"; 101 typeItem.getItemProperty(PropertyId.caption).setValue(caption); 102 typeItem.getItemProperty(PropertyId.icon).setValue( 103 CmsResourceUtil.getSmallIconResource(typeSetting, null)); 104 typeItem.getItemProperty(PropertyId.isXmlContent).setValue( 105 Boolean.valueOf(type instanceof CmsResourceTypeXmlContent)); 106 typeItem.getItemProperty(PropertyId.isFolder).setValue( 107 Boolean.valueOf(type instanceof A_CmsResourceTypeFolderBase)); 108 } 109 } 110 return types; 111 } 112}