com.metamatrix.common.tree.directory
Class FileSystemView

java.lang.Object
  extended by com.metamatrix.common.tree.directory.FileSystemView
All Implemented Interfaces:
PropertiedObjectView, DirectoryEntryView, TreeView

public class FileSystemView
extends java.lang.Object
implements DirectoryEntryView

This interface defines a view of a hierarchy of DirectoryEntry instances.


Constructor Summary
FileSystemView()
          Construct a file system view with a domain of the entire file system, and where the roots represent the root mounts of the file system, such as the drives on a Windows machine or the root directories on a Unix system.
FileSystemView(java.io.File root, boolean showRoot)
          Construct a file system view with a domain of the specified root folder and its contents, and optionally include the specified root as an accessible folder.
 
Method Summary
 boolean allowsChild(TreeNode parent, TreeNode potentialChild)
          Determine whether the specified parent TreeNode may contain the specified child node.
 boolean allowsChildren(TreeNode entry)
          Determine whether the specified TreeNode may contain children.
 void entryMoved(java.io.File originalFile, TreeNode entry)
          Update the dirEntries after a node has been moved by the FS Editor
protected  void filter(java.util.List entries)
           
 java.lang.String getAbsolutePath(TreeNode entry)
          Obtain the absoluate path for this DirectoryEntry, which includes the path of the root.
protected  java.util.List getActualRoots()
          Returns all root partitians on this DirectoryEntry system regardless of whether they are hidden.
protected  java.io.File[] getChildFiles(TreeNode parent)
          Return the array of File instances that are considered the children of the specified DirectoryEntry.
 java.util.List getChildren(TreeNode parent)
          Obtain the list of entries that are considered the children of the specified DirectoryEntry.
 java.util.Comparator getComparator()
          Set the comparator that provides the order for children returned from this view.
 DirectoryEntryEditor getDirectoryEntryEditor()
          Return the directory entry editor for this view.
protected  java.io.File getFile(TreeNode entry)
           
 FileSystemEntryEditor getFileEntryEditor()
          Return the file system editor for this view.
protected  FileSystemEntry getFileSystemEntry(java.io.File f, ObjectDefinition type)
           
 TreeNodeFilter getFilter()
          Set the filter that limits the set of DirectoryEntry instances returned from this view.
 TreeNode getHome()
          Obtain the DirectoryEntry that represents the folder within this view that represents the single, well-known "bookmarked" folder for this view.
 java.util.Set getMarked()
          Return the set of marked nodes for this view.
 TreeNode getParent(TreeNode entry)
          Determine the parent DirectoryEntry for the specified entry, or null if the specified entry is a root.
 java.lang.String getPath(TreeNode entry)
          Obtain the abstract path for this DirectoryEntry.
 PropertiedObjectEditor getPropertiedObjectEditor()
          Return the propertied object editor for this view.
 java.util.List getPropertyDefinitions()
          Get the definitions of the properties for the DirectoryEntry instances returned from this view.
 java.util.List getRoots()
          Returns all root partitians on this DirectoryEntry system.
 java.lang.String getSeparator()
          Obtain the character (as a String) that is used to separate names in a path sequence for the abstract path.
 char getSeparatorChar()
          Obtain the character that is used to separate names in a path sequence for the abstract path.
 TreeNodeEditor getTreeNodeEditor()
          Return the tree node editor for this view.
 boolean isAncestorOf(TreeNode ancestor, TreeNode descendent)
          Determine whether the specified node is a descendent of the given ancestor node.
 boolean isHidden(TreeNode entry)
          Determine whether the specified DirectoryEntry is hidden.
 boolean isMarked(TreeNode entry)
          Return the marked state of the specified entry.
 boolean isParentOf(TreeNode parent, TreeNode child)
          Determine whether the specified node is a child of the given parent node.
 boolean isRoot(TreeNode entry)
          Determine whether the specified DirectoryEntry is a root of the underlying system.
 java.util.Iterator iterator()
          Obtain an iterator for this whole view, which navigates the view's nodes using pre-order rules (i.e., it visits a node before its children).
 java.util.Iterator iterator(TreeNode startingPoint)
          Obtain an iterator for the view starting at the specified node.
 DirectoryEntry lookup(java.lang.String path)
          Lookup the node referenced by the relative path in this view.
 DirectoryEntry lookup(java.lang.String path, java.lang.String separator)
          Lookup the node referenced by the relative path in this view, but specify a separator.
 void setComparator(java.util.Comparator comparator)
          Set the comparator that should be used to order the children.
 void setFilter(TreeNodeFilter filter)
          Set the filter that limits the set of DirectoryEntry instances returned from this view.
 void setHome(TreeNode home)
          Set the DirectoryEntry that represents the home folder for this view.
 void setMarked(TreeNode entry, boolean markedState)
          Set the marked state of the specified entry.
