📄 cmshtmllist.java
字号:
}
if (m_visibleItems != null) {
m_visibleItems.addAll(listItems);
}
if (state != null) {
setState(state, locale);
}
}
/**
* Inserts an item in an already initialized list.<p>
*
* Keeping care of all the state like sorted column, sorting order, displayed page and search filter.<p>
*
* @param listItem the list item to insert
* @param locale the locale
*/
public void insertItem(CmsListItem listItem, Locale locale) {
CmsListState state = null;
if (m_filteredItems != null || m_visibleItems != null) {
state = getState();
}
addItem(listItem);
if (m_filteredItems != null) {
m_filteredItems.add(listItem);
}
if (m_visibleItems != null) {
m_visibleItems.add(listItem);
}
if (state != null) {
setState(state, locale);
}
}
/**
* Returns the printable flag.<p>
*
* @return the printable flag
*/
public boolean isPrintable() {
return m_printable;
}
/**
* Generates the csv output for the list.<p>
*
* Synchronized to not collide with <code>{@link #listHtml(CmsWorkplace)}</code>.<p>
*
* @param wp the workplace object
*
* @return csv output
*/
public synchronized String listCsv(CmsWorkplace wp) {
StringBuffer csv = new StringBuffer(5120);
csv.append(m_metadata.csvHeader(wp));
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, wp));
}
}
return wp.resolveMacros(csv.toString());
}
/**
* Generates the html code for the list.<p>
*
* Synchronized to not collide with <code>{@link #printableHtml(CmsWorkplace)}</code>.<p>
*
* @param wp the workplace object
*
* @return html code
*/
public synchronized String listHtml(CmsWorkplace wp) {
if (isPrintable()) {
m_visibleItems = new ArrayList(getContent());
} else {
m_visibleItems = new ArrayList(getCurrentPageItems());
}
StringBuffer html = new StringBuffer(5120);
html.append(htmlBegin(wp));
if (!isPrintable()) {
html.append(htmlTitle(wp));
html.append(htmlToolBar(wp));
} 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, wp));
if (m_visibleItems.isEmpty()) {
html.append(m_metadata.htmlEmptyTable(wp.getLocale()));
} else {
Iterator itItems = m_visibleItems.iterator();
boolean odd = true;
while (itItems.hasNext()) {
CmsListItem item = (CmsListItem)itItems.next();
html.append(m_metadata.htmlItem(item, wp, odd, isPrintable()));
odd = !odd;
}
}
html.append("</table>\n");
if (!isPrintable()) {
html.append(htmlPagingBar(wp));
}
html.append(htmlEnd(wp));
return wp.resolveMacros(html.toString());
}
/**
* Generate the need js code for the list.<p>
*
* @param locale the locale
*
* @return js code
*/
public String listJs(Locale locale) {
StringBuffer js = new StringBuffer(1024);
CmsMessages messages = Messages.get().getBundle(locale);
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>
*
* Synchronized to not collide with <code>{@link #listHtml(CmsWorkplace)}</code>.<p>
*
* @param wp the workplace object
*
* @return html code
*/
public synchronized String printableHtml(CmsWorkplace wp) {
m_printable = true;
String html = listHtml(wp);
m_printable = false;
return html;
}
/**
* Removes a collection of list items from the list.<p>
*
* Keeping care of all the state like sorted column, sorting order, displayed page and search filter.<p>
*
* Try to use it instead of <code>{@link A_CmsListDialog#refreshList()}</code>.<p>
*
* @param ids the collection of ids of the items to remove
* @param locale the locale
*
* @return the list of removed list items
*/
public List removeAllItems(Collection ids, Locale locale) {
List removedItems = new ArrayList();
Iterator itItems = m_originalItems.iterator();
while (itItems.hasNext()) {
CmsListItem listItem = (CmsListItem)itItems.next();
if (ids.contains(listItem.getId())) {
removedItems.add(listItem);
}
}
if (removedItems.isEmpty()) {
return removedItems;
}
CmsListState state = null;
if (m_filteredItems != null || m_visibleItems != null) {
state = getState();
}
m_originalItems.removeAll(removedItems);
if (m_filteredItems != null) {
m_filteredItems.removeAll(removedItems);
}
if (m_visibleItems != null) {
m_visibleItems.removeAll(removedItems);
}
if (state != null) {
setState(state, locale);
}
return removedItems;
}
/**
* Removes an item from the list.<p>
*
* Keeping care of all the state like sorted column, sorting order, displayed page and search filter.<p>
*
* Try to use it instead of <code>{@link A_CmsListDialog#refreshList()}</code>.<p>
*
* @param id the id of the item to remove
* @param locale the locale
*
* @return the removed list item
*/
public CmsListItem removeItem(String id, Locale locale) {
CmsListItem item = null;
Iterator itItems = m_originalItems.iterator();
while (itItems.hasNext()) {
CmsListItem listItem = (CmsListItem)itItems.next();
if (listItem.getId().equals(id)) {
item = listItem;
break;
}
}
if (item == null) {
return null;
}
CmsListState state = null;
if (m_filteredItems != null || m_visibleItems != null) {
state = getState();
}
m_originalItems.remove(item);
if (m_filteredItems != null) {
m_filteredItems.remove(item);
}
if (m_visibleItems != null) {
m_visibleItems.remove(item);
}
if (state != null) {
setState(state, locale);
}
return item;
}
/**
* Replace a list of items in the list.<p>
*
* Keeping care of all the state like sorted column, sorting order, displayed page and search filter.<p>
*
* If the list already contains an item with the id of a given list item, it will be removed and
* replaced by the new list item. if not, this method is the same as the
* <code>{@link #insertAllItems(Collection, Locale)}</code> method.
*
* Try to use it instead of <code>{@link A_CmsListDialog#refreshList()}</code>.<p>
*
* @param listItems the list of <code>{@link CmsListItem}</code>s to replace
* @param locale the locale
*
* @return the removed list item, or <code>null</code>
*/
public List replaceAllItems(List listItems, Locale locale) {
List removedItems = new ArrayList();
Iterator itItems = m_originalItems.iterator();
while (itItems.hasNext()) {
CmsListItem listItem = (CmsListItem)itItems.next();
Iterator itNewItems = listItems.iterator();
while (itNewItems.hasNext()) {
if (listItem.equals(((CmsListItem)itNewItems.next()).getId())) {
removedItems.add(listItem);
}
}
}
CmsListState state = null;
if (m_filteredItems != null || m_visibleItems != null) {
state = getState();
}
if (!removedItems.isEmpty()) {
m_originalItems.removeAll(removedItems);
}
addAllItems(listItems);
if (state != null) {
setState(state, locale);
}
return removedItems;
}
/**
* Replace an item in the list.<p>
*
* Keeping care of all the state like sorted column, sorting order, displayed page and search filter.<p>
*
* If the list already contains an item with the id of the given list item, it will be removed and
* replaced by the new list item. if not, this method is the same as the
* <code>{@link #insertItem(CmsListItem, Locale)}</code> method.
*
* Try to use it instead of <code>{@link A_CmsListDialog#refreshList()}</code>.<p>
*
* @param listItem the listItem to replace
* @param locale the locale
*
* @return the removed list item, or <code>null</code>
*/
public CmsListItem replaceItem(CmsListItem listItem, Locale locale) {
CmsListItem item = null;
Iterator itItems = m_originalItems.iterator();
while (itItems.hasNext()) {
CmsListItem tmp = (CmsListItem)itItems.next();
if (tmp.getId().equals(listItem.getId())) {
item = tmp;
break;
}
}
CmsListState state = null;
if (m_filteredItems != null || m_visibleItems != null) {
state = getState();
}
if (item != null) {
m_originalItems.remove(item);
}
addItem(listItem);
if (state != null) {
setState(state, locale);
}
return item;
}
/**
* 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;
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -