001: package vicazh.hyperpool.stream.net.http;
002:
003: import java.io.*;
004: import java.text.*;
005: import java.util.*;
006: import java.util.logging.*;
007: import javax.swing.table.*;
008: import vicazh.hyperpool.Reader;
009: import vicazh.hyperpool.Start;
010:
011: /**
012: * The explorer table model
013: *
014: * @author Victor Zhigunov
015: * @version 0.4.0
016: */
017: public class IExplorerModel extends AbstractTableModel {
018: private Object file;
019:
020: private Object type;
021:
022: private Object length;
023:
024: private Object create;
025:
026: private Object check;
027:
028: private Reader reader;
029:
030: /**
031: * @param file
032: * column name for file
033: * @param type
034: * column name for type
035: * @param length
036: * column name for length
037: * @param create
038: * column name for create date
039: * @param check
040: * column name for check date
041: * @param reader
042: * xsl source transformer
043: */
044: public IExplorerModel(Object file, Object type, Object length,
045: Object create, Object check, Reader reader) {
046: this .file = file;
047: this .type = type;
048: this .length = length;
049: this .create = create;
050: this .check = check;
051: this .reader = reader;
052: }
053:
054: public Class<?> getColumnClass(int c) {
055: switch (c) {
056: case 2:
057: return Long.class;
058: }
059: return String.class;
060: }
061:
062: public boolean isCellEditable(int row, int col) {
063: return false;
064: }
065:
066: private ExplorerServiceMBean service;
067:
068: public void setService(ExplorerServiceMBean service) {
069: this .service = service;
070: }
071:
072: private File[] files;
073:
074: private int row = -1;
075:
076: void setData(File[] files) {
077: this .files = files;
078: row = -1;
079: fireTableDataChanged();
080: }
081:
082: private Session session;
083:
084: public Object getValueAt(int row, int column) {
085: if (this .row != row) {
086: try {
087: session = (Session) reader.getObject(service
088: .get(files[row]));
089: } catch (Exception e) {
090: Start.logger.log(Level.SEVERE, e.getMessage(), e);
091: }
092: this .row = row;
093: }
094: switch (column) {
095: case 0:
096: return new IExplorerDoc(session.getClient().getFile());
097: case 1:
098: return session.getServer().getFields().get("content-type");
099: case 2:
100: String l = (String) session.getServer().getFields().get(
101: "content-length");
102: return l == null ? null : new Long(l);
103: case 3:
104: String s = (String) session.getServer().getFields().get(
105: "last-modified");
106: try {
107: return s == null ? null : DateFormat
108: .getDateTimeInstance().format(
109: new SimpleDateFormat(
110: "E, dd MMM yyyy HH:mm:ss z",
111: Locale.ENGLISH).parse(s));
112: } catch (ParseException e) {
113: Start.logger.log(Level.SEVERE, e.getMessage(), e);
114: }
115: case 4:
116: return DateFormat.getDateTimeInstance().format(
117: new Date(service.lastModified(files[row])));
118: }
119: return null;
120: }
121:
122: public int getRowCount() {
123: if (files == null)
124: return 0;
125: return files.length;
126: }
127:
128: public int getColumnCount() {
129: return 5;
130: }
131:
132: public String getColumnName(int columnIndex) {
133: switch (columnIndex) {
134: case 0:
135: return file.toString();
136: case 1:
137: return type.toString();
138: case 2:
139: return length.toString();
140: case 3:
141: return create.toString();
142: case 4:
143: return check.toString();
144: }
145: return null;
146: }
147: }
|