com.sas.io
Class FileList

com.sas.io.FileList
All Implemented Interfaces:
com.sas.beans.PropertyChangeSource, com.sas.beans.VetoableChangeSource, com.sas.collection.ContentsChangedSource, StaticCollectionInterface, StaticOrderedCollectionInterface, ComponentInterface, LinkPropertiesInterface, ModelInterface, NodeIconInterface, NodeInterface, SimpleNodeInterface, TreeInterface, com.sas.PublicClonable, com.sas.util.Countable, com.sas.util.Enumerable, IndexedGetInterface, ViewInterface, MultipleValueEventSourceInterface, java.beans.PropertyChangeListener, java.io.ObjectInputValidation, java.io.Serializable, java.lang.Cloneable, java.util.EventListener

public class FileList
implements TreeInterface, NodeIconInterface, StaticOrderedCollectionInterface, java.beans.PropertyChangeListener

A class that holds a list of File and Directory names that are available in a Directory on a specified FileSystem.

Creating a FileList Component

FileList fl = new FileList("c:\\NashvilleProject", "*.gif", true); Usage

A FileList object can be used as a model for ListBox, ComboBox or Tree. Create a FileList object, set its property - startingDirectories and filterPredicates and include directories. If the properties are not set, then a list of fileSystems (drives) are displayed in a tree and list of files in the listbox. Specify the options - recursive. To create a FileList Object FileList fl = new FileList("*", "*.gif", true) will create a list of all the files that are gif files. The flag set to true in above constructor will affect the list if it is displayed in a tree, otherwise it is ignored. To use this class to search the directories recursively, use it by dropping it on a tree. A call to getitem() method will only return the files in the starting directories that match the file filter, it will not do a recursive search.


 

See Also:
Serialized Form

Field Summary
protected static OrderedCollection coc
           
protected static OrderedCollection driveCollection
           
protected static java.lang.String environmentVariable
           
protected  StringCollection fileNameList
           
protected  com.sas.collection.ContentsChangedListener[] listenerList
           
protected static OrderedCollection newPathCollection
           
protected  OrderedCollection oc
           
protected static OrderedCollection pathCollection
           
protected static java.lang.String RB_KEY
           
protected static boolean showDirectories
           
protected static boolean showFiles
           
protected static boolean sortSelected
           
 
Constructor Summary
FileList()
          A default constructor initilaizes the list with the fileSystem names (drive names).
FileList(java.lang.String startingDirs, java.lang.String filters, boolean recursive)
          A constructor that takes the directory name and filter and fills this list based on the file filter.
 
Method Summary
 void addContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
          Add a listener for the com.sas.collection.ContentsChangedEvent event.
 void apply(com.sas.util.ApplyInterface action)
          Applies the 'apply' function in the action to every item in the collection.
 java.lang.Object clone()
          Create a copy of the current model
 boolean contains(java.lang.Object element)
          Test for the presence of an object(absolute path name of file) in the collection (StaticOrderedCollection implementation)
 int count()
          Returns the number of files and directories in the current collection (StaticOrderedCollection implementation)
 int countNodeChildren(int maximumChildCount)
          Counts the children of the current node.
 boolean equals(StaticOrderedCollectionInterface orderedCollection)
          Compare the current collection of absolute file name strings with those in another collection and tell whether the collections are identical.
 void fireContentsChanged(com.sas.collection.ContentsChangedEvent event)
          Send a ChangedEvent event to all the ChangedListener objects in the listener list.
 java.lang.Object get(int index)
          Fetch an item (absolute path name of file) at an index.
 com.sas.visuals.IconInterface getDefaultIcon()
          Returns the default icon for the current node.
 com.sas.visuals.IconInterface getExpandedIcon()
          Returns the expanded icon for the current node.
 com.sas.visuals.IconInterface getExpandedSelectedIcon()
          Sets the expandedSelected icon for the current node.
