]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/fs/NioFileLabelProvider.java
Improve Javadoc
[lgpl/argeo-commons.git] / org.argeo.eclipse.ui / src / org / argeo / eclipse / ui / fs / NioFileLabelProvider.java
1 package org.argeo.eclipse.ui.fs;
2
3 import java.io.IOException;
4 import java.nio.file.Files;
5 import java.nio.file.Path;
6
7 import org.argeo.eclipse.ui.EclipseUiUtils;
8 import org.eclipse.jface.viewers.ColumnLabelProvider;
9
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;
14
15 public NioFileLabelProvider(String propName) {
16 this.propName = propName;
17 }
18
19 @Override
20 public String getText(Object element) {
21 Path path = (Path) element;
22 try {
23 switch (propName) {
24 case FsUiConstants.PROPERTY_SIZE:
25 if (Files.isDirectory(path))
26 return "-";
27 else
28 return FsUiUtils.humanReadableByteCount(Files.size(path), false);
29 case FsUiConstants.PROPERTY_LAST_MODIFIED:
30 return Files.getLastModifiedTime(path).toString();
31 case FsUiConstants.PROPERTY_TYPE:
32 if (Files.isDirectory(path))
33 return "Folder";
34 else {
35 String mimeType = Files.probeContentType(path);
36 if (EclipseUiUtils.isEmpty(mimeType))
37 return "Unknown";
38 else
39 return mimeType;
40 }
41 default:
42 throw new IllegalArgumentException("Unsupported property " + propName);
43 }
44 } catch (IOException ioe) {
45 throw new FsUiException("Cannot get property " + propName + " on " + path.toString());
46 }
47 }
48 }