cmshtmllist.java
来自「找了很久才找到到源代码」· Java 代码 · 共 1,128 行 · 第 1/3 页
JAVA
1,128 行
* 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)getTotalSize() / getMaxItemsPerPage());
}
/**
* Return the total number of items.<p>
*
* @return the total number of items
*/
public int getTotalSize() {
if (m_metadata.isSelfManaged() && (m_totalSize != 0)) {
return m_totalSize;
}
return getAllContent().size();
}
/**
* Returns the workplace dialog object.<p>
*
* @return the workplace dialog object
*/
public A_CmsListDialog getWp() {
return m_wp;
}
/**
* Returns the isBoxed flag.<p>
*
* If this flag is set the list will be surrounded by a box.<p>
*
* @return the isBoxed flag
*/
public boolean isBoxed() {
return m_isBoxed;
}
/**
* Returns the printable flag.<p>
*
* @return the printable flag
*/
public boolean isPrintable() {
return m_printable;
}
/**
* Returns if the list title is shown.<p>
*
* @return true if the list title is shown, otherwise false
*/
public boolean isShowTitle() {
return m_showTitle;
}
/**
* Generates the csv output for the list.<p>
*
* @return csv output
*/
public String listCsv() {
StringBuffer csv = new StringBuffer(5120);
csv.append(m_metadata.csvHeader());
if (getContent().isEmpty()) {
csv.append(m_metadata.csvEmptyList());
} else {
Iterator itItems = getContent().iterator();
while (itItems.hasNext()) {
CmsListItem item = (CmsListItem)itItems.next();
csv.append(m_metadata.csvItem(item));
}
}
return getWp().resolveMacros(csv.toString());
}
/**
* Generates the html code for the list.<p>
*
* @return html code
*/
public synchronized String listHtml() {
// check if progress should be set in the thread
CmsProgressThread thread = null;
int progressOffset = 0;
if (Thread.currentThread() instanceof CmsProgressThread) {
thread = (CmsProgressThread)Thread.currentThread();
progressOffset = thread.getProgress();
}
// this block has to be executed before calling htmlBegin()
if (isPrintable()) {
m_visibleItems = new ArrayList(getContent());
} else {
m_visibleItems = new ArrayList(getCurrentPageItems());
}
StringBuffer html = new StringBuffer(5120);
html.append(htmlBegin());
if (!isPrintable()) {
html.append(htmlTitle());
html.append(htmlToolBar());
} else {
html.append("<style type='text/css'>\n");
html.append("td.listdetailitem, \n");
html.append(".linkdisabled {\n");
html.append("\tcolor: black;\n");
html.append("}\n");
html.append(".list th {\n");
html.append("\tborder: 1px solid black;\n");
html.append("}\n");
html.append(".list {\n");
html.append("\tborder: 1px solid black;\n");
html.append("}\n");
html.append("</style>");
}
html.append("<table width='100%' cellpadding='1' cellspacing='0' class='list'>\n");
html.append(m_metadata.htmlHeader(this));
if (m_visibleItems.isEmpty()) {
html.append(m_metadata.htmlEmptyTable());
} else {
Iterator itItems = m_visibleItems.iterator();
boolean odd = true;
int count = 0;
while (itItems.hasNext()) {
// set progress in thread
count++;
if (thread != null) {
if (thread.isInterrupted()) {
throw new CmsIllegalStateException(org.opencms.workplace.commons.Messages.get().container(
org.opencms.workplace.commons.Messages.ERR_PROGRESS_INTERRUPTED_0));
}
thread.setProgress((count * (100 - progressOffset) / m_visibleItems.size()) + progressOffset);
thread.setDescription(org.opencms.workplace.commons.Messages.get().getBundle(thread.getLocale()).key(
org.opencms.workplace.commons.Messages.GUI_PROGRESS_PUBLISH_STEP4_2,
new Integer(count),
new Integer(m_visibleItems.size())));
}
CmsListItem item = (CmsListItem)itItems.next();
html.append(m_metadata.htmlItem(item, odd, isPrintable()));
odd = !odd;
}
}
html.append("</table>\n");
if (!isPrintable()) {
html.append(htmlPagingBar());
}
html.append(htmlEnd());
return getWp().resolveMacros(html.toString());
}
/**
* Generate the need js code for the list.<p>
*
* @return js code
*/
public String listJs() {
StringBuffer js = new StringBuffer(1024);
CmsMessages messages = Messages.get().getBundle(getWp().getLocale());
js.append("<script type='text/javascript' src='");
js.append(CmsWorkplace.getSkinUri());
js.append("admin/javascript/list.js'></script>\n");
if (!m_metadata.getMultiActions().isEmpty()) {
js.append("<script type='text/javascript'>\n");
js.append("\tvar ");
js.append(NO_SELECTION_HELP_VAR);
js.append(" = '");
js.append(CmsStringUtil.escapeJavaScript(messages.key(Messages.GUI_LIST_ACTION_NO_SELECTION_0)));
js.append("';\n");
Iterator it = m_metadata.getMultiActions().iterator();
while (it.hasNext()) {
CmsListMultiAction action = (CmsListMultiAction)it.next();
if (action instanceof CmsListRadioMultiAction) {
CmsListRadioMultiAction rAction = (CmsListRadioMultiAction)action;
js.append("\tvar ");
js.append(NO_SELECTION_MATCH_HELP_VAR);
js.append(rAction.getId());
js.append(" = '");
js.append(CmsStringUtil.escapeJavaScript(messages.key(
Messages.GUI_LIST_ACTION_NO_SELECTION_MATCH_1,
new Integer(rAction.getSelections()))));
js.append("';\n");
}
}
js.append("</script>\n");
}
return js.toString();
}
/**
* Returns a new list item for this list.<p>
*
* @param id the id of the item has to be unique
* @return a new list item
*/
public CmsListItem newItem(String id) {
return new CmsListItem(getMetadata(), id);
}
/**
* Returns html code for printing the list.<p>
*
* @return html code
*/
public String printableHtml() {
m_printable = true;
String html = listHtml();
m_printable = false;
return html;
}
/**
* Sets the isBoxed flag.<p>
*
* If this flag is set, the list will be surrounded by a box.<p>
*
* @param isBoxed the isBoxed flag to set
*/
public void setBoxed(boolean isBoxed) {
m_isBoxed = isBoxed;
}
/**
* Sets the list item to display in the list.<p>
*
* @param listItems a collection of {@link CmsListItem} objects
*/
public void setContent(Collection listItems) {
if (m_metadata.isSelfManaged()) {
m_filteredItems = new ArrayList(listItems);
m_originalItems = null;
} else {
m_filteredItems = null;
m_originalItems = new ArrayList(listItems);
}
}
/**
* Sets the current page.<p>
*
* @param currentPage the current page to set
*
* @throws CmsIllegalArgumentException if the argument is invalid
*/
public void setCurrentPage(int currentPage) throws CmsIllegalArgumentException {
if (getSize() != 0) {
if ((currentPage < 1) || (currentPage > getNumberOfPages())) {
throw new CmsIllegalArgumentException(Messages.get().container(
Messages.ERR_LIST_INVALID_PAGE_1,
new Integer(currentPage)));
}
}
m_currentPage = currentPage;
}
/**
* Sets the maximum number of items per page.<p>
*
* @param maxItemsPerPage the maximum number of items per page to set
*/
public void setMaxItemsPerPage(int maxItemsPerPage) {
this.m_maxItemsPerPage = maxItemsPerPage;
}
/**
* Sets the name of the list.<p>
*
* @param name the name of the list
*/
public void setName(CmsMessageContainer name) {
m_name = name;
}
/**
* Sets the search filter.<p>
*
* @param searchFilter the search filter to set
*/
public void setSearchFilter(String searchFilter) {
if (!m_metadata.isSearchable()) {
return;
}
if (CmsStringUtil.isEmptyOrWhitespaceOnly(searchFilter)) {
// reset content if filter is empty
if (!m_metadata.isSelfManaged()) {
m_filteredItems = null;
}
m_searchFilter = "";
getMetadata().getSearchAction().getShowAllAction().setVisible(false);
} else {
if (!m_metadata.isSelfManaged()) {
m_filteredItems = getMetadata().getSearchAction().filter(getAllContent(), searchFilter);
}
m_searchFilter = searchFilter;
getMetadata().getSearchAction().getShowAllAction().setVisible(true);
}
String sCol = m_sortedColumn;
m_sortedColumn = "";
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(sCol)) {
CmsListOrderEnum order = getCurrentSortOrder();
setSortedColumn(sCol);
if (order == CmsListOrderEnum.ORDER_DESCENDING) {
setSortedColumn(sCol);
}
}
setCurrentPage(1);
}
/**
* Sets if the list title is shown.<p>
*
* @param showTitle true if the list title is shown, otherwise false
*/
public void setShowTitle(boolean showTitle) {
m_showTitle = showTitle;
}
/**
* Sets the current filtered size, only used if data self managed.<p>
*
* @param size the size to set
*/
public void setSize(int size) {
m_size = size;
}
/**
* Sets the sorted column.<p>
*
* @param sortedColumn the sorted column to set
*
* @throws CmsIllegalArgumentException if the <code>sortedColumn</code> argument is invalid
*/
public void setSortedColumn(String sortedColumn) throws CmsIllegalArgumentException {
if ((getMetadata().getColumnDefinition(sortedColumn) == null)
|| !getMetadata().getColumnDefinition(sortedColumn).isSorteable()) {
return;
}
// check if the parameter is valid
if (m_metadata.getColumnDefinition(sortedColumn) == null) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?