static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
           
 java.lang.String getFilters()
          Gets the file filters seperated by semicolon.
 int getIndex(java.lang.Object element, int startIndex)
          Returns the index associated with the item (searches forward) (StaticOrderedCollection implementation)
 java.util.Enumeration getItems()
          Returns list of file name Strings as an enumeration.
 java.util.Enumeration getItems(int start, int end)
          Returns an enumeration of a subset of the items (an absolute path name of files) from a collection.
 int getLastIndex(java.lang.Object element, int startIndex)
          Returns the index associated with the item (searches backward) (StaticOrderedCollection implementation)
 SimpleNodeInterface getNodeChild(int index)
          Returns the child node at the specified index.
 int getNodeChildCount()
          Returns the number of children.
 SimpleNodeInterface[] getNodeChildren(int startIndex, int count)
          Returns the specified range of children for the current node.
 java.lang.String getNodeExpandedText()
          Returns the value of the nodeExpandedText property.
 java.lang.String getNodeText()
          Returns the value of the nodeText property.
 java.lang.String getNodeType()
          Returns the value of the nodeType property.
 NodeInterface getRoot()
          Gets the root for the tree implementation of the list.
 com.sas.visuals.IconInterface getSelectedIcon()
          Returns the selected icon for the current node.
 java.lang.String getStartingDirectories()
          get the starting direcotry property for this filelist.
 boolean isLeafNode()
          Indicates whether the current node is a leaf.
 boolean isRecursive()
          return a flag indicating whether to show directories or not
 com.sas.util.PredicateInterface newFilterPredicate(java.lang.Object predicateString)
          Create a new predicate and return it.
 void refresh()
          Adds the names to the filenames only if the list is not filled
 void refreshAlways()
          Add the filenames to the list again.
 void removeContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
          Remove a listener for the com.sas.collection.ContentsChangedEvent event.
 void setDefaultValues()
          This method sets the initial property values to their default values.
 void setFilters(java.lang.String fils)
          Sets the file filterPredicates to match the filenames to add to this list.
 void setPredicates(com.sas.util.PredicateInterface[] predicates)
          Sets the filterPredicates property to the the predicates passed in.
 void setRecursive(boolean recursive)
          Set the flag to show directories or not
 void setStartingDirectories(java.lang.String startingDirs)
          Set the starting directories property for this list.
protected  void sort(com.sas.util.Comparator comparator)
           
 void sort(com.sas.util.Comparator comparator, int start, int end)
          Sorts a range of items from the current collection using the provided comparison function.
 java.lang.String toString()
          Returns the list as filenames seperated by comma
 
Methods inherited from class com.sas.Component
addLink, addPropertyChangeListener, addVetoableChangeListener, anyPropertyChangeListeners, attachModel, attachView, beansIsDesignTime, beansSetDesignTime, clone, detachModel, detachView, dumpComponent, firePropertyChange, firePropertyChange, fireVetoableChange, getComponentDescription, getComponentSupportInfo, getEventMethod, getEventValues, getLinkInfo, getModelInterface, getRequiredInterfaces, getResources, getStringResource, getViewInterfaceSupportInfo, initialize, initializeComponent, isDesignTime, isLinked, propertyChange, queryLinks, queryLinks, refresh, removeAllLinks, removeInterfaceTraps, removeLink, removePropertyChangeListener, removeVetoableChangeListener, setComponentDescription, setComponentSupportInfo, setLinkInfo, setModelInterface, setRequiredInterfaces, setViewInterfaceSupportInfo, supportsListenerInterface, supportsRequiredInterfaces, trapInterfaceEvents, validateObject
 
Methods inherited from interface com.sas.beans.PropertyChangeSource
addPropertyChangeListener, removePropertyChangeListener
 

Field Detail

environmentVariable

protected static java.lang.String environmentVariable

coc

protected static OrderedCollection coc

driveCollection

protected static OrderedCollection driveCollection

pathCollection

protected static OrderedCollection pathCollection

newPathCollection

protected static OrderedCollection newPathCollection

showFiles

protected static boolean showFiles

showDirectories

protected static boolean showDirectories

sortSelected

protected static boolean sortSelected

RB_KEY

protected static final java.lang.String RB_KEY
See Also:
Constant Field Values

oc

protected transient OrderedCollection oc

fileNameList

protected transient StringCollection fileNameList

listenerList

protected com.sas.collection.ContentsChangedListener[] listenerList
Constructor Detail

FileList

public FileList()
A default constructor initilaizes the list with the fileSystem names (drive names).


FileList

public FileList(java.lang.String startingDirs,
                java.lang.String filters,
                boolean recursive)
A constructor that takes the directory name and filter and fills this list based on the file filter. The list will contain directories only if the recursive flag is set to true

Parameters:
startingDirectories - a semicolon seperated list of directories to start the search from.
filters - a semicolon seperated list of file filters to match the filenames against.
recursive - indicated whether the list should contain directories or not.
Method Detail

