TrueZIP File* 7.0

de.schlichtherle.truezip.file.swing
Class TFileTreeModel

java.lang.Object
  extended by de.schlichtherle.truezip.file.swing.TFileTreeModel
All Implemented Interfaces:
TreeModel

@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
public final class TFileTreeModel
extends Object
implements TreeModel

A TreeModel which traverses TFile instances. The TArchiveDetector of the root of this tree model is used to detect any archive files in the directory tree.

Author:
Christian Schlichtherle

Field Summary
private  Map<TFile,TFile[]> cache
          Used to cache the contents of directories.
private  Comparator<? super TFile> comparator
          A comparator for TFile or super classes.
private  FileFilter filter
           
private  EventListenerList listeners
           
private  TFile root
           
 
Constructor Summary
TFileTreeModel(TFile root, FileFilter filter, Comparator<? super TFile> comparator)
          Creates a new TFileTreeModel which browses the specified root file.
 
Method Summary
 void addTreeModelListener(TreeModelListener l)
          Adds a listener to this model.
 void cp_p(TFile oldNode, TFile node)
          Copies oldNode to node preserving its last modification time and updates the tree accordingly.
 void cp_r(TFile oldNode, TFile node)
          Copies oldNode to node recursively and updates the tree accordingly.
 void cp_rp(TFile oldNode, TFile node)
          Copies oldNode to node recursively preserving its last modification time and updates the tree accordingly.
 void cp(InputStream in, TFile node)
          Copies in to node and updates the tree accordingly.
 void cp(TFile oldNode, TFile node)
          Copies oldNode to node and updates the tree accordingly.
 boolean createNewFile(TFile node)
          Creates node as a new file in the file system and updates the tree accordingly.
protected  void fireTreeNodesChanged(TreeModelEvent evt)
          This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel.
protected  void fireTreeNodesInserted(TreeModelEvent evt)
          This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel.
protected  void fireTreeNodesRemoved(TreeModelEvent evt)
          This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel.
protected  void fireTreeStructureChanged(TreeModelEvent evt)
          This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel.
(package private)  void forget(TFile node)
          Clears the internal cache associated with node and all of its children.
private  void forget(TFile node, boolean childrenToo)
          Clears the internal cache associated with node.
 TFile getChild(Object parent, int index)
           
 int getChildCount(Object parent)
           
private  TFile[] getChildren(TFile parent)
           
 int getIndexOfChild(Object parent, Object child)
           
 TFile getRoot()
           
 boolean isLeaf(Object node)
           
 void mkdir(TFile node, boolean recursive)
          Ensures that node exists as a (virtual) directory in the (federated) file system and updates the tree accordingly.
 void mv(TFile oldNode, TFile node)
          Moves oldNode to node and updates the tree accordingly.
private  TFile[] newPath(TFile node)
          Returns an array of TFile objects indicating the path from the root to the given node.
private  TFile[] newPath(TFile node, int level)
           
(package private)  TreePath newTreePath(TFile node)
          Returns a new TreePath for the given node or null if node is not part of this file tree or is null.
 void nodeChanged(TFile node)
          Updates the given node in the tree.
 void nodeInserted(TFile node)
          Inserts the given node in the tree.
 void nodeInsertedOrStructureChanged(TFile node)
          Inserts the given node in the tree or reloads the tree structure for the given node if it already exists.
 void nodeRemoved(TFile node)
          Removes the given node from the tree.
 void refresh()
          Refreshes the tree structure for the entire tree.
 void refresh(TFile node)
          Alias for structureChanged(TFile).
 void removeTreeModelListener(TreeModelListener l)
          Removes a listener from this model.
 void rm_r(TFile node)
          Deletes the file or (probably not empty) directory node and updates the tree accordingly.
 void rm(TFile node)
          Deletes the file or empty directory node and updates the tree accordingly.
 void structureChanged(TFile node)
          Reloads the tree structure for the given node.
 void valueForPathChanged(TreePath path, Object newValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

private final Map<TFile,TFile[]> cache
Used to cache the contents of directories. Maps TFile -> TFile[] instances.


root

@CheckForNull
private final TFile root

filter

@CheckForNull
private final FileFilter filter

comparator

private final Comparator<? super TFile> comparator
A comparator for TFile or super classes.


listeners

private final EventListenerList listeners
Constructor Detail

TFileTreeModel

public TFileTreeModel(@CheckForNull
                      TFile root,
                      @CheckForNull
                      FileFilter filter,
                      Comparator<? super TFile> comparator)
Creates a new TFileTreeModel which browses the specified root file. If file is an instance of TFile, its archive detector is used to detect any archive files in the directory tree.

Parameters:
root - The root of this TFileTreeModel. If this is null, an empty tree is created.
filter - Used to filter the files and directories which are present in this TreeModel. If this is null, all files are accepted.
comparator - A comparator for TFile instances or super classes. This must not be null.
Throws:
NullPointerException - If comparator is null.
IllegalArgumentException - If root isn't null and comparing it to itself didn't result in 0.
ClassCastException - If root isn't null and comparator isn't a Comparator for TFile or super class instances.
Method Detail

getRoot

public TFile getRoot()
Specified by:
getRoot in interface TreeModel

getChild

@Nullable
public TFile getChild(Object parent,
                               int index)
Specified by:
getChild in interface TreeModel

getChildCount

public int getChildCount(Object parent)
Specified by:
getChildCount in interface TreeModel

isLeaf

public boolean isLeaf(Object node)
Specified by:
isLeaf in interface TreeModel

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                Object newValue)
Specified by:
valueForPathChanged in interface TreeModel

getIndexOfChild

public int getIndexOfChild(Object parent,
                           Object child)
