projectviewer.importer
Class Importer

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

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).

Version:
$Id: Importer.java 9051 2007-03-01 07:01:35Z vanza $
Author:
Marcelo Vanzin

Nested Class Summary
protected  class Importer.NodeStructureChange
           
protected  class Importer.ShowNode
          Makes sure a node is visible.
 
Field Summary
protected  java.util.ArrayList added
          The list of added files, if any, for event firing purposes.
protected  boolean fireEvent
          Whether this class should automatically fire the project event.
protected  java.lang.Runnable postAction
          An action to be executed after the import occurs.
protected  VPTProject project
           
protected  java.util.ArrayList removed
          The list of removed files, if any, for event firing purposes.
protected  VPTNode selected
           
protected  ProjectViewer viewer
          The node to where the imported nodes will be added.
 
Constructor Summary
Importer(VPTNode node)
           
Importer(VPTNode node, boolean noThread)
           
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
 void doImport()
          Main import method.
protected  VPTNode findDirectory(java.io.File dir, VPTNode parent, boolean create)
          Looks, in the children list for the given parent, for a directory with the given path.
protected  void fireProjectEvent()
          Fires an event based on the imported file(s).
protected  void importNode(VPTNode node)
          Imports the node into the selected parent.
protected  void importNode(VPTNode child, VPTNode where)
          Imports a child into the given parent.
protected abstract  java.util.Collection internalDoImport()
          Method to be called when importing nodes.
protected  void loadImportFilterStatus(VPTProject project, ImportDialog dlg)
           
protected  VPTNode makePathTo(java.lang.String path, java.util.ArrayList added)
          Inserts all nodes from the root up to and including the given path, if the nodes are not yet inserted.
protected  void registerFile(VPTFile file)
          Registers the file in the project.
 void run()
           
protected  void saveImportFilterStatus(VPTProject project, ImportDialog dlg)
           
protected  void setViewerEnabled(boolean flag)
           
protected  void unregisterFile(VPTFile file)
          Unregisters a file from a project and adds the file to the list of files that have been removed.
 
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.


selected

protected VPTNode selected

project

protected VPTProject project

added

protected java.util.ArrayList added
The list of added files, if any, for event firing purposes.


removed

protected java.util.ArrayList removed
The list of removed files, if any, for event firing purposes.


fireEvent

protected boolean fireEvent
Whether this class should automatically fire the project event.


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)

Importer

public Importer(VPTNode node)

Importer

public Importer(VPTNode node,
                boolean noThread)
Method Detail

doImport

public 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.


importNode

protected void importNode(VPTNode child,
                          VPTNode where)
Imports a child into the given parent.

Important: when using a separate thread, wrap a call to this method in a call to SwingUtilities.invokeLater() or SwingUtilities.invokeAndWait(), to ensure thread safety.


importNode

protected void importNode(VPTNode node)
Imports the node into the selected parent. The selected parent is defined in the constructor for the importer (and generally should be a selected node in the tree).

Important: when using a separate thread, wrap a call to this method in a call to SwingUtilities.invokeLater() or SwingUtilities.invokeAndWait(), to ensure thread safety.


internalDoImport

protected abstract java.util.Collection internalDoImport()
Method to be called when importing nodes. The implementation should eeturn a list of nodes to be added to the selected node. The method importNode(VPTNode) will be called for each element of the collection.


findDirectory

protected VPTNode findDirectory(java.io.File dir,
                                VPTNode parent,
                                boolean create)
Looks, in the children list for the given parent, for a directory with the given path. If it exists, return it. If not, creates a new directory node if create is true, or else return null.

Parameters:
dir - 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.

makePathTo

protected VPTNode makePathTo(java.lang.String path,
                             java.util.ArrayList added)
Inserts all nodes from the root up to and including the given path, if the nodes are not yet inserted. Returns the node representing the given path.


registerFile

protected void registerFile(VPTFile file)
Registers the file in the project. Also, checks if the file's absolute path is equal to the canonical path, and registers the canonical path in the project in case they differ.


unregisterFile

protected void unregisterFile(VPTFile file)
Unregisters a file from a project and adds the file to the list of files that have been removed. It automatically checks that "added" list to see if the file is already in there, so that the event does not contain the same file being added and removed at the same time.


setViewerEnabled

protected void setViewerEnabled(boolean flag)

run

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

fireProjectEvent

protected void fireProjectEvent()
Fires an event based on the imported file(s).


saveImportFilterStatus

protected void saveImportFilterStatus(VPTProject project,
                                      ImportDialog dlg)

loadImportFilterStatus

protected void loadImportFilterStatus(VPTProject project,
                                      ImportDialog dlg)