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.configuration.preferences; 029 030import org.opencms.ade.configuration.CmsElementView; 031import org.opencms.file.CmsObject; 032import org.opencms.main.OpenCms; 033import org.opencms.xml.content.CmsXmlContentProperty; 034 035import java.util.Collection; 036import java.util.Locale; 037 038/** 039 * Element view preference configuration.<p> 040 */ 041public class CmsElementViewPreference extends CmsBuiltinPreference { 042 043 /** The preference name. */ 044 public static final String PREFERENCE_NAME = "elementView"; 045 046 /** The nice name. */ 047 private static final String NICE_NAME = "%(key." 048 + org.opencms.workplace.commons.Messages.GUI_PREF_ELEMENT_VIEW_0 049 + ")"; 050 051 /** Preference name for the explorer. */ 052 public static final String EXPLORER_PREFERENCE_NAME = "explorerElementView"; 053 054 /** 055 * Constructor.<p> 056 * 057 * @param propName the name of the bean property used to access this preference 058 */ 059 public CmsElementViewPreference(String propName) { 060 061 super(propName); 062 m_basic = false; 063 } 064 065 /** 066 * Gets the nice name key.<p> 067 * 068 * @return the nice name key 069 */ 070 public String getNiceName() { 071 072 return NICE_NAME; 073 } 074 075 /** 076 * @see org.opencms.configuration.preferences.CmsBuiltinPreference#getPropertyDefinition() 077 */ 078 @Override 079 public CmsXmlContentProperty getPropertyDefinition() { 080 081 CmsXmlContentProperty prop = new CmsXmlContentProperty( 082 getName(), //name 083 "string", //type 084 null, //widget 085 null, //widgetconfig 086 null, //regex 087 null, //ruletype 088 getDefaultValue(), //default 089 getNiceName(), //nicename 090 null, //description 091 null, //error 092 null //preferfolder 093 ); 094 return prop; 095 } 096 097 /** 098 * @see org.opencms.configuration.preferences.A_CmsPreference#getPropertyDefinition(org.opencms.file.CmsObject) 099 */ 100 @Override 101 public CmsXmlContentProperty getPropertyDefinition(CmsObject cms) { 102 103 Collection<CmsElementView> views = OpenCms.getADEManager().getElementViews(cms).values(); 104 Locale wpLocale = OpenCms.getWorkplaceManager().getWorkplaceLocale(cms); 105 StringBuffer resultBuffer = new StringBuffer(); 106 boolean first = true; 107 for (CmsElementView view : views) { 108 if (view.hasPermission(cms, null) && !view.isOther()) { 109 if (!first) { 110 resultBuffer.append("|"); 111 } 112 first = false; 113 resultBuffer.append(view.getId().toString()); 114 resultBuffer.append(":"); 115 resultBuffer.append(view.getTitle(cms, wpLocale)); 116 } 117 } 118 CmsXmlContentProperty prop = new CmsXmlContentProperty( 119 getName(), //name 120 "string", //type 121 "select_notnull", //widget 122 resultBuffer.toString(), //widgetconfig 123 null, //regex 124 null, //ruletype 125 getDefaultValue(), //default 126 getNiceName(), //nicename 127 null, //description 128 null, //error 129 null //preferfolder 130 ); 131 return prop; 132 } 133}