pl.edu.agh.cast.project
Class ProjectUtil

java.lang.Object
  extended by pl.edu.agh.cast.project.ProjectUtil
All Implemented Interfaces:
PropertyChangeListener, EventListener

public final class ProjectUtil
extends Object
implements PropertyChangeListener

Utility methods for operating on projects.

Author:
AGH CAST Team

Nested Class Summary
static class ProjectUtil.ProjectOpenStatus
          Enumeration of open project result statuses.
 
Field Summary
static String PERSISTENCE_PROVIDER_CONFIG_PROPERTY
          Project persistence provider config/store file property.
static String PERSISTENCE_PROVIDER_ID_PROPERTY
          Project persistence provider id property.
static String[] PROJECT_BAD_CHARS
          List of characters that cannot be used in a project name.
static String PROJECT_DISPLAY_NAME_PROPERTY
          Project display name property used.
static String PROJECT_ID_PROPERTY
          Project id property.
static String PROJECT_VERSION
           
static String PROJECT_VERSION_PROPERTY
          Project version property.
 
Method Summary
 org.eclipse.core.resources.IProject changeProjectLocation(String newLocation)
          Removes project from workspace and adds project pointed to by newLocation.
 boolean closeProject(org.eclipse.core.resources.IProject project)
          Closes a project, closing all editors as well.
 org.eclipse.core.resources.IProject createAndActivateProject(String projectName, org.eclipse.core.runtime.IPath location)
          Create project of specified name if it does not exists and activates created project.
 org.eclipse.core.resources.IProject createProject(String projectName, org.eclipse.core.runtime.IPath location)
          Create project of specified name if it does not exists.
 void destroyPersistenceProvider()
          Destroys persistence provider for active project.
 String escapeName(String name)
          Escapes non-standard characters in project's name.
 String generateProjectId()
          Create unique identifier for the project.
 String getDisplayName(org.eclipse.core.resources.IProject project)
          Returns project's display name.
static ProjectUtil getInstance()
          Returns single, shared instance of ProjectUtil.
static String getProperty(org.eclipse.core.resources.IProject project, String propertyId)
          Reads projects properties using Eclipse Preferences mechanism.
 boolean handleExistingProjectAction(String location)
          Handles a situation when a project is already opened by another application.
 void handleInvalidProjectAction()
          Handles a situation when invalid project is given.
 void handleMissingProjectFile(String location)
          Handles a situation when project location does not contain .projectfile.
 void handleNoProjectAction()
          Handles a situation when no project was selected to be opened.
 void handlePersistenceProviderInitializationError(org.eclipse.core.resources.IProject project)
          Handles a situation when invalid project is given.
 void handleWrongProjectLocationAction(String location)
          Handles a situation when invalid project location is given.
 void init(org.eclipse.core.resources.IProject project)
          Initializes the new project.
 void initializePersistenceProvider(org.eclipse.core.resources.IProject project)
          Initializes persistence provider for given project.
 ProjectUtil.ProjectOpenStatus openProject(String location, boolean force)
          Opens existing project from specified directory.
 void propertyChange(PropertyChangeEvent evt)
          Property change notification.
 void removeProject(String projectName, org.eclipse.core.runtime.IPath location)
           
 void setDisplayName(org.eclipse.core.resources.IProject project, String name)
          Sets project's display name.
static void setProperty(org.eclipse.core.resources.IProject project, String propertyId, String value)
          Sets property for given project.
 boolean tryOpenRecentProject(MostRecentlyUsedProject mrup)
          Tries to open a project described by MostRecentlyUsedProject.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROJECT_VERSION

public static final String PROJECT_VERSION
See Also:
Constant Field Values

PROJECT_BAD_CHARS

public static final String[] PROJECT_BAD_CHARS
List of characters that cannot be used in a project name.


PROJECT_DISPLAY_NAME_PROPERTY

public static final String PROJECT_DISPLAY_NAME_PROPERTY
Project display name property used.

See Also:
Constant Field Values

PROJECT_VERSION_PROPERTY

public static final String PROJECT_VERSION_PROPERTY
Project version property.

See Also:
Constant Field Values

PROJECT_ID_PROPERTY

public static final String PROJECT_ID_PROPERTY
Project id property.

See Also:
Constant Field Values

PERSISTENCE_PROVIDER_ID_PROPERTY

public static final String PERSISTENCE_PROVIDER_ID_PROPERTY
Project persistence provider id property.

See Also:
Constant Field Values

PERSISTENCE_PROVIDER_CONFIG_PROPERTY

public static final String PERSISTENCE_PROVIDER_CONFIG_PROPERTY
Project persistence provider config/store file property.

See Also:
Constant Field Values
Method Detail

getProperty

public static String getProperty(org.eclipse.core.resources.IProject project,
                                 String propertyId)
Reads projects properties using Eclipse Preferences mechanism.

Parameters:
project - project which properties are read
propertyId - id of property to read
Returns:
property with given id found for specified project

setProperty

public static void setProperty(org.eclipse.core.resources.IProject project,
                               String propertyId,
                               String value)
