001: /*
002: Copyright (c) 2003 eInnovation Inc. All rights reserved
003:
004: This library is free software; you can redistribute it and/or modify it under the terms
005: of the GNU Lesser General Public License as published by the Free Software Foundation;
006: either version 2.1 of the License, or (at your option) any later version.
007:
008: This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
009: without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: See the GNU Lesser General Public License for more details.
011: */
012:
013: package org.openedit.links.webtree;
014:
015: import java.util.List;
016:
017: import org.openedit.links.Link;
018: import org.openedit.links.LinkTree;
019:
020: import com.openedit.webui.tree.DefaultWebTreeModel;
021: import com.openedit.webui.tree.RepositoryTreeNode;
022:
023: /**
024: * This model represents a tree of site content.
025: *
026: * @author Matt Avery, mavery@einnovation.com
027: */
028: public class LinkTreeModel extends DefaultWebTreeModel {
029: protected LinkTree fieldLinkTree;
030: protected String fieldRootPath;
031: long lastMod = 1001;
032:
033: /**
034: * Constructor for PageTreeModel.
035: *
036: * @param inSiteContext DOCUMENT ME!
037: */
038: public LinkTreeModel(LinkTree inLinkTree) {
039: this (inLinkTree, null);
040: }
041:
042: public LinkTreeModel(LinkTree inLinkTree, String inRootPath) {
043: super ();
044: fieldLinkTree = inLinkTree;
045: fieldRootPath = inRootPath;
046: }
047:
048: /* (non-Javadoc)
049: * @see TreeModel#getRoot()
050: */
051: public Object getRoot() {
052: if (fieldRoot == null) {
053: reload();
054: }
055:
056: return fieldRoot;
057: }
058:
059: public List getChildren(Object parent) {
060: // if( getLinkTree().getLastModified() != lastMod )
061: // {
062: // reload();
063: // }
064: return super .getChildren(parent);
065: }
066:
067: /**
068: * Find the page tree node at the given path. This method will not automatically expand any
069: * node in the tree if it is not already expanded.
070: *
071: * @param inPath The path (e.g. "abc/def/ghi.html")
072: *
073: * @return The node at the given path, or <code>null</code> if no node could be found that
074: * matched the given path
075: */
076: public LinkNode findNode(String inPath) {
077: return ((LinkNode) getRoot()).findNode(inPath);
078: }
079:
080: /**
081: *
082: */
083: public void reload() {
084: Link rootItem;
085: if (getRootPath() == null) {
086: rootItem = getLinkTree().getRootLink();
087: } else {
088: rootItem = getLinkTree().getLink(getRootPath());
089: }
090: LinkNode newRoot = new LinkNode(rootItem);
091: fieldRoot = newRoot;
092: lastMod = getLinkTree().getLastModified();
093: }
094:
095: /**
096: * @param inString
097: */
098: public void ignore(String inString) {
099: LinkNode node = (LinkNode) getRoot();
100: node.getIgnoreTypes().add(inString);
101: }
102:
103: public LinkTree getLinkTree() {
104: return fieldLinkTree;
105: }
106:
107: public void setLinkTree(LinkTree LinkTree) {
108: fieldLinkTree = LinkTree;
109: }
110:
111: public String getRootPath() {
112: return fieldRootPath;
113: }
114:
115: public void setRootPath(String rootPath) {
116: fieldRootPath = rootPath;
117: }
118:
119: protected boolean hasLoadedChildren(Object inRoot) {
120: //Only look in nodes with already loaded children
121: LinkNode parent = (LinkNode) inRoot;
122: return parent.hasLoadedChildren();
123: }
124:
125: }
|