BrightSide Workbench Full Report + Source Code
FileColumn.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.file.zul.tree;
19 
20 import java.text.DateFormat;
21 import java.util.Date;
22 import org.turro.action.Plugins;
23 import org.turro.i18n.I_;
24 import org.turro.plugin.acceptance.IAcceptanceCtrl;
25 import org.zkoss.zk.ui.Component;
26 import org.zkoss.zul.Space;
27 import org.zkoss.zul.Treecell;
28 import org.zkoss.zul.Treecol;
29 
34 public class FileColumn extends Treecol {
35 
36  private FileColumnType type;
37 
38  public FileColumn(FileColumnType type) {
39  this(null, type);
40  }
41 
42  public FileColumn(String label, FileColumnType type) {
43  super(label == null ? I_.byKey(type.toString()) : label);
44  this.type = type;
45  if(type.equals(FileColumnType.FILE_NAME_COLUMN)) {
46  //
47  } else if(type.equals(FileColumnType.FILE_SIZE_COLUMN)) {
48  setWidth("90px");
49  } else if(type.equals(FileColumnType.FILE_DATE_COLUMN)) {
50  setWidth("110px");
51  }
52  }
53 
54  public Treecell getCell(FileItem fileItem) {
55  if(type.equals(FileColumnType.FILE_NAME_COLUMN)) {
56  Treecell cell = new Treecell(
57  fileItem.getFileLabel() != null ?
58  fileItem.getFileLabel() :
59  fileItem.getFile().getName());
60  if(fileItem.getFile().isFile()) {
61  cell.appendChild(new Space());
62  IAcceptanceCtrl accept = (IAcceptanceCtrl) Plugins.loadImplementation(IAcceptanceCtrl.class);//PluginChecker.get("acceptctrl");
63  accept.setEntity(fileItem.getFile().getAbsolutePath());
64  cell.appendChild((Component) accept);
65  }
66  return cell;
67  } else if(type.equals(FileColumnType.FILE_SIZE_COLUMN)) {
68  if(fileItem.getFile().isDirectory()) {
69  return new Treecell("");
70  } else {
71  return new Treecell(new org.turro.formatter.BytesFormatter(fileItem.getFile().length()).toString());
72  }
73  } else if(type.equals(FileColumnType.FILE_DATE_COLUMN)) {
74  DateFormat df = DateFormat.getDateInstance();
75  return new Treecell(df.format(new Date(fileItem.getFile().lastModified())));
76  }
77  return null;
78  }
79 
80 }
static< T > T loadImplementation(Class< T > jclass)
Definition: Plugins.java:57
Treecell getCell(FileItem fileItem)
Definition: FileColumn.java:54
FileColumn(FileColumnType type)
Definition: FileColumn.java:38
FileColumn(String label, FileColumnType type)
Definition: FileColumn.java:42
static String byKey(String key)
Definition: I_.java:83