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 javax.swing.table.AbstractTableModel;
027: import org.skunk.dav.client.DAVFile;
028: import org.skunk.dav.client.DAVProperty;
029: import org.skunk.dav.client.Lock;
030: import org.skunk.trace.Debug;
031:
032: public class DAVTableModel extends AbstractTableModel {
033: private DAVFile file;
034: private DAVTableHeader[] headers;
035:
036: public DAVTableModel(DAVFile file, DAVTableHeader[] headers) {
037: super ();
038: this .file = file;
039: this .headers = headers;
040: }
041:
042: public DAVTableModel(DAVTableHeader[] headers) {
043: this (null, headers);
044: }
045:
046: public void setDAVFile(DAVFile file) {
047: this .file = file;
048: fireTableDataChanged();
049: }
050:
051: public int getRowCount() {
052: if (file != null)
053: return file.getChildCount();
054: else
055: return 0;
056: }
057:
058: /**
059: * This is currently just a wrapper around DAVFile.getChildAt(int),
060: * but should later include a hook for sorting routines.
061: */
062: private DAVFile getChildAt(DAVFile daFile, int row) {
063: return daFile.getChildAt(row);
064: }
065:
066: public DAVFile getDAVFile() {
067: return file;
068: }
069:
070: public DAVFile getDAVFile(int row) {
071: if (row >= 0 & row < getRowCount()) {
072: return getChildAt(file, row);
073: }
074: return null;
075: }
076:
077: public int getColumnCount() {
078: return headers.length;
079: }
080:
081: public Object getValueAt(int r, int c) {
082: if (file != null) {
083: DAVTableHeader header = headers[c];
084: DAVFile child = getChildAt(file, r);
085: return getValueForHeader(child, header);
086: } else
087: return "";
088: }
089:
090: public String getColumnName(int c) {
091: return ((c < headers.length) && c >= 0)
092: //&& (!headers[c].equals(DAVTableHeader.LOCK)))
093: ? headers[c].toString()
094: : null;
095: }
096:
097: public Class getColumnClass(int c) {
098: return ((c < headers.length) && c >= 0) ? headers[c]
099: .getRenderingClass() : null;
100: }
101:
102: protected void setTableHeaders(DAVTableHeader[] headers) {
103: this .headers = headers;
104: fireTableStructureChanged();
105: }
106:
107: private static Object getValueForHeader(DAVFile file,
108: DAVTableHeader header) {
109: if (header.equals(DAVTableHeader.LOCK))
110: return file.getExclusiveLock();
111: else if (header.equals(DAVTableHeader.FILE_NAME))
112: return URLDecoder.decode(file.getFileName());
113: else if (header.equals(DAVTableHeader.CREATION_DATE))
114: return getDate(file.getCreationDate());
115: else if (header.equals(DAVTableHeader.DISPLAY_NAME))
116: return file.getDisplayName();
117: else if (header.equals(DAVTableHeader.CONTENT_LANGUAGE))
118: return file.getContentLanguage();
119: else if (header.equals(DAVTableHeader.CONTENT_LENGTH))
120: return getLong(file.getContentLength());
121: else if (header.equals(DAVTableHeader.CONTENT_TYPE))
122: return file.getContentType();
123: else if (header.equals(DAVTableHeader.ETAG))
124: return file.getEtag();
125: else if (header.equals(DAVTableHeader.LAST_MODIFIED))
126: return getDate(file.getLastModified());
127: else if (header.equals(DAVTableHeader.EXECUTABLE))
128: return file.getCustomProperty(DAVProperty.EXECUTABLE);
129: else if (header.equals(DAVTableHeader.LOCKTOKEN))
130: return file.getExclusiveLockToken();
131: else if (header.equals(DAVTableHeader.LOCKTYPE)) {
132: Lock lock = file.getExclusiveLock();
133: return (lock == null) ? null : lock.getLockType();
134: } else if (header.equals(DAVTableHeader.LOCKSCOPE)) {
135: Lock lock = file.getExclusiveLock();
136: return (lock == null) ? null : lock.getLockScope();
137: } else if (header.equals(DAVTableHeader.OWNER)) {
138: Lock lock = file.getExclusiveLock();
139: return (lock == null) ? null : lock.getOwner();
140: } else if (header.equals(DAVTableHeader.RESOURCETYPE)) {
141: return new Boolean(file.isCollection());
142: } else {
143: Debug.trace(DAVTableModel.class, Debug.DP3,
144: "tableHeader {0} not recognized!", header);
145: }
146: return null;
147: }
148:
149: private static Object getLong(Object input) {
150: if (input == null)
151: return null;
152: try {
153: return new Long(input.toString());
154: } catch (NumberFormatException nafta) {
155: }
156: return input;
157: }
158:
159: private static Object getDate(Object input) {
160: //to be done
161: return input;
162: }
163: }
164:
165: /* $Log: DAVTableModel.java,v $
166: /* Revision 1.16 2001/07/18 03:23:06 smulloni
167: /* added URL decoding to filename display in the table model and copy/move/rename dialogs;
168: /* not in the PropertiesDialog table, however.
169: /*
170: /* Revision 1.15 2000/12/19 22:36:05 smulloni
171: /* adjustments to preamble.
172: /*
173: /* Revision 1.14 2000/12/03 23:53:26 smulloni
174: /* added license and copyright preamble to java files.
175: /*
176: /* Revision 1.13 2000/11/10 22:40:06 smullyan
177: /* added icon to table for resource type; fixes to copy and move; disabling of
178: /* menu items that are inappropriate.
179: /*
180: /* Revision 1.12 2000/11/09 23:34:55 smullyan
181: /* log added to every Java file, with the help of python. Lock stealing
182: /* implemented, and treatment of locks made more robust.
183: /* */
|