X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=rcp%2Forg.argeo.cms.desktop%2Fsrc%2Forg%2Fargeo%2Fcms%2Fdesktop%2FDesktopLayer.java;fp=rcp%2Forg.argeo.cms.desktop%2Fsrc%2Forg%2Fargeo%2Fcms%2Fdesktop%2FDesktopLayer.java;h=0000000000000000000000000000000000000000;hb=2669e5797bdf4bcfa3a15b273ca4239e215d9cd4;hp=0565e7320949b351db652701da086b5fcfcc14ce;hpb=9b60a87396b76e794032a259609d845e52b757b7;p=lgpl%2Fargeo-commons.git diff --git a/rcp/org.argeo.cms.desktop/src/org/argeo/cms/desktop/DesktopLayer.java b/rcp/org.argeo.cms.desktop/src/org/argeo/cms/desktop/DesktopLayer.java deleted file mode 100644 index 0565e7320..000000000 --- a/rcp/org.argeo.cms.desktop/src/org/argeo/cms/desktop/DesktopLayer.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.argeo.cms.desktop; - -import java.io.IOException; -import java.nio.file.DirectoryStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -import org.apache.commons.io.FilenameUtils; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.program.Program; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; - -public class DesktopLayer { - // TODO make it configurable - private Path desktopDir = Paths.get(System.getProperty("user.home"), "tmp"); - - public void init(Composite parentShell) { -// Decorations shell = new Decorations(parentShell, SWT.CLOSE); -// shell.setLayoutData(new GridData(GridData.FILL_BOTH)); - createUi(parentShell, desktopDir); - // shell.open(); - } - - public Control createUi(Composite parent, Path context) { - // parent.setLayout(new FillLayout()); - try { - DirectoryStream ds = Files.newDirectoryStream(context); - ds.forEach((path) -> createIcon(parent, path)); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return parent; - - } - - protected void createIcon(Composite parent, Path path) { - String ext = FilenameUtils.getExtension(path.getFileName().toString()); - Program program = Program.findProgram(ext); - if (program == null) { - createDefaultIcon(parent, path); - return; - } - - Display display = parent.getDisplay(); - ImageData iconData = program.getImageData(); - - Image iconImage; - if (iconData == null) { - iconImage = display.getSystemImage(SWT.ICON_INFORMATION); - iconData = iconImage.getImageData(); - } else { - iconImage = new Image(display, iconData); - } - - Composite icon = new Composite(parent, SWT.NONE); - icon.setLayoutData(new GridData(48, 72)); - icon.setLayout(new GridLayout()); - // Button - Button iconB = new Button(icon, SWT.FLAT); - iconB.setImage(iconImage); - // iconB.setLayoutData(new GridData(iconData.width, iconData.height)); - iconB.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); - iconB.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent e) { - program.execute(path.toString()); - } - - }); - // Label - Label iconL = new Label(icon, SWT.WRAP); - iconL.setText(path.getFileName().toString()); - iconL.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); - } - - protected void createDefaultIcon(Composite parent, Path path) { - Composite icon = new Composite(parent, SWT.NONE); - icon.setLayout(new GridLayout()); - Label iconL = new Label(icon, SWT.NONE); - iconL.setText(path.getFileName().toString()); - iconL.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true)); - } -}