- java.lang.Object
-
- eu.ess.xaos.ui.control.tree.directory.TreeDirectoryModel<I,T>
-
- Type Parameters:
I- Type of the initiator of changes to the model.T- Type of the object returned byTreeItem.getValue().
- All Implemented Interfaces:
DirectoryModel<I,T>,io.reactivex.disposables.Disposable
public class TreeDirectoryModel<I,T> extends Object implements DirectoryModel<I,T>
ADirectoryModelthat can be used in aTreeView.This model uses the
DEFAULT_GRAPHIC_FACTORYto provide graphics to the tree nodes. That can be changed invokingsetGraphicFactory(TreeDirectoryModel.GraphicFactory)after this model is built.Note:
dispose()should be called when the model is no more used (typically when the viewer using it is disposed).- Author:
- claudio.rosati@esss.se
- See Also:
- LiveDirsFX:org.fxmisc.livedirs.LiveDirsModel
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTreeDirectoryModel.DefaultGraphicFactoryDefault graphic factory returning a folder icon for a directory and a document icon for a regular file.static interfaceTreeDirectoryModel.GraphicFactoryFactory to create graphics forTreeItems in aDirectoryModel.-
Nested classes/interfaces inherited from interface eu.ess.xaos.ui.control.tree.DirectoryModel
DirectoryModel.Reporter<I>, DirectoryModel.Update<I>, DirectoryModel.UpdateType
-
-
Field Summary
Fields Modifier and Type Field Description static TreeDirectoryModel.GraphicFactoryDEFAULT_GRAPHIC_FACTORYGraphic factory that returns a folder icon for a directory and a document icon for a regular file.static TreeDirectoryModel.GraphicFactoryNO_GRAPHIC_FACTORYGraphic factory that always returnsnull.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDirectory(Path directory)Add a no-top-lever directory to the model.voidaddDirectory(Path directory, I initiator)Add a no-top-level directory to the model.voidaddFile(Path file, FileTime lastModified)Add a file to the model.voidaddFile(Path file, FileTime lastModified, I initiator)Add a file to the model.voidaddTopLevelDirectory(Path directory)Add a top-lever directory to the model.voidaddTopLevelDirectory(Path directory, Consumer<? super TreeDirectoryItems.DirectoryItem<T>> onCollapse, Consumer<? super TreeDirectoryItems.DirectoryItem<T>> onExpand)Add a top-lever directory to the model.booleancontains(Path path)Indicates whether this directory model contains the givenpath.booleancontainsPrefixOf(Path path)Indicates whether this directory model contains roots whose name is a prefix in the givenpathname.io.reactivex.Observable<DirectoryModel.Update<I>>creations()voiddelete(Path path)Delete the given path from the model.voiddelete(Path path, I initiator)Delete the given path from the model.io.reactivex.Observable<DirectoryModel.Update<I>>deletions()voiddispose()io.reactivex.Observable<Throwable>errors()TreeItem<T>getRoot()Returns a tree item that can be used as a root of aTreeView.booleanisDisposed()io.reactivex.Observable<DirectoryModel.Update<I>>modifications()voidsetGraphicFactory(TreeDirectoryModel.GraphicFactory factory)Sets graphic factory used to create graphics ofTreeItems in this directory model.voidsync(Path directory)Synchronize the model with the givendirectoryelement.voidsync(Path directory, I initiator)Synchronize the model with the givendirectoryelement.voidupdateModificationTime(Path path, FileTime lastModified)Updates the modification time for the item associated to the givenPath.voidupdateModificationTime(Path path, FileTime lastModified, I initiator)Updates the modification time for the item associated to the givenPath.
-
-
-
Field Detail
-
DEFAULT_GRAPHIC_FACTORY
public static final TreeDirectoryModel.GraphicFactory DEFAULT_GRAPHIC_FACTORY
Graphic factory that returns a folder icon for a directory and a document icon for a regular file.
-
NO_GRAPHIC_FACTORY
public static final TreeDirectoryModel.GraphicFactory NO_GRAPHIC_FACTORY
Graphic factory that always returnsnull.
-
-
Constructor Detail
-
TreeDirectoryModel
public TreeDirectoryModel(I defaultInitiator, Function<T,Path> projector, Function<Path,T> injector)
Create a new instance of this model.- Parameters:
defaultInitiator- The initiator used when not explicitly provided as parameter in methods.projector- AFunctionconverting the object returned byTreeItem.getValue()) into the correspondingPath.injector- AFunctionconverting aPathinto the object used as value in the correspondingTreeItem.
-
-
Method Detail
-
addDirectory
public void addDirectory(Path directory)
Add a no-top-lever directory to the model.- Parameters:
directory- ThePathto be added as a directory.
-
addDirectory
public void addDirectory(Path directory, I initiator)
Add a no-top-level directory to the model.- Parameters:
directory- ThePathto be added as a directory.initiator- The initiator of changes to the model.
-
addFile
public void addFile(Path file, FileTime lastModified)
Add a file to the model.- Parameters:
file- ThePathto be added as a file.lastModified- The timestamp of the last modification to the file.
-
addFile
public void addFile(Path file, FileTime lastModified, I initiator)
Add a file to the model.- Parameters:
file- ThePathto be added as a file.lastModified- The timestamp of the last modification to the file.initiator- The initiator of changes to the model.
-
addTopLevelDirectory
public void addTopLevelDirectory(Path directory)
Add a top-lever directory to the model.Note: The model is not synchronized automatically with the given
directory. An explicit call tosync(Path), orsync(Path, java.lang.Object)has to be performed if synchronization is required.- Parameters:
directory- ThePathto be added as a top-level directory.
-
addTopLevelDirectory
public void addTopLevelDirectory(Path directory, Consumer<? super TreeDirectoryItems.DirectoryItem<T>> onCollapse, Consumer<? super TreeDirectoryItems.DirectoryItem<T>> onExpand)
Add a top-lever directory to the model.Note: The model is not synchronized automatically with the given
directory. An explicit call tosync(Path), orsync(Path, java.lang.Object)has to be performed if synchronization is required.Note:
addDirectory(Path)andaddDirectory(Path, Object)methods will pass the givenonCollapseandonExpandparameters to the newly createdTreeDirectoryItems.DirectoryItem.
-
contains
public boolean contains(Path path)
Description copied from interface:DirectoryModelIndicates whether this directory model contains the givenpath.- Specified by:
containsin interfaceDirectoryModel<I,T>- Parameters:
path- ThePathto be verified.- Returns:
trueif the givenpathis contained in this model.
-
containsPrefixOf
public boolean containsPrefixOf(Path path)
Indicates whether this directory model contains roots whose name is a prefix in the givenpathname.- Parameters:
path- ThePathto be verified.- Returns:
trueif this directory model contains roots whose name is a prefix in the givenpathname.
-
creations
public io.reactivex.Observable<DirectoryModel.Update<I>> creations()
- Specified by:
creationsin interfaceDirectoryModel<I,T>- Returns:
- An observable stream of additions to the model.
-
delete
public void delete(Path path)
Delete the given path from the model.- Parameters:
path- ThePathto be removed.
-
delete
public void delete(Path path, I initiator)
Delete the given path from the model.- Parameters:
path- ThePathto be removed.initiator- The initiator of changes to the model.
-
deletions
public io.reactivex.Observable<DirectoryModel.Update<I>> deletions()
- Specified by:
deletionsin interfaceDirectoryModel<I,T>- Returns:
- An observable stream of removals from the model.
-
dispose
public void dispose()
- Specified by:
disposein interfaceio.reactivex.disposables.Disposable
-
errors
public io.reactivex.Observable<Throwable> errors()
- Specified by:
errorsin interfaceDirectoryModel<I,T>- Returns:
- An observable stream of errors.
-
getRoot
public TreeItem<T> getRoot()
Description copied from interface:DirectoryModelReturns a tree item that can be used as a root of aTreeView.The returned TreeItem does not contain any
Path(itsTreeItem.getValue()method returnsnull), but its children are roots of directory trees represented in this model. As a consequence, the returnedTreeItemshall be used withTreeView.showRootProperty()set tofalse.
-
isDisposed
public boolean isDisposed()
- Specified by:
isDisposedin interfaceio.reactivex.disposables.Disposable
-
modifications
public io.reactivex.Observable<DirectoryModel.Update<I>> modifications()
- Specified by:
modificationsin interfaceDirectoryModel<I,T>- Returns:
- An observable stream of file modifications in the model.
-
setGraphicFactory
public void setGraphicFactory(TreeDirectoryModel.GraphicFactory factory)
Sets graphic factory used to create graphics ofTreeItems in this directory model.DEFAULT_GRAPHIC_FACTORYandNO_GRAPHIC_FACTORYare two factories already available.TreeItems created before this method is called will be displayed using the previous graphic factory.- Parameters:
factory- The new graphic factory instance. Ifnull,DEFAULT_GRAPHIC_FACTORYwill be used.
-
sync
public void sync(Path directory)
Synchronize the model with the givendirectoryelement. Missing items will be added to the model for the expanded tree items, and a callback is registered to update the collapsed tree items when will expand. Items will be removed from the model if no more existing. Files timestamps will be updated too.- Parameters:
directory- ThePathused to synchronize the model.
-
sync
public void sync(Path directory, I initiator)
Synchronize the model with the givendirectoryelement. Missing items will be added to the model for the expanded tree items, and a callback is registered to update the collapsed tree items when will expand. Items will be removed from the model if no more existing. Files timestamps will be updated too.- Parameters:
directory- ThePathused to synchronize the model.initiator- The initiator of changes to the model.
-
updateModificationTime
public void updateModificationTime(Path path, FileTime lastModified)
Updates the modification time for the item associated to the givenPath.- Parameters:
path- The path whose associated item must be updated.lastModified- The new modification time.
-
updateModificationTime
public void updateModificationTime(Path path, FileTime lastModified, I initiator)
Updates the modification time for the item associated to the givenPath.- Parameters:
path- The path whose associated item must be updated.lastModified- The new modification time.initiator- The initiator of changes to the model.
-
-