]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - rcp/org.argeo.cms.desktop/src/org/argeo/cms/desktop/DesktopLayer.java
1 package org
.argeo
.cms
.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
.apache
.commons
.io
.FilenameUtils
;
10 import org
.eclipse
.swt
.SWT
;
11 import org
.eclipse
.swt
.events
.SelectionAdapter
;
12 import org
.eclipse
.swt
.events
.SelectionEvent
;
13 import org
.eclipse
.swt
.graphics
.Image
;
14 import org
.eclipse
.swt
.graphics
.ImageData
;
15 import org
.eclipse
.swt
.layout
.GridData
;
16 import org
.eclipse
.swt
.layout
.GridLayout
;
17 import org
.eclipse
.swt
.program
.Program
;
18 import org
.eclipse
.swt
.widgets
.Button
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
20 import org
.eclipse
.swt
.widgets
.Control
;
21 import org
.eclipse
.swt
.widgets
.Display
;
22 import org
.eclipse
.swt
.widgets
.Label
;
24 public class DesktopLayer
{
25 // TODO make it configurable
26 private Path desktopDir
= Paths
.get(System
.getProperty("user.home"), "tmp");
28 public void init(Composite parentShell
) {
29 // Decorations shell = new Decorations(parentShell, SWT.CLOSE);
30 // shell.setLayoutData(new GridData(GridData.FILL_BOTH));
31 createUi(parentShell
, desktopDir
);
35 public Control
createUi(Composite parent
, Path context
) {
36 // parent.setLayout(new FillLayout());
38 DirectoryStream
<Path
> ds
= Files
.newDirectoryStream(context
);
39 ds
.forEach((path
) -> createIcon(parent
, path
));
40 } catch (IOException e
) {
41 // TODO Auto-generated catch block
48 protected void createIcon(Composite parent
, Path path
) {
49 String ext
= FilenameUtils
.getExtension(path
.getFileName().toString());
50 Program program
= Program
.findProgram(ext
);
51 if (program
== null) {
52 createDefaultIcon(parent
, path
);
56 Display display
= parent
.getDisplay();
57 ImageData iconData
= program
.getImageData();
60 if (iconData
== null) {
61 iconImage
= display
.getSystemImage(SWT
.ICON_INFORMATION
);
62 iconData
= iconImage
.getImageData();
64 iconImage
= new Image(display
, iconData
);
67 Composite icon
= new Composite(parent
, SWT
.NONE
);
68 icon
.setLayoutData(new GridData(48, 72));
69 icon
.setLayout(new GridLayout());
71 Button iconB
= new Button(icon
, SWT
.FLAT
);
72 iconB
.setImage(iconImage
);
73 // iconB.setLayoutData(new GridData(iconData.width, iconData.height));
74 iconB
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false));
75 iconB
.addSelectionListener(new SelectionAdapter() {
78 public void widgetSelected(SelectionEvent e
) {
79 program
.execute(path
.toString());
84 Label iconL
= new Label(icon
, SWT
.WRAP
);
85 iconL
.setText(path
.getFileName().toString());
86 iconL
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false));
89 protected void createDefaultIcon(Composite parent
, Path path
) {
90 Composite icon
= new Composite(parent
, SWT
.NONE
);
91 icon
.setLayout(new GridLayout());
92 Label iconL
= new Label(icon
, SWT
.NONE
);
93 iconL
.setText(path
.getFileName().toString());
94 iconL
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, true, true));