📄 cmslistcolumndefinition.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListColumnDefinition.java,v $
* Date : $Date: 2006/03/27 14:52:28 $
* Version: $Revision: 1.25 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.workplace.list;
import org.opencms.i18n.CmsMessageContainer;
import org.opencms.i18n.CmsMessages;
import org.opencms.main.CmsIllegalArgumentException;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.tools.A_CmsHtmlIconButton;
import org.opencms.workplace.tools.CmsHtmlIconButtonStyleEnum;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
/**
* Html list column definition.<p>
*
* @author Michael Moossen
*
* @version $Revision: 1.25 $
*
* @since 6.0.0
*/
public class CmsListColumnDefinition {
/** Standard list button location. */
public static final String ICON_DOWN = "list/arrow_down.png";
/** Standard list button location. */
public static final String ICON_UP = "list/arrow_up.png";
/** Column alignment. */
private CmsListColumnAlignEnum m_align = CmsListColumnAlignEnum.ALIGN_LEFT;
/** Comparator for sorting. */
private I_CmsListItemComparator m_comparator = new CmsListItemDefaultComparator();
/** Default action. */
private List m_defaultActions = new ArrayList();
/** List of actions. */
private List m_directActions = new ArrayList();
/** Data formatter. */
private I_CmsListFormatter m_formatter;
/** Customized help text. */
private CmsMessageContainer m_helpText;
/** Unique id. */
private final String m_id;
/** List id. */
private String m_listId;
/** Display name. */
private CmsMessageContainer m_name;
/** Is printable flag. */
private boolean m_printable = true;
/** Flag for text wrapping. */
private boolean m_textWrapping = false;
/** Visible Flag. */
private boolean m_visible = true;
/** Column width. */
private String m_width;
/**
* Default Constructor.<p>
*
* @param id the unique id
*/
public CmsListColumnDefinition(String id) {
if (CmsStringUtil.isEmptyOrWhitespaceOnly(id)) {
throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_LIST_INVALID_NULL_ARG_1, "id"));
}
m_id = id;
}
/**
* Adds a default Action.<p>
*
* A column could have more than one default action if the visibilities are complementary.<p>
*
* @param defaultAction the default Action to add
*/
public void addDefaultAction(CmsListDefaultAction defaultAction) {
if (m_listId != null) {
// set the list id
defaultAction.setListId(m_listId);
}
// set the column id
defaultAction.setColumnForLink(getId());
m_defaultActions.add(defaultAction);
}
/**
* Adds a new action to the column.<p>
*
* @param listAction the action to add
*/
public void addDirectAction(I_CmsListDirectAction listAction) {
if (m_listId != null) {
listAction.setListId(m_listId);
}
m_directActions.add(listAction);
}
/**
* returns the csv output for a cell.<p>
*
* @param item the item to render the cell for
* @param wp the workplace context
*
* @return csv output
*/
public String csvCell(CmsListItem item, CmsWorkplace wp) {
if (!isVisible()) {
return "";
}
StringBuffer csv = new StringBuffer(512);
if (m_formatter == null) {
// unformatted output
if (item.get(m_id) != null) {
// null values are not showed by default
csv.append(item.get(m_id).toString());
} else {
Iterator itActions = m_directActions.iterator();
while (itActions.hasNext()) {
I_CmsListDirectAction action = (I_CmsListDirectAction)itActions.next();
if (action.isVisible()) {
action.setItem(item);
csv.append(action.getName().key(wp.getLocale()));
}
}
}
} else {
// formatted output
csv.append(m_formatter.format(item.get(m_id), wp.getLocale()));
}
return csv.toString();
}
/**
* Returns the csv output for a column header.<p>
*
* @param wp the workplace instance
*
* @return csv header
*/
public String csvHeader(CmsWorkplace wp) {
if (!isVisible()) {
return "";
}
return getName().key(wp.getLocale());
}
/**
* Returns the align.<p>
*
* @return the align
*/
public CmsListColumnAlignEnum getAlign() {
return m_align;
}
/**
* Returns a default action by id.<p>
*
* @param actionId the id of the action
*
* @return the action if found or null
*/
public CmsListDefaultAction getDefaultAction(String actionId) {
Iterator it = m_defaultActions.iterator();
while (it.hasNext()) {
CmsListDefaultAction action = (CmsListDefaultAction)it.next();
if (action.getId().equals(actionId)) {
return action;
}
}
return null;
}
/**
* Returns the default Action Ids list.<p>
*
* @return the default Action Ids list
*/
public List getDefaultActionIds() {
List ids = new ArrayList();
Iterator itDefActions = m_defaultActions.iterator();
while (itDefActions.hasNext()) {
I_CmsListDirectAction action = (I_CmsListDirectAction)itDefActions.next();
ids.add(action.getId());
}
return Collections.unmodifiableList(ids);
}
/**
* Returns the default Actions list.<p>
*
* @return the default Actions list
*/
public List getDefaultActions() {
return Collections.unmodifiableList(m_defaultActions);
}
/**
* Returns a direct action by id.<p>
*
* @param actionId the id of the action
*
* @return the action if found or null
*/
public I_CmsListDirectAction getDirectAction(String actionId) {
Iterator it = m_directActions.iterator();
while (it.hasNext()) {
I_CmsListDirectAction action = (I_CmsListDirectAction)it.next();
if (action.getId().equals(actionId)) {
return action;
}
}
return null;
}
/**
* Returns the direct Action Ids list.<p>
*
* @return the direct Action Ids list
*/
public List getDirectActionIds() {
List ids = new ArrayList();
Iterator itDirActions = m_directActions.iterator();
while (itDirActions.hasNext()) {
I_CmsListDirectAction action = (I_CmsListDirectAction)itDirActions.next();
ids.add(action.getId());
}
return Collections.unmodifiableList(ids);
}
/**
* Returns all direct actions.<p>
*
* @return a list of <code>{@link I_CmsListDirectAction}</code>s.
*/
public List getDirectActions() {
return Collections.unmodifiableList(m_directActions);
}
/**
* Returns the data formatter.<p>
*
* @return the data formatter
*/
public I_CmsListFormatter getFormatter() {
return m_formatter;
}
/**
* Returns the customized help Text.<p>
*
* if <code>null</code> a default help text indicating the sort actions is used.<p>
*
* @return the customized help Text
*/
public CmsMessageContainer getHelpText() {
return m_helpText;
}
/**
* Returns the id.<p>
*
* @return the id
*/
public String getId() {
return m_id;
}
/**
* Returns the comparator, used for sorting.<p>
*
* if no comparator was set, the default list item comparator is used.<p>
*
* @return the comparator
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -