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.jsp.CmsJspActionElement; 031import org.opencms.main.CmsException; 032import org.opencms.main.CmsRuntimeException; 033import org.opencms.relations.CmsCategory; 034import org.opencms.workplace.list.CmsListColumnAlignEnum; 035import org.opencms.workplace.list.CmsListColumnDefinition; 036import org.opencms.workplace.list.CmsListDirectAction; 037import org.opencms.workplace.list.CmsListItem; 038import org.opencms.workplace.list.CmsListMetadata; 039 040import java.util.List; 041 042import javax.servlet.http.HttpServletRequest; 043import javax.servlet.http.HttpServletResponse; 044import javax.servlet.jsp.PageContext; 045 046/** 047 * Resource categories view.<p> 048 * 049 * @since 6.9.2 050 */ 051public class CmsResourceCategoriesList extends A_CmsResourceCategoriesList { 052 053 /** list action id constant. */ 054 public static final String LIST_ACTION_REMOVE1 = "ar1"; 055 056 /** list action id constant. */ 057 public static final String LIST_ACTION_REMOVE2 = "ar2"; 058 059 /** list id constant. */ 060 public static final String LIST_ID = "lrc"; 061 062 /** list action id constant. */ 063 public static final String LIST_MACTION_REMOVE = "mr"; 064 065 /** 066 * Public constructor.<p> 067 * 068 * @param jsp an initialized JSP action element 069 */ 070 public CmsResourceCategoriesList(CmsJspActionElement jsp) { 071 072 this(jsp, LIST_ID); 073 } 074 075 /** 076 * Public constructor with JSP variables.<p> 077 * 078 * @param context the JSP page context 079 * @param req the JSP request 080 * @param res the JSP response 081 */ 082 public CmsResourceCategoriesList(PageContext context, HttpServletRequest req, HttpServletResponse res) { 083 084 this(new CmsJspActionElement(context, req, res)); 085 } 086 087 /** 088 * Protected constructor.<p> 089 * @param jsp an initialized JSP action element 090 * @param listId the id of the specialized list 091 */ 092 protected CmsResourceCategoriesList(CmsJspActionElement jsp, String listId) { 093 094 super(jsp, listId, Messages.get().container(Messages.GUI_RESOURCECATEGORIES_LIST_NAME_0), true); 095 } 096 097 /** 098 * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions() 099 */ 100 @Override 101 public void executeListSingleActions() throws CmsRuntimeException { 102 103 if (getParamListAction().equals(LIST_ACTION_REMOVE1) || getParamListAction().equals(LIST_ACTION_REMOVE2)) { 104 try { 105 // lock resource if autolock is enabled 106 checkLock(getParamResource()); 107 108 CmsListItem listItem = getSelectedItem(); 109 String categoryPath = listItem.getId(); 110 getCategoryService().removeResourceFromCategory(getCms(), getParamResource(), categoryPath); 111 getCategoryService().repairRelations(getCms(), getParamResource()); 112 } catch (CmsException e) { 113 throw new CmsRuntimeException(e.getMessageContainer(), e); 114 } 115 } else { 116 throwListUnsupportedActionException(); 117 } 118 listSave(); 119 } 120 121 /** 122 * @see org.opencms.workplace.list.A_CmsListDialog#defaultActionHtmlStart() 123 */ 124 @Override 125 protected String defaultActionHtmlStart() { 126 127 return getList().listJs() + dialogContentStart(getParamTitle()); 128 } 129 130 /** 131 * @see org.opencms.workplace.commons.A_CmsResourceCategoriesList#getCategories() 132 */ 133 @Override 134 protected List<CmsCategory> getCategories() throws CmsException { 135 136 return getResourceCategories(); 137 } 138 139 /** 140 * @see org.opencms.workplace.commons.A_CmsResourceCategoriesList#setStateActionCol(org.opencms.workplace.list.CmsListMetadata) 141 */ 142 @Override 143 protected void setStateActionCol(CmsListMetadata metadata) { 144 145 // create column for state change 146 CmsListColumnDefinition stateCol = new CmsListColumnDefinition(LIST_COLUMN_STATE); 147 stateCol.setName(Messages.get().container(Messages.GUI_CATEGORIES_LIST_COLS_STATE_0)); 148 stateCol.setHelpText(Messages.get().container(Messages.GUI_CATEGORIES_LIST_COLS_STATE_HELP_0)); 149 stateCol.setWidth("20"); 150 stateCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 151 stateCol.setSorteable(false); 152 // add remove action with confirmation message 153 CmsListDirectAction stateAction1 = new CmsListDirectAction(LIST_ACTION_REMOVE1) { 154 155 /** 156 * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible() 157 */ 158 @Override 159 public boolean isVisible() { 160 161 if ((getItem() == null) || ((Boolean)getItem().get(LIST_COLUMN_LEAFS)).booleanValue()) { 162 return false; 163 } 164 return true; 165 } 166 }; 167 stateAction1.setName(Messages.get().container(Messages.GUI_CATEGORIES_LIST_DEFACTION_REMOVE_NAME_0)); 168 stateAction1.setHelpText(Messages.get().container(Messages.GUI_CATEGORIES_LIST_DEFACTION_REMOVE_HELP_0)); 169 stateAction1.setIconPath(ICON_MINUS); 170 stateAction1.setConfirmationMessage( 171 Messages.get().container(Messages.GUI_CATEGORIES_LIST_DEFACTION_REMOVE_CONF_MORE_0)); 172 stateCol.addDirectAction(stateAction1); 173 // add remove action without confirmation message 174 CmsListDirectAction stateAction2 = new CmsListDirectAction(LIST_ACTION_REMOVE2) { 175 176 /** 177 * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible() 178 */ 179 @Override 180 public boolean isVisible() { 181 182 if ((getItem() == null) || ((Boolean)getItem().get(LIST_COLUMN_LEAFS)).booleanValue()) { 183 return true; 184 } 185 return false; 186 } 187 }; 188 stateAction2.setName(Messages.get().container(Messages.GUI_CATEGORIES_LIST_DEFACTION_REMOVE_NAME_0)); 189 stateAction2.setHelpText(Messages.get().container(Messages.GUI_CATEGORIES_LIST_DEFACTION_REMOVE_HELP_0)); 190 stateAction2.setIconPath(ICON_MINUS); 191 stateCol.addDirectAction(stateAction2); 192 // add it to the list definition 193 metadata.addColumn(stateCol); 194 } 195}