protected  void setRoot(java.io.File root, boolean showRoot)
          Set the DirectoryEntryView root to use for the underlying system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSystemView

public FileSystemView()
Construct a file system view with a domain of the entire file system, and where the roots represent the root mounts of the file system, such as the drives on a Windows machine or the root directories on a Unix system.


FileSystemView

public FileSystemView(java.io.File root,
                      boolean showRoot)
Construct a file system view with a domain of the specified root folder and its contents, and optionally include the specified root as an accessible folder. This method also sets the home folder, which is a well known "bookmarked" directory for this view, to the specified root.

Parameters:
root - the folder that is to be the root of this view.
showRoot - boolean flag that if true specifies that the root folder should be accessible and returned as the single entry from the getRoots method, or false if the child folders are to be returned as roots of thi view.
Method Detail

isMarked

public boolean isMarked(TreeNode entry)
Return the marked state of the specified entry.

Specified by:
isMarked in interface TreeView
Returns:
the marked state of the entry.

entryMoved

public void entryMoved(java.io.File originalFile,
                       TreeNode entry)
Update the dirEntries after a node has been moved by the FS Editor

Parameters:
the - orignal File for the FileSystemEntry
the - updated FileSystemEntry

setMarked

public void setMarked(TreeNode entry,
                      boolean markedState)
Set the marked state of the specified entry.

Specified by:
setMarked in interface TreeView
Parameters:
true - if the node is to be marked, or false if it is to be un-marked.

getMarked

public java.util.Set getMarked()
Return the set of marked nodes for this view.

Specified by:
getMarked in interface TreeView
Parameters:
the - unmodifiable set of marked nodes; never null

setFilter

public void setFilter(TreeNodeFilter filter)
Set the filter that limits the set of DirectoryEntry instances returned from this view.

Specified by:
setFilter in interface TreeView
Parameters:
filter - the filter, or null if the default "pass-through" filter should be used.

getFilter

public TreeNodeFilter getFilter()
Set the filter that limits the set of DirectoryEntry instances returned from this view.

Specified by:
getFilter in interface TreeView
Returns:
the current filter; never null

setComparator

public void setComparator(java.util.Comparator comparator)
Set the comparator that should be used to order the children.

Specified by:
setComparator in interface TreeView
Parameters:
comparator - the comparator, or null if entry name sorting should be used.

getComparator

public java.util.Comparator getComparator()
Set the comparator that provides the order for children returned from this view.

Specified by:
getComparator in interface TreeView
Returns:
the current comparator; never null

getPropertyDefinitions

public java.util.List getPropertyDefinitions()
Get the definitions of the properties for the DirectoryEntry instances returned from this view.

Specified by:
getPropertyDefinitions in interface TreeView
Returns:
the unmodifiable list of PropertyDefinition instances; never null

getRoots

public java.util.List getRoots()
Returns all root partitians on this DirectoryEntry system.

Specified by:
getRoots in interface TreeView
Returns:
the unmodifiable collection of DirectoryEntry instances that represent the roots

getActualRoots

protected java.util.List getActualRoots()
Returns all root partitians on this DirectoryEntry system regardless of whether they are hidden.

Returns:
the unmodifiable collection of DirectoryEntry instances that represent the hidden and visible roots

filter

