org.argouml.kernel
Class Project

java.lang.Object
  extended byorg.argouml.kernel.Project
All Implemented Interfaces:
EventListener, Serializable, TargetListener

public class Project
extends Object
implements Serializable, TargetListener

The Project is a datastructure that represents the designer's current project. It manages the list of diagrams and UML models.

See Also:
Serialized Form

Nested Class Summary
private  class Project.Vcl
          Listener to events from the Diagram class.
 
Field Summary
private  ArgoDiagram activeDiagram
          The active diagram, pointer to a diagram in the list with diagrams.
private  String authorname
           
private  GenerationPreferences cgPrefs
           
private  Object currentNamespace
           
private  Object defaultModel
           
private  HashMap defaultModelCache
          Cache for the default model.
private  String description
           
private  Vector diagrams
          Instances of the uml diagrams.
private  String historyFile
           
private static Logger LOG
          Logger.
private  MemberList members
           
private  Vector models
          Instances of the uml model.
private  int persistenceVersion
          The version number of the persistence format that last saved this project.
private  Vector searchpath
           
(package private) static long serialVersionUID
           
private  Collection trashcan
           
private  Object treeRoot
          The root of the modeltree the user is working on.
private static String UNTITLED_FILE
          Default name for a project.
private  URL url
          TODO: should just be the directory to write.
private  HashMap uuidRefs
           
private  String version
           
private  VetoableChangeSupport vetoSupport
           
 
Constructor Summary
Project()
          Constructor.
Project(URL theProjectUrl)
          Constructor.
 
Method Summary
 void addDiagram(ArgoDiagram d)
           
private  void addDiagramMember(ArgoDiagram d)
           
 void addMember(Object m)
           
 void addModel(Object m)
           
private  void addModelMember(Object m)
           
 void addSearchPath(String searchPathElement)
           
private  void addTodoMember(ProjectMemberTodoList pm)
           
private  Collection collectAllEnclosedFigsRecursively(org.tigris.gef.presentation.Fig f)
           
 Collection findAllPresentationsFor(Object obj)
          Returns a list with all figs for some UML object on all diagrams.
private  Collection findAllPresentationsFor(Object obj, boolean includeEnclosedOnes)
          Get all figs from all diagrams (+ enclosed ones recursively) for some object obj.
 Collection findFigsForMember(Object member)
          Finds all figs on the diagrams for some project member, including the figs containing the member (so for some operation, the containing figclass is returned).
 Object findType(String s)
          Searches for a type/classifier with name s.
 Object findType(String s, boolean defineNew)
          Searches for a type/classifier with name s.
 Object findTypeInDefaultModel(String name)
          Find a type by name in the default model.
 Object findTypeInModel(String s, Object ns)
          Finds a classifier with a certain name.
 ArgoDiagram getActiveDiagram()
          Get the current viewed diagram.
 String getAuthorname()
          Get the author name.
 String getBaseName()
          Find the base name of this project.
 GenerationPreferences getCgPrefs()
          Returns the cgPrefs.
 Object getCurrentNamespace()
           
 Object getDefaultModel()
          Get the default model.
 String getDescription()
          Get the description.
 ArgoDiagram getDiagram(String name)
          Finds a diagram with a specific name or UID.
 int getDiagramCount()
          Get the number of diagrams in this project.
 Vector getDiagrams()
           
 GenerationPreferences getGenerationPrefs()
           
 String getHistoryFile()
          Get the history file.
 Object getInitialTarget()
           
 MemberList getMembers()
          Get all members of the project.
 Object getModel()
          Return the model.
 Collection getModels()
          Returns all models, including the default model (default.xmi).
 String getName()
           
 int getPersistenceVersion()
           
 int getPresentationCountFor(Object me)
           
 Object getRoot()
          Returns the root.
 Vector getSearchpath()
          Returns the searchpath.
 Vector getSearchPath()
           
 URL getUrl()
          Returns the url.
 URL getURL()
          Get the URL for this project.
 Vector getUserDefinedModels()
          Returns all models defined by the user.
 HashMap getUUIDRefs()
          Returns the uUIDRefs.
 String getVersion()
          Get the version.
 VetoableChangeSupport getVetoSupport()
           
 boolean isInTrash(Object obj)
           
 boolean isValidDiagramName(String name)
          Returns true if the given name is a valid name for a diagram.
protected  void makeUntitledProject()
          Makes a just created project to an untitled project with a class diagram and a usecase diagram and an untitled model.
 void moveToTrash(Object obj)
          Moves some object to trash, i.e.
 void postLoad()
          This is executed after a load.
 void postSave()
          This is execcuted after a save.
 void preSave()
          This is executed before a save.
 void remove()
          Remove the project.
private  void removeAllFigs(Collection c)
           
