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.tools.projects; 029 030import org.opencms.file.history.CmsHistoryProject; 031import org.opencms.jsp.CmsJspActionElement; 032import org.opencms.main.CmsException; 033import org.opencms.main.CmsRuntimeException; 034import org.opencms.workplace.list.A_CmsListDialog; 035import org.opencms.workplace.list.CmsListColumnAlignEnum; 036import org.opencms.workplace.list.CmsListColumnDefinition; 037import org.opencms.workplace.list.CmsListDateMacroFormatter; 038import org.opencms.workplace.list.CmsListDirectAction; 039import org.opencms.workplace.list.CmsListItem; 040import org.opencms.workplace.list.CmsListItemDetails; 041import org.opencms.workplace.list.CmsListItemDetailsFormatter; 042import org.opencms.workplace.list.CmsListMetadata; 043import org.opencms.workplace.list.CmsListOrderEnum; 044import org.opencms.workplace.list.CmsListSearchAction; 045 046import java.util.ArrayList; 047import java.util.Date; 048import java.util.Iterator; 049import java.util.List; 050 051import javax.servlet.http.HttpServletRequest; 052import javax.servlet.http.HttpServletResponse; 053import javax.servlet.jsp.PageContext; 054 055/** 056 * Main project management view.<p> 057 * 058 * @since 6.0.0 059 */ 060public class CmsProjectHistoryList extends A_CmsListDialog { 061 062 /** list action constant. */ 063 public static final String LIST_ACTION_ICON = "ai"; 064 065 /** list column id constant. */ 066 public static final String LIST_COLUMN_CREATION = "cc"; 067 068 /** list column id constant. */ 069 public static final String LIST_COLUMN_DESCRIPTION = "cd"; 070 071 /** list column id constant. */ 072 public static final String LIST_COLUMN_ICON = "ci"; 073 074 /** list column id constant. */ 075 public static final String LIST_COLUMN_MANAGER = "cm"; 076 077 /** list column id constant. */ 078 public static final String LIST_COLUMN_NAME = "cn"; 079 080 /** list column id constant. */ 081 public static final String LIST_COLUMN_OWNER = "co"; 082 083 /** list column id constant. */ 084 public static final String LIST_COLUMN_PUBLISHED_BY = "cb"; 085 086 /** list column id constant. */ 087 public static final String LIST_COLUMN_PUBLISHED_DATE = "cp"; 088 089 /** list column id constant. */ 090 public static final String LIST_COLUMN_USER = "cu"; 091 092 /** list detail constant. */ 093 public static final String LIST_DETAIL_RESOURCES = "dr"; 094 095 /** list id constant. */ 096 public static final String LIST_ID = "lph"; 097 098 /** 099 * Public constructor.<p> 100 * 101 * @param jsp an initialized JSP action element 102 */ 103 public CmsProjectHistoryList(CmsJspActionElement jsp) { 104 105 super( 106 jsp, 107 LIST_ID, 108 Messages.get().container(Messages.GUI_PROJECTHISTORY_LIST_NAME_0), 109 LIST_COLUMN_PUBLISHED_DATE, 110 CmsListOrderEnum.ORDER_DESCENDING, 111 null); 112 } 113 114 /** 115 * Public constructor with JSP variables.<p> 116 * 117 * @param context the JSP page context 118 * @param req the JSP request 119 * @param res the JSP response 120 */ 121 public CmsProjectHistoryList(PageContext context, HttpServletRequest req, HttpServletResponse res) { 122 123 this(new CmsJspActionElement(context, req, res)); 124 } 125 126 /** 127 * This method should handle every defined list multi action, 128 * by comparing <code>{@link #getParamListAction()}</code> with the id 129 * of the action to execute.<p> 130 * 131 * @throws CmsRuntimeException to signal that an action is not supported 132 * 133 */ 134 @Override 135 public void executeListMultiActions() throws CmsRuntimeException { 136 137 throwListUnsupportedActionException(); 138 } 139 140 /** 141 * This method should handle every defined list single action, 142 * by comparing <code>{@link #getParamListAction()}</code> with the id 143 * of the action to execute.<p> 144 * 145 * @throws CmsRuntimeException to signal that an action is not supported or in case an action failed 146 */ 147 @Override 148 public void executeListSingleActions() throws CmsRuntimeException { 149 150 throwListUnsupportedActionException(); 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 // get content 160 List projects = getList().getAllContent(); 161 Iterator itProjects = projects.iterator(); 162 while (itProjects.hasNext()) { 163 CmsListItem item = (CmsListItem)itProjects.next(); 164 try { 165 if (detailId.equals(LIST_DETAIL_RESOURCES)) { 166 CmsHistoryProject project = getCms().readHistoryProject(Integer.valueOf(item.getId()).intValue()); 167 StringBuffer html = new StringBuffer(512); 168 Iterator resources = project.getProjectResources().iterator(); 169 while (resources.hasNext()) { 170 html.append(resources.next().toString()); 171 html.append("<br>"); 172 } 173 item.set(LIST_DETAIL_RESOURCES, html.toString()); 174 } 175 } catch (Exception e) { 176 // ignore 177 } 178 } 179 } 180 181 /** 182 * @see org.opencms.workplace.list.A_CmsListDialog#getListItems() 183 */ 184 @Override 185 protected List getListItems() throws CmsException { 186 187 List ret = new ArrayList(); 188 // get content 189 List projects = getCms().getAllHistoricalProjects(); 190 Iterator itProjects = projects.iterator(); 191 while (itProjects.hasNext()) { 192 CmsHistoryProject project = (CmsHistoryProject)itProjects.next(); 193 CmsListItem item = getList().newItem(Integer.valueOf(project.getPublishTag()).toString()); 194 item.set(LIST_COLUMN_NAME, project.getName()); 195 item.set(LIST_COLUMN_DESCRIPTION, project.getDescription()); 196 try { 197 item.set(LIST_COLUMN_OWNER, project.getOwnerName(getCms())); 198 } catch (Exception e) { 199 // ignore 200 } 201 try { 202 item.set(LIST_COLUMN_MANAGER, project.getGroupManagersName(getCms())); 203 } catch (Exception e) { 204 // ignore 205 } 206 try { 207 item.set(LIST_COLUMN_USER, project.getGroupUsersName(getCms())); 208 } catch (Exception e) { 209 // ignore 210 } 211 try { 212 item.set(LIST_COLUMN_PUBLISHED_DATE, new Date(project.getPublishingDate())); 213 } catch (Exception e) { 214 // ignore 215 } 216 try { 217 item.set(LIST_COLUMN_PUBLISHED_BY, project.getPublishedByName(getCms())); 218 } catch (Exception e) { 219 // ignore 220 } 221 item.set(LIST_COLUMN_CREATION, new Date(project.getDateCreated())); 222 ret.add(item); 223 } 224 225 return ret; 226 } 227 228 /** 229 * @see org.opencms.workplace.CmsWorkplace#initMessages() 230 */ 231 @Override 232 protected void initMessages() { 233 234 // add specific dialog resource bundle 235 addMessages(Messages.get().getBundleName()); 236 // add default resource bundles 237 super.initMessages(); 238 } 239 240 /** 241 * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata) 242 */ 243 @Override 244 protected void setColumns(CmsListMetadata metadata) { 245 246 // create column for icon 247 CmsListColumnDefinition iconCol = new CmsListColumnDefinition(LIST_COLUMN_ICON); 248 iconCol.setName(Messages.get().container(Messages.GUI_PROJECTS_LIST_COLS_ICON_0)); 249 iconCol.setHelpText(Messages.get().container(Messages.GUI_PROJECTS_LIST_COLS_ICON_HELP_0)); 250 iconCol.setWidth("20"); 251 iconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 252 iconCol.setSorteable(false); 253 // add files action 254 CmsListDirectAction iconAction = new CmsListDirectAction(LIST_ACTION_ICON); 255 iconAction.setName(Messages.get().container(Messages.GUI_PROJECTS_LIST_ACTION_ICON_NAME_0)); 256 iconAction.setHelpText(Messages.get().container(Messages.GUI_PROJECTS_LIST_ACTION_ICON_HELP_0)); 257 iconAction.setIconPath(CmsProjectsList.PATH_BUTTONS + "project.png"); 258 iconAction.setEnabled(false); 259 iconCol.addDirectAction(iconAction); 260 // add it to the list definition 261 metadata.addColumn(iconCol); 262 263 // create column for name 264 CmsListColumnDefinition nameCol = new CmsListColumnDefinition(LIST_COLUMN_NAME); 265 nameCol.setName(Messages.get().container(Messages.GUI_PROJECTS_LIST_COLS_NAME_0)); 266 nameCol.setWidth("10%"); 267 // add it to the list definition 268 metadata.addColumn(nameCol); 269 270 // add column for description 271 CmsListColumnDefinition descriptionCol = new CmsListColumnDefinition(LIST_COLUMN_DESCRIPTION); 272 descriptionCol.setName(Messages.get().container(Messages.GUI_PROJECTS_LIST_COLS_DESCRIPTION_0)); 273 descriptionCol.setWidth("30%"); 274 descriptionCol.setTextWrapping(true); 275 metadata.addColumn(descriptionCol); 276 277 // add column for published date 278 CmsListColumnDefinition publishingDateCol = new CmsListColumnDefinition(LIST_COLUMN_PUBLISHED_DATE); 279 publishingDateCol.setName(Messages.get().container(Messages.GUI_PROJECTS_LIST_COLS_PUBLISHED_DATE_0)); 280 publishingDateCol.setWidth("10%"); 281 publishingDateCol.setFormatter(CmsListDateMacroFormatter.getDefaultDateFormatter()); 282 metadata.addColumn(publishingDateCol); 283 284 // add column for published by 285 CmsListColumnDefinition publishedByCol = new CmsListColumnDefinition(LIST_COLUMN_PUBLISHED_BY); 286 publishedByCol.setName(Messages.get().container(Messages.GUI_PROJECTS_LIST_COLS_PUBLISHED_BY_0)); 287 publishedByCol.setWidth("10%"); 288 metadata.addColumn(publishedByCol); 289 290 // add column for owner user 291 CmsListColumnDefinition ownerCol = new CmsListColumnDefinition(LIST_COLUMN_OWNER); 292 ownerCol.setName(Messages.get().container(Messages.GUI_PROJECTS_LIST_COLS_OWNER_0)); 293 ownerCol.setWidth("10%"); 294 metadata.addColumn(ownerCol); 295 296 // add column for manager group 297 CmsListColumnDefinition managerCol = new CmsListColumnDefinition(LIST_COLUMN_MANAGER); 298 managerCol.setName(Messages.get().container(Messages.GUI_PROJECTS_LIST_COLS_MANAGER_0)); 299 managerCol.setWidth("10%"); 300 metadata.addColumn(managerCol); 301 302 // add column for user group 303 CmsListColumnDefinition userCol = new CmsListColumnDefinition(LIST_COLUMN_USER); 304 userCol.setName(Messages.get().container(Messages.GUI_PROJECTS_LIST_COLS_USER_0)); 305 userCol.setWidth("10%"); 306 metadata.addColumn(userCol); 307 308 // add column for creation date 309 CmsListColumnDefinition creationCol = new CmsListColumnDefinition(LIST_COLUMN_CREATION); 310 creationCol.setName(Messages.get().container(Messages.GUI_PROJECTS_LIST_COLS_CREATION_0)); 311 creationCol.setWidth("10%"); 312 creationCol.setFormatter(CmsListDateMacroFormatter.getDefaultDateFormatter()); 313 metadata.addColumn(creationCol); 314 } 315 316 /** 317 * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata) 318 */ 319 @Override 320 protected void setIndependentActions(CmsListMetadata metadata) { 321 322 // add publishing info details 323 CmsListItemDetails resourcesDetails = new CmsListItemDetails(LIST_DETAIL_RESOURCES); 324 resourcesDetails.setAtColumn(LIST_COLUMN_NAME); 325 resourcesDetails.setVisible(false); 326 resourcesDetails.setShowActionName( 327 Messages.get().container(Messages.GUI_PROJECTS_DETAIL_SHOW_RESOURCES_NAME_0)); 328 resourcesDetails.setShowActionHelpText( 329 Messages.get().container(Messages.GUI_PROJECTS_DETAIL_SHOW_RESOURCES_HELP_0)); 330 resourcesDetails.setHideActionName( 331 Messages.get().container(Messages.GUI_PROJECTS_DETAIL_HIDE_RESOURCES_NAME_0)); 332 resourcesDetails.setHideActionHelpText( 333 Messages.get().container(Messages.GUI_PROJECTS_DETAIL_HIDE_RESOURCES_HELP_0)); 334 resourcesDetails.setName(Messages.get().container(Messages.GUI_PROJECTS_DETAIL_RESOURCES_NAME_0)); 335 resourcesDetails.setFormatter( 336 new CmsListItemDetailsFormatter(Messages.get().container(Messages.GUI_PROJECTS_DETAIL_RESOURCES_NAME_0))); 337 metadata.addItemDetails(resourcesDetails); 338 339 // makes the list searchable 340 CmsListSearchAction searchAction = new CmsListSearchAction(metadata.getColumnDefinition(LIST_COLUMN_NAME)); 341 searchAction.addColumn(metadata.getColumnDefinition(LIST_COLUMN_DESCRIPTION)); 342 metadata.setSearchAction(searchAction); 343 344 } 345 346 /** 347 * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata) 348 */ 349 @Override 350 protected void setMultiActions(CmsListMetadata metadata) { 351 352 //noop 353 } 354 355}