1 package org
.argeo
.eclipse
.ui
.fs
;
3 import java
.nio
.file
.Files
;
4 import java
.nio
.file
.Path
;
5 import java
.util
.ArrayList
;
8 import org
.argeo
.api
.cms
.CmsLog
;
9 import org
.argeo
.eclipse
.ui
.ColumnDefinition
;
10 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
11 import org
.eclipse
.jface
.viewers
.DoubleClickEvent
;
12 import org
.eclipse
.jface
.viewers
.IDoubleClickListener
;
13 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
14 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
15 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
16 import org
.eclipse
.jface
.viewers
.Viewer
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.custom
.SashForm
;
19 import org
.eclipse
.swt
.events
.KeyEvent
;
20 import org
.eclipse
.swt
.events
.KeyListener
;
21 import org
.eclipse
.swt
.layout
.GridData
;
22 import org
.eclipse
.swt
.layout
.GridLayout
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Label
;
25 import org
.eclipse
.swt
.widgets
.Table
;
28 * Experimental UI upon Java 7 nio files api: SashForm layout with bookmarks on
29 * the left hand side and a simple table on the right hand side.
31 public class SimpleFsBrowser
extends Composite
{
32 private final static CmsLog log
= CmsLog
.getLog(SimpleFsBrowser
.class);
33 private static final long serialVersionUID
= -40347919096946585L;
35 private Path currSelected
;
36 private FsTableViewer bookmarksViewer
;
37 private FsTableViewer directoryDisplayViewer
;
39 public SimpleFsBrowser(Composite parent
, int style
) {
42 // parent.layout(true, true);
45 public Viewer
getViewer() {
46 return directoryDisplayViewer
;
49 private void createContent(Composite parent
) {
50 parent
.setLayout(EclipseUiUtils
.noSpaceGridLayout());
52 SashForm form
= new SashForm(parent
, SWT
.HORIZONTAL
);
53 Composite leftCmp
= new Composite(form
, SWT
.NONE
);
54 populateBookmarks(leftCmp
);
56 Composite rightCmp
= new Composite(form
, SWT
.BORDER
);
57 populateDisplay(rightCmp
);
58 form
.setLayoutData(EclipseUiUtils
.fillAll());
59 form
.setWeights(new int[] { 1, 3 });
62 public void setInput(Path
... paths
) {
63 bookmarksViewer
.setPathsInput(paths
);
64 bookmarksViewer
.getTable().getParent().layout(true, true);
67 private void populateBookmarks(final Composite parent
) {
68 // GridLayout layout = EclipseUiUtils.noSpaceGridLayout();
69 // layout.verticalSpacing = 5;
70 parent
.setLayout(new GridLayout());
72 ISelectionChangedListener selList
= new MySelectionChangedListener();
74 appendTitle(parent
, "My bookmarks");
75 bookmarksViewer
= new FsTableViewer(parent
, SWT
.MULTI
| SWT
.NO_SCROLL
);
76 Table table
= bookmarksViewer
.configureDefaultSingleColumnTable(500);
77 GridData gd
= EclipseUiUtils
.fillWidth();
78 gd
.horizontalIndent
= 10;
79 table
.setLayoutData(gd
);
80 bookmarksViewer
.addSelectionChangedListener(selList
);
82 appendTitle(parent
, "Jcr + File");
84 FsTableViewer jcrFilesViewers
= new FsTableViewer(parent
, SWT
.MULTI
| SWT
.NO_SCROLL
);
85 table
= jcrFilesViewers
.configureDefaultSingleColumnTable(500);
86 gd
= EclipseUiUtils
.fillWidth();
87 gd
.horizontalIndent
= 10;
88 table
.setLayoutData(gd
);
89 jcrFilesViewers
.addSelectionChangedListener(selList
);
91 // FileSystemProvider fsProvider = new JackrabbitMemoryFsProvider();
93 // Path testPath = fsProvider.getPath(new URI("jcr+memory:/"));
94 // jcrFilesViewers.setPathsInput(testPath);
95 // } catch (URISyntaxException e) {
96 // // TODO Auto-generated catch block
97 // e.printStackTrace();
101 private Label
appendTitle(Composite parent
, String value
) {
102 Label titleLbl
= new Label(parent
, SWT
.NONE
);
103 titleLbl
.setText(value
);
104 titleLbl
.setFont(EclipseUiUtils
.getBoldFont(parent
));
105 GridData gd
= EclipseUiUtils
.fillWidth();
106 gd
.horizontalIndent
= 5;
107 gd
.verticalIndent
= 5;
108 titleLbl
.setLayoutData(gd
);
112 private class MySelectionChangedListener
implements ISelectionChangedListener
{
114 public void selectionChanged(SelectionChangedEvent event
) {
115 IStructuredSelection selection
= (IStructuredSelection
) bookmarksViewer
.getSelection();
116 if (selection
.isEmpty())
119 Path newSelected
= (Path
) selection
.getFirstElement();
120 if (newSelected
.equals(currSelected
))
122 currSelected
= newSelected
;
123 directoryDisplayViewer
.setInput(currSelected
, "*");
128 private void populateDisplay(final Composite parent
) {
129 parent
.setLayout(EclipseUiUtils
.noSpaceGridLayout());
130 directoryDisplayViewer
= new FsTableViewer(parent
, SWT
.MULTI
);
131 List
<ColumnDefinition
> colDefs
= new ArrayList
<>();
132 colDefs
.add(new ColumnDefinition(new FileIconNameLabelProvider(), "Name", 200));
133 colDefs
.add(new ColumnDefinition(new NioFileLabelProvider(FsUiConstants
.PROPERTY_SIZE
), "Size", 100));
134 colDefs
.add(new ColumnDefinition(new NioFileLabelProvider(FsUiConstants
.PROPERTY_TYPE
), "Type", 250));
135 colDefs
.add(new ColumnDefinition(new NioFileLabelProvider(FsUiConstants
.PROPERTY_LAST_MODIFIED
),
136 "Last modified", 200));
137 Table table
= directoryDisplayViewer
.configureDefaultTable(colDefs
);
138 table
.setLayoutData(EclipseUiUtils
.fillAll());
140 table
.addKeyListener(new KeyListener() {
141 private static final long serialVersionUID
= -8083424284436715709L;
144 public void keyReleased(KeyEvent e
) {
148 public void keyPressed(KeyEvent e
) {
149 log
.debug("Key event received: " + e
.keyCode
);
150 IStructuredSelection selection
= (IStructuredSelection
) directoryDisplayViewer
.getSelection();
151 Path selected
= null;
152 if (!selection
.isEmpty())
153 selected
= ((Path
) selection
.getFirstElement());
154 if (e
.keyCode
== SWT
.CR
) {
155 if (!Files
.isDirectory(selected
))
157 if (selected
!= null) {
158 currSelected
= selected
;
159 directoryDisplayViewer
.setInput(currSelected
, "*");
161 } else if (e
.keyCode
== SWT
.BS
) {
162 currSelected
= currSelected
.getParent();
163 directoryDisplayViewer
.setInput(currSelected
, "*");
164 directoryDisplayViewer
.getTable().setFocus();
169 // directoryDisplayViewer.addDoubleClickListener(new IDoubleClickListener() {
171 // public void doubleClick(DoubleClickEvent event) {
172 // IStructuredSelection selection = (IStructuredSelection) directoryDisplayViewer.getSelection();
173 // Path selected = null;
174 // if (!selection.isEmpty()) {
175 // Object obj = selection.getFirstElement();
176 // if (obj instanceof Path)
177 // selected = (Path) obj;
178 // else if (obj instanceof ParentDir)
179 // selected = ((ParentDir) obj).getPath();
181 // if (selected != null) {
182 // if (!Files.isDirectory(selected))
184 // currSelected = selected;
185 // directoryDisplayViewer.setInput(currSelected, "*");
190 directoryDisplayViewer
.addDoubleClickListener(new IDoubleClickListener() {
192 public void doubleClick(DoubleClickEvent event
) {
193 IStructuredSelection selection
= (IStructuredSelection
) directoryDisplayViewer
.getSelection();
194 Path selected
= null;
195 if (!selection
.isEmpty()) {
196 Object obj
= selection
.getFirstElement();
197 if (obj
instanceof Path
)
198 selected
= (Path
) obj
;
199 else if (obj
instanceof ParentDir
)
200 selected
= ((ParentDir
) obj
).getPath();
202 if (selected
!= null) {
203 if (!Files
.isDirectory(selected
))
205 currSelected
= selected
;
206 directoryDisplayViewer
.setInput(currSelected
, "*");