1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package wjhk.jupload2.gui.filepanel.treeview;
27
28 import java.io.File;
29 import java.io.InputStream;
30 import java.util.ArrayList;
31 import java.util.Date;
32 import java.util.List;
33
34 import javax.swing.tree.TreeModel;
35 import javax.swing.tree.TreePath;
36
37 import wjhk.jupload2.exception.JUploadException;
38 import wjhk.jupload2.exception.JUploadIOException;
39 import wjhk.jupload2.filedata.FileData;
40 import wjhk.jupload2.gui.filepanel.FilePanelFlatDataModel2;
41 import wjhk.jupload2.upload.helper.ByteArrayEncoder;
42
43
44
45
46 public class FileDataNode implements TreeFileDataNode {
47
48
49 MyTreeTableModel<TreeFileDataNode> treeModel = null;
50
51
52
53
54
55
56
57
58 FilePanelFlatDataModel2 flatModel = null;
59
60
61 FileData fileData = null;
62
63
64
65
66
67 TreeFileDataNode parent = null;
68
69
70
71
72 public FileDataNode(FileData fileData) {
73 this.fileData = fileData;
74 fileData.setTreeFileDataNode(this);
75 }
76
77
78 public int getTotalChildCount() {
79 return 0;
80 }
81
82 public List<MyTreeNode> getChildren() {
83 return new ArrayList<MyTreeNode>(0);
84 }
85
86 public void appendFileProperties(ByteArrayEncoder bae, int index) throws JUploadIOException {
87 fileData.appendFileProperties(bae, index);
88 }
89
90 public void beforeUpload(String uploadFileRoot) throws JUploadException {
91 fileData.beforeUpload(uploadFileRoot);
92 }
93
94 public long getUploadLength() {
95 return fileData.getUploadLength();
96 }
97
98 public void afterUpload() {
99 fileData.afterUpload();
100 }
101
102 public InputStream getInputStream() throws JUploadException {
103 return fileData.getInputStream();
104 }
105
106 public String getFileName() {
107 return fileData.getFileName();
108 }
109
110 public String getFileExtension() {
111 return fileData.getFileExtension();
112 }
113
114 public long getFileLength() {
115 return fileData.getFileLength();
116 }
117
118 public Date getLastModified() {
119 return fileData.getLastModified();
120 }
121
122 public boolean getUploadFlag() {
123 return fileData.getUploadFlag();
124 }
125
126 public void setUploadFlag(boolean uploadFlag) {
127 if (fileData.getUploadFlag() != uploadFlag) {
128
129 fileData.setUploadFlag(uploadFlag);
130 if (treeModel != null) {
131 treeModel.fireTreeNodesChanged(this, treeModel.getTreePath((TreeFileDataNode) getParent()),
132 FolderNode.getIntArray((getParent().getChildren()).indexOf(this)),
133 FolderNode.getItemArray((TreeFileDataNode) this));
134 }
135 }
136 }
137
138 public String getDirectory() {
139 return fileData.getDirectory();
140 }
141
142 public String getMD5() throws JUploadException {
143 return fileData.getMD5();
144 }
145
146 public String getMimeType() {
147 return fileData.getMimeType();
148 }
149
150 public boolean canRead() {
151 return fileData.canRead();
152 }
153
154 public File getFile() {
155 throw new IllegalAccessError("Internal error: getFile is deprecated and should not be called from "
156 + this.getClass().getName());
157 }
158
159 public String getRelativeDir() {
160 return fileData.getRelativeDir();
161 }
162
163 public String getAbsolutePath() {
164 return FolderNode.getAbsolutePath(this);
165 }
166
167 public boolean isPreparedForUpload() {
168 return fileData.isPreparedForUpload();
169 }
170
171 public int getChildCount() {
172 return 0;
173 }
174
175 public MyTreeNode getChild(int index) {
176 return null;
177 }
178
179 public MyTreeNode getChild(String name) {
180
181 return null;
182 }
183
184 public MyTreeNode getParent() {
185 return this.parent;
186 }
187
188
189 public void setParent(MyTreeNode parent) {
190 this.parent = (TreeFileDataNode) parent;
191 }
192
193
194 @SuppressWarnings("unchecked")
195 public void setTreeModel(TreeModel model) {
196 this.treeModel = (MyTreeTableModel<TreeFileDataNode>) model;
197 }
198
199
200 public void setFlatModel(FilePanelFlatDataModel2 flatModel) {
201 this.flatModel = flatModel;
202 }
203
204 public void removeChild(MyTreeNode child) {
205 throw new IllegalArgumentException(this.getClass().getName() + " can't have children");
206 }
207
208 public boolean isLeaf() {
209 return true;
210 }
211
212
213
214
215
216
217 @Override
218 public String toString() {
219 return getFileName();
220 }
221
222 public TreeFileDataNode getTreeFileDataNode() {
223 return this;
224 }
225
226 public void setTreeFileDataNode(TreeFileDataNode node) {
227 throw new IllegalStateException("setTreeFileDataNode may not be called againts a " + this.getClass().getName());
228 }
229
230 public TreePath getTreePath() {
231 if (parent == null) {
232 return new TreePath(this);
233 } else {
234 return parent.getTreePath().pathByAddingChild(this);
235 }
236 }
237 }