Sets property for given project.

Parameters:
project - project which property is to be set
propertyId - property id
value - new value of property

getInstance

public static ProjectUtil getInstance()
Returns single, shared instance of ProjectUtil.

Returns:
single, shared instance of ProjectUtil

getDisplayName

public String getDisplayName(org.eclipse.core.resources.IProject project)
Returns project's display name.

Parameters:
project - the project
Returns:
project's display name

setDisplayName

public void setDisplayName(org.eclipse.core.resources.IProject project,
                           String name)
Sets project's display name.

Parameters:
project - the project
name - project's display name

escapeName

public String escapeName(String name)
Escapes non-standard characters in project's name.

Parameters:
name - name to escape
Returns:
escaped name

createProject

public org.eclipse.core.resources.IProject createProject(String projectName,
                                                         org.eclipse.core.runtime.IPath location)
                                                  throws org.eclipse.core.runtime.CoreException
Create project of specified name if it does not exists.

Parameters:
projectName - name of the project
location - location of the project
Returns:
new instance of a project
Throws:
org.eclipse.core.runtime.CoreException

init

public void init(org.eclipse.core.resources.IProject project)
          throws org.eclipse.core.runtime.CoreException
Initializes the new project.

Parameters:
project - the new project
Throws:
org.eclipse.core.runtime.CoreException

createAndActivateProject

public org.eclipse.core.resources.IProject createAndActivateProject(String projectName,
                                                                    org.eclipse.core.runtime.IPath location)
                                                             throws org.eclipse.core.runtime.CoreException
Create project of specified name if it does not exists and activates created project.

Parameters:
projectName - name of the project
location - location of the project
Returns:
new instance of an activated project
Throws:
org.eclipse.core.runtime.CoreException

openProject

public ProjectUtil.ProjectOpenStatus openProject(String location,
                                                 boolean force)
                                          throws FileNotFoundException,
                                                 org.eclipse.core.runtime.CoreException
Opens existing project from specified directory.

Parameters:
location - project location which contains .project description file
force - if true opens project with the same name which exists in the workspace
Returns:
true if specified project has been opened; false otherwise: if the specified project exists already in the workspace and force flag has been set to false
Throws:
FileNotFoundException - if project description file (.project) is not found in specified location
org.eclipse.core.runtime.CoreException - if loading description failed. Reasons include:
  • The stream could not be read.
  • The stream does not contain a legal project description.

changeProjectLocation

public org.eclipse.core.resources.IProject changeProjectLocation(String newLocation)
Removes project from workspace and adds project pointed to by newLocation. Project name is taken from project description stored in newLocation.

Parameters:
newLocation - new project location
Returns:
moved project

generateProjectId

public String generateProjectId()
Create unique identifier for the project.

Returns:
unique project identifier

tryOpenRecentProject

public boolean tryOpenRecentProject(MostRecentlyUsedProject mrup)
Tries to open a project described by MostRecentlyUsedProject.

Parameters:
mrup - project to open
Returns:
true if project was correctly opened, or if the operation was cancelled by the user when closing currently opened editors

closeProject

public boolean closeProject(org.eclipse.core.resources.IProject project)
Closes a project, closing all editors as well. Asks the user for confirmation to save dirty editors.

Parameters:
project - project to close
Returns:
true if all editors were closed

removeProject

public void removeProject(String projectName,
                          org.eclipse.core.runtime.IPath location)
                   throws org.eclipse.core.runtime.CoreException
Throws:
org.eclipse.core.runtime.CoreException

handleExistingProjectAction

public boolean handleExistingProjectAction(String location)
Handles a situation when a project is already opened by another application.

Parameters:
location - location of the project
Returns:
true if the project was successfully opened

handleNoProjectAction

public void handleNoProjectAction()
Handles a situation when no project was selected to be opened. In such case the MRU project is opened, and if that fails, the ProjectStartupDialog is shown.


handleWrongProjectLocationAction

public void handleWrongProjectLocationAction(String location)
Handles a situation when invalid project location is given.

Parameters:
location - given project location

handleInvalidProjectAction

public void handleInvalidProjectAction()
Handles a situation when invalid project is given.


handleMissingProjectFile

public void handleMissingProjectFile(String location)
Handles a situation when project location does not contain .projectfile.

Parameters:
location - project location

handlePersistenceProviderInitializationError

public void handlePersistenceProviderInitializationError(org.eclipse.core.resources.IProject project)
Handles a situation when invalid project is given.


propertyChange

public void propertyChange(PropertyChangeEvent evt)
Property change notification.

Specified by:
propertyChange in interface PropertyChangeListener
See Also:
PropertyChangeListener.propertyChange(java.beans.PropertyChangeEvent)

initializePersistenceProvider

public void initializePersistenceProvider(org.eclipse.core.resources.IProject project)
Initializes persistence provider for given project.

Parameters:
project - the project

destroyPersistenceProvider

public void destroyPersistenceProvider()
Destroys persistence provider for active project.



Copyright © 2007-2009 IISG AGH-UST Krakow, Poland. All Rights Reserved.