getExtendedBeanInfo

public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()

setDefaultValues

public void setDefaultValues()
Description copied from interface: ComponentInterface
This method sets the initial property values to their default values. It is called by initializeComponent. Subclasses of the Component class or classes that implement the ComponentInterface should override setDefaultValues to perform their initialization.

Note that the designTime property is not initialized when setDefaultValues is called, so initialization which depends on the value of designTime should take place in initializeComponent.

Specified by:
setDefaultValues in interface ComponentInterface
Overrides:
setDefaultValues in class Component
See Also:
ComponentInterface.setDefaultValues()

setStartingDirectories

public void setStartingDirectories(java.lang.String startingDirs)
Set the starting directories property for this list. This list will be filled starting at the directories specified.

Parameters:
a - semicolon separated directory names.

getStartingDirectories

public java.lang.String getStartingDirectories()
get the starting direcotry property for this filelist.

Returns:
a comma or semicolon separated list of starting directories.

setFilters

public void setFilters(java.lang.String fils)
Sets the file filterPredicates to match the filenames to add to this list.

Parameters:
a - semicolon or coma seperated list of file filterPredicates.

getFilters

public java.lang.String getFilters()
Gets the file filters seperated by semicolon. This filter are of the form "*;*.gif". This filterPredicates are applied to the startingDirectories property for the list of files.

Returns:
file filterPredicates separated by semicolon

newFilterPredicate

public com.sas.util.PredicateInterface newFilterPredicate(java.lang.Object predicateString)
Create a new predicate and return it.

Parameters:
predicateString - to be converted to predicate
Returns:
a new String predicate

setPredicates

public void setPredicates(com.sas.util.PredicateInterface[] predicates)
Sets the filterPredicates property to the the predicates passed in.

Parameters:
preicates - to be set for this list

getItems

public java.util.Enumeration getItems()
Returns list of file name Strings as an enumeration. This method only searches the starting directory(top level) and includes the directory names if the recursive flag is on.

Specified by:
getItems in interface com.sas.util.Enumerable
Returns:
an enumeration of the File name strings.

getRoot

public NodeInterface getRoot()
Gets the root for the tree implementation of the list. Based on the values of drivefilter, directoryfilter and filefilter will create a tree with the filterPredicates as root node and list as its children node.
  FileList fl = new FileList("d:\\images", "*")
    - will create a root node called FileList(d:\\images\\*) and 
      set its children to (d:\\images\\*) and its children to the files
      and directories in images directories..
 
(TreeInterface implementation)

Specified by:
getRoot in interface TreeInterface
Returns:
NodeInterface

isRecursive

public boolean isRecursive()
return a flag indicating whether to show directories or not

Returns:
flag indicating whether to show directories or not.

setRecursive

public void setRecursive(boolean recursive)
Set the flag to show directories or not

Parameters:
recursive - flag shows directories if true.

addContentsChangedListener

public void addContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
Add a listener for the com.sas.collection.ContentsChangedEvent event.

Specified by:
addContentsChangedListener in interface com.sas.collection.ContentsChangedSource
Parameters:
listener - an object which handles ChangedEvent events the listener is not added a second time if it already exists in the list of listeners for this event.
See Also:
ContentsChangedSource

removeContentsChangedListener

public void removeContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
Remove a listener for the com.sas.collection.ContentsChangedEvent event. Nothing happens if the listener is not in the list of listeners for this event.

Specified by:
removeContentsChangedListener in interface com.sas.collection.ContentsChangedSource
Parameters:
listener - an object which handles ContentsChangedEvent events
See Also:
ContentsChangedSource

fireContentsChanged

public void fireContentsChanged(com.sas.collection.ContentsChangedEvent event)
Send a ChangedEvent event to all the ChangedListener objects in the listener list. The listener list is copied first, so the event is sent only to each item which is in the list at the time of this copy, even if adds or removes are performed after the send has started.

Parameters:
event - the event to send

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Create a copy of the current model

Specified by:
clone in interface StaticCollectionInterface
Specified by:
clone in interface StaticOrderedCollectionInterface
Specified by:
clone in interface com.sas.PublicClonable
Overrides:
clone in class Component
Returns:
a clone of the object.
Throws:
java.lang.CloneNotSupportedException - if the model attached to the component being cloned will not allow the clone to attach.

getNodeExpandedText

