- 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>
ADirectoryModel
that can be used in aTreeView
.This model uses the
DEFAULT_GRAPHIC_FACTORY
to 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 class
TreeDirectoryModel.DefaultGraphicFactory
Default graphic factory returning a folder icon for a directory and a document icon for a regular file.static interface
TreeDirectoryModel.GraphicFactory
Factory to create graphics forTreeItem
s 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.GraphicFactory
DEFAULT_GRAPHIC_FACTORY
Graphic factory that returns a folder icon for a directory and a document icon for a regular file.static TreeDirectoryModel.GraphicFactory
NO_GRAPHIC_FACTORY
Graphic factory that always returnsnull
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDirectory(Path directory)
Add a no-top-lever directory to the model.void
addDirectory(Path directory, I initiator)
Add a no-top-level directory to the model.void
addFile(Path file, FileTime lastModified)
Add a file to the model.void
addFile(Path file, FileTime lastModified, I initiator)
Add a file to the model.void
addTopLevelDirectory(Path directory)
Add a top-lever directory to the model.void
addTopLevelDirectory(Path directory, Consumer<? super TreeDirectoryItems.DirectoryItem<T>> onCollapse, Consumer<? super TreeDirectoryItems.DirectoryItem<T>> onExpand)
Add a top-lever directory to the model.boolean
contains(Path path)
Indicates whether this directory model contains the givenpath
.boolean
containsPrefixOf(Path path)
Indicates whether this directory model contains roots whose name is a prefix in the givenpath
name.io.reactivex.Observable<DirectoryModel.Update<I>>
creations()
void
delete(Path path)
Delete the given path from the model.void
delete(Path path, I initiator)
Delete the given path from the model.io.reactivex.Observable<DirectoryModel.Update<I>>
deletions()
void
dispose()
io.reactivex.Observable<Throwable>
errors()
TreeItem<T>
getRoot()
Returns a tree item that can be used as a root of aTreeView
.boolean
isDisposed()
io.reactivex.Observable<DirectoryModel.Update<I>>
modifications()
void
setGraphicFactory(TreeDirectoryModel.GraphicFactory factory)
Sets graphic factory used to create graphics ofTreeItem
s in this directory model.void
sync(Path directory)
Synchronize the model with the givendirectory
element.void
sync(Path directory, I initiator)
Synchronize the model with the givendirectory
element.void
updateModificationTime(Path path, FileTime lastModified)
Updates the modification time for the item associated to the givenPath
.void
updateModificationTime(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
- AFunction
converting the object returned byTreeItem.getValue()
) into the correspondingPath
.injector
- AFunction
converting aPath
into 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
- ThePath
to be added as a directory.
-
addDirectory
public void addDirectory(Path directory, I initiator)
Add a no-top-level directory to the model.- Parameters:
directory
- ThePath
to 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
- ThePath
to 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
- ThePath
to 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
- ThePath
to 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 givenonCollapse
andonExpand
parameters to the newly createdTreeDirectoryItems.DirectoryItem
.
-
contains
public boolean contains(Path path)
Description copied from interface:DirectoryModel
Indicates whether this directory model contains the givenpath
.- Specified by:
contains
in interfaceDirectoryModel<I,T>
- Parameters:
path
- ThePath
to be verified.- Returns:
true
if the givenpath
is contained in this model.
-
containsPrefixOf
public boolean containsPrefixOf(Path path)
Indicates whether this directory model contains roots whose name is a prefix in the givenpath
name.- Parameters:
path
- ThePath
to be verified.- Returns:
true
if this directory model contains roots whose name is a prefix in the givenpath
name.
-
creations
public io.reactivex.Observable<DirectoryModel.Update<I>> creations()
- Specified by:
creations
in 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
- ThePath
to be removed.
-
delete
public void delete(Path path, I initiator)
Delete the given path from the model.- Parameters:
path
- ThePath
to be removed.initiator
- The initiator of changes to the model.
-
deletions
public io.reactivex.Observable<DirectoryModel.Update<I>> deletions()
- Specified by:
deletions
in interfaceDirectoryModel<I,T>
- Returns:
- An observable stream of removals from the model.
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceio.reactivex.disposables.Disposable
-
errors
public io.reactivex.Observable<Throwable> errors()
- Specified by:
errors
in interfaceDirectoryModel<I,T>
- Returns:
- An observable stream of errors.
-
getRoot
public TreeItem<T> getRoot()
Description copied from interface:DirectoryModel
Returns 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 returnedTreeItem
shall be used withTreeView.showRootProperty()
set tofalse
.
-
isDisposed
public boolean isDisposed()
- Specified by:
isDisposed
in interfaceio.reactivex.disposables.Disposable
-
modifications
public io.reactivex.Observable<DirectoryModel.Update<I>> modifications()
- Specified by:
modifications
in 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 ofTreeItem
s in this directory model.DEFAULT_GRAPHIC_FACTORY
andNO_GRAPHIC_FACTORY
are two factories already available.TreeItem
s created before this method is called will be displayed using the previous graphic factory.- Parameters:
factory
- The new graphic factory instance. Ifnull
,DEFAULT_GRAPHIC_FACTORY
will be used.
-
sync
public void sync(Path directory)
Synchronize the model with the givendirectory
element. 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
- ThePath
used to synchronize the model.
-
sync
public void sync(Path directory, I initiator)
Synchronize the model with the givendirectory
element. 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
- ThePath
used 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.
-
-