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 GmbH & Co. KG, 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.workplace.commons; 029 030import org.opencms.db.CmsUserSettings; 031import org.opencms.file.CmsObject; 032import org.opencms.file.CmsResource; 033import org.opencms.file.CmsResourceFilter; 034import org.opencms.jsp.CmsJspActionElement; 035import org.opencms.main.CmsException; 036import org.opencms.main.CmsRuntimeException; 037import org.opencms.main.OpenCms; 038import org.opencms.util.CmsStringUtil; 039import org.opencms.workplace.explorer.CmsResourceUtil; 040import org.opencms.workplace.list.A_CmsListExplorerDialog; 041import org.opencms.workplace.list.A_CmsListResourceCollector; 042import org.opencms.workplace.list.CmsListExplorerColumn; 043import org.opencms.workplace.list.CmsListItem; 044import org.opencms.workplace.list.CmsListMetadata; 045import org.opencms.workplace.list.I_CmsListResourceCollector; 046 047import java.util.Arrays; 048import java.util.Collections; 049import java.util.List; 050import java.util.Map; 051 052/** 053 * List to show siblings of a given resource.<p> 054 * 055 * @since 6.9.2 056 */ 057public class CmsShowSiblingsList extends A_CmsListExplorerDialog { 058 059 /** The list id for this class. */ 060 private static final String LIST_ID = "lshsib"; 061 062 /** The resource collector for this class. */ 063 private I_CmsListResourceCollector m_collector; 064 065 /** 066 * Default constructor.<p> 067 * 068 * @param jsp an initialized JSP action element 069 */ 070 public CmsShowSiblingsList(CmsJspActionElement jsp) { 071 072 super(jsp, LIST_ID, Messages.get().container(Messages.GUI_SHOW_SIBLINGS_LIST_NAME_0)); 073 074 // set the right resource util parameters 075 CmsResourceUtil resUtil = getResourceUtil(); 076 resUtil.setAbbrevLength(50); 077 resUtil.setRelativeTo(getCms().getRequestContext().addSiteRoot(jsp.getRequestContext().getFolderUri())); 078 resUtil.setSiteMode(CmsResourceUtil.SITE_MODE_MATCHING); 079 } 080 081 /** 082 * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions() 083 */ 084 @Override 085 public void executeListMultiActions() throws CmsRuntimeException { 086 087 throwListUnsupportedActionException(); 088 } 089 090 /** 091 * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions() 092 */ 093 @Override 094 public void executeListSingleActions() throws CmsRuntimeException { 095 096 throwListUnsupportedActionException(); 097 } 098 099 /** 100 * @see org.opencms.workplace.list.A_CmsListExplorerDialog#getCollector() 101 */ 102 @Override 103 public I_CmsListResourceCollector getCollector() { 104 105 if (m_collector == null) { 106 m_collector = new A_CmsListResourceCollector(this) { 107 108 /** Parameter of the default collector name. */ 109 private static final String COLLECTOR_NAME = "showSiblings"; 110 111 /** 112 * @see org.opencms.file.collectors.I_CmsResourceCollector#getCollectorNames() 113 */ 114 @Override 115 public List<String> getCollectorNames() { 116 117 return Collections.unmodifiableList(Arrays.asList(new String[] {COLLECTOR_NAME})); 118 } 119 120 /** 121 * @see org.opencms.workplace.list.A_CmsListResourceCollector#getResources(org.opencms.file.CmsObject, java.util.Map) 122 */ 123 @Override 124 public List<CmsResource> getResources(CmsObject cms, Map<String, String> params) throws CmsException { 125 126 return getCms().readSiblings( 127 ((CmsShowSiblingsList)getWp()).getParamResource(), 128 CmsResourceFilter.ALL); 129 } 130 131 /** 132 * @see org.opencms.workplace.list.A_CmsListResourceCollector#setAdditionalColumns(org.opencms.workplace.list.CmsListItem, org.opencms.workplace.explorer.CmsResourceUtil) 133 */ 134 @Override 135 protected void setAdditionalColumns(CmsListItem item, CmsResourceUtil resUtil) { 136 137 // empty 138 } 139 }; 140 } 141 return m_collector; 142 } 143 144 /** 145 * @see org.opencms.workplace.list.A_CmsListDialog#defaultActionHtmlStart() 146 */ 147 @Override 148 protected String defaultActionHtmlStart() { 149 150 return getList().listJs() + CmsListExplorerColumn.getExplorerStyleDef() + dialogContentStart(getParamTitle()); 151 } 152 153 /** 154 * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String) 155 */ 156 @Override 157 protected void fillDetails(String detailId) { 158 159 // empty 160 } 161 162 /** 163 * @see org.opencms.workplace.list.A_CmsListExplorerDialog#setColumns(org.opencms.workplace.list.CmsListMetadata) 164 */ 165 @Override 166 protected void setColumns(CmsListMetadata metadata) { 167 168 super.setColumns(metadata); 169 metadata.getColumnDefinition(A_CmsListExplorerDialog.LIST_COLUMN_NAME).setName( 170 org.opencms.workplace.explorer.Messages.get().container( 171 org.opencms.workplace.explorer.Messages.GUI_INPUT_PATH_0)); 172 } 173 174 /** 175 * @see org.opencms.workplace.list.A_CmsListExplorerDialog#isColumnVisible(int) 176 */ 177 @Override 178 protected boolean isColumnVisible(int colFlag) { 179 180 boolean isVisible = (colFlag == CmsUserSettings.FILELIST_TITLE); 181 isVisible = isVisible || (colFlag == LIST_COLUMN_TYPEICON.hashCode()); 182 isVisible = isVisible || (colFlag == LIST_COLUMN_LOCKICON.hashCode()); 183 isVisible = isVisible || (colFlag == LIST_COLUMN_PROJSTATEICON.hashCode()); 184 isVisible = isVisible || (colFlag == LIST_COLUMN_NAME.hashCode()); 185 isVisible = isVisible || (colFlag == CmsUserSettings.FILELIST_TYPE); 186 isVisible = isVisible || (colFlag == CmsUserSettings.FILELIST_SIZE); 187 isVisible = isVisible 188 || ((colFlag == LIST_COLUMN_SITE.hashCode()) && (OpenCms.getSiteManager().getSites().size() > 1)); 189 return isVisible; 190 } 191 192 /** 193 * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata) 194 */ 195 @Override 196 protected void setMultiActions(CmsListMetadata metadata) { 197 198 // empty 199 } 200 201 /** 202 * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters() 203 */ 204 @Override 205 protected void validateParamaters() throws Exception { 206 207 if (CmsStringUtil.isEmptyOrWhitespaceOnly(getParamResource())) { 208 throw new Exception(); 209 } 210 } 211}