public java.lang.String getNodeExpandedText()
Returns the value of the nodeExpandedText property. The expanded text is usually a more descriptive version of the nodeText property. For example, a node that represents a file can return the file name for the nodeText property and the full path name for the nodeExpandedText property.

Specified by:
getNodeExpandedText in interface NodeInterface
Returns:
the nodeExpandedText property

getNodeText

public java.lang.String getNodeText()
Returns the value of the nodeText property.

Specified by:
getNodeText in interface NodeInterface
Returns:
the nodeText property

getNodeType

public java.lang.String getNodeType()
Returns the value of the nodeType property. The type can be used for categorizing nodes.

Specified by:
getNodeType in interface NodeInterface
Returns:
the nodeType property

countNodeChildren

public int countNodeChildren(int maximumChildCount)
Counts the children of the current node. countNodeChildren differs from getNodeChildCount when the number of children is unknown, i.e. when getNodeChildCount returns -1. If your implementation of getNodeChildCount never returns -1, then simply define countNodeChildren as a return of getNodeChildCount, otherwise read-on.

countNodeChildren is an instruction to determine the number of children even though that number is not readily known. To limit the potential overhead of this determination, the maximum number of children to read may be specified.

Specified by:
countNodeChildren in interface SimpleNodeInterface
Parameters:
maxCount - Maximum number of children to read, or 0 to read indefinitely. Implementations where the number of children is always known should ignore this parameter. In cases where the total number of children is unknown, but the number known so far is greater than maxCount should return the larger known number. Thus maxCount is only used as a limiting factor when the implementation has to actually do computation (e.g. fetch observations).
Returns:
The number of children known to be available.

getNodeChildCount

public int getNodeChildCount()
Returns the number of children. If the number of children is unknown, -1 should be returned.

Specified by:
getNodeChildCount in interface SimpleNodeInterface
Returns:
the number of children or -1 if unknown

isLeafNode

public boolean isLeafNode()
Indicates whether the current node is a leaf. A true value indicates that the current node is a leaf and hence will not have any children.

Specified by:
isLeafNode in interface SimpleNodeInterface
Returns:
true if the current node is a leaf, otherwise false

getNodeChild

public SimpleNodeInterface getNodeChild(int index)
Returns the child node at the specified index.

Specified by:
getNodeChild in interface SimpleNodeInterface
Parameters:
index - the 0-based index of the child node to retrieve
Returns:
the child at index or null if the leafNode property value is true.

getNodeChildren

public SimpleNodeInterface[] getNodeChildren(int startIndex,
                                             int count)
Returns the specified range of children for the current node. If there are less children than are queried for, an implementation can return an array whose size if representative of the actual number of children being returned or an array whose size is the same as the number of children asked for. If the resulting array's size is the same as the number asked for and there are fewer children returned than asked for the implementation should assign the unused values in the array to null.

Specified by:
getNodeChildren in interface SimpleNodeInterface
Parameters:
startIndex - 0-based index which identifies the start of the range
count - the amount of children to get
Returns:
an array containing the specified range of children or null if the leafNode property value is true.

getDefaultIcon

public com.sas.visuals.IconInterface getDefaultIcon()
Returns the default icon for the current node.

Specified by:
getDefaultIcon in interface NodeIconInterface
Returns:
the default icon for the current node

getExpandedIcon

public com.sas.visuals.IconInterface getExpandedIcon()
Returns the expanded icon for the current node. If the expanded icon is null then the result of getDefaultIcon should be returned.

Specified by:
getExpandedIcon in interface NodeIconInterface
Returns:
the expanded icon for the current node

getSelectedIcon

public com.sas.visuals.IconInterface getSelectedIcon()
Returns the selected icon for the current node. If the selected icon is null then the result of getDefaultIcon should be returned.

Specified by:
getSelectedIcon in interface NodeIconInterface
Returns:
the selected icon for the current node

getExpandedSelectedIcon

public com.sas.visuals.IconInterface getExpandedSelectedIcon()
Sets the expandedSelected icon for the current node. If the expandedSelected icon is null then the result of getExpandedIcon should be returned.

Specified by:
getExpandedSelectedIcon in interface NodeIconInterface
Returns:
the expandedSelected icon for the current node

equals

public boolean equals(StaticOrderedCollectionInterface orderedCollection)
Compare the current collection of absolute file name strings with those in another collection and tell whether the collections are identical. The equals method is used to compare collection items. (StaticOrderedCollection implementation)

