kaapo.projectmanager
Class ProjectManager

java.lang.Object
  extended by kaapo.Observable
      extended by kaapo.projectmanager.ProjectManager

public class ProjectManager
extends Observable

Class that holds reference to the open project. This class is designed to hide the implementation of project and diagrams from GUI and to support undo history. GUI should never directly edit the project, but use appropriate edits and give them to ProjectManager to execute.

All the diagram-editing and state changing goes through ProjectManager. The (G)UI using this class communicates the edits on the project and its diagrams are handled by an UndoableEdit/Edit interface. For every action on the diagram panel either an UndoableEdit or an Edit object is created. This object is then given to executeEdit() for execution and depending on the edit's type also saving for undoing and redoing.

ProjectManager class implements the Observable interface, so that GUI can observe it's state. Currently the selection changes and visible diagram changes launch observers update method.

Author:
iheikkin, hprajani, paltamaa
See Also:
Observable, Observer

Nested Class Summary
static class ProjectManager.ObservableMessage
           
 
Constructor Summary
ProjectManager(Project project)
          Constructs a new ProjectManager associated with given project.
 
Method Summary
 boolean canRedo()
          Checks if it is possible to redo the latest undo.
 boolean canUndo()
          Checks if it is possible to undo the latest edit.
 void endCompound()
          Closes the compound and adds it as a single undoable object to the undomanager
 void executeCompoundEdit(AbstractUndoableEdit edit)
          Executes the latest UndoableEdit and adds it to compound for the mass-undo or -redo possibly to be done later
 void executeEdit(AbstractUndoableEdit edit)
          Executes the latest UndoableEdit and saves it for possible undo/redo-action.
 void executeEdit(Edit edit)
          Executes the latest Edit.
 Project getProject()
          Returns the associated project
 Selection getSelection()
          Returns the current selection
 DiagramWrapper getVisibleDiagram()
          Returns the visible diagram.
 boolean isProjectModified()
          Returns the true if the project has been modified since last reset.
 void notifyObservers()
          Notifies observers.
 void redo()
          Redos the last undone edit.
 void resetProjectModified()
          Resets the project modified status.
 void setSelection(Selection selection)
          Updates the selection to the given one.
 void setVisibleDiagram(DiagramWrapper diagram)
          Sets a new visible diagram.
 void undo()
          Undos the latest edit.
 
Methods inherited from class kaapo.Observable
addObserver, notifyObservers, removeAllObservers, removeObserver, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProjectManager

public ProjectManager(Project project)
Constructs a new ProjectManager associated with given project.

Parameters:
project - the project this ProjectManager is associated with
Method Detail

undo

public void undo()
          throws CannotRedoException
Undos the latest edit.

Throws:
CannotUndoException - if cannot undo
CannotRedoException

redo

public void redo()
          throws CannotRedoException
Redos the last undone edit.

Throws:
CannotRedoException - if cannot redo

canUndo

public boolean canUndo()
Checks if it is possible to undo the latest edit.

Returns:
true if undoing is possible, otherwise false.

canRedo

public boolean canRedo()
Checks if it is possible to redo the latest undo.

Returns:
true if redoing is possible, otherwise false.

executeEdit

public void executeEdit(AbstractUndoableEdit edit)
                 throws EditFailedException
Executes the latest UndoableEdit and saves it for possible undo/redo-action.

Parameters:
edit - the edit to execute
Throws:
EditFailedException - if editing fails for some reason

executeCompoundEdit

public void executeCompoundEdit(AbstractUndoableEdit edit)
                         throws EditFailedException
Executes the latest UndoableEdit and adds it to compound for the mass-undo or -redo possibly to be done later

Parameters:
edit - the edit to execute
Throws:
EditFailedException - if editing fails for some reason

executeEdit

public void executeEdit(Edit edit)
                 throws EditFailedException
Executes the latest Edit.

Parameters:
edit - the edit to execute
Throws:
EditFailedException - if editing fails for some reason

getVisibleDiagram

public DiagramWrapper getVisibleDiagram()
Returns the visible diagram.

Returns:
the active and visible diagram

setVisibleDiagram

public void setVisibleDiagram(DiagramWrapper diagram)
Sets a new visible diagram.

Parameters:
diagram - the new visible diagram

getProject

public Project getProject()
Returns the associated project

Returns:
a project

getSelection

public Selection getSelection()
Returns the current selection

Returns:
the current selection

setSelection

public void setSelection(Selection selection)
Updates the selection to the given one.

Parameters:
selection - the latest selection

isProjectModified

public boolean isProjectModified()
Returns the true if the project has been modified since last reset. It understands undo and redo too, so the GUI doesn't have to count them. This means that if you call resetProjectModified, execute an edit and then undo it, project modified status is false again. And if you redo the edit, modified status is true.

Returns:
true if modified, false if not

resetProjectModified

public void resetProjectModified()
Resets the project modified status.


notifyObservers

public void notifyObservers()
Notifies observers. No need to call this outside ProjectManager class.

Overrides:
notifyObservers in class Observable
See Also:
Observable.notifyObservers()

endCompound

public void endCompound()
Closes the compound and adds it as a single undoable object to the undomanager