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.list; 029 030import org.opencms.i18n.CmsMessageContainer; 031import org.opencms.main.CmsIllegalArgumentException; 032import org.opencms.util.CmsStringUtil; 033import org.opencms.workplace.tools.A_CmsHtmlIconButton; 034 035/** 036 * The default skeleton for a list action.<p> 037 * 038 * @since 6.0.0 039 */ 040public abstract class A_CmsListAction extends A_CmsHtmlIconButton implements I_CmsListAction { 041 042 /** Confirmation Message. */ 043 private CmsMessageContainer m_confirmationMsg; 044 045 /** The id of the associated list. */ 046 private String m_listId; 047 048 /** The related workplace dialog object. */ 049 private A_CmsListDialog m_wp; 050 051 /** 052 * Default Constructor.<p> 053 * 054 * @param id unique id 055 */ 056 public A_CmsListAction(String id) { 057 058 super(id); 059 if (CmsStringUtil.isEmptyOrWhitespaceOnly(id)) { 060 throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_LIST_INVALID_NULL_ARG_1, "id")); 061 } 062 setConfirmationMessage(null); 063 } 064 065 /** 066 * Generates html for the confirmation message when having one confirmation message 067 * for several actions.<p> 068 * 069 * @param confId the id of the confirmation message 070 * @param confText the confirmation message 071 * 072 * @return html code 073 */ 074 public static String defaultConfirmationHtml(String confId, String confText) { 075 076 StringBuffer html = new StringBuffer(1024); 077 html.append("<div class='hide' id='conf"); 078 html.append(confId); 079 html.append("'>"); 080 html.append(CmsStringUtil.isEmptyOrWhitespaceOnly(confText) ? "null" : confText); 081 html.append("</div>\n"); 082 return html.toString(); 083 } 084 085 /** 086 * @see org.opencms.workplace.list.I_CmsListAction#buttonHtml() 087 */ 088 public String buttonHtml() { 089 090 return buttonHtml(getWp()); 091 } 092 093 /** 094 * @see org.opencms.workplace.list.I_CmsListAction#getConfirmationMessage() 095 */ 096 public CmsMessageContainer getConfirmationMessage() { 097 098 return m_confirmationMsg; 099 } 100 101 /** 102 * @see org.opencms.workplace.list.I_CmsListAction#getListId() 103 */ 104 public String getListId() { 105 106 return m_listId; 107 } 108 109 /** 110 * @see org.opencms.workplace.list.I_CmsListAction#getWp() 111 */ 112 public A_CmsListDialog getWp() { 113 114 return m_wp; 115 } 116 117 /** 118 * @see org.opencms.workplace.list.I_CmsListAction#setConfirmationMessage(org.opencms.i18n.CmsMessageContainer) 119 */ 120 public void setConfirmationMessage(CmsMessageContainer confirmationMsg) { 121 122 if (confirmationMsg == null) { 123 confirmationMsg = EMPTY_MESSAGE; 124 } 125 m_confirmationMsg = confirmationMsg; 126 } 127 128 /** 129 * @see org.opencms.workplace.list.I_CmsListAction#setListId(java.lang.String) 130 */ 131 public void setListId(String listId) { 132 133 if (CmsStringUtil.isEmptyOrWhitespaceOnly(listId)) { 134 throw new CmsIllegalArgumentException( 135 Messages.get().container(Messages.ERR_LIST_INVALID_NULL_ARG_1, "listId")); 136 } 137 m_listId = listId; 138 } 139 140 /** 141 * @see org.opencms.workplace.list.I_CmsListAction#setWp(org.opencms.workplace.list.A_CmsListDialog) 142 */ 143 public void setWp(A_CmsListDialog wp) { 144 145 m_wp = wp; 146 } 147}