Specified by:
getIndexOfChild in interface TreeModel

getChildren

@Nullable
private TFile[] getChildren(TFile parent)

newTreePath

@Nullable
TreePath newTreePath(TFile node)
Returns a new TreePath for the given node or null if node is not part of this file tree or is null.


newPath

@Nullable
private TFile[] newPath(TFile node)
Returns an array of TFile objects indicating the path from the root to the given node.

Parameters:
node - The TFile object to get the path for.
Returns:
An array of TFile objects, suitable as a constructor argument for TreePath or null if node is not part of this file tree or is null.

newPath

@Nullable
private TFile[] newPath(@CheckForNull
                                 TFile node,
                                 int level)

createNewFile

public boolean createNewFile(TFile node)
                      throws IOException
Creates node as a new file in the file system and updates the tree accordingly. If you would like to create a new file with initial content, please use cp(InputStream, TFile) instead. Note that the current selection may get lost.

Returns:
Whether or not the file has been newly created.
Throws:
IOException - if any I/O error occurs.

mkdir

public void mkdir(TFile node,
                  boolean recursive)
           throws IOException
Ensures that node exists as a (virtual) directory in the (federated) file system and updates the tree accordingly. Note that the current selection may get lost.

Parameters:
recursive - whether or not any missing ancestor directories shall get created if required.
Throws:
IOException - if any I/O error occurs.

cp

public void cp(InputStream in,
               TFile node)
        throws IOException
Copies in to node and updates the tree accordingly. Note that the given stream is always closed and that the current selection may get lost.

Throws:
IOException - if any I/O error occurs.

cp

public void cp(TFile oldNode,
               TFile node)
        throws IOException
Copies oldNode to node and updates the tree accordingly. Note that the current selection may get lost.

Throws:
IOException - if any I/O error occurs.

cp_r

public void cp_r(TFile oldNode,
                 TFile node)
          throws IOException
Copies oldNode to node recursively and updates the tree accordingly. Note that the current selection may get lost.

Throws:
IOException - if any I/O error occurs.

cp_p

public void cp_p(TFile oldNode,
                 TFile node)
          throws IOException
Copies oldNode to node preserving its last modification time and updates the tree accordingly. Note that the current selection may get lost.

Throws:
IOException - if any I/O error occurs.

cp_rp

public void cp_rp(TFile oldNode,
                  TFile node)
           throws IOException
Copies oldNode to node recursively preserving its last modification time and updates the tree accordingly. Note that the current selection may get lost.

Throws:
IOException - if any I/O error occurs.

mv

public void mv(TFile oldNode,
               TFile node)
        throws IOException
Moves oldNode to node and updates the tree accordingly. Note that the current selection may get lost.

Throws:
IOException - if any I/O error occurs.

rm

public void rm(TFile node)
        throws IOException
Deletes the file or empty directory node and updates the tree accordingly. Note that the current selection may get lost.

Throws:
IOException - if any I/O error occurs.

rm_r

public void rm_r(TFile node)
          throws IOException
Deletes the file or (probably not empty) directory node and updates the tree accordingly. Note that the current selection may get lost.

Throws:
IOException - if any I/O error occurs.

nodeInsertedOrStructureChanged

public void nodeInsertedOrStructureChanged(TFile node)
Inserts the given node in the tree or reloads the tree structure for the given node if it already exists. This method calls TreeModelListener.treeNodesInserted(TreeModelEvent) on all listeners of this TreeModel.


nodeInserted

public void nodeInserted(TFile node)
Inserts the given node in the tree. If node already exists, nothing happens. This method calls TreeModelListener.treeNodesInserted(TreeModelEvent) on all listeners of this TreeModel.


nodeChanged

public void nodeChanged(TFile node)
Updates the given node in the tree. This method calls TreeModelListener.treeNodesChanged(TreeModelEvent) on all listeners of this TreeModel.


nodeRemoved

public void nodeRemoved(TFile node)
Removes the given node from the tree. This method calls TreeModelListener.treeNodesRemoved(TreeModelEvent) on all listeners of this TreeModel.


refresh

public void refresh()
Refreshes the tree structure for the entire tree. This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel.


refresh

public final void refresh(TFile node)
Alias for structureChanged(TFile).


structureChanged

public void structureChanged(TFile node)
Reloads the tree structure for the given node. This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel.


forget

void forget(TFile node)
Clears the internal cache associated with node and all of its children.


forget

private void forget(@Nullable
                    TFile node,
                    boolean childrenToo)
Clears the internal cache associated with node.

Parameters:
childrenToo - If and only if true, the internal cache for all children is cleared, too.

addTreeModelListener

public void addTreeModelListener(TreeModelListener l)
Adds a listener to this model.

Specified by:
addTreeModelListener in interface TreeModel
Parameters:
l - The listener to add.

removeTreeModelListener

public void removeTreeModelListener(TreeModelListener l)
Removes a listener from this model.

Specified by:
removeTreeModelListener in interface TreeModel
Parameters:
l - The listener to remove.

fireTreeNodesChanged

protected void fireTreeNodesChanged(TreeModelEvent evt)
This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel. May be used to tell the listeners about a change in the file system.


fireTreeNodesInserted

protected void fireTreeNodesInserted(TreeModelEvent evt)
This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel. May be used to tell the listeners about a change in the file system.


fireTreeNodesRemoved

protected void fireTreeNodesRemoved(TreeModelEvent evt)
This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel. May be used to tell the listeners about a change in the file system.


fireTreeStructureChanged

protected void fireTreeStructureChanged(TreeModelEvent evt)
This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel. May be used to tell the listeners about a change in the file system.


TrueZIP File* 7.0

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.