]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/fs/FsTableViewer.java
370d9b9bdf43f7d0ff51732a16efae1850333d6e
[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(false);
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 this.setContentProvider(new MyLazyCP());
46 return table;
47 }
48
49 public Table configureDefaultTable(List<ColumnDefinition> columns) {
50 this.setContentProvider(new MyLazyCP());
51 Table table = this.getTable();
52 table.setLinesVisible(true);
53 table.setHeaderVisible(true);
54 // CmsUtils.markup(table);
55 // CmsUtils.style(table, MaintenanceStyles.BROWSER_COLUMN);
56 for (ColumnDefinition colDef : columns) {
57 TableViewerColumn column = new TableViewerColumn(this, SWT.NONE);
58 column.setLabelProvider(colDef.getLabelProvider());
59 TableColumn tcol = column.getColumn();
60 tcol.setResizable(true);
61 tcol.setText(colDef.getLabel());
62 tcol.setWidth(colDef.getMinWidth());
63 }
64 return table;
65 }
66
67 public void setInput(Path dir, String filter) {
68 Object[] rows = FsUiUtils.getChildren(dir, filter, showHiddenItems, folderFirst, orderProperty, reverseOrder);
69 this.setInput(rows);
70 int length = rows == null ? 0 : rows.length;
71 this.setItemCount(length);
72 this.refresh();
73 }
74
75 /** Directly displays bookmarks **/
76 public void setPathsInput(Path... paths) {
77 this.setInput((Object[]) paths);
78 this.setItemCount(paths.length);
79 this.refresh();
80 }
81
82 private class MyLazyCP implements ILazyContentProvider {
83 private static final long serialVersionUID = 9096550041395433128L;
84 private Object[] elements;
85
86 public void dispose() {
87 }
88
89 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
90 // IMPORTANT: don't forget this: an exception will be thrown if
91 // a selected object is not part of the results anymore.
92 viewer.setSelection(null);
93 this.elements = (Object[]) newInput;
94 }
95
96 public void updateElement(int index) {
97 FsTableViewer.this.replace(elements[index], index);
98 }
99 }
100 }