protected  void removeDiagram(ArgoDiagram d)
          Removes a diagram from the list with diagrams.
protected  void removeProjectMemberDiagram(ArgoDiagram d)
          Removes a project member diagram completely from the project.
 void setActiveDiagram(ArgoDiagram theDiagram)
           
 void setAuthorname(String s)
          Set the author name.
 void setCgPrefs(GenerationPreferences theCgPrefs)
          Sets the cgPrefs.
 void setCurrentNamespace(Object m)
           
 void setDefaultModel(Object theDefaultModel)
           
 void setDescription(String s)
          Set a new description.
 void setFile(File file)
          Set the project file.
 void setGenerationPrefs(GenerationPreferences cgp)
           
 void setHistoryFile(String s)
          Set the history file.
 void setName(String n)
          Set the project URL.
 void setPersistenceVersion(int pv)
           
 void setRoot(Object root)
          Sets the root.
 void setSearchpath(Vector theSearchpath)
          Sets the searchpath.
private  void setTarget(Object target)
          Called to update the current namespace and active diagram after the target has changed.
 void setUrl(URL theUrl)
          Sets the url.
 void setURL(URL theUrl)
          Set the URL for this project.
 void setUUIDRefs(HashMap uUIDRefs)
          Sets the uUIDRefs.
 void setVersion(String s)
          Set the new version.
 void setVetoSupport(VetoableChangeSupport theVetoSupport)
          Sets the vetoSupport.
 void targetAdded(TargetEvent e)
          Fired when a target is added to the list of targets.
 void targetRemoved(TargetEvent e)
          Fired when a target is removed from the list of targets
 void targetSet(TargetEvent e)
          Fired when a total new set of targets is set
protected  void trashInternal(Object obj)
          Removes some object from the project.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final Logger LOG
Logger.


UNTITLED_FILE

private static final String UNTITLED_FILE
Default name for a project.

See Also:
Constant Field Values

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

url

private URL url
TODO: should just be the directory to write.


authorname

private String authorname

description

private String description

version

private String version

searchpath

private Vector searchpath

members

private MemberList members

historyFile

private String historyFile

persistenceVersion

private int persistenceVersion
The version number of the persistence format that last saved this project.


models

private Vector models
Instances of the uml model.


diagrams

private Vector diagrams
Instances of the uml diagrams.


defaultModel

private Object defaultModel

currentNamespace

private Object currentNamespace

uuidRefs

private HashMap uuidRefs

cgPrefs

private GenerationPreferences cgPrefs

vetoSupport

private transient VetoableChangeSupport vetoSupport

treeRoot

private Object treeRoot
The root of the modeltree the user is working on. (The untitledModel in the navpane).


activeDiagram

private ArgoDiagram activeDiagram
The active diagram, pointer to a diagram in the list with diagrams.


defaultModelCache

private HashMap defaultModelCache
Cache for the default model.


trashcan

private Collection trashcan
Constructor Detail

Project

public Project(URL theProjectUrl)
Constructor.

Parameters:
theProjectUrl - Url to read the project from.

Project

public Project()
Constructor.

Method Detail

makeUntitledProject

protected void makeUntitledProject()
Makes a just created project to an untitled project with a class diagram and a usecase diagram and an untitled model.


getBaseName

public String getBaseName()
Find the base name of this project.

This is the name minus any valid file extension.

Returns:
The name (a String).

getName

public String getName()
Returns:
the name of the project

setName

public void setName(String n)
             throws MalformedURLException
Set the project URL.

Parameters:
n - The new URL (as a String).
Throws:
MalformedURLException - if the argument cannot be converted to an URL.

getURL

public URL getURL()
Get the URL for this project.

Returns:
The URL.

setURL

public void setURL(URL theUrl)
Set the URL for this project.

Parameters:
theUrl - The URL to set.

setFile

public void setFile(File file)
Set the project file. This only works if it is possible to convert the File to an url.

Parameters:
file - File to set the project to.

getSearchPath

public Vector getSearchPath()
Returns:
the search path

addSearchPath

public void addSearchPath(String searchPathElement)
Parameters:
searchPathElement - the element to be added to the searchpath

getMembers

public MemberList getMembers()
Get all members of the project.

Returns:
a Vector with all members.

addDiagramMember

private void addDiagramMember(ArgoDiagram d)
Parameters:
d - the diagram

addTodoMember

private void addTodoMember(ProjectMemberTodoList pm)
Parameters:
pm - the member to be added

addMember

public void addMember(Object m)
Parameters:
m - the member to be added

addModelMember

private void addModelMember(Object m)
Parameters:
m - the model

addModel

public void addModel(Object m)
Parameters:
m - a namespace

removeProjectMemberDiagram

protected void removeProjectMemberDiagram(ArgoDiagram d)
Removes a project member diagram completely from the project.

