]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - swt/org.argeo.swt.minidesktop/src/org/argeo/minidesktop/MiniExplorer.java
1 package org
.argeo
.minidesktop
;
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
.widgets
.Composite
;
19 import org
.eclipse
.swt
.widgets
.Display
;
20 import org
.eclipse
.swt
.widgets
.Shell
;
21 import org
.eclipse
.swt
.widgets
.Table
;
22 import org
.eclipse
.swt
.widgets
.TableItem
;
23 import org
.eclipse
.swt
.widgets
.Text
;
25 public class MiniExplorer
{
27 private Text addressT
;
28 private Table browser
;
30 private boolean showHidden
= false;
32 public MiniExplorer(Composite parent
, String url
) {
37 public MiniExplorer(Composite parent
) {
38 parent
.setLayout(noSpaceGridLayout(new GridLayout()));
40 Composite toolBar
= new Composite(parent
, SWT
.NONE
);
41 toolBar
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
42 toolBar
.setLayout(new FillLayout());
43 addressT
= new Text(toolBar
, SWT
.SINGLE
);
44 addressT
.addSelectionListener(new SelectionAdapter() {
47 public void widgetDefaultSelected(SelectionEvent e
) {
48 setUrl(addressT
.getText().trim());
51 browser
= createTable(parent
, this.path
);
55 public void setPath(Path url
) {
58 addressT
.setText(url
.toString());
59 if (browser
!= null) {
60 Composite parent
= browser
.getParent();
62 browser
= createTable(parent
, this.path
);
63 parent
.layout(true, true);
68 protected void pathChanged(Path path
) {
72 protected Table
createTable(Composite parent
, Path path
) {
73 Table table
= new Table(parent
, SWT
.BORDER
);
74 table
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
75 table
.addMouseListener(new MouseAdapter() {
78 public void mouseDoubleClick(MouseEvent e
) {
79 Point pt
= new Point(e
.x
, e
.y
);
80 TableItem item
= table
.getItem(pt
);
81 Path path
= (Path
) item
.getData();
82 if (Files
.isDirectory(path
)) {
85 //Program.launch(path.toString());
91 if (path
.getParent() != null) {
92 TableItem parentTI
= new TableItem(table
, SWT
.NONE
);
93 parentTI
.setText("..");
94 parentTI
.setData(path
.getParent());
99 DirectoryStream
<Path
> ds
= Files
.newDirectoryStream(path
, p
-> Files
.isDirectory(p
) && isShown(p
));
101 TableItem ti
= new TableItem(table
, SWT
.NONE
);
102 ti
.setText(p
.getFileName().toString() + "/");
106 ds
= Files
.newDirectoryStream(path
, p
-> !Files
.isDirectory(p
) && isShown(p
));
108 TableItem ti
= new TableItem(table
, SWT
.NONE
);
109 ti
.setText(p
.getFileName().toString());
112 } catch (IOException e1
) {
113 // TODO Auto-generated catch block
114 e1
.printStackTrace();
120 protected boolean isShown(Path path
) {
124 return !Files
.isHidden(path
);
125 } catch (IOException e
) {
126 throw new IllegalArgumentException("Cannot check " + path
, e
);
130 public void setUrl(String url
) {
131 setPath(Paths
.get(url
));
134 private static GridLayout
noSpaceGridLayout(GridLayout layout
) {
135 layout
.horizontalSpacing
= 0;
136 layout
.verticalSpacing
= 0;
137 layout
.marginWidth
= 0;
138 layout
.marginHeight
= 0;
142 public static void main(String
[] args
) {
143 Display display
= Display
.getCurrent() == null ?
new Display() : Display
.getCurrent();
144 Shell shell
= new Shell(display
, SWT
.SHELL_TRIM
);
146 String url
= args
.length
> 0 ? args
[0] : System
.getProperty("user.home");
147 new MiniExplorer(shell
, url
) {
150 protected void pathChanged(Path path
) {
151 shell
.setText(path
.toString());
157 shell
.setSize(new Point(800, 480));
158 while (!shell
.isDisposed()) {
159 if (!display
.readAndDispatch())