com.borland.primetime.node
Class Project

java.lang.Object
  |
  +--com.borland.primetime.node.Node
        |
        +--com.borland.primetime.node.UrlNode
              |
              +--com.borland.primetime.node.Project
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
JBProject

public abstract class Project
extends UrlNode

There are several ways in which a project node is unusual and needs special care:


Field Summary
static java.lang.String CATEGORY_DEFAULT
          The default project category "sys".
static java.lang.String ENCODING
          The encoding category "Encoding" which retains the setting used when read/write text files.
static java.lang.String PREFIX_UNTITLED
          The default prefix "Untitled" used by the createProject() and createFileNode() methods.
protected  java.util.ArrayList projectListeners
          Array of registered ProjectListeners.
 
Fields inherited from class com.borland.primetime.node.Node
EMPTY_ARRAY, nodeListeners
 
Constructor Summary
protected Project(Url url)
          Creates a new project instance to represent a particular Url.
 
Method Summary
 void addProjectListener(ProjectListener listener)
          Adds given listener to list of registered listeners for Project events.
 void check()
          Ensure that the project's properties are resynchronized with the current state of its paths.
 FileNode createFileNode(java.lang.String extension)
          Generates a unique Url with the specified extension for new files that the user has not yet been prompted to name.
static Project createProject(java.lang.String extension)
          Generates a unique Url with the specified extension for new projects that the user has not yet been prompted to name.
 void dumpAllNodes()
          Strictly a diagnostic method
