Class FilesystemContainer
- java.lang.Object
-
- com.vaadin.data.util.FilesystemContainer
-
- All Implemented Interfaces:
Container,Container.Hierarchical,Serializable
public class FilesystemContainer extends Object implements Container.Hierarchical
A hierarchical container wrapper for a filesystem.- Since:
- 3.0
- Author:
- Vaadin Ltd.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classFilesystemContainer.FileExtensionFilterGeneric file extension filter for displaying only files having certain extension.classFilesystemContainer.FileItemA Item wrapper for files in a filesystem.-
Nested classes/interfaces inherited from interface com.vaadin.data.Container
Container.Editor, Container.Filter, Container.Filterable, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeEvent, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeEvent, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.SimpleFilterable, Container.Sortable, Container.Viewer
-
-
Field Summary
Fields Modifier and Type Field Description static Collection<String>FILE_PROPERTIESList of the string identifiers for the available properties.static StringPROPERTY_ICONString identifier of a file's "icon" property.static StringPROPERTY_LASTMODIFIEDString identifier of a file's "last modified" property.static StringPROPERTY_NAMEString identifier of a file's "name" property.static StringPROPERTY_SIZEString identifier of a file's "size" property.
-
Constructor Summary
Constructors Constructor Description FilesystemContainer(File root)Constructs a newFileSystemContainerwith the specified file as the root of the filesystem.FilesystemContainer(File root, boolean recursive)Constructs a newFileSystemContainerwith the specified file as the root of the filesystem.FilesystemContainer(File root, FilenameFilter filter, boolean recursive)Constructs a newFileSystemContainerwith the specified root and recursivity status.FilesystemContainer(File root, String extension, boolean recursive)Constructs a newFileSystemContainerwith the specified file as the root of the filesystem.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddContainerProperty(Object propertyId, Class<?> type, Object defaultValue)Adds a new Property to all Items in the Container.ObjectaddItem()Creates a new Item into the Container, and assign it an automatic ID.ItemaddItem(Object itemId)Creates a new Item with the given ID in the Container.voidaddRoot(File root)Adds new root file directory.booleanareChildrenAllowed(Object itemId)Tests if the specified Item in the container may have children.booleancontainsId(Object itemId)Tests if the Container contains the specified Item.Collection<File>getChildren(Object itemId)Gets the IDs of all Items that are children of the specified Item.PropertygetContainerProperty(Object itemId, Object propertyId)Gets the specified property of the specified file Item.Collection<String>getContainerPropertyIds()Gets the collection of available file properties.FilenameFiltergetFilter()Returns the file filter used to limit the files in this container.ItemgetItem(Object itemId)Gets theItemwith the given Item ID from the Container.Collection<File>getItemIds()Gets the ID's of all visible (after filtering and sorting) Items stored in the Container.ObjectgetParent(Object itemId)Gets the ID of the parent Item of the specified Item.Class<?>getType(Object propertyId)Gets the specified property's data type.booleanhasChildren(Object itemId)Tests if the Item specified withitemIdhas child Items or if it is a leaf.booleanisRecursive()Is this container recursive filesystem.booleanisRoot(Object itemId)Tests if the Item specified withitemIdis a root Item.booleanremoveAllItems()Removes all Items from the Container.booleanremoveContainerProperty(Object propertyId)Removes a Property specified by the given Property ID from the Container.booleanremoveItem(Object itemId)Removes the Item identified byItemIdfrom the Container.Collection<File>rootItemIds()Gets the IDs of all Items in the container that don't have a parent.booleansetChildrenAllowed(Object itemId, boolean areChildrenAllowed)Returnsfalsewhen conversion from files to directories is not supported.voidsetFilter(FilenameFilter filter)Sets the file filter used to limit the files in this container.voidsetFilter(String extension)Sets the file filter used to limit the files in this container.booleansetParent(Object itemId, Object newParentId)Returnsfalsewhen moving files around in the filesystem is not supported.voidsetRecursive(boolean recursive)Sets the container recursive property.intsize()Gets the number of Items in the container.
-
-
-
Field Detail
-
PROPERTY_NAME
public static String PROPERTY_NAME
String identifier of a file's "name" property.
-
PROPERTY_SIZE
public static String PROPERTY_SIZE
String identifier of a file's "size" property.
-
PROPERTY_ICON
public static String PROPERTY_ICON
String identifier of a file's "icon" property.
-
PROPERTY_LASTMODIFIED
public static String PROPERTY_LASTMODIFIED
String identifier of a file's "last modified" property.
-
FILE_PROPERTIES
public static Collection<String> FILE_PROPERTIES
List of the string identifiers for the available properties.
-
-
Constructor Detail
-
FilesystemContainer
public FilesystemContainer(File root)
Constructs a newFileSystemContainerwith the specified file as the root of the filesystem. The files are included recursively.- Parameters:
root- the root file for the new file-system container. Null values are ignored.
-
FilesystemContainer
public FilesystemContainer(File root, boolean recursive)
Constructs a newFileSystemContainerwith the specified file as the root of the filesystem. The files are included recursively.- Parameters:
root- the root file for the new file-system container.recursive- should the container recursively contain subdirectories.
-
FilesystemContainer
public FilesystemContainer(File root, String extension, boolean recursive)
Constructs a newFileSystemContainerwith the specified file as the root of the filesystem.- Parameters:
root- the root file for the new file-system container.extension- the Filename extension (w/o separator) to limit the files in container.recursive- should the container recursively contain subdirectories.
-
FilesystemContainer
public FilesystemContainer(File root, FilenameFilter filter, boolean recursive)
Constructs a newFileSystemContainerwith the specified root and recursivity status.- Parameters:
root- the root file for the new file-system container.filter- the Filename filter to limit the files in container.recursive- should the container recursively contain subdirectories.
-
-
Method Detail
-
addRoot
public void addRoot(File root)
Adds new root file directory. Adds a file to be included as root file directory in theFilesystemContainer.- Parameters:
root- the File to be added as root directory. Null values are ignored.
-
areChildrenAllowed
public boolean areChildrenAllowed(Object itemId)
Tests if the specified Item in the container may have children. Since aFileSystemContainercontains files and directories, this method returnstruefor directory Items only.- Specified by:
areChildrenAllowedin interfaceContainer.Hierarchical- Parameters:
itemId- the id of the item.- Returns:
trueif the specified Item is a directory,falseotherwise.
-
getChildren
public Collection<File> getChildren(Object itemId)
Description copied from interface:Container.HierarchicalGets the IDs of all Items that are children of the specified Item. The returned collection is unmodifiable.- Specified by:
getChildrenin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item whose children the caller is interested in- Returns:
- An unmodifiable
collectioncontaining the IDs of all other Items that are children in the container hierarchy;nullif item does not have any children.
-
getParent
public Object getParent(Object itemId)
Description copied from interface:Container.HierarchicalGets the ID of the parent Item of the specified Item.- Specified by:
getParentin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item whose parent the caller wishes to find out.- Returns:
- the ID of the parent Item. Will be
nullif the specified Item is a root element.
-
hasChildren
public boolean hasChildren(Object itemId)
Description copied from interface:Container.HierarchicalTests if the Item specified with
itemIdhas child Items or if it is a leaf. TheContainer.Hierarchical.getChildren(Object itemId)method always returnsnullfor leaf Items.Note that being a leaf does not imply whether or not an Item is allowed to have children.
- Specified by:
hasChildrenin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item to be tested- Returns:
trueif the specified Item has children,falseif not (is a leaf)
-
isRoot
public boolean isRoot(Object itemId)
Description copied from interface:Container.HierarchicalTests if the Item specified withitemIdis a root Item. The hierarchical container can have more than one root and must have at least one unless it is empty. TheContainer.Hierarchical.getParent(Object itemId)method always returnsnullfor root Items.- Specified by:
isRootin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item whose root status is to be tested- Returns:
trueif the specified Item is a root,falseif not
-
rootItemIds
public Collection<File> rootItemIds()
Description copied from interface:Container.HierarchicalGets the IDs of all Items in the container that don't have a parent. Such items are calledrootItems. The returned collection is unmodifiable.- Specified by:
rootItemIdsin interfaceContainer.Hierarchical- Returns:
- An unmodifiable
collectioncontaining IDs of all root elements of the container
-
setChildrenAllowed
public boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed) throws UnsupportedOperationException
Returnsfalsewhen conversion from files to directories is not supported.- Specified by:
setChildrenAllowedin interfaceContainer.Hierarchical- Parameters:
itemId- the ID of the item.areChildrenAllowed- the boolean value specifying if the Item can have children or not.- Returns:
trueif the operaton is successful otherwisefalse.- Throws:
UnsupportedOperationException- if the setChildrenAllowed is not supported.
-
setParent
public boolean setParent(Object itemId, Object newParentId) throws UnsupportedOperationException
Returnsfalsewhen moving files around in the filesystem is not supported.- Specified by:
setParentin interfaceContainer.Hierarchical- Parameters:
itemId- the ID of the item.newParentId- the ID of the Item that's to be the new parent of the Item identified with itemId.- Returns:
trueif the operation is successful otherwisefalse.- Throws:
UnsupportedOperationException- if the setParent is not supported.
-
containsId
public boolean containsId(Object itemId)
Description copied from interface:ContainerTests if the Container contains the specified Item.Filtering can hide items so that they will not be visible through the container API, and this method should respect visibility of items (i.e. only indicate visible items as being in the container) if feasible for the container.
- Specified by:
containsIdin interfaceContainer- Parameters:
itemId- ID the of Item to be tested- Returns:
- boolean indicating if the Container holds the specified Item
-
getItem
public Item getItem(Object itemId)
Description copied from interface:ContainerGets theItemwith the given Item ID from the Container. If the Container does not contain the requested Item,nullis returned.Containers should not return Items that are filtered out.
-
getItemIds
public Collection<File> getItemIds()
Description copied from interface:ContainerGets the ID's of all visible (after filtering and sorting) Items stored in the Container. The ID's cannot be modified through the returned collection.If the container is
Container.Ordered, the collection returned by this method should follow that order. If the container isContainer.Sortable, the items should be in the sorted order.Calling this method for large lazy containers can be an expensive operation and should be avoided when practical.
- Specified by:
getItemIdsin interfaceContainer- Returns:
- unmodifiable collection of Item IDs
-
getContainerProperty
public Property getContainerProperty(Object itemId, Object propertyId)
Gets the specified property of the specified file Item. The available file properties are "Name", "Size" and "Last Modified". If propertyId is not one of those,nullis returned.- Specified by:
getContainerPropertyin interfaceContainer- Parameters:
itemId- the ID of the file whose property is requested.propertyId- the property's ID.- Returns:
- the requested property's value, or
null
-
getContainerPropertyIds
public Collection<String> getContainerPropertyIds()
Gets the collection of available file properties.- Specified by:
getContainerPropertyIdsin interfaceContainer- Returns:
- Unmodifiable collection containing all available file properties.
-
getType
public Class<?> getType(Object propertyId)
Gets the specified property's data type. "Name" is aString, "Size" is aLong, "Last Modified" is aDate. If propertyId is not one of those,nullis returned.
-
size
public int size()
Gets the number of Items in the container. In effect, this is the combined amount of files and directories.
-
getFilter
public FilenameFilter getFilter()
Returns the file filter used to limit the files in this container.- Returns:
- Used filter instance or null if no filter is assigned.
-
setFilter
public void setFilter(FilenameFilter filter)
Sets the file filter used to limit the files in this container.- Parameters:
filter- The filter to set.nulldisables filtering.
-
setFilter
public void setFilter(String extension)
Sets the file filter used to limit the files in this container.- Parameters:
extension- the Filename extension (w/o separator) to limit the files in container.
-
isRecursive
public boolean isRecursive()
Is this container recursive filesystem.- Returns:
trueif container is recursive,falseotherwise.
-
setRecursive
public void setRecursive(boolean recursive)
Sets the container recursive property. Set this to false to limit the files directly under the root file.Note : This is meaningful only if the root really is a directory.
- Parameters:
recursive- the New value for recursive property.
-
addContainerProperty
public boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue) throws UnsupportedOperationException
Description copied from interface:ContainerAdds a new Property to all Items in the Container. The Property ID, data type and default value of the new Property are given as parameters.This functionality is optional.
- Specified by:
addContainerPropertyin interfaceContainer- Parameters:
propertyId- ID of the Propertytype- Data type of the new PropertydefaultValue- The value all created Properties are initialized to- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- if the container does not support explicitly adding container properties
-
addItem
public Object addItem() throws UnsupportedOperationException
Description copied from interface:ContainerCreates a new Item into the Container, and assign it an automatic ID.The new ID is returned, or
nullif the operation fails. After a successful call you can use themethod to fetch the Item.getItemThis functionality is optional.
- Specified by:
addItemin interfaceContainer- Returns:
- ID of the newly created Item, or
nullin case of a failure - Throws:
UnsupportedOperationException- if adding an item without an explicit item ID is not supported by the container
-
addItem
public Item addItem(Object itemId) throws UnsupportedOperationException
Description copied from interface:ContainerCreates a new Item with the given ID in the Container.The new Item is returned, and it is ready to have its Properties modified. Returns
nullif the operation fails or the Container already contains a Item with the given ID.This functionality is optional.
- Specified by:
addItemin interfaceContainer- Parameters:
itemId- ID of the Item to be created- Returns:
- Created new Item, or
nullin case of a failure - Throws:
UnsupportedOperationException- if adding an item with an explicit item ID is not supported by the container
-
removeAllItems
public boolean removeAllItems() throws UnsupportedOperationExceptionDescription copied from interface:ContainerRemoves all Items from the Container.Note that Property ID and type information is preserved. This functionality is optional.
- Specified by:
removeAllItemsin interfaceContainer- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- if the container does not support removing all items
-
removeItem
public boolean removeItem(Object itemId) throws UnsupportedOperationException
Description copied from interface:Container.HierarchicalRemoves the Item identified by
ItemIdfrom the Container.Note that this does not remove any children the item might have.
- Specified by:
removeItemin interfaceContainer- Specified by:
removeItemin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item to remove- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- if the container does not support removing individual items
-
removeContainerProperty
public boolean removeContainerProperty(Object propertyId) throws UnsupportedOperationException
Description copied from interface:ContainerRemoves a Property specified by the given Property ID from the Container. Note that the Property will be removed from all Items in the Container.This functionality is optional.
- Specified by:
removeContainerPropertyin interfaceContainer- Parameters:
propertyId- ID of the Property to remove- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- if the container does not support removing container properties
-
-