aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorelmot <elmotelmot.vaadin.com>2018-04-27 15:50:25 +0300
committerelmot <elmotelmot.vaadin.com>2018-04-27 15:50:25 +0300
commitbbe90d483c37920a0b26a6870e103dcde7daad36 (patch)
treedca4525c497faa9e32a74d34aa080c7cc1a5ba73
parentc638a56f4813eeff8967ffe64143b31ebc14636d (diff)
downloadvaadin-framework-bbe90d483c37920a0b26a6870e103dcde7daad36.tar.gz
vaadin-framework-bbe90d483c37920a0b26a6870e103dcde7daad36.zip
Move old stuff to compatibility
Fixes #10851
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/data/util/FilesystemContainer.java74
-rw-r--r--server/src/main/java/com/vaadin/util/FileTypeResolver.java70
2 files changed, 73 insertions, 71 deletions
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/FilesystemContainer.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/FilesystemContainer.java
index 6789e9bd81..593ad44fb8 100644
--- a/compatibility-server/src/main/java/com/vaadin/v7/data/util/FilesystemContainer.java
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/FilesystemContainer.java
@@ -28,8 +28,11 @@ import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import com.vaadin.server.Resource;
+import com.vaadin.server.ThemeResource;
import com.vaadin.util.FileTypeResolver;
import com.vaadin.v7.data.Container;
import com.vaadin.v7.data.Item;
@@ -50,6 +53,10 @@ import com.vaadin.v7.data.Property;
public class FilesystemContainer implements Container.Hierarchical {
/**
+ * MIME type to Icon mapping.
+ */
+ private static final Map<String, Resource> MIME_TO_ICON_MAP = new ConcurrentHashMap<>();
+ /**
* String identifier of a file's "name" property.
*/
public static String PROPERTY_NAME = "Name";
@@ -172,6 +179,71 @@ public class FilesystemContainer implements Container.Hierarchical {
setRecursive(recursive);
}
+ static {
+ // Initialize Icons
+ ThemeResource folder = new ThemeResource("../runo/icons/16/folder.png");
+ FilesystemContainer.addIcon("inode/drive", folder);
+ FilesystemContainer.addIcon("inode/directory", folder);
+
+ }
+
+ /**
+ * Gets the descriptive icon representing file, based on the filename. First
+ * the mime-type for the given filename is resolved, and then the
+ * corresponding icon is fetched from the internal icon storage. If it is
+ * not found the default icon is returned.
+ *
+ * @param fileName the name of the file whose icon is requested.
+ * @return the icon corresponding to the given file
+ */
+ public static Resource getIcon(String fileName) {
+ return getIconByMimeType(FileTypeResolver.getMIMEType(fileName));
+ }
+
+ private static Resource getIconByMimeType(String mimeType) {
+ final Resource icon = MIME_TO_ICON_MAP.get(mimeType);
+ if (icon != null) {
+ return icon;
+ }
+
+ // If nothing is known about the file-type, general file
+ // icon is used
+ return FileTypeResolver.DEFAULT_ICON;
+ }
+
+ /**
+ * Gets the descriptive icon representing a file. First the mime-type for
+ * the given file name is resolved, and then the corresponding icon is
+ * fetched from the internal icon storage. If it is not found the default
+ * icon is returned.
+ *
+ * @param file the file whose icon is requested.
+ * @return the icon corresponding to the given file
+ */
+ public static Resource getIcon(File file) {
+ return getIconByMimeType(FileTypeResolver.getMIMEType(file));
+ }
+
+ /**
+ * Adds a icon for the given mime-type. If the mime-type also has a
+ * corresponding icon, it is replaced with the new icon.
+ *
+ * @param mimeType the mime-type whose icon is to be changed.
+ * @param icon the new icon to be associated with <code>MIMEType</code>.
+ */
+ public static void addIcon(String mimeType, Resource icon) {
+ MIME_TO_ICON_MAP.put(mimeType, icon);
+ }
+
+ /**
+ * Gets the internal mime-type to icon mapping.
+ *
+ * @return unmodifiable map containing the current mime-type to icon mapping
+ */
+ public static Map<String, Resource> getMIMETypeToIconMapping() {
+ return Collections.unmodifiableMap(MIME_TO_ICON_MAP);
+ }
+
/**
* Adds new root file directory. Adds a file to be included as root file
* directory in the <code>FilesystemContainer</code>.
@@ -714,7 +786,7 @@ public class FilesystemContainer implements Container.Hierarchical {
* @return the icon of this file.
*/
public Resource getIcon() {
- return FileTypeResolver.getIcon(file);
+ return FilesystemContainer.getIcon(file);
}
/**
diff --git a/server/src/main/java/com/vaadin/util/FileTypeResolver.java b/server/src/main/java/com/vaadin/util/FileTypeResolver.java
index 4606463683..43126872ea 100644
--- a/server/src/main/java/com/vaadin/util/FileTypeResolver.java
+++ b/server/src/main/java/com/vaadin/util/FileTypeResolver.java
@@ -213,11 +213,6 @@ public class FileTypeResolver implements Serializable {
*/
private static final Map<String, String> EXT_TO_MIME_MAP = new ConcurrentHashMap<>();
- /**
- * MIME type to Icon mapping.
- */
- private static final Map<String, Resource> MIME_TO_ICON_MAP = new ConcurrentHashMap<>();
-
static {
// Initialize extension to MIME map
@@ -233,10 +228,6 @@ public class FileTypeResolver implements Serializable {
}
}
- // Initialize Icons
- ThemeResource folder = new ThemeResource("../runo/icons/16/folder.png");
- addIcon("inode/drive", folder);
- addIcon("inode/directory", folder);
}
/**
@@ -282,45 +273,6 @@ public class FileTypeResolver implements Serializable {
}
/**
- * Gets the descriptive icon representing file, based on the filename. First
- * the mime-type for the given filename is resolved, and then the
- * corresponding icon is fetched from the internal icon storage. If it is
- * not found the default icon is returned.
- *
- * @param fileName
- * the name of the file whose icon is requested.
- * @return the icon corresponding to the given file
- */
- public static Resource getIcon(String fileName) {
- return getIconByMimeType(getMIMEType(fileName));
- }
-
- private static Resource getIconByMimeType(String mimeType) {
- final Resource icon = MIME_TO_ICON_MAP.get(mimeType);
- if (icon != null) {
- return icon;
- }
-
- // If nothing is known about the file-type, general file
- // icon is used
- return DEFAULT_ICON;
- }
-
- /**
- * Gets the descriptive icon representing a file. First the mime-type for
- * the given file name is resolved, and then the corresponding icon is
- * fetched from the internal icon storage. If it is not found the default
- * icon is returned.
- *
- * @param file
- * the file whose icon is requested.
- * @return the icon corresponding to the given file
- */
- public static Resource getIcon(File file) {
- return getIconByMimeType(getMIMEType(file));
- }
-
- /**
* Gets the mime-type for a file. Currently the returned file type is
* resolved by the filename extension only.
*
@@ -364,19 +316,6 @@ public class FileTypeResolver implements Serializable {
}
/**
- * Adds a icon for the given mime-type. If the mime-type also has a
- * corresponding icon, it is replaced with the new icon.
- *
- * @param mimeType
- * the mime-type whose icon is to be changed.
- * @param icon
- * the new icon to be associated with <code>MIMEType</code>.
- */
- public static void addIcon(String mimeType, Resource icon) {
- MIME_TO_ICON_MAP.put(mimeType, icon);
- }
-
- /**
* Gets the internal file extension to mime-type mapping.
*
* @return unmodifiable map containing the current file extension to
@@ -386,15 +325,6 @@ public class FileTypeResolver implements Serializable {
return Collections.unmodifiableMap(EXT_TO_MIME_MAP);
}
- /**
- * Gets the internal mime-type to icon mapping.
- *
- * @return unmodifiable map containing the current mime-type to icon mapping
- */
- public static Map<String, Resource> getMIMETypeToIconMapping() {
- return Collections.unmodifiableMap(MIME_TO_ICON_MAP);
- }
-
private FileTypeResolver() {
}
}