📄 cmshtmllist.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsHtmlList.java,v $
* Date : $Date: 2006/03/27 14:52:27 $
* Version: $Revision: 1.35 $
*
* 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.CmsDialog;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.tools.A_CmsHtmlIconButton;
import org.opencms.workplace.tools.CmsHtmlIconButtonStyleEnum;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
/**
* The main class of the html list widget.<p>
*
* @author Michael Moossen
*
* @version $Revision: 1.35 $
*
* @since 6.0.0
*/
public class CmsHtmlList {
/** Standard list button location. */
public static final String ICON_LEFT = "list/leftarrow.png";
/** Standard list button location. */
public static final String ICON_RIGHT = "list/rightarrow.png";
/** Constant for item separator char used for coding/encoding multiselection. */
public static final String ITEM_SEPARATOR = "|";
/** Var name for error message if no item has been selected. */
public static final String NO_SELECTION_HELP_VAR = "noSelHelp";
/** Var name for error message if number of selected items does not match. */
public static final String NO_SELECTION_MATCH_HELP_VAR = "noSelMatchHelp";
/** Current displayed page number. */
private int m_currentPage;
/** Current sort order. */
private CmsListOrderEnum m_currentSortOrder;
/** Filtered list of items or <code>null</code> if no filter is set and not sorted. */
private List m_filteredItems;
/** Dhtml id. */
private final String m_id;
/** Maximum number of items per page. */
private int m_maxItemsPerPage = 20;
/** Metadata for building the list. */
private CmsListMetadata m_metadata;
/** Display Name of the list. */
private final CmsMessageContainer m_name;
/** Really content of the list. */
private final List m_originalItems = new ArrayList();
/** printable flag. */
private boolean m_printable;
/** Search filter text. */
private String m_searchFilter;
/** Column name to be sorted. */
private String m_sortedColumn;
/** Items currently displayed. */
private List m_visibleItems;
/**
* Default Constructor.<p>
*
* @param id unique id of the list, is used as name for controls and js functions and vars
* @param name the display name
* @param metadata the list's metadata
*/
public CmsHtmlList(String id, CmsMessageContainer name, CmsListMetadata metadata) {
m_id = id;
m_name = name;
m_metadata = metadata;
m_currentPage = 1;
}
/**
* Adds a collection new list items to the content of the list.<p>
*
* If you need to add or remove items from or to the list at a later step, use the
* <code>{@link #insertAllItems(Collection, Locale)}</code> or
* <code>{@link #removeAllItems(Collection, Locale)}</code> methods.<p>
*
* @param listItems the collection of list items to add
*
* @see List#addAll(Collection)
*/
public void addAllItems(Collection listItems) {
m_originalItems.addAll(listItems);
}
/**
* Adds a new item to the content of the list.<p>
*
* If you need to add or remove an item from or to the list at a later step, use the
* <code>{@link #insertItem(CmsListItem, Locale)}</code> or
* <code>{@link #removeItem(String, Locale)}</code> methods.<p>
*
* @param listItem the list item
*
* @see List#add(Object)
*/
public void addItem(CmsListItem listItem) {
m_originalItems.add(listItem);
}
/**
* This method resets the content of the list (no the metadata).<p>
*
* @param locale the locale for sorting/searching
*/
public void clear(Locale locale) {
m_originalItems.clear();
m_filteredItems = null;
if (m_visibleItems != null) {
m_visibleItems.clear();
}
setSearchFilter("", locale);
m_sortedColumn = null;
}
/**
* Returns all list items in the list, may be not visible and sorted.<p>
*
* @return all list items
*/
public List getAllContent() {
return Collections.unmodifiableList(m_originalItems);
}
/**
* Returns the filtered list of list items.<p>
*
* Equals to <code>{@link #getAllContent()}</code> if no filter is set.<p>
*
* @return the filtered list of list items
*/
public List getContent() {
if (m_filteredItems == null) {
return getAllContent();
} else {
return Collections.unmodifiableList(m_filteredItems);
}
}
/**
* returns the number of the current page.<p>
*
* @return the number of the current page
*/
public int getCurrentPage() {
return m_currentPage;
}
/**
* Returns all items of the current page.<p>
*
* @return all items of the current page, a list of {@link CmsListItem} objects
*/
public List getCurrentPageItems() {
if (getSize() == 0) {
return Collections.EMPTY_LIST;
}
return Collections.unmodifiableList(getContent().subList(displayedFrom() - 1, displayedTo()));
}
/**
* Returns the current used sort order.<p>
*
* @return the current used sort order
*/
public CmsListOrderEnum getCurrentSortOrder() {
return m_currentSortOrder;
}
/**
* Returns the id.<p>
*
* @return the id
*/
public String getId() {
return m_id;
}
/**
* This method returns the item identified by the parameter id.<p>
*
* Only current visible item can be retrieved using this method.<p>
*
* @param id the id of the item to look for
*
* @return the requested item or <code>null</code> if not found
*/
public CmsListItem getItem(String id) {
Iterator it = m_originalItems.iterator();
while (it.hasNext()) {
CmsListItem item = (CmsListItem)it.next();
if (item.getId().equals(id)) {
return item;
}
}
return null;
}
/**
* Returns the maximum number of items per page.<p>
*
* @return the maximum number of items per page
*/
public int getMaxItemsPerPage() {
return m_maxItemsPerPage;
}
/**
* Returns the metadata.<p>
*
* @return the metadata
*/
public CmsListMetadata getMetadata() {
return m_metadata;
}
/**
* Returns the name of the list.<p>
*
* @return the list's name
*/
public CmsMessageContainer getName() {
return m_name;
}
/**
* Returns the filtered number of pages.<p>
*
* Equals to <code>{@link #getTotalNumberOfPages()}</code> if no filter is set.<p>
*
* @return the filtered of pages
*/
public int getNumberOfPages() {
return (int)Math.ceil((double)getSize() / getMaxItemsPerPage());
}
/**
* Returns the search filter.<p>
*
* @return the search filter
*/
public String getSearchFilter() {
return m_searchFilter;
}
/**
* Return the filtered number of items.<p>
*
* Equals to <code>{@link #getTotalSize()}</code> if no filter is set.<p>
*
* @return the filtered number of items
*/
public int getSize() {
return getContent().size();
}
/**
* Returns the sorted column's name.<p>
*
* @return the sorted column's name
*/
public String getSortedColumn() {
return m_sortedColumn;
}
/**
* Returns a filled list state.<p>
*
* @return the state of the list
*/
public CmsListState getState() {
return new CmsListState(this);
}
/**
* Returns the total number of pages.<p>
*
* @return the total number of pages
*/
public int getTotalNumberOfPages() {
return (int)Math.ceil((double)getAllContent().size() / getMaxItemsPerPage());
}
/**
* Return the total number of items.<p>
*
* @return the total number of items
*/
public int getTotalSize() {
return getAllContent().size();
}
/**
* Inserts a collection of list items in an already initialized list.<p>
*
* Keeping care of all the state like sorted column, sorting order, displayed page and search filter.<p>
*
* @param listItems the collection of list items to insert
* @param locale the locale
*/
public void insertAllItems(Collection listItems, Locale locale) {
CmsListState state = null;
if (m_filteredItems != null || m_visibleItems != null) {
state = getState();
}
addAllItems(listItems);
if (m_filteredItems != null) {
m_filteredItems.addAll(listItems);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -