Extension SDK

oracle.ide.model
Class HierarchicalFilter

java.lang.Object
  extended byoracle.ide.model.DefaultFilter
      extended byoracle.ide.model.HierarchicalFilter
All Implemented Interfaces:
ChildFilter, Displayable
Direct Known Subclasses:
DirectoryFilter, PackageFilter

public abstract class HierarchicalFilter
extends DefaultFilter

The HierarchicalFilter defines common behavior for filters that organize the children of a source folder into a hierarchical (tree) structure view. The HierarchicalFilter also defines an abstract interface which all concrete subclasses must implement.

See Also:
DirectoryFilter, PackageFilter

Nested Class Summary
protected  class HierarchicalFilter.HierarchicalComparator
           
 
Nested classes inherited from class oracle.ide.model.DefaultFilter
DefaultFilter.SortedComparator, DefaultFilter.SortedFolderFirstComparator
 
Field Summary
protected  java.util.Map childMap
          The Map that maps a folder key to the List of project children belonging to that folder.
protected  java.util.Collection children
          A Collection of the top-level child Element objects for this filter.
protected  boolean isOpen
          Flag denoting whether the contents of the filter have been read.
protected  CategoryFolder miscFolder
          The "Miscellaneous Files" folder that contains children that are not on the source path.
protected  WeakCache nodeCache
          The cache mapping an URL to its respective TNode.
protected static java.lang.Object NULL_KEY
          Folder key constant used for the Miscellaneous Files folder.
protected  int options
          Bit mask specifying the view options for this filter.
protected  URLPath sourcePath
          Cached canonicalized version of the source path for the project.
protected static java.lang.Object TOP_FOLDER_KEY
          Folder key constant used for top-level children of the filter.
protected  java.util.Set uniqueNames
          The Set of unique top-level child names already belonging to this filter.
protected  URLFilter urlFilter
          The URLFilter used to filter URLs returned by URLFileSystem.list(URL, URLFilter).
static int VIEW_HIERARCHICALLY
          Flag denoting whether the filter should display its contents hierarchically or flat.
static int VIEW_PROJECT_FILES_ONLY
          Flag denoting whether the filter should display project files or all files.
 
Fields inherited from class oracle.ide.model.DefaultFilter
folderFirstComparator, sortedComparator
 
Fields inherited from interface oracle.ide.explorer.ChildFilter
NO_OPTIONS
 
Constructor Summary
HierarchicalFilter()
          Constructs a HierarchicalFilter.
 
Method Summary
protected  void add(Element element)
          Add the child Element to the collection of the filter's top-level children.
 void cache(TNode node)
          Adds the specified TNode to the node cache.
 boolean canRefresh(TNode[] nodes)
          Always returns true.
 TNode childrenAdded(java.util.List added, TNode par, TreeExplorer tree)
          Adds the specified List of child Element objects to the TreeExplorer.
 TNode childrenRemoved(java.util.List removed, TNode par, TreeExplorer tree)
          Removes the specified List of child Element objects from the TreeExplorer.
protected  void clearChildren()
          Removes all top-level children of the filter.
protected  Element createElement(java.net.URL url)
          Finds or creates a child Element for the given URL.
protected abstract  Folder createFolder(java.lang.Object key)
          Creates the child Folder for the given folder key.
protected abstract  Folder createFolder(java.net.URL url)
          Creates the child Folder for the given directory URL.
protected  CategoryFolder getCategoryFolder()
          Returns the CategoryFolder that owns this filter, or null if the filter is not owned by a CategoryFolder.
protected abstract  java.lang.String getChildName(java.lang.Object parentKey, java.lang.Object childKey)
          Returns just the name part of a child folder given a parent folder key and the child folder key, or null if the first folder key is not a parent key of the second folder key.
 java.util.Iterator getChildren()
          Returns an Iterator for traversing the top-level children of the filter.
protected  Folder getFolder()
          Returns the Folder that owns this filter.
protected  java.util.Iterator getFolderChildren(HierarchicalFolder folder)
          Returns an Iterator for traversing the children belonging to the specified HierarchicalFolder; if the specified folder is null, then an Iterator over the top-level children of the filter is returned.
protected  java.util.Iterator getFolderChildren(java.lang.Object key)
          Returns an Iterator for traversing the children belonging to the folder corresponding to the specified folder key.
protected abstract  java.lang.Object getFolderKey(java.net.URL url)
          Gets the folder key for the given URL that is used for mapping a Folder to the list of project children belonging to that folder.
protected  CategoryFolder getMiscFolder()
          Return the "Miscellaneous Files" CategoryFolder for this filter.
 int getOptions()
          Gets the options bit mask used to control the filter's display.
protected abstract  java.lang.Object getParentKey(java.lang.Object key)
          Gets the parent folder key for a given folder key.
protected  Project getProject()
          Returns the Project that owns this filter.
protected  URLPath getSourcePath()
          Returns the source path for the owning folder.
protected  java.net.URL getSourcePathEntry(java.net.URL url)
          Returns the URL for the source path entry that contains the specified URL.
 URLFilter getURLFilter()
          Returns the URLFilter used to exclude files from the filter's display.
 boolean getViewAllFiles()
          Returns true if the filter is currently displaying all files, or false if the filter is displaying project files only.
 boolean getViewHierarchically()
          Returns true if the filter is currently displaying its folders in nested view, or false if the filter is displaying its folders in flat view
protected  boolean hasMiscFiles()
          Returns true if there are miscellaneous files to be displayed.
protected abstract  void initChildren()
          Initializes the collection of top-level children for the filter.
protected  void initializeChildMap()
          Initialize the Map that maps each folder by its folder key to the List of child Element objects belonging to that folder.
protected  void initMiscFolder()
          Creates and initializes the Miscellaneous Files folder, if necessary.
protected  boolean isDirInProject(java.net.URL url)
          Returns true if the URL specifies a directory that contains at least one Element in the project; otherwise false.
protected  boolean isInSourcePath(java.net.URL url)
          Returns true if the URL is contained by an entry on the source path.
protected  boolean isParentKey(java.lang.Object key, java.lang.Object childKey)
          Returns true if the first specified folder key is a parent key of the second specified folder key; otherwise, returns false.
protected  boolean isSourcePathEntry(java.net.URL url)
          Returns true if the URL is an entry on the source path.
protected  java.net.URL[] list(java.net.URL url)
          Lists the children of an URL, applying this filter's current URLFilter to the result set.
protected  java.net.URL[] list(URLPath urlPath)
          Lists the children of an URLPath as if it were simply a single URL.
 void refresh(TNode[] nodes)
          Completely refreshes the filter's display.
protected  void remove(Element element)
          Removes the child Element from the collection of the filter's top-level children.
protected  void setComparator(java.util.Comparator comparator)
           
 void setOptions(int options)
          Sets the options bit mask used to control the filter's display.
protected  void setSourcePath(URLPath sourcePath)
          Sets the source path to the specified URLPath.
 void setURLFilter(URLFilter urlFilter)
          Sets the URLFilter used to exclude files from the filter's display.
 void setViewAllFiles(boolean viewAllFiles)
          Sets the filter to display all files or project files only.
 void setViewHierarchically(boolean viewHierarchically)
          Sets the filter to display folders in nested or flat view.
 void uncache(TNode tnode)
          Removes the specified TNode from the node cache.
 TNode update(TNode node, UpdateMessage change)
          Updates the filter's display in response to an UpdateMessage.
 
Methods inherited from class oracle.ide.model.DefaultFilter
getComparator, getIcon, getLongLabel, getOwner, getShortLabel, getToolTipText, getType, refreshExplorerNode, setOwner, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VIEW_PROJECT_FILES_ONLY

public static final int VIEW_PROJECT_FILES_ONLY
Flag denoting whether the filter should display project files or all files.

See Also:
Constant Field Values

VIEW_HIERARCHICALLY

public static final int VIEW_HIERARCHICALLY
Flag denoting whether the filter should display its contents hierarchically or flat.

See Also:
Constant Field Values

NULL_KEY

protected static final java.lang.Object NULL_KEY
Folder key constant used for the Miscellaneous Files folder.


TOP_FOLDER_KEY

protected static final java.lang.Object TOP_FOLDER_KEY
Folder key constant used for top-level children of the filter.


isOpen

protected boolean isOpen
Flag denoting whether the contents of the filter have been read.


options

protected int options
Bit mask specifying the view options for this filter.


nodeCache

protected WeakCache nodeCache
The cache mapping an URL to its respective TNode.


childMap

protected java.util.Map childMap
The Map that maps a folder key to the List of project children belonging to that folder.


urlFilter

protected URLFilter urlFilter
The URLFilter used to filter URLs returned by URLFileSystem.list(URL, URLFilter).


miscFolder

protected CategoryFolder miscFolder
The "Miscellaneous Files" folder that contains children that are not on the source path.


sourcePath

protected URLPath sourcePath
Cached canonicalized version of the source path for the project.


children

protected java.util.Collection children
A Collection of the top-level child Element objects for this filter.


uniqueNames

protected java.util.Set uniqueNames
The Set of unique top-level child names already belonging to this filter.

Constructor Detail

HierarchicalFilter

public HierarchicalFilter()
Constructs a HierarchicalFilter.

Method Detail

createFolder

protected abstract Folder createFolder(java.net.URL url)
Creates the child Folder for the given directory URL. Subclasses should provide an appropriate implementation.

Parameters:
url - the URL of the Folder to create.
Returns:
a Folder instance, or null if the Folder could not be created for the specified URL.

createFolder

protected abstract Folder createFolder(java.lang.Object key)
Creates the child Folder for the given folder key. Subclasses should provide an appropriate implementation.

Returns:
a Folder instance, or null if the Folder could not be created for the specified folder key.
See Also:
getFolderKey(URL), getParentKey(Object)

getFolderKey

protected abstract java.lang.Object getFolderKey(java.net.URL url)
Gets the folder key for the given URL that is used for mapping a Folder to the list of project children belonging to that folder. Subclasses should provide an appropriate implementation.

The URL specified need not be a directory URL. Generally it is the URL of a Locatable element that belongs to the project; in this case, the parent URL of the specified URL is used to obtain the folder key.

Implementations should return TOP_FOLDER_KEY when the URL corresponds to a top-level child of the filter and NULL_KEY when the specified URL is not on the source path.

Parameters:
url - the URL of the Locatable to return the folder key for.
Returns:
an Object representing the key in the Map for the specified folder URL.

getParentKey

protected abstract java.lang.Object getParentKey(java.lang.Object key)
Gets the parent folder key for a given folder key. Subclasses should provide an appropriate implementation.

Implementations should return TOP_FOLDER_KEY when the parent folder key corresponds to the top-level children of the filter and NULL_KEY when the parent folder key cannot be obtained or is no longer on the source path.

Parameters:
key - the folder key to get the parent key for.
Returns:
an Object representing the parent key in the Map for the specified folder key.
See Also:
getFolderKey(URL)

getChildName

protected abstract java.lang.String getChildName(java.lang.Object parentKey,
                                                 java.lang.Object childKey)
Returns just the name part of a child folder given a parent folder key and the child folder key, or null if the first folder key is not a parent key of the second folder key. Subclasses should provide an appropriate implementation.

Subclasses should return the child name without a trailing '/' appended.

Parameters:
parentKey - the prospective parent folder key.
childKey - the prospective child folder key.

initChildren

protected abstract void initChildren()
Initializes the collection of top-level children for the filter.

Subclasses should add Element objects to the collection of top-level children by calling the add(Element) method on the filter.


getChildren

public java.util.Iterator getChildren()
Returns an Iterator for traversing the top-level children of the filter.

Specified by:
getChildren in interface ChildFilter
Overrides:
getChildren in class DefaultFilter

childrenAdded

public TNode childrenAdded(java.util.List added,
                           TNode par,
                           TreeExplorer tree)
Adds the specified List of child Element objects to the TreeExplorer. The tree is maintained according to the view options for this filter.

Specified by:
childrenAdded in interface ChildFilter
Overrides:
childrenAdded in class DefaultFilter

childrenRemoved

public TNode childrenRemoved(java.util.List removed,
                             TNode par,
                             TreeExplorer tree)
Removes the specified List of child Element objects from the TreeExplorer. The tree is maintained according to the view options for this filter.

Specified by:
childrenRemoved in interface ChildFilter
Overrides:
childrenRemoved in class DefaultFilter

cache

public void cache(TNode node)
Adds the specified TNode to the node cache.

Specified by:
cache in interface ChildFilter
Overrides:
cache in class DefaultFilter

uncache

public void uncache(TNode tnode)
Removes the specified TNode from the node cache.

Specified by:
uncache in interface ChildFilter
Overrides:
uncache in class DefaultFilter

getURLFilter

public URLFilter getURLFilter()
Returns the URLFilter used to exclude files from the filter's display.

Specified by:
getURLFilter in interface ChildFilter
Overrides:
getURLFilter in class DefaultFilter

setURLFilter

public void setURLFilter(URLFilter urlFilter)
Sets the URLFilter used to exclude files from the filter's display.

Specified by:
setURLFilter in interface ChildFilter
Overrides:
setURLFilter in class DefaultFilter

getOptions

public int getOptions()
Gets the options bit mask used to control the filter's display. The options may consist of one or more of the following flags:

Specified by:
getOptions in interface ChildFilter
Overrides:
getOptions in class DefaultFilter

setOptions

public void setOptions(int options)
Sets the options bit mask used to control the filter's display. The options may consist of one or more of the following flags:

Specified by:
setOptions in interface ChildFilter
Overrides:
setOptions in class DefaultFilter

refresh

public void refresh(TNode[] nodes)
Completely refreshes the filter's display.

Specified by:
refresh in interface ChildFilter
Overrides:
refresh in class DefaultFilter
Parameters:
nodes - the array of TNodes to refresh (ignored).

canRefresh

public boolean canRefresh(TNode[] nodes)
Always returns true.

Specified by:
canRefresh in interface ChildFilter
Overrides:
canRefresh in class DefaultFilter

update

public TNode update(TNode node,
                    UpdateMessage change)
Updates the filter's display in response to an UpdateMessage.

Specified by:
update in interface ChildFilter
Overrides:
update in class DefaultFilter

getViewAllFiles

public boolean getViewAllFiles()
Returns true if the filter is currently displaying all files, or false if the filter is displaying project files only.


setViewAllFiles

public void setViewAllFiles(boolean viewAllFiles)
Sets the filter to display all files or project files only.

Parameters:
viewAllFiles - if true, the filter will display all files; if false, the filter will display project files only.

getViewHierarchically

public boolean getViewHierarchically()
Returns true if the filter is currently displaying its folders in nested view, or false if the filter is displaying its folders in flat view


setViewHierarchically

public void setViewHierarchically(boolean viewHierarchically)
Sets the filter to display folders in nested or flat view.

Parameters:
viewHierarchically - if true, the filter will display folders in nested view; if false, the filter will display folders in flat view.

clearChildren

protected void clearChildren()
Removes all top-level children of the filter.


add

protected void add(Element element)
Add the child Element to the collection of the filter's top-level children.


remove

protected void remove(Element element)
Removes the child Element from the collection of the filter's top-level children.


isDirInProject

protected boolean isDirInProject(java.net.URL url)
Returns true if the URL specifies a directory that contains at least one Element in the project; otherwise false.

Parameters:
url - the URL to test; if the URL specifies a file and not a directory, then the parent directory URL for the file is tested instead.

initializeChildMap

protected void initializeChildMap()
Initialize the Map that maps each folder by its folder key to the List of child Element objects belonging to that folder.


getFolderChildren

protected java.util.Iterator getFolderChildren(HierarchicalFolder folder)
Returns an Iterator for traversing the children belonging to the specified HierarchicalFolder; if the specified folder is null, then an Iterator over the top-level children of the filter is returned.

Parameters:
folder - the HierarchicalFolder to get the children of; if null, then the top-level children of the filter are returned.
See Also:
getFolderChildren(Object)

getFolderChildren

protected java.util.Iterator getFolderChildren(java.lang.Object key)
Returns an Iterator for traversing the children belonging to the folder corresponding to the specified folder key. If the specified folder key is TOP_FOLDER_KEY, then an Iterator over the top-level children of the filter is returned. If the specified folder key is NULL_KEY, then an Iterator over the children that are not on the source path (the Miscellanous Files children) is returned.

The returned Iterator specifies all child Folder and Element objects belonging to the specified folder. If the filter is displaying folders in flat view, however, then the Iterator will only enumerate Folder children for the top-level children of the filter.

This method cannot be called unless only project files are being displayed by the filter, except when the folder key is NULL_KEY. If all files are being displayed, then the HierarchicalFolder.list() method should instead be used to determine the contents of the folder.