protected void filter(java.util.List entries)

isRoot

public boolean isRoot(TreeNode entry)
Determine whether the specified DirectoryEntry is a root of the underlying system.

Specified by:
isRoot in interface TreeView
Parameters:
entry - the DirectoryEntry instance that is to be checked; may not be null
Returns:
true if the entry is a root, or false otherwise.

isHidden

public boolean isHidden(TreeNode entry)
Determine whether the specified DirectoryEntry is hidden.

Specified by:
isHidden in interface TreeView
Parameters:
entry - the DirectoryEntry instance that is to be checked; may not be null
Returns:
true if the entry is hidden, or false otherwise.

setRoot

protected void setRoot(java.io.File root,
                       boolean showRoot)
Set the DirectoryEntryView root to use for the underlying system.

Parameters:
root - the File that represents the root.
showRoot - indicates if the root should be displays in the hierarchy

setHome

public void setHome(TreeNode home)
Set the DirectoryEntry that represents the home folder for this view. The home is simply a folder that is widely known and can be treated as a bookmark.

Parameters:
home - the directory entry that represents the home folder; may not be null and must exist within this view's domain of directory entries.
Throws:
java.lang.AssertionError - if home is null, if the entry does not represent an existing folder, or if it is not contained within the domain of this view.

getHome

public TreeNode getHome()
Obtain the DirectoryEntry that represents the folder within this view that represents the single, well-known "bookmarked" folder for this view. One example is for a FileSystemView accessing the whole the Windows file system (i.e., no root is specified in the constructor), the home folder represents the user's profile directory.

Specified by:
getHome in interface TreeView
Returns:
the entry that represents the home folder, or null if no home concept is supported.

getPath

public java.lang.String getPath(TreeNode entry)
Obtain the abstract path for this DirectoryEntry.

Specified by:
getPath in interface TreeView
Returns:
the string that represents the abstract path of this entry; never null

getSeparatorChar

public char getSeparatorChar()
Obtain the character that is used to separate names in a path sequence for the abstract path. This character is completely dependent upon the implementation.

Specified by:
getSeparatorChar in interface TreeView
Returns:
the charater used to delimit names in the abstract path.

getSeparator

public java.lang.String getSeparator()
Obtain the character (as a String) that is used to separate names in a path sequence for the abstract path.

Specified by:
getSeparator in interface TreeView
Returns:
the string containing the charater used to delimit names in the abstract path; never null

getAbsolutePath

public java.lang.String getAbsolutePath(TreeNode entry)
Obtain the absoluate path for this DirectoryEntry, which includes the path of the root. The separator character is used between each of the names in the sequence.

Returns:
the string that represents the absolute path of this entry.

getParent

public TreeNode getParent(TreeNode entry)
Determine the parent DirectoryEntry for the specified entry, or null if the specified entry is a root.

Specified by:
getParent in interface TreeView
Parameters:
entry - the DirectoryEntry instance for which the parent is to be obtained; may not be null
Returns:
the parent entry, or null if there is no parent

allowsChildren

public boolean allowsChildren(TreeNode entry)
Determine whether the specified TreeNode may contain children.

Specified by:
allowsChildren in interface TreeView
Parameters:
entry - the TreeNode instance that is to be checked; may not be null
Returns:
true if the entry can contain children, or false otherwise.

allowsChild

public boolean allowsChild(TreeNode parent,
                           TreeNode potentialChild)
Determine whether the specified parent TreeNode may contain the specified child node.

Specified by:
allowsChild in interface TreeView
Parameters:
parent - the TreeNode instance that is to be the parent; may not be null
potentialChild - the TreeNode instance that is to be the child; may not be null
Returns:
true if potentialChild can be placed as a child of parent, or false otherwise.

getChildren

public java.util.List getChildren(TreeNode parent)
Obtain the list of entries that are considered the children of the specified DirectoryEntry.

Specified by:
getChildren in interface TreeView
Parameters:
parent - the DirectoryEntry instance for which the child entries are to be obtained; may not be null
Returns:
the unmodifiable list of DirectoryEntry instances that are considered the children of the specified entry; never null but possibly empty