Parameters:
d - the ArgoDiagram

getAuthorname

public String getAuthorname()
Get the author name.

Returns:
The author name.

setAuthorname

public void setAuthorname(String s)
Set the author name.

Parameters:
s - The new author name.

getVersion

public String getVersion()
Get the version.

Returns:
the version.

setVersion

public void setVersion(String s)
Set the new version.

Parameters:
s - The new version.

getDescription

public String getDescription()
Get the description.

Returns:
the description.

setDescription

public void setDescription(String s)
Set a new description.

Parameters:
s - The new description.

getHistoryFile

public String getHistoryFile()
Get the history file.

Returns:
The history file.

setHistoryFile

public void setHistoryFile(String s)
Set the history file.

Parameters:
s - The new history file.

getUserDefinedModels

public Vector getUserDefinedModels()
Returns all models defined by the user. I.e. this does not return the default model but all other models.

Returns:
A Vector of all user defined models.

getModels

public Collection getModels()
Returns all models, including the default model (default.xmi).

Returns:
A Collection containing all models.

getModel

public Object getModel()
Return the model.

If there isn't exactly one model, null is returned.

Returns:
the model.

findType

public Object findType(String s)
Searches for a type/classifier with name s. If the type is not found, a new type is created and added to the current namespace.

Parameters:
s - the name of the type/classifier to be found
Returns:
MClassifier

findType

public Object findType(String s,
                       boolean defineNew)
Searches for a type/classifier with name s. If defineNew is true, a new type is defined if the type/classifier is not found. The newly created type is added to the currentNamespace and given the name s.

Parameters:
s - the name of the type/classifier to be found
defineNew - if true, define a new one
Returns:
MClassifier the found classifier

findFigsForMember

public Collection findFigsForMember(Object member)
Finds all figs on the diagrams for some project member, including the figs containing the member (so for some operation, the containing figclass is returned).

Parameters:
member - The member we are looking for. This can be a NSUML object but also another object.
Returns:
Collection The collection with the figs.

findAllPresentationsFor

public Collection findAllPresentationsFor(Object obj)
Returns a list with all figs for some UML object on all diagrams.

Parameters:
obj - the given UML object
Returns:
List the list of figs

findAllPresentationsFor

private Collection findAllPresentationsFor(Object obj,
                                           boolean includeEnclosedOnes)
Get all figs from all diagrams (+ enclosed ones recursively) for some object obj.

See issue 3042 for an explanation of the 2nd parameter.

Parameters:
obj - the given object
includeEnclosedOnes - true to return also enclosed figs
Returns:
the figs

findTypeInModel

public Object findTypeInModel(String s,
                              Object ns)
Finds a classifier with a certain name.

Will only return first classifier with the matching name.

Parameters:
s - is short name.
ns - Namespace where we do the search.
Returns:
the found classifier (or null if not found).

setCurrentNamespace

public void setCurrentNamespace(Object m)
Parameters:
m - the namespace

getCurrentNamespace

public Object getCurrentNamespace()
Returns:
the namespace

getDiagrams

public Vector getDiagrams()
Returns:
the diagrams

getDiagramCount

public int getDiagramCount()
Get the number of diagrams in this project. Used by argo2.tee!!

Returns:
the number of diagrams in this project.

getDiagram

public ArgoDiagram getDiagram(String name)
Finds a diagram with a specific name or UID.

Parameters:
name - is the name to search for.
Returns:
the diagram object (if found). Otherwize null.

addDiagram

public void addDiagram(ArgoDiagram d)
Parameters:
d - the diagram to be added

removeDiagram

protected void removeDiagram(ArgoDiagram d)
Removes a diagram from the list with diagrams. Removes (hopefully) the event listeners for this diagram. Does not remove the diagram from the project members. This should not be called directly. Use moveToTrash if you want to remove a diagram.

Parameters:
d - the ArgoDiagram

getPresentationCountFor

public int getPresentationCountFor(Object me)
Parameters:
me - the given modelelement
Returns:
the total number of presentation for the given modelelement in the project

getInitialTarget

public Object getInitialTarget()
Returns:
an initial target, in casu a diagram or a model

setGenerationPrefs

public void setGenerationPrefs(GenerationPreferences cgp)
Parameters:
cgp - the generation preferences

getGenerationPrefs

public GenerationPreferences getGenerationPrefs()
Returns:
the generation preferences

getVetoSupport

public VetoableChangeSupport getVetoSupport()
Returns:
the VetoableChangeSupport

preSave

public void preSave()
This is executed before a save.


postSave

public void postSave()
This is execcuted after a save.


postLoad

public void postLoad()
This is executed after a load.


moveToTrash

public void moveToTrash(Object obj)
Moves some object to trash, i.e. deletes it completely with all dependent structures.