Specified by:
equals in interface StaticOrderedCollectionInterface
Parameters:
orderedCollection - Another ordered collection of absolute file name strings to be compared to.
Returns:
True if identical, False otherwise.

get

public java.lang.Object get(int index)
Fetch an item (absolute path name of file) at an index. (StaticOrderedCollection implementation)

Specified by:
get in interface IndexedGetInterface
Parameters:
index - the position of the item, zero-based indexing.
Returns:
the item associated with the index value
Throws:
java.lang.IndexOutOfBoundsException - if index is not in the range [0, count()-1].

getIndex

public int getIndex(java.lang.Object element,
                    int startIndex)
Returns the index associated with the item (searches forward) (StaticOrderedCollection implementation)

Specified by:
getIndex in interface StaticOrderedCollectionInterface
Parameters:
element - item (an absolute path name of file) to search for
startIndex - the position where the search should start
Returns:
the zero-based index corresponding to the list item or -1 if the item is not found.
Throws:
java.lang.IndexOutOfBoundsException - if the index is not in the range [0..count()-1].
com.sas.util.InvalidElementTypeException - In some implementations, the objects that are stored may be restricted to a particular type (such as String). (a RuntimeException)

getItems

public java.util.Enumeration getItems(int start,
                                      int end)
Returns an enumeration of a subset of the items (an absolute path name of files) from a collection. (StaticOrderedCollection implementation)

Specified by:
getItems in interface StaticOrderedCollectionInterface
Parameters:
start - the index of the first item, zero based.
end - one past the index of the last item to include in the enumeration, zero based. Note that the range of elements returned in the Enumeration does not include the endthe item; this is consistent with substring(start, end) in java.lang.String, for example.
Returns:
an enumeration of the requested elements.
Throws:
java.lang.IndexOutOfBoundsException - if start is not in the range [0, count()-1], or start>last or end is not in the range [0, count()]

getLastIndex

public int getLastIndex(java.lang.Object element,
                        int startIndex)
Returns the index associated with the item (searches backward) (StaticOrderedCollection implementation)

Specified by:
getLastIndex in interface StaticOrderedCollectionInterface
Parameters:
element - the item(absolute path name of file) to search for
startIndex - the position where the search should start
Returns:
the zero-based index corresponding to the list item or -1 if the item is not found.
Throws:
java.lang.IndexOutOfBoundsException - if the index is not in the range [0..count()-1]
com.sas.util.InvalidElementTypeException - when the object is not of type String (a RuntimeException) (a RuntimeException)

contains

public boolean contains(java.lang.Object element)
Test for the presence of an object(absolute path name of file) in the collection (StaticOrderedCollection implementation)

Specified by:
contains in interface StaticCollectionInterface
Parameters:
element - The item(absolute file name) to search for
Returns:
True if and only if the item exists
Throws:
com.sas.util.InvalidElementTypeException - when the object is not of type String (a RuntimeException)

count

public int count()
Returns the number of files and directories in the current collection (StaticOrderedCollection implementation)

Specified by:
count in interface com.sas.util.Countable
Returns:
the number of items in the collection

apply

public void apply(com.sas.util.ApplyInterface action)
Applies the 'apply' function in the action to every item in the collection. This is a general way to modify all the items in a collection. (StaticOrderedCollection implementation)

Specified by:
apply in interface StaticCollectionInterface
Parameters:
action - An object that provides a function which takes object as an argument and then does something to it. The application of the action continues until all items in the the collection have been operated on, of until a call to the action.apply(Object item) method returns ApplyInterface.ABORT

sort

public void sort(com.sas.util.Comparator comparator,
                 int start,
                 int end)
Sorts a range of items from the current collection using the provided comparison function. The sort is performed in place. (StaticOrderedCollection implementation)

Parameters:
comparator - An instance of a subclass of Comparator which provides a compare(Object,Object) function.
start - the index of the first item in the range to sort
end - sort the items between start and (end-1)
See Also:
Comparator

toString

public java.lang.String toString()
Returns the list as filenames seperated by comma

Overrides:
toString in class java.lang.Object
Returns:
filenames seperated by coma.

refresh

public void refresh()
Adds the names to the filenames only if the list is not filled


refreshAlways

public void refreshAlways()
Add the filenames to the list again.


sort

protected void sort(com.sas.util.Comparator comparator)



Copyright © 2009 SAS Institute Inc. All Rights Reserved.