]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - rcp/org.argeo.eclipse.ui.rcp/src/org/argeo/swt/desktop/MiniExplorer.java
1 package org
.argeo
.swt
.desktop
;
3 import java
.io
.IOException
;
4 import java
.nio
.file
.DirectoryStream
;
5 import java
.nio
.file
.Files
;
6 import java
.nio
.file
.Path
;
7 import java
.nio
.file
.Paths
;
9 import org
.eclipse
.swt
.SWT
;
10 import org
.eclipse
.swt
.events
.MouseAdapter
;
11 import org
.eclipse
.swt
.events
.MouseEvent
;
12 import org
.eclipse
.swt
.events
.SelectionAdapter
;
13 import org
.eclipse
.swt
.events
.SelectionEvent
;
14 import org
.eclipse
.swt
.graphics
.Point
;
15 import org
.eclipse
.swt
.layout
.FillLayout
;
16 import org
.eclipse
.swt
.layout
.GridData
;
17 import org
.eclipse
.swt
.layout
.GridLayout
;
18 import org
.eclipse
.swt
.program
.Program
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
20 import org
.eclipse
.swt
.widgets
.Display
;
21 import org
.eclipse
.swt
.widgets
.Shell
;
22 import org
.eclipse
.swt
.widgets
.Table
;
23 import org
.eclipse
.swt
.widgets
.TableItem
;
24 import org
.eclipse
.swt
.widgets
.Text
;
26 public class MiniExplorer
{
28 private Text addressT
;
29 private Table browser
;
31 private boolean showHidden
= false;
33 public MiniExplorer(Composite parent
, int style
) {
34 parent
.setLayout(new GridLayout());
36 Composite toolBar
= new Composite(parent
, SWT
.NONE
);
37 toolBar
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
38 toolBar
.setLayout(new FillLayout());
39 addressT
= new Text(toolBar
, SWT
.SINGLE
| SWT
.BORDER
);
40 // addressT.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
41 addressT
.addSelectionListener(new SelectionAdapter() {
44 public void widgetDefaultSelected(SelectionEvent e
) {
45 setUrl(addressT
.getText().trim());
48 browser
= createTable(parent
, this.url
);
52 public void setUrl(Path url
) {
55 addressT
.setText(url
.toString());
56 if (browser
!= null) {
57 Composite parent
= browser
.getParent();
59 browser
= createTable(parent
, this.url
);
60 parent
.layout(true, true);
64 protected Table
createTable(Composite parent
, Path path
) {
65 Table table
= new Table(parent
, SWT
.BORDER
);
66 table
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
67 table
.addMouseListener(new MouseAdapter() {
70 public void mouseDoubleClick(MouseEvent e
) {
71 Point pt
= new Point(e
.x
, e
.y
);
72 TableItem item
= table
.getItem(pt
);
73 Path path
= (Path
) item
.getData();
74 if (Files
.isDirectory(path
)) {
77 Program
.launch(path
.toString());
83 if (path
.getParent() != null) {
84 TableItem parentTI
= new TableItem(table
, SWT
.NONE
);
85 parentTI
.setText("..");
86 parentTI
.setData(path
.getParent());
91 DirectoryStream
<Path
> ds
= Files
.newDirectoryStream(url
, p
-> Files
.isDirectory(p
) && isShown(p
));
93 TableItem ti
= new TableItem(table
, SWT
.NONE
);
94 ti
.setText(p
.getFileName().toString() + "/");
98 ds
= Files
.newDirectoryStream(url
, p
-> !Files
.isDirectory(p
) && isShown(p
));
100 TableItem ti
= new TableItem(table
, SWT
.NONE
);
101 ti
.setText(p
.getFileName().toString());
104 } catch (IOException e1
) {
105 // TODO Auto-generated catch block
106 e1
.printStackTrace();
112 protected boolean isShown(Path path
) {
116 return !Files
.isHidden(path
);
117 } catch (IOException e
) {
118 throw new IllegalArgumentException("Cannot check " + path
, e
);
122 public void setUrl(String url
) {
123 setUrl(Paths
.get(url
));
126 public static void main(String
[] args
) {
127 Display display
= Display
.getCurrent() == null ?
new Display() : Display
.getCurrent();
128 Shell shell
= new Shell(display
, SWT
.SHELL_TRIM
);
130 MiniExplorer miniBrowser
= new MiniExplorer(shell
, SWT
.NONE
);
131 String url
= args
.length
> 0 ? args
[0] : System
.getProperty("user.home");
132 miniBrowser
.setUrl(url
);
135 shell
.setSize(new Point(800, 480));
136 while (!shell
.isDisposed()) {
137 if (!display
.readAndDispatch())