Deleting an object involves:

 - Removing Target history
 - Deleting all Fig representations for the object
 - Deleting the UML element
 - Deleting all dependent UML modelelements
 - Deleting CommentEdges (which are not UML elements)
 - Move to trash for enclosed objects, i.e. graphically drawn on top of
 - Move to trash subdiagrams for the object
 - Saveguard that there is always at least 1 diagram left
 - Trigger the explorer when a diagram is deleted
 - Set the needsSave (dirty) flag of the projectmanager
 

Parameters:
obj - The object to be deleted
See Also:
trashInternal(Object)

trashInternal

protected void trashInternal(Object obj)
Removes some object from the project.

Parameters:
obj - the object to be thrown away

collectAllEnclosedFigsRecursively

private Collection collectAllEnclosedFigsRecursively(org.tigris.gef.presentation.Fig f)

removeAllFigs

private void removeAllFigs(Collection c)
Parameters:
c - a collection of figs

isInTrash

public boolean isInTrash(Object obj)
Parameters:
obj - the object
Returns:
true if the object is trashed

setDefaultModel

public void setDefaultModel(Object theDefaultModel)
Parameters:
theDefaultModel - a uml model

getDefaultModel

public Object getDefaultModel()
Get the default model.

Returns:
A model.

findTypeInDefaultModel

public Object findTypeInDefaultModel(String name)
Find a type by name in the default model.

Parameters:
name - the name.
Returns:
the type.

getRoot

public Object getRoot()
Returns the root.

Returns:
MModel

setRoot

public void setRoot(Object root)
Sets the root.

Parameters:
root - The root to set, a uml model

isValidDiagramName

public boolean isValidDiagramName(String name)
Returns true if the given name is a valid name for a diagram. Valid means that it does not occur as a name for a diagram yet.

Parameters:
name - The name to test
Returns:
boolean True if there are no problems with this name, false if it's not valid.

getCgPrefs

public GenerationPreferences getCgPrefs()
Returns the cgPrefs.

Returns:
GenerationPreferences

getSearchpath

public Vector getSearchpath()
Returns the searchpath.

Returns:
Vector

getUrl

public URL getUrl()
Returns the url.

Returns:
URL

getUUIDRefs

public HashMap getUUIDRefs()
Returns the uUIDRefs.

Returns:
HashMap

setCgPrefs

public void setCgPrefs(GenerationPreferences theCgPrefs)
Sets the cgPrefs.

Parameters:
theCgPrefs - The cgPrefs to set

setSearchpath

public void setSearchpath(Vector theSearchpath)
Sets the searchpath.

Parameters:
theSearchpath - The searchpath to set

setUrl

public void setUrl(URL theUrl)
Sets the url.

Parameters:
theUrl - The url to set

setUUIDRefs

public void setUUIDRefs(HashMap uUIDRefs)
Sets the uUIDRefs.

Parameters:
uUIDRefs - The uUIDRefs to set

setVetoSupport

public void setVetoSupport(VetoableChangeSupport theVetoSupport)
Sets the vetoSupport.

Parameters:
theVetoSupport - The vetoSupport to set

getActiveDiagram

public ArgoDiagram getActiveDiagram()
Get the current viewed diagram.

Returns:
the current viewed diagram

setActiveDiagram

public void setActiveDiagram(ArgoDiagram theDiagram)
Parameters:
theDiagram - the ArgoDiagram

targetAdded

public void targetAdded(TargetEvent e)
Description copied from interface: TargetListener
Fired when a target is added to the list of targets.

Specified by:
targetAdded in interface TargetListener
Parameters:
e - The targetevent, name will be TARGET_ADDED
See Also:
TargetListener.targetAdded(TargetEvent)

targetRemoved

public void targetRemoved(TargetEvent e)
Description copied from interface: TargetListener
Fired when a target is removed from the list of targets

Specified by:
targetRemoved in interface TargetListener
Parameters:
e - The targetevent, name will be TARGET_REMOVED
See Also:
TargetListener.targetRemoved(TargetEvent)

targetSet

public void targetSet(TargetEvent e)
Description copied from interface: TargetListener
Fired when a total new set of targets is set

Specified by:
targetSet in interface TargetListener
Parameters:
e - The targetevent, name will be TARGET_SET
See Also:
TargetListener.targetSet(TargetEvent)

setTarget

private void setTarget(Object target)
Called to update the current namespace and active diagram after the target has changed.

Parameters:
target -

remove

public void remove()
Remove the project.


getPersistenceVersion

public int getPersistenceVersion()
Returns:
Returns the persistenceVersion.

setPersistenceVersion

public void setPersistenceVersion(int pv)
Parameters:
pv - The persistenceVersion to set.


ArgoUML © 1996-2004 (20050222)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook