001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (C) Alkacon Software (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.widgets; 029 030import org.opencms.file.CmsObject; 031import org.opencms.file.CmsResource; 032import org.opencms.file.types.I_CmsResourceType; 033import org.opencms.i18n.CmsMessages; 034import org.opencms.loader.CmsResourceManager; 035import org.opencms.main.OpenCms; 036import org.opencms.xml.types.A_CmsXmlContentValue; 037 038import java.util.ArrayList; 039import java.util.Collections; 040import java.util.List; 041import java.util.Locale; 042 043import com.google.common.base.Joiner; 044 045/** 046 * A widget for selecting resource types which are direct editable. 047 */ 048public class CmsTypeFilterWidget extends CmsFilterSelectWidget { 049 050 /** 051 * Default constructor.<p> 052 */ 053 public CmsTypeFilterWidget() { 054 055 super(); 056 } 057 058 /** 059 * Constructor with a configuration parameter.<p> 060 * @param config the configuration string 061 */ 062 public CmsTypeFilterWidget(String config) { 063 064 super(); 065 super.setConfiguration(createConfiguration()); 066 067 } 068 069 /** 070 * @see org.opencms.widgets.I_CmsADEWidget#getConfiguration(org.opencms.file.CmsObject, org.opencms.xml.types.A_CmsXmlContentValue, org.opencms.i18n.CmsMessages, org.opencms.file.CmsResource, java.util.Locale) 071 */ 072 @Override 073 public String getConfiguration( 074 CmsObject cms, 075 A_CmsXmlContentValue schemaType, 076 CmsMessages messages, 077 CmsResource resource, 078 Locale contentLocale) { 079 080 return CmsSelectWidgetOption.createConfigurationString( 081 CmsSelectWidgetOption.parseOptions(createConfiguration())); 082 } 083 084 /** 085 * @see org.opencms.widgets.I_CmsADEWidget#getCssResourceLinks(org.opencms.file.CmsObject) 086 */ 087 @Override 088 public List<String> getCssResourceLinks(CmsObject cms) { 089 090 return null; 091 } 092 093 /** 094 * @see org.opencms.widgets.I_CmsADEWidget#getInitCall() 095 */ 096 @Override 097 public String getInitCall() { 098 099 return null; 100 } 101 102 /** 103 * @see org.opencms.widgets.I_CmsADEWidget#getJavaScriptResourceLinks(org.opencms.file.CmsObject) 104 */ 105 @Override 106 public List<String> getJavaScriptResourceLinks(CmsObject cms) { 107 108 return null; 109 } 110 111 /** 112 * @see org.opencms.widgets.CmsSelectWidget#getWidgetName() 113 */ 114 @Override 115 public String getWidgetName() { 116 117 return CmsFilterSelectWidget.class.getName(); 118 } 119 120 /** 121 * @see org.opencms.widgets.I_CmsADEWidget#isInternal() 122 */ 123 @Override 124 public boolean isInternal() { 125 126 return true; 127 } 128 129 130 /** 131 * @see org.opencms.widgets.I_CmsWidget#newInstance() 132 */ 133 @Override 134 public I_CmsWidget newInstance() { 135 136 return new CmsTypeFilterWidget(""); 137 } 138 139 /** 140 * @see org.opencms.widgets.A_CmsWidget#setConfiguration(java.lang.String) 141 */ 142 @Override 143 public void setConfiguration(String config) { 144 145 super.setConfiguration(createConfiguration()); 146 } 147 148 /** 149 * Internal method to create the configuration string from the available types.<p> 150 * 151 * @return the configuration string 152 */ 153 private String createConfiguration() { 154 155 CmsResourceManager resManager = OpenCms.getResourceManager(); 156 if (resManager == null) { 157 // can happen during the OpenCms startup 158 return ""; 159 } 160 List<I_CmsResourceType> resTypes = resManager.getResourceTypes(); 161 List<String> options = new ArrayList<String>(); 162 for (I_CmsResourceType resType : resTypes) { 163 if (resType.isDirectEditable()) { 164 options.add(resType.getTypeName()); 165 } 166 } 167 Collections.sort(options); 168 return Joiner.on("|").join(options); 169 } 170 171}