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 CmsTypeComboWidget extends CmsComboWidget { 049 050 /** 051 * Default constructor.<p> 052 */ 053 public CmsTypeComboWidget() { 054 055 super(); 056 } 057 058 /** 059 * Constructor with a configuration parameter.<p> 060 * @param config the configuration string 061 */ 062 public CmsTypeComboWidget(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.I_CmsADEWidget#isInternal() 113 */ 114 @Override 115 public boolean isInternal() { 116 117 return true; 118 } 119 120 /** 121 * @see org.opencms.widgets.I_CmsWidget#newInstance() 122 */ 123 @Override 124 public I_CmsWidget newInstance() { 125 126 return new CmsTypeComboWidget(""); 127 } 128 129 /** 130 * @see org.opencms.widgets.A_CmsWidget#setConfiguration(java.lang.String) 131 */ 132 @Override 133 public void setConfiguration(String config) { 134 135 super.setConfiguration(createConfiguration()); 136 } 137 138 /** 139 * Internal method to create the configuration string from the available types.<p> 140 * 141 * @return the configuration string 142 */ 143 private String createConfiguration() { 144 145 CmsResourceManager resManager = OpenCms.getResourceManager(); 146 if (resManager == null) { 147 // can happen during the OpenCms startup 148 return ""; 149 } 150 List<I_CmsResourceType> resTypes = resManager.getResourceTypes(); 151 List<String> options = new ArrayList<String>(); 152 for (I_CmsResourceType resType : resTypes) { 153 if (resType.isDirectEditable()) { 154 options.add(resType.getTypeName()); 155 } 156 } 157 Collections.sort(options); 158 return Joiner.on("|").join(options); 159 } 160 161}