Nicht sichtbare Kategorien (Category#setVisible(false)) werden jetzt nur noch angezeigt, wenn sie explizit aufgerufen werden.

git-svn-id: https://svn.libreccm.org/ccm/trunk@2173 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2013-06-05 16:47:42 +00:00
parent 4edddb7faa
commit d29291bd87
1 changed files with 140 additions and 113 deletions

View File

@ -15,10 +15,8 @@
* 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 com.arsdigita.navigation.ui.category;
import com.arsdigita.navigation.ui.CategoryComponent;
import com.arsdigita.navigation.Navigation;
@ -55,10 +53,10 @@ public abstract class AbstractTree extends CategoryComponent {
private static Logger s_log = Logger.getLogger(AbstractTree.class);
protected Element generateTreeXML(HttpServletRequest request,
HttpServletResponse response,
Category cat,
CategoryCollection cats,
BigDecimal[] selected) {
HttpServletResponse response,
Category cat,
CategoryCollection cats,
BigDecimal[] selected) {
Map children = new HashMap();
Category currentCat = new Category(selected[selected.length - 1]);
while (cats.next()) {
@ -80,59 +78,61 @@ public abstract class AbstractTree extends CategoryComponent {
s_log.debug("Parent is " + parent.getName());
}
Set childList = (Set)children.get(parentID);
Set childList = (Set) children.get(parentID);
if (childList == null) {
childList = new TreeSet();
s_log.debug("Adding new list for this parent");
children.put(parentID, childList);
}
childList.add(new CategorySortKeyPair
(category,
(BigDecimal)cats.get("parents.link.sortKey"),
isDefault.booleanValue()));
childList.add(new CategorySortKeyPair(category,
(BigDecimal) cats.get("parents.link.sortKey"),
isDefault.booleanValue()));
}
String path = URLService.locate(cat.getOID());
return generateNodeXML(request,
response,
cat,
null,
selected,
children,
path,
Collections.EMPTY_LIST);
response,
cat,
null,
selected,
children,
path,
Collections.EMPTY_LIST);
}
/**
* implementations may override this method to change the parent associated with the current category
* enabling categories to be skipped without breaking the tree
*/
protected BigDecimal getParentID(CategoryCollection cats,
Category currentCat,
Category currentChild,
BigDecimal[] selected) {
return (BigDecimal)cats.get("parents.id");
Category currentCat,
Category currentChild,
BigDecimal[] selected) {
return (BigDecimal) cats.get("parents.id");
}
protected Element generateNodeXML(HttpServletRequest request,
HttpServletResponse response,
Category cat,
BigDecimal sortKey,
BigDecimal[] selected,
Map children,
String path,
List idPath) {
HttpServletResponse response,
Category cat,
BigDecimal sortKey,
BigDecimal[] selected,
Map children,
String path,
List idPath) {
if (!cat.isEnabled()) {
return null;
}
s_log.debug("generating node XML for category " + cat.getName() );
s_log.debug("generating node XML for category " + cat.getName());
// replace idPath list with one containing cat.id appended
idPath = new ArrayList(idPath);
@ -141,46 +141,65 @@ public abstract class AbstractTree extends CategoryComponent {
StringBuffer buff = new StringBuffer("ID Path is ");
Iterator it = idPath.iterator();
while (it.hasNext()) {
BigDecimal id = (BigDecimal)it.next();
BigDecimal id = (BigDecimal) it.next();
Category thisCat = new Category(id);
buff.append(thisCat.getName() + " - ");
}
s_log.debug(buff.toString());
}
boolean isSelected = false;
if (selected.length >= idPath.size()) {
isSelected = true;
for (int x = 0; x < idPath.size(); x++) {
if (!idPath.get(x).equals(selected[x])) {
isSelected = false;
}
}
} else {
isSelected = false;
}
if (!isSelected && !cat.isVisible()) {
return null;
}
// We will concatenate category URLs only if all ancestors have
// their URLs set correctly. We recognize that is the case if
// path ends with slash. Otherwise resort to generic (ie. redirect)
// URLs.
boolean concatURLs = (path != null && path.endsWith("/"));
boolean concatURLs = (path != null && path.endsWith("/"));
Element el = generateCategoryXML(request,
response,
cat.getID(),
cat.getName(),
cat.getDescription(),
concatURLs ? path : Navigation.redirectURL(cat.getOID()));
response,
cat.getID(),
cat.getName(),
cat.getDescription(),
concatURLs ? path : Navigation.redirectURL(cat.getOID()));
el.addAttribute("AbstractTree", "AbstractTree");
el.addAttribute("sortKey", XML.format(sortKey));
// compare idPath with the start of selected
if (selected.length >= idPath.size()) {
boolean isSelected = true;
for (int x=0; x<idPath.size(); x++) {
if (!idPath.get(x).equals(selected[x])) {
isSelected = false;
}
}
if (isSelected) {
el.addAttribute("isSelected", "true" );
}
if (isSelected) {
el.addAttribute("isSelected", "true");
}
// compare idPath with the start of selected
// if (selected.length >= idPath.size()) {
// boolean isSelected = true;
// for (int x = 0; x < idPath.size(); x++) {
// if (!idPath.get(x).equals(selected[x])) {
// isSelected = false;
// }
// }
// if (isSelected) {
// el.addAttribute("isSelected", "true");
// }
// }
// Quasimodo: Begin
Set c = (Set)children.get(cat.getID());
Set c = (Set) children.get(cat.getID());
if (c != null) {
Iterator i = c.iterator();
@ -195,21 +214,20 @@ public abstract class AbstractTree extends CategoryComponent {
BigDecimal childSortKey = pair.getSortKey();
Element childEl = generateNodeXML(request,
response,
child,
childSortKey,
selected,
children,
concatURLs && child.getURL() != null
? path + child.getURL() + "/"
: null,
idPath
);
response,
child,
childSortKey,
selected,
children,
concatURLs && child.getURL() != null
? path + child.getURL() + "/"
: null,
idPath);
if (childEl != null) {
// Respect the calculated maxChildCounter
if(childCounter < maxChildCounter) {
if (childCounter < maxChildCounter) {
boolean isDefault = pair.isDefault();
childEl.addAttribute("isDefault", String.valueOf(isDefault));
@ -219,9 +237,9 @@ public abstract class AbstractTree extends CategoryComponent {
} else {
// add showMore attribute
el.addAttribute(Menu.MORE_ATTRIB, "true");
break;
// add showMore attribute
el.addAttribute(Menu.MORE_ATTRIB, "true");
break;
}
@ -242,13 +260,17 @@ public abstract class AbstractTree extends CategoryComponent {
protected boolean compareCategoryCollection(CategoryCollection a, CategoryCollection b) {
// Not equal, if sizes don't match
if(a.size() != b.size()) return false;
if (a.size() != b.size()) {
return false;
}
// Access every Object in the Collections
while(a.next() && b.next()) {
while (a.next() && b.next()) {
// If they don't match, they ain't equal
if(!a.getCategory().equals(b.getCategory())) return false;
if (!a.getCategory().equals(b.getCategory())) {
return false;
}
}
// Hurray, they are equal
@ -268,6 +290,7 @@ public abstract class AbstractTree extends CategoryComponent {
// Quasimodo: End
private class CategorySortKeyPair implements Comparable {
private Category m_category;
private BigDecimal m_sortKey;
private boolean m_isDefault;
@ -277,18 +300,22 @@ public abstract class AbstractTree extends CategoryComponent {
m_sortKey = sortKey;
m_isDefault = isDefault;
}
public Category getCategory() {
return m_category;
}
public BigDecimal getSortKey() {
return m_sortKey;
}
public boolean isDefault() {
return m_isDefault;
}
public int compareTo(Object o) {
return m_sortKey.compareTo(((CategorySortKeyPair)o).m_sortKey);
}
}
public int compareTo(Object o) {
return m_sortKey.compareTo(((CategorySortKeyPair) o).m_sortKey);
}
}
}