static void dumpProjects()
          Strictly a diagnostic method
 FileNode findNode(Url url)
          Returns a FileNode for the given Url if it had been created earlier in this project for it.
 LightweightNode[] findNodes(java.lang.String name)
          Returns an array of the registered lightweight nodes that are part of this Project (e.g.
static Project findProject(Url url)
          Maps given Url into a known, cached Project.
 void fireChildrenChanged(Node parent)
          Notifies all registered ProjectListeners that a node has been been added to or removed from a parent node the project.
 void fireNodeChanged(Node node)
          Notifies all registered ProjectListeners that a node's display name or icon has changed.
 void fireProjectPropertyChanged(java.lang.String category, java.lang.String property, java.lang.String oldValue, java.lang.String newValue)
          Notifies all registered ProjectListeners that a property on the project node has been changed.
 java.lang.String getAutoProperty(java.lang.String category, java.lang.String property)
          Gets the value of an automatic project property.
 javax.swing.Icon getDisplayIcon()
          Returns the 16x16 icon used to represent a Project.
 java.lang.String getDisplayName()
          Uses the the FileNode's underlying Url to derive a display name.
 int getDisplaySequence()
          Returns sort sequence for ProjectPane.
 java.lang.String getEncoding()
          Describes the standard encoding used to read and write text files for this project.
 java.lang.String getLongDisplayName()
          Uses the the FileNode's underlying Url to derive a full display name.
 FileNode getNode(Url url)
          Returns an appropriate FileNode from the given Url by either finding one created earlier in this Project for it, or by constructing one using a registered file type based on the file extension.
 Project getProject()
          Returns Project which contains this node.
static Project getProject(Url url)
          Maps given Url into a Project by first searching cache, then if not found will create an cache an instance of the Project.
 Url getProjectPath()
          Returns the Url representing the directory the project is stored in.
 Url getUrl()
          Returns the Url the project is currently associated with.
 boolean isModified()
          Describes whether or not unsaved changes exist in the project's state.
 boolean isNew()
          Describes whether or not the project needs to be renamed before it can be saved.
 boolean isPersistant()
          Determines whether or not the node definition and its properties will be saved with in a project file.
static boolean isProjectExtension(java.lang.String extension)
          Returns true if the given extension is registered as a project file type.
static boolean isProjectUrl(Url url)
          Returns true if given Url has a registered project file extension.
protected  void postProjectLoad(Url rootUrl)
          Hook for doing postprocessing after the project is saved.
protected  void preProjectSave(Url rootUrl)
          Hook for doing preprocessing prior to project being saved.
 void refresh()
          Invoked whenever the "refresh" button is pressed from the project view's toolbar.
static void registerProjectClass(java.lang.String extension, java.lang.String description, java.lang.Class projectClass, javax.swing.Icon icon)
          Add a new project type to the registry of known types and their associated extensions.
 void removeProjectListener(ProjectListener listener)
          Removes given listener from list of registered listeners for Project events.
 void rename(Url url)
          Rename cannot change the type of a Project.
 void revert()
          Revert a project to its on-disk state.
 void save()
          Updates the project's permanent storage to reflect the current state of the project.
 void saveAs(Url url)
          saveAs _can_ change the extension of a Project since all state is maintained by the Project instance itself and not the buffer representation, and all project buffers _must_ be associated with Project nodes.
 void setAutoProperty(java.lang.String category, java.lang.String property, java.lang.String value)
          Sets an automatic project property, which is always saved whether or not the project itself is saved.
 void setEncoding(java.lang.String encoding)
          Changes the standard encoding used to read and write text files for this project.
protected  void setUrl(Url url)
          Used internally by rename() and saveAs() to change the underlying Url associated with the project.
 
Methods inherited from class com.borland.primetime.node.UrlNode
getSuggestedUrl
 
Methods inherited from class com.borland.primetime.node.Node
addNodeListener, compareTo, dumpNodes, dumpNodes, dumpNodes, equals, fireNodeRenamed, getChildren, getDisplayChildren, getNodeID, getParent, getProperties, getProperty, getProperty, getProperty, hasChildren, hasDisplayChildren, hashCode, makePersistant, removeNodeListener, setParent, setProperty, setProperty, setProperty, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CATEGORY_DEFAULT

public static final java.lang.String CATEGORY_DEFAULT
The default project category "sys".

ENCODING

public static final java.lang.String ENCODING
The encoding category "Encoding" which retains the setting used when read/write text files.

PREFIX_UNTITLED

public static final java.lang.String PREFIX_UNTITLED
The default prefix "Untitled" used by the createProject() and createFileNode() methods.

projectListeners

protected java.util.ArrayList projectListeners
Array of registered ProjectListeners.
Constructor Detail

Project

protected Project(Url url)
           throws DuplicateNodeException,
                  InvalidUrlException
Creates a new project instance to represent a particular Url. This constructor should not be invoked directly, it is used internally by the factory method getProject(url).
Parameters:
url - The resource to read the project definition from.
Throws:
DuplicateNodeException - If a project is already registered for the specified Url.
Method Detail

getEncoding

public java.lang.String getEncoding()
Describes the standard encoding used to read and write text files for this project.
Returns:
A Java encoding name, or "default" if the default encoding should be used.

setEncoding

public void setEncoding(java.lang.String encoding)
Changes the standard encoding used to read and write text files for this project.
Parameters:
encoding - The Java encoding to use or null if the default encoding should be used.

setUrl

protected void setUrl(Url url)
               throws DuplicateNodeException
Used internally by rename() and saveAs() to change the underlying Url associated with the project.
Parameters:
url - The new Url to be associated with the project. This value must not be null.

getUrl

public Url getUrl()
Returns the Url the project is currently associated with.
Overrides:
getUrl in class UrlNode
Returns:
A valid non-null Url.

getProjectPath

public Url getProjectPath()
Returns the Url representing the directory the project is stored in.
Returns:
A valid non-null Url unless the project is in the new filesystem, in which case null may be returned.

isProjectUrl

public static boolean isProjectUrl(Url url)
Returns true if given Url has a registered project file extension.
Parameters:
url - The Url to test.
Returns:
Returns true if url has a registered project file extension.

isProjectExtension

public static boolean isProjectExtension(java.lang.String extension)
Returns true if the given extension is registered as a project file type.
Parameters:
extension - The file extension without the leading period.
Returns:
Returns true if a registered project file type extension.

registerProjectClass

public static void registerProjectClass(java.lang.String extension,
                                        java.lang.String description,
                                        java.lang.Class projectClass,
                                        javax.swing.Icon icon)
Add a new project type to the registry of known types and their associated extensions.
Parameters:
type - The extension that this registration is associated with. Extensions are case-insensitive and do not include the leading period character.
projectClass - A subclass of Project that should be instantiated to represent projects with the matching extension.

findProject

public static Project findProject(Url url)
Maps given Url into a known, cached Project.
Parameters:
url - Url to map into a Project.
Returns:
Returns Project if it has been opend and cached, otherwised null.

getProject

public static Project getProject(Url url)
                          throws InvalidUrlException
Maps given Url into a Project by first searching cache, then if not found will create an cache an instance of the Project.
Parameters:
url - Url to map into a Project
Returns:
Returns Project or null if error other than DuplicateNodeException.
Throws:
DuplicateNodeException - If same Project created twice despite earlier cache check.

preProjectSave

protected void preProjectSave(Url rootUrl)
Hook for doing preprocessing prior to project being saved.
Parameters:
rootUrl - Url for the project being saved.

postProjectLoad

protected void postProjectLoad(Url rootUrl)
Hook for doing postprocessing after the project is saved.
Parameters:
rootUrl - Url for the project being saved.

revert

public void revert()

Revert a project to its on-disk state. Note that this isn't the ideal implementation but is sufficient presuming that all references to project nodes are being discarded.

Ideally, we'd rather not lose FileNode instance identity and we would need to rework parentage on surviving nodes, etc.

Overrides:
revert in class UrlNode
Following copied from class: com.borland.primetime.node.UrlNode
Throws:
java.io.IOException - If the Url specifies a resource that could not be successfully reverted.

saveAs

public void saveAs(Url url)
            throws java.io.IOException,
                   InvalidUrlException,
                   DuplicateNodeException
saveAs _can_ change the extension of a Project since all state is maintained by the Project instance itself and not the buffer representation, and all project buffers _must_ be associated with Project nodes. saveAs will overwrite existing files.
Overrides:
saveAs in class UrlNode
Parameters:
url - The destination location.
Throws:
java.io.IOException - When error doing the physical save.
InvalidUrlException - When saving a project using a different file extension.

rename

public void rename(Url url)
            throws java.io.IOException,
                   InvalidUrlException,
                   DuplicateNodeException,
                   ReadOnlyException
Rename cannot change the type of a Project.
Overrides:
rename in class UrlNode
Parameters:
url - The new name (cannot be different file extension).
Throws:
java.io.IOException - When error doing the physical change.
InvalidUrlException - When saving using a different file extension.
ReadOnlyException - If the file being renamed is read-only.

createProject

public static Project createProject(java.lang.String extension)
Generates a unique Url with the specified extension for new projects that the user has not yet been prompted to name.
Parameters:
extension - A registered file extension for projects without the period.
Returns:
A valid Url uniquely identifying a new filesystem path.

createFileNode

public FileNode createFileNode(java.lang.String extension)
Generates a unique Url with the specified extension for new files that the user has not yet been prompted to name.
Parameters:
extension - A registered file extension for projects without the period.
Returns:
A valid Url uniquely identifying a new filesystem path.

getNode

public FileNode getNode(Url url)
Returns an appropriate FileNode from the given Url by either finding one created earlier in this Project for it, or by constructing one using a registered file type based on the file extension.
Parameters:
url - Storage associated with this file.
Returns:
Returns FileNode or throws exception based on illegal input.
Throws:
DuplicateNodeException -  

findNode

public FileNode findNode(Url url)
Returns a FileNode for the given Url if it had been created earlier in this project for it.
Returns:
Returns FileNode or null if not found.

findNodes

public LightweightNode[] findNodes(java.lang.String name)
Returns an array of the registered lightweight nodes that are part of this Project (e.g. FolderNodes or PackageNodes).
Parameters:
name - The registered name of a particular type of lightweight node.
Returns:
Returns array of those lightweight nodes of the given type which were found.

setAutoProperty

public void setAutoProperty(java.lang.String category,
                            java.lang.String property,
                            java.lang.String value)
Sets an automatic project property, which is always saved whether or not the project itself is saved.
Parameters:
category - The category to which the property belongs.
property - The name of the property.
value - The value of the property.

getAutoProperty

public java.lang.String getAutoProperty(java.lang.String category,
                                        java.lang.String property)
Gets the value of an automatic project property.
Parameters:
category - The category to which the property belongs.
property - The name of the property.
Returns:
Returns the value of the property, or null if not set and there is no default value.

addProjectListener

public void addProjectListener(ProjectListener listener)
Adds given listener to list of registered listeners for Project events.
Parameters:
listener - The listener to be registered.

removeProjectListener

public void removeProjectListener(ProjectListener listener)
Removes given listener from list of registered listeners for Project events.
Parameters:
listener - The listener to be unregistered.

fireProjectPropertyChanged

public void fireProjectPropertyChanged(java.lang.String category,
                                       java.lang.String property,
                                       java.lang.String oldValue,
                                       java.lang.String newValue)
Notifies all registered ProjectListeners that a property on the project node has been changed.
Parameters:
category - The category of the property, may be null.
property - The name of the property.
oldValue - The old value of the property, may be null.
newValue - The new value of the proeprty, may be null.

fireChildrenChanged

public void fireChildrenChanged(Node parent)
Notifies all registered ProjectListeners that a node has been been added to or removed from a parent node the project.
Parameters:
parent - Parent where children have been removed or added.

fireNodeChanged

public void fireNodeChanged(Node node)
Notifies all registered ProjectListeners that a node's display name or icon has changed.
Parameters:
node - Node where name or icon has been changed.

isPersistant

public boolean isPersistant()
Determines whether or not the node definition and its properties will be saved with in a project file. Project nodes are always persistant.
Overrides:
isPersistant in class Node
Returns:
True if the node should be saved, false otherwise.

check

public void check()
Ensure that the project's properties are resynchronized with the current state of its paths.
Overrides:
check in class Node

isModified

public boolean isModified()
Describes whether or not unsaved changes exist in the project's state.
Overrides:
isModified in class UrlNode
Returns:
True if changes have been made that have not yet been saved to the project file.

isNew

public boolean isNew()
Describes whether or not the project needs to be renamed before it can be saved.
Overrides:
isNew in class UrlNode
Returns:
True if the project's current Url should not be used for saving, false if the current Url is okay.

save

public void save()
          throws java.io.IOException,
                 InvalidUrlException
Updates the project's permanent storage to reflect the current state of the project.
Overrides:
save in class UrlNode
Following copied from class: com.borland.primetime.node.UrlNode
Throws:
java.io.IOException -  
InvalidUrlException -  

getProject

public Project getProject()
Returns Project which contains this node.
Overrides:
getProject in class Node
Returns:
Always returns reference to itself.

getDisplaySequence

public int getDisplaySequence()
Returns sort sequence for ProjectPane.
Overrides:
getDisplaySequence in class Node
Returns:
Always returns 100.

getDisplayName

public java.lang.String getDisplayName()
Uses the the FileNode's underlying Url to derive a display name.
Overrides:
getDisplayName in class Node
Returns:
The filename of the node's Url with the path component removed.

getLongDisplayName

public java.lang.String getLongDisplayName()
Uses the the FileNode's underlying Url to derive a full display name.
Overrides:
getLongDisplayName in class Node
Returns:
The filename of the node's Url.

getDisplayIcon

public javax.swing.Icon getDisplayIcon()
Returns the 16x16 icon used to represent a Project.
Overrides:
getDisplayIcon in class Node
Returns:
Always returns BrowserIcons.ICON_PROJECT.

refresh

public void refresh()
Invoked whenever the "refresh" button is pressed from the project view's toolbar.

dumpProjects

public static void dumpProjects()
Strictly a diagnostic method

dumpAllNodes

public void dumpAllNodes()
Strictly a diagnostic method