getChildFiles

protected java.io.File[] getChildFiles(TreeNode parent)
Return the array of File instances that are considered the children of the specified DirectoryEntry.

Parameters:
parent - the DirectoryEntry instance for which the child entries are to be obtained; may not be null
Returns:
the array of File instances that are considered the children of the specified entry; never null but possibly empty

iterator

public java.util.Iterator iterator()
Obtain an iterator for this whole view, which navigates the view's nodes using pre-order rules (i.e., it visits a node before its children).

Specified by:
iterator in interface TreeView
Returns:
the view iterator

iterator

public java.util.Iterator iterator(TreeNode startingPoint)
Obtain an iterator for the view starting at the specified node. This implementation currently navigates the subtree using pre-order rules (i.e., it visits a node before its children).

Specified by:
iterator in interface TreeView
Parameters:
startingPoint - the root of the subtree over which the iterator is to navigate; may not be null
Returns:
the iterator that traverses the nodes in the subtree starting at the specified node; never null

isParentOf

public boolean isParentOf(TreeNode parent,
                          TreeNode child)
Determine whether the specified node is a child of the given parent node.

Specified by:
isParentOf in interface TreeView
Returns:
true if the node is a child of the given parent node.

isAncestorOf

public boolean isAncestorOf(TreeNode ancestor,
                            TreeNode descendent)
Determine whether the specified node is a descendent of the given ancestor node.

Specified by:
isAncestorOf in interface TreeView
Returns:
true if the node is a descendent of the given ancestor node.

getPropertiedObjectEditor

public PropertiedObjectEditor getPropertiedObjectEditor()
Return the propertied object editor for this view.

Specified by:
getPropertiedObjectEditor in interface PropertiedObjectView
Returns:
the PropertiedObjectEditor instance

getTreeNodeEditor

public TreeNodeEditor getTreeNodeEditor()
Return the tree node editor for this view.

Specified by:
getTreeNodeEditor in interface TreeView
Returns:
the TreeNodeEditor instance

getDirectoryEntryEditor

public DirectoryEntryEditor getDirectoryEntryEditor()
Return the directory entry editor for this view.

Specified by:
getDirectoryEntryEditor in interface DirectoryEntryView
Returns:
the DirectoryEntryEditor instance

getFileEntryEditor

public FileSystemEntryEditor getFileEntryEditor()
Return the file system editor for this view.

Returns:
the FileSystemEntryEditor instance

lookup

public DirectoryEntry lookup(java.lang.String path)
Lookup the node referenced by the relative path in this view. Depending upon the implementation, this method may return a null reference if a node with the specified path is not found.

This implementation never returns null if the specified path doesn't exist, but in this case the implementation instead returns a FileSystemEntry that will not exist.

Specified by:
lookup in interface DirectoryEntryView
Parameters:
path - the path of the desired node specified in terms of this view (i.e., the result of calling getPath() on this view with the returned node as the parameter should result in the same value as path); may not be null or zero-length
Returns:
the node referenced by the specified path, or null if no such node exists
Throws:
java.lang.AssertionError - if the path is null or zero-length

lookup

public DirectoryEntry lookup(java.lang.String path,
                             java.lang.String separator)
Lookup the node referenced by the relative path in this view, but specify a separator. This method allows the lookup of a path with a different separator than used by this view. Depending upon the implementation, this method may return a null reference if a node with the specified path is not found.

Specified by:
lookup in interface DirectoryEntryView
Parameters:
path - the path of the desired node specified in terms of this view (i.e., the result of calling getPath() on this view with the returned node as the parameter should result in the same value as path); may not be null or zero-length
separater - the string used to separate the components of a name.
Returns:
the node referenced by the specified path, or null if no such node exists
Throws:
java.lang.AssertionError - if the path is null or zero-length

getFile

protected java.io.File getFile(TreeNode entry)

getFileSystemEntry

protected FileSystemEntry getFileSystemEntry(java.io.File f,
                                             ObjectDefinition type)


Copyright © 2009. All Rights Reserved.