📄 cmslistmetadata.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListMetadata.java,v $
* Date : $Date: 2006/03/27 14:52:28 $
* Version: $Revision: 1.22 $
*
* 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.main.CmsIllegalStateException;
import org.opencms.util.CmsIdentifiableObjectContainer;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsWorkplace;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.TreeSet;
/**
* This is class contains all the information for defining a whole html list.<p>
*
* @author Michael Moossen
*
* @version $Revision: 1.22 $
*
* @since 6.0.0
*/
public class CmsListMetadata {
/** Container for column definitions. */
private CmsIdentifiableObjectContainer m_columns = new CmsIdentifiableObjectContainer(true, false);
/** Container for of independent actions. */
private CmsIdentifiableObjectContainer m_indepActions = new CmsIdentifiableObjectContainer(true, false);
/** Container for item detail definitions. */
private CmsIdentifiableObjectContainer m_itemDetails = new CmsIdentifiableObjectContainer(true, false);
/** The id of the list. */
private String m_listId;
/** Container for multi actions. */
private CmsIdentifiableObjectContainer m_multiActions = new CmsIdentifiableObjectContainer(true, false);
/** Search action. */
private CmsListSearchAction m_searchAction;
/** <code>true</code> if this metadata object should not be cached.<p>. */
private boolean m_volatile = false;
/**
* Default Constructor.<p>
*
* @param listId the id of the list
*/
public CmsListMetadata(String listId) {
m_listId = listId;
}
/**
* Adds a new column definition at the end.<p>
*
* By default a column is printable if it is the first column in the list,
* or if it is sorteable.<p>
*
* If you want to override this behaviour, use the
* {@link CmsListColumnDefinition#setPrintable(boolean)}
* method after calling this one.
*
* @param listColumn the column definition
*
* @see CmsIdentifiableObjectContainer
*/
public void addColumn(CmsListColumnDefinition listColumn) {
setListIdForColumn(listColumn);
if (m_columns.elementList().isEmpty()) {
listColumn.setPrintable(true);
} else {
listColumn.setPrintable(listColumn.isSorteable());
}
m_columns.addIdentifiableObject(listColumn.getId(), listColumn);
}
/**
* Adds a new column definition at the given position.<p>
*
* By default a column is printable if it is the first column in the list,
* or if it is sorteable.<p>
*
* If you want to override this behaviour, use the
* {@link CmsListColumnDefinition#setPrintable(boolean)}
* method after calling this one.
*
* @param listColumn the column definition
* @param position the position
*
* @see CmsIdentifiableObjectContainer
*/
public void addColumn(CmsListColumnDefinition listColumn, int position) {
setListIdForColumn(listColumn);
if (m_columns.elementList().isEmpty()) {
listColumn.setPrintable(true);
} else {
listColumn.setPrintable(listColumn.isSorteable());
}
m_columns.addIdentifiableObject(listColumn.getId(), listColumn, position);
}
/**
* Adds a list item independent action.<p>
*
* @param action the action
*/
public void addIndependentAction(I_CmsListAction action) {
action.setListId(getListId());
m_indepActions.addIdentifiableObject(action.getId(), action);
}
/**
* Adds a new item detail definition at the end.<p>
*
* @param itemDetail the item detail definition
*
* @see CmsIdentifiableObjectContainer
*/
public void addItemDetails(CmsListItemDetails itemDetail) {
itemDetail.setListId(getListId());
m_itemDetails.addIdentifiableObject(itemDetail.getId(), itemDetail);
}
/**
* Adds a new item detail definition at the given position.<p>
*
* @param itemDetail the item detail definition
* @param position the position
*
* @see CmsIdentifiableObjectContainer
*/
public void addItemDetails(CmsListItemDetails itemDetail, int position) {
itemDetail.setListId(getListId());
m_itemDetails.addIdentifiableObject(itemDetail.getId(), itemDetail, position);
}
/**
* Adds an action applicable to more than one list item at once.<p>
*
* It will be executed with a list of <code>{@link CmsListItem}</code>s.<p>
*
* @param multiAction the action
*/
public void addMultiAction(CmsListMultiAction multiAction) {
multiAction.setListId(getListId());
m_multiActions.addIdentifiableObject(multiAction.getId(), multiAction);
}
/**
* Generates the csv output for an empty table.<p>
*
* @return csv output
*/
public String csvEmptyList() {
StringBuffer html = new StringBuffer(512);
html.append("\n");
return html.toString();
}
/**
* Returns the csv output for the header of the list.<p>
*
* @param wp the workplace instance
*
* @return csv output
*/
public String csvHeader(CmsWorkplace wp) {
StringBuffer csv = new StringBuffer(1024);
Iterator itCols = m_columns.elementList().iterator();
while (itCols.hasNext()) {
CmsListColumnDefinition col = (CmsListColumnDefinition)itCols.next();
if (!col.isVisible()) {
continue;
}
csv.append(col.csvHeader(wp));
csv.append("\t");
}
csv.append("\n\n");
return csv.toString();
}
/**
* Returns the csv output for a list item.<p>
*
* @param item the list item to render
* @param wp the workplace context
*
* @return csv output
*/
public String csvItem(CmsListItem item, CmsWorkplace wp) {
StringBuffer csv = new StringBuffer(1024);
Iterator itCols = m_columns.elementList().iterator();
while (itCols.hasNext()) {
CmsListColumnDefinition col = (CmsListColumnDefinition)itCols.next();
if (!col.isVisible()) {
continue;
}
csv.append(col.csvCell(item, wp));
csv.append("\t");
}
csv.append("\n");
return csv.toString();
}
/**
* Returns a column definition object for a given column id.<p>
*
* @param columnId the column id
*
* @return the column definition, or <code>null</code> if not present
*/
public CmsListColumnDefinition getColumnDefinition(String columnId) {
return (CmsListColumnDefinition)m_columns.getObject(columnId);
}
/**
* Returns all columns definitions.<p>
*
* @return a list of <code>{@link CmsListColumnDefinition}</code>s.
*/
public List getColumnDefinitions() {
return m_columns.elementList();
}
/**
* Returns an independent action object for a given id.<p>
*
* @param actionId the id
*
* @return the independent action, or <code>null</code> if not present
*/
public I_CmsListAction getIndependentAction(String actionId) {
return (I_CmsListAction)m_indepActions.getObject(actionId);
}
/**
* Returns the list of independent actions.<p>
*
* @return a list of <code>{@link I_CmsListAction}</code>s
*/
public List getIndependentActions() {
return m_indepActions.elementList();
}
/**
* Returns the item details definition object for a given id.<p>
*
* @param itemDetailId the id
*
* @return the item details definition, or <code>null</code> if not present
*/
public CmsListItemDetails getItemDetailDefinition(String itemDetailId) {
return (CmsListItemDetails)m_itemDetails.getObject(itemDetailId);
}
/**
* Returns all detail definitions.<p>
*
* @return a list of <code>{@link CmsListItemDetails}</code>.
*/
public List getItemDetailDefinitions() {
return m_itemDetails.elementList();
}
/**
* Returns the id of the list.<p>
*
* @return the id of list
*/
public String getListId() {
return m_listId;
}
/**
* Returns a multi action object for a given id.<p>
*
* @param actionId the id
*
* @return the multi action, or <code>null</code> if not present
*/
public CmsListMultiAction getMultiAction(String actionId) {
return (CmsListMultiAction)m_multiActions.getObject(actionId);
}
/**
* Returns the list of multi actions.<p>
*
* @return a list of <code>{@link CmsListMultiAction}</code>s
*/
public List getMultiActions() {
return m_multiActions.elementList();
}
/**
* Returns the search action.<p>
*
* @return the search action
*/
public CmsListSearchAction getSearchAction() {
return m_searchAction;
}
/**
* Returns the total number of displayed columns.<p>
*
* @return the total number of displayed columns
*/
public int getWidth() {
return m_columns.elementList().size() + (hasCheckMultiActions() ? 1 : 0);
}
/**
* Returns <code>true</code> if the list definition contains an action.<p>
*
* @return <code>true</code> if the list definition contains an action
*/
public boolean hasActions() {
return !m_indepActions.elementList().isEmpty();
}
/**
* Returns <code>true</code> if at least 'check' multiaction has been set.<p>
*
* @return <code>true</code> if at least 'check' multiaction has been set
*/
public boolean hasCheckMultiActions() {
Iterator it = m_multiActions.elementList().iterator();
while (it.hasNext()) {
CmsListMultiAction action = (CmsListMultiAction)it.next();
if (!(action instanceof CmsListRadioMultiAction)) {
return true;
}
}
return false;
}
/**
* Returns <code>true</code> if the list definition contains a multi action.<p>
*
* @return <code>true</code> if the list definition contains a multi action
*/
public boolean hasMultiActions() {
return !m_multiActions.elementList().isEmpty();
}
/**
* Returns <code>true</code> if any column definition contains a single action.<p>
*
* @return <code>true</code> if any column definition contains a single action
*/
public boolean hasSingleActions() {
Iterator itCols = m_columns.elementList().iterator();
while (itCols.hasNext()) {
CmsListColumnDefinition col = (CmsListColumnDefinition)itCols.next();
if (!col.getDefaultActions().isEmpty() || !col.getDirectActions().isEmpty()) {
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -