projectviewer.importer
Class Importer

java.lang.Object
  extended by projectviewer.importer.Importer
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
FileImporter, NewFileImporter

public abstract class Importer
extends java.lang.Object
implements java.lang.Runnable

Base class for importers. Importers are classes that select a set of nodes (which can be of any kind) and add them to a given node.

Trees are updated in the following manner: when a node is inserted, the folder tree is updated immediately. The other two trees (which are a "flat" version of the file list, basically) are updated once at the end of the importing (to make the code simpler for those trees).

Since a lot of time may be required to import large number of files, the importing is done in its own separate thread, so that the GUI may be used normally during the process. This behaviour can be prevented if wished. If importing in a separate thread, the PV GUI will be blocked during the import phase (but the rest of jEdit will be usable).

Author:
Marcelo Vanzin

Nested Class Summary
protected  class Importer.NodeStructureChange
           
protected  class Importer.ShowNodes
          Makes sure all newly imported nodes are visible.
 
Field Summary
protected  boolean isNodeStructureUpdate
          Whether to do one single "node structure" update on the selected node instead of individual updates on each modified node.
protected  java.lang.Runnable postAction
          An action to be executed after the import occurs.
protected  VPTProject project
           
protected  VPTNode selected
           
protected  boolean silent
           
protected  ProjectViewer viewer
          The node to where the imported nodes will be added.
 
Constructor Summary
Importer(VPTNode node, ProjectViewer viewer)
           
Importer(VPTNode node, ProjectViewer viewer, boolean noThread)
          If noThread is true, inhibits the use of a separate Thread to do the importing.
 
Method Summary
protected  void addNode(VPTNode node, VPTNode parent)
          Marks a node for importing.
protected  void cleanup()
          This is called after internalDoImport() is invoked, so implementations can clean up any internal state.
protected  VPTNode constructPath(VPTNode root, java.lang.String path)
          Creates a subtree starting at the given root, going down to the given path, updating the given list of added nodes as necessary.
 void doImport()
          Main import method.
protected  VPTNode findChild(java.lang.String url, VPTNode parent, boolean create)
          Looks, in the children list for the given parent, for a node with the given path.
protected  void importFiles(VPTNode dest, org.gjt.sp.jedit.io.VFSFileFilter filter, boolean recurse, boolean flatten)
          Imports the files directly under the given node, optionally recursing into sub-directories.
protected  void importFiles(VPTNode dest, org.gjt.sp.jedit.io.VFSFileFilter filter, boolean recurse, boolean flatten, boolean addHidden)
          Imports the files directly under the given node, optionally recursing into sub-directories.
protected abstract  void internalDoImport()
          Method called when importing nodes.
protected  ImporterFileFilter loadImportFilterStatus(VPTProject project, ImportDialog dlg, java.lang.String name)
           
protected  void removeDirectory(VPTDirectory dir)
          Marks a directory for removal.
protected  void removeFile(VPTFile file)
          Marks a file for removal.
 void run()
           
protected  void saveImportFilterStatus(VPTProject project, ImportDialog dlg, java.lang.String name)
           
 void setSilent(boolean silent)
          Sets the silent member.
protected  void setViewerEnabled(boolean flag)
           
protected  void setViewStatus(java.lang.String msgKey)
          Sets a message in the view's status bar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

viewer

protected final ProjectViewer viewer
The node to where the imported nodes will be added.


isNodeStructureUpdate

protected boolean isNodeStructureUpdate
Whether to do one single "node structure" update on the selected node instead of individual updates on each modified node.


selected

protected final VPTNode selected

project

protected final VPTProject project

silent

protected boolean silent

postAction

protected java.lang.Runnable postAction
An action to be executed after the import occurs. It will be executed in the AWT thread.

Constructor Detail

Importer

public Importer(VPTNode node,
                ProjectViewer viewer,
                boolean noThread)
If noThread is true, inhibits the use of a separate Thread to do the importing. If you know just a few nodes will be imported, you may use this.


Importer

public Importer(VPTNode node,
                ProjectViewer viewer)
Method Detail

doImport

public final void doImport()
Main import method. It starts a new thread to actually do the importing, so that the UI is not blocked during the process, which can take some time for large numbers of files.

This method should be called from the AWT thread. It will lock the project, so if the calling code also locks the project for any reason, make sure it does so from the AWT thread or it will result in a deadlock.


internalDoImport

protected abstract void internalDoImport()
Method called when importing nodes. The implementation should add files for import using one of the following methods:

Since:
PV 3.0.0

cleanup

protected void cleanup()
This is called after internalDoImport() is invoked, so implementations can clean up any internal state. Default implementation does nothing.

Since:
PV 3.0.0

addNode

protected void addNode(VPTNode node,
                       VPTNode parent)
Marks a node for importing. The run() method of this class will take care of processing all these nodes and properly registering files and updating the trees. It is assumed that either the parent node already exists in the project, or it has been properly imported using this method. If the node is a direct descendent of an already existing node, then it will be processed later when the UI is updated. Otherwise it will be added to the parent's list of children right away.

Parameters:
node - The node being inserted.
parent - Where the node is being inserted.
Since:
PV 3.0.0

findChild

protected VPTNode findChild(java.lang.String url,
                            VPTNode parent,
                            boolean create)
                     throws java.io.IOException
Looks, in the children list for the given parent, for a node with the given path. If it exists, return it. If not, creates either a directory or file node (depending on what VFS says) if create is true, otherwise return null.

Parameters:
url - The URL of the directory to look for.
parent - The node where to look for the directory.
create - Whether to create a new node if a corresponding path is not found in the parent node.
Returns:
The node representing the given URL, or null if not found and create is false.
Throws:
java.io.IOException

constructPath

protected VPTNode constructPath(VPTNode root,
                                java.lang.String path)
                         throws java.io.IOException
Creates a subtree starting at the given root, going down to the given path, updating the given list of added nodes as necessary.

Parameters:
root - Root node where to start constructing the path.
path - Path to insert (should be under the given root).
Returns:
The newly created node.
Throws:
java.io.IOException - If an I/O error occur.
Since:
PV 3.0.0

importFiles

protected void importFiles(VPTNode dest,
                           org.gjt.sp.jedit.io.VFSFileFilter filter,
                           boolean recurse,
                           boolean flatten)
                    throws java.io.IOException
Imports the files directly under the given node, optionally recursing into sub-directories.

Parameters:
dest - Node where to add the new imported files.
filter - File filter to use when listing directories.
recurse - Whether to recurse into sub-directories.
flatten - Whether to import all files (even from sub-directories) into the dest node.
Throws:
java.io.IOException
Since:
PV 3.0.0

importFiles

protected void importFiles(VPTNode dest,
                           org.gjt.sp.jedit.io.VFSFileFilter filter,
                           boolean recurse,
                           boolean flatten,
                           boolean addHidden)
                    throws java.io.IOException
Imports the files directly under the given node, optionally recursing into sub-directories.

Parameters:
dest - Node where to add the new imported files.
filter - File filter to use when listing directories.
recurse - Whether to recurse into sub-directories.
flatten - Whether to import all files (even from sub-directories) into the dest node.
addHidden - Whether to add hidden files.
Throws:
java.io.IOException
Since:
PV 3.0.1

removeDirectory

protected void removeDirectory(VPTDirectory dir)
Marks a directory for removal. Directories will only be removed if, at the end of the import process, they are empty - meaning that the only children they have are other directories.


removeFile

protected void removeFile(VPTFile file)
Marks a file for removal. At the end of the importing process, all removed files are unregistered from the project.


setViewerEnabled

protected void setViewerEnabled(boolean flag)

run

public final void run()
Specified by:
run in interface java.lang.Runnable

saveImportFilterStatus

protected void saveImportFilterStatus(VPTProject project,
                                      ImportDialog dlg,
                                      java.lang.String name)

loadImportFilterStatus

protected ImporterFileFilter loadImportFilterStatus(VPTProject project,
                                                    ImportDialog dlg,
                                                    java.lang.String name)

setViewStatus

protected void setViewStatus(java.lang.String msgKey)
Sets a message in the view's status bar.

Parameters:
msgKey - jEdit property key, or message to be displayed.
Since:
PV 3.0.0

setSilent

public void setSilent(boolean silent)
Sets the silent member. If Importer is not silent, it shows messages on failures.