cmshtmllist.java
来自「找了很久才找到到源代码」· Java 代码 · 共 1,128 行 · 第 1/3 页
JAVA
1,128 行
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsHtmlList.java,v $
* Date : $Date: 2007-08-13 16:29:48 $
* Version: $Revision: 1.37 $
*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) 2002 - 2007 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.main.CmsIllegalStateException;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.commons.CmsProgressThread;
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.37 $
*
* @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;
/** If this flag is set the list will be surrounded by a box. */
private boolean m_isBoxed = true;
/** 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 CmsMessageContainer m_name;
/** Really content of the list. */
private List m_originalItems = new ArrayList();
/** printable flag. */
private boolean m_printable;
/** Search filter text. */
private String m_searchFilter;
/** Show the title of the list. */
private boolean m_showTitle;
/** The filtered content size, only used if data self managed. */
private int m_size;
/** Column name to be sorted. */
private String m_sortedColumn;
/** The total size, only used is data self managed. */
private int m_totalSize;
/** Items currently displayed. */
private List m_visibleItems;
/** The related workplace dialog object. */
private transient A_CmsListDialog m_wp;
/**
* 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;
m_showTitle = true;
}
/**
* Generates the list of html option elements for a html select control to select a page of a list.<p>
*
* @param nrPages the total number of pages
* @param itemsPage the maximum number of items per page
* @param nrItems the total number of items
* @param curPage the current page
* @param locale the locale
*
* @return html code
*/
public static String htmlPageSelector(int nrPages, int itemsPage, int nrItems, int curPage, Locale locale) {
StringBuffer html = new StringBuffer(256);
for (int i = 0; i < nrPages; i++) {
int displayedFrom = i * itemsPage + 1;
int displayedTo = (i + 1) * itemsPage < nrItems ? (i + 1) * itemsPage : nrItems;
html.append("\t\t\t\t<option value='");
html.append(i + 1);
html.append("'");
html.append((i + 1) == curPage ? " selected" : "");
html.append(">");
html.append(Messages.get().getBundle(locale).key(
Messages.GUI_LIST_PAGE_ENTRY_3,
new Integer(i + 1),
new Integer(displayedFrom),
new Integer(displayedTo)));
html.append("</option>\n");
}
return html.toString();
}
/**
* This method resets the content of the list (no the metadata).<p>
*/
public void clear() {
if (m_originalItems != null) {
m_originalItems.clear();
}
m_filteredItems = null;
synchronized (this) {
if (m_visibleItems != null) {
m_visibleItems.clear();
}
}
setSearchFilter("");
m_sortedColumn = null;
}
/**
* Returns all list items in the list, may be not visible and sorted.<p>
*
* @return all list items
*/
public List getAllContent() {
if (m_metadata.isSelfManaged()) {
if (m_filteredItems != null) {
return Collections.unmodifiableList(m_filteredItems);
} else {
return Collections.EMPTY_LIST;
}
} else {
if (m_originalItems != null) {
return Collections.unmodifiableList(m_originalItems);
} else {
return Collections.EMPTY_LIST;
}
}
}
/**
* 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;
}
if (m_metadata.isSelfManaged()) {
return getContent();
}
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 = getAllContent().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() {
if (m_metadata.isSelfManaged() && (m_size != 0)) {
return m_size;
}
return getContent().size();
}
/**
* Returns the sorted column's name.<p>
*
* @return the sorted column's name
*/
public String getSortedColumn() {
return m_sortedColumn;
}
/**
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?