Parameters:
key - the folder key of the folder to get the children of.
Returns:
an Iterator enumerating all children in the specified folder.
Throws:
java.lang.IllegalStateException - if the VIEW_PROJECT_FILES_ONLY filter option is not set and the specified key is not NULL_KEY.

getSourcePath

protected URLPath getSourcePath()
Returns the source path for the owning folder. Each entry along the source path must canonicalized to ensure that the filter will be able to determine later whether or not a given child URL is in the source path.

Returns:
the URLPath that represents the owning folder's source path.

setSourcePath

protected void setSourcePath(URLPath sourcePath)
Sets the source path to the specified URLPath.


getSourcePathEntry

protected java.net.URL getSourcePathEntry(java.net.URL url)
Returns the URL for the source path entry that contains the specified URL.

Parameters:
url - the URL to get the source path entry for.
Returns:
the URL for the source path entry that contains the specified URL, or null if the URL is not on the source path.

isInSourcePath

protected boolean isInSourcePath(java.net.URL url)
Returns true if the URL is contained by an entry on the source path.

Parameters:
url - the URL to test; the URL can correspond to either a file or a directory.

isSourcePathEntry

protected boolean isSourcePathEntry(java.net.URL url)
Returns true if the URL is an entry on the source path.

Parameters:
url - the URL to test; the URL should correspond to a directory.

getFolder

protected Folder getFolder()
Returns the Folder that owns this filter.


getCategoryFolder

protected CategoryFolder getCategoryFolder()
Returns the CategoryFolder that owns this filter, or null if the filter is not owned by a CategoryFolder. Identical to getFolder(), except that the Folder is returned as a CategoryFolder.


getProject

protected Project getProject()
Returns the Project that owns this filter.


getMiscFolder

protected CategoryFolder getMiscFolder()
Return the "Miscellaneous Files" CategoryFolder for this filter. This folder contains all children of the owning folder that are not on the source path.


list

protected java.net.URL[] list(java.net.URL url)
Lists the children of an URL, applying this filter's current URLFilter to the result set. The specified URL is assumed to correspond to a directory. If the urlFilter is null, then no filtering is done.

This method generates the list of children for the specified URL with URLFileSystem.list(URL, URLFilter). However, that method may not turn up all files if those files have been created in the IDE but not yet saved to the file system, so we also have to add all project children of the URL that were not in the list.

Parameters:
url - the directory URL to list.
Returns:
an array of URL objects naming the files and directories contained by the URL; if the contents of this URL cannot be listed, then null is returned.
See Also:
URLFileSystem.list(URL, URLFilter)

list

protected java.net.URL[] list(URLPath urlPath)
Lists the children of an URLPath as if it were simply a single URL. The contents of each URL along the URLPath are individually listed and merged into a single return array with duplicate entries removed. Entries must be unique according to the file name part of the URL; if more than one entry with the same file name is found along the URLPath, only the first entry found is returned.

This filter's current URLFilter is applied to the result set of each individual list operation. If the urlFilter is null, then no filtering is done.

Parameters:
urlPath - the URLPath to list.
Returns:
an array of URL objects naming the files and directories contained by the URLPath; if the contents of this URLPath cannot be listed, then null is returned.
See Also:
list(URL)

hasMiscFiles

protected boolean hasMiscFiles()
Returns true if there are miscellaneous files to be displayed.


initMiscFolder

protected void initMiscFolder()
Creates and initializes the Miscellaneous Files folder, if necessary.


createElement

protected Element createElement(java.net.URL url)
Finds or creates a child Element for the given URL. If the URL represents a directory path, then a Folder element is created, otherwise a standard Node element is created.

Parameters:
url - the URL of the Element to create.
Returns:
an Element instance, or null if the Element could not be created for the specified URL.

isParentKey

protected boolean isParentKey(java.lang.Object key,
                              java.lang.Object childKey)
Returns true if the first specified folder key is a parent key of the second specified folder key; otherwise, returns false.

Parameters:
key - the prospective parent folder key.
childKey - the prospective child folder key.

setComparator

protected void setComparator(java.util.Comparator comparator)

Extension SDK

 

Copyright ©1997, 2003, Oracle. All rights reserved.