001:/*
002: * Copyright (c) 2000, Jacob Smullyan.
003: *
004: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
005: * for the latest version.
006: *
007: * SkunkDAV is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License as published
009: * by the Free Software Foundation; either version 2, or (at your option)
010: * any later version.
011: *
012: * SkunkDAV is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with SkunkDAV; see the file COPYING. If not, write to the Free
019: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
020: * 02111-1307, USA.
021:*/
022:
023:package org.skunk.dav.client.gui;
024:
025:import java.net.URLDecoder;
026:import java.util.Enumeration;
027:import java.util.Iterator;
028:import java.util.Vector;
029:import javax.swing.tree.DefaultMutableTreeNode;
030:import javax.swing.tree.TreeNode;
031:import org.skunk.assert.Assertion;
032:import org.skunk.dav.client.DAVFile;
033:import org.skunk.trace.Debug;
034:
035:public class DAVTreeNode extends DefaultMutableTreeNode
036:{
037: private DAVFile file;
038: private boolean showNonCollections;
039: private boolean refreshed;
040: private boolean showHost;
041:
042: public DAVTreeNode(DAVFile file, boolean showNonCollections)
043: {
044: super ();
045: this .file=file;
046: this .showNonCollections=showNonCollections;
047: this .showHost=false;
048: Debug.trace(this ,
049: Debug.DP5,
050: "in constructor: DAVTreeNode({0}, {1})",
051: new Object[] {file, new Boolean(showNonCollections)});
052: }
053:
054: public DAVTreeNode(DAVFile file)
055: {
056: this (file, false);
057: }
058:
059: public boolean isShowingHost()
060: {
061: return showHost;
062: }
063:
064: public void setShowingHost(boolean showingHost)
065: {
066: this .showHost=showingHost;
067: }
068:
069: public boolean isLeaf()
070: {
071: if (showNonCollections)
072: return (! file.isCollection());
073: else return false;
074: }
075:
076: private void setChildNodes()
077: {
078: removeAllChildren();
079: Assertion.assert(file!=null, "DAVFile is not null");
080: Iterator it=file.children();
081: while (it.hasNext())
082: {
083: Object o=it.next();
084: Assertion.assert((o instanceof DAVFile),
085: "child of DAVFile is a DAVFile");
086: DAVFile kiddie=(DAVFile) o;
087: if (kiddie.isCollection() || showNonCollections)
088: add(new DAVTreeNode(kiddie, showNonCollections));
089: }
090: }
091:
092: public Object getUserObject()
093: {
094: return toString();
095: }
096:
097: public String toString()
098: {
099: // fixes bug found by Elias Sinderson at the 2001 WebDAV Interop
100: return (showHost)
101: ? URLDecoder.decode(file.getFullName())
102: : URLDecoder.decode(file.getFileName());
103: }
104:
105: public void setRefreshed(boolean refreshed)
106: {
107: this .refreshed=refreshed;
108: }
109:
110: public boolean isRefreshed()
111: {
112: return this .refreshed;
113: }
114:
115: public DAVFile getDAVFile()
116: {
117: return file;
118: }
119:
120: public void setDAVFile(DAVFile file)
121: {
122: this .file=file;
123: setChildNodes();
124: }
125:}
126:
127:/* $Log: DAVTreeNode.java,v $
128:/* Revision 1.11 2001/07/25 20:05:34 smulloni
129:/* bug fix: explorer tree wasn't url-decoding filenames.
130:/*
131:/* Revision 1.10 2001/01/03 00:30:35 smulloni
132:/* a number of modifications along the way to replacing JFileChooser with
133:/* something more suitable for remote (virtual) files.
134:/*
135:/* Revision 1.9 2001/01/02 17:32:24 smulloni
136:/* bugfix: was hard-coding showNonCollections to false for child nodes, which made no
137:/* sense.
138:/*
139:/* Revision 1.8 2000/12/19 22:36:05 smulloni
140:/* adjustments to preamble.
141:/*
142:/* Revision 1.7 2000/12/03 23:53:26 smulloni
143:/* added license and copyright preamble to java files.
144:/*
145:/* Revision 1.6 2000/11/09 23:34:56 smullyan
146:/* log added to every Java file, with the help of python. Lock stealing
147:/* implemented, and treatment of locks made more robust.
148:/* */
|