]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/fs/NioFileLabelProvider.java
1 package org
.argeo
.eclipse
.ui
.fs
;
3 import java
.io
.IOException
;
4 import java
.nio
.file
.Files
;
5 import java
.nio
.file
.Path
;
7 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
8 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
10 /** Expect a {@link Path} as input element */
11 public class NioFileLabelProvider
extends ColumnLabelProvider
{
12 private static final long serialVersionUID
= 2160026425187796930L;
13 private final String propName
;
15 public NioFileLabelProvider(String propName
) {
16 this.propName
= propName
;
20 public String
getText(Object element
) {
21 Path path
= (Path
) element
;
24 case FsUiConstants
.PROPERTY_SIZE
:
25 return FsUiUtils
.humanReadableByteCount(Files
.size(path
), false);
26 case FsUiConstants
.PROPERTY_LAST_MODIFIED
:
27 return Files
.getLastModifiedTime(path
).toString();
28 case FsUiConstants
.PROPERTY_TYPE
:
29 if (Files
.isDirectory(path
))
32 String mimeType
= Files
.probeContentType(path
);
33 if (EclipseUiUtils
.isEmpty(mimeType
))
39 throw new IllegalArgumentException("Unsupported property " + propName
);
41 } catch (IOException ioe
) {
42 throw new FsUiException("Cannot get property " + propName
+ " on " + path
.toString());