BrightSide Workbench Full Report + Source Code
FileNavigatorGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 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 
19 package org.turro.file.zul.navigator;
20 
21 import java.io.File;
22 import org.turro.i18n.I_;
23 import org.turro.zkoss.grid.PagingGrid;
24 import org.zkoss.zk.ui.ext.AfterCompose;
25 import org.zkoss.zul.Column;
26 import org.zkoss.zul.Columns;
27 
32 public class FileNavigatorGrid extends PagingGrid implements AfterCompose {
33 
34  private FileFolder currentFolder;
35  private boolean readOnly;
36 
37  public FileNavigatorGrid() {
38  addColumns();
39  }
40 
41  public boolean isReadOnly() {
42  return readOnly;
43  }
44 
45  public void setReadOnly(boolean readOnly) {
46  this.readOnly = readOnly;
47  }
48 
50  return currentFolder;
51  }
52 
53  public void setCurrentFolder(FileFolder currentFolder) {
54  this.currentFolder = currentFolder;
55  populateList();
56  }
57 
58  private void populateList() {
59  getRows(true).getChildren().clear();
60  if(currentFolder != null) {
61  for(FileFolder f : currentFolder.getFileFolders()) {
62  getRows(true).appendChild(new FolderRow(f));
63  }
64  for(File a : currentFolder.getFiles()) {
65  getRows(true).appendChild(new FileRow(a, readOnly));
66  }
67  }
68  setRowCount(getRows(true).getChildren().size());
69  }
70 
71  @Override
72  public void afterCompose() {
73  }
74 
75  private void addColumns() {
76  Columns cols = getColumns(true);
77 
79 
80  Column col = new Column();
81  col.setLabel(I_.get("Name"));
82  col.setHflex("1");
83  cols.appendChild(col);
84 
85  col = new Column();
86  col.setLabel(I_.get("Size"));
87  col.setAlign("right");
88  col.setWidth("120px");
89  cols.appendChild(col);
90 
91  col = new Column();
92  col.setLabel(I_.get("Date"));
93  col.setWidth("180px");
94  cols.appendChild(col);
95  }
96 
97 }
Collection< FileFolder > getFileFolders()
void setCurrentFolder(FileFolder currentFolder)
static String get(String msg)
Definition: I_.java:41
Columns getColumns(boolean create)
Rows getRows(boolean create)