]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/fs/FsTableViewer.java
Next developemt cycle
[lgpl/argeo-commons.git] / org.argeo.eclipse.ui / src / org / argeo / eclipse / ui / fs / FsTableViewer.java
1 package org.argeo.eclipse.ui.fs;
2
3 import java.nio.file.Path;
4 import java.util.List;
5
6 import org.argeo.eclipse.ui.ColumnDefinition;
7 import org.eclipse.jface.viewers.ILazyContentProvider;
8 import org.eclipse.jface.viewers.TableViewer;
9 import org.eclipse.jface.viewers.TableViewerColumn;
10 import org.eclipse.jface.viewers.Viewer;
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.layout.GridData;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Table;
15 import org.eclipse.swt.widgets.TableColumn;
16
17 /**
18 * Canonical implementation of a JFace table viewer to display the content of a
19 * file folder
20 */
21 public class FsTableViewer extends TableViewer {
22 private static final long serialVersionUID = -5632407542678477234L;
23
24 private boolean showHiddenItems = false;
25 private boolean folderFirst = true;
26 private boolean reverseOrder = false;
27 private String orderProperty = FsUiConstants.PROPERTY_NAME;
28
29 public FsTableViewer(Composite parent, int style) {
30 super(parent, style | SWT.VIRTUAL);
31 }
32
33 public Table configureDefaultSingleColumnTable(int tableWidthHint) {
34 Table table = this.getTable();
35 table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
36 table.setLinesVisible(true);
37 table.setHeaderVisible(false);
38 // CmsUtils.markup(table);
39 // CmsUtils.style(table, MaintenanceStyles.BROWSER_COLUMN);
40
41 TableViewerColumn column = new TableViewerColumn(this, SWT.NONE);
42 TableColumn tcol = column.getColumn();
43 tcol.setWidth(tableWidthHint);
44 column.setLabelProvider(new FileIconNameLabelProvider());
45
46 this.setContentProvider(new MyLazyCP());
47 return table;
48 }
49
50 public Table configureDefaultTable(List<ColumnDefinition> columns) {
51 this.setContentProvider(new MyLazyCP());
52 Table table = this.getTable();
53 table.setLinesVisible(true);
54 table.setHeaderVisible(true);
55 // CmsUtils.markup(table);
56 // CmsUtils.style(table, MaintenanceStyles.BROWSER_COLUMN);
57 for (ColumnDefinition colDef : columns) {
58 TableViewerColumn column = new TableViewerColumn(this, SWT.NONE);
59 column.setLabelProvider(colDef.getLabelProvider());
60 TableColumn tcol = column.getColumn();
61 tcol.setResizable(true);
62 tcol.setText(colDef.getLabel());
63 tcol.setWidth(colDef.getMinWidth());
64 }
65 return table;
66 }
67
68 public void setInput(Path dir, String filter) {
69 Object[] rows = FsUiUtils.getChildren(dir, filter, showHiddenItems, folderFirst, orderProperty, reverseOrder);
70 this.setInput(rows);
71 int length = rows == null ? 0 : rows.length;
72 this.setItemCount(length);
73 this.refresh();
74 }
75
76 /** Directly displays bookmarks **/
77 public void setPathsInput(Path... paths) {
78 this.setInput((Object[]) paths);
79 this.setItemCount(paths.length);
80 this.refresh();
81 }
82
83 private class MyLazyCP implements ILazyContentProvider {
84 private static final long serialVersionUID = 9096550041395433128L;
85 private Object[] elements;
86
87 public void dispose() {
88 }
89
90 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
91 // IMPORTANT: don't forget this: an exception will be thrown if
92 // a selected object is not part of the results anymore.
93 viewer.setSelection(null);
94 this.elements = (Object[]) newInput;
95 }
96
97 public void updateElement(int index) {
98 FsTableViewer.this.replace(elements[index], index);
99 }
100 }
101 }