edu.rice.cs.drjava.model
Class GlobalEventNotifier

java.lang.Object
  extended by edu.rice.cs.drjava.model.EventNotifier<GlobalModelListener>
      extended by edu.rice.cs.drjava.model.GlobalEventNotifier
All Implemented Interfaces:
CompilerListener, GlobalModelListener, JavadocListener, JUnitListener, InteractionsListener

public class GlobalEventNotifier
extends EventNotifier<GlobalModelListener>
implements GlobalModelListener

Keeps track of all listeners to the model, and has the ability to notify them of some event.

This class has a specific role of managing GlobalModelListeners. Other classes with similar names use similar code to perform the same function for other interfaces, e.g. InteractionsEventNotifier and JavadocEventNotifier. These classes implement the appropriate interface definition so that they can be used transparently as composite packaging for a particular listener interface.

Components which might otherwise manage their own list of listeners use EventNotifiers instead to simplify their internal implementation. Notifiers should therefore be considered a private implementation detail of the components, and should not be used directly outside of the "host" component.

TODO: remove direct references to GlobalEventNotifier outside of DefaultGlobalModel TODO: remove public modifier from this class when above has happened All methods in this class must use the synchronization methods provided by ReaderWriterLock. This ensures that multiple notifications (reads) can occur simultaneously, but only one thread can be adding or removing listeners (writing) at a time, and no reads can occur during a write.

No methods on this class should be synchronized using traditional Java synchronization!

Version:
$Id: GlobalEventNotifier.java 4691 2008-12-02 23:33:27Z dlsmith $

Nested Class Summary
static class GlobalEventNotifier.Notifier
          Deprecated. Use listener methods directly instead.
static class GlobalEventNotifier.Poller
          Deprecated. Use listener methods directly instead.
 
Field Summary
 
Fields inherited from class edu.rice.cs.drjava.model.EventNotifier
_listeners, _lock
 
Constructor Summary
GlobalEventNotifier()
           
 
Method Summary
 void activeCompilerChanged()
          Called after the active compiler has been changed.
 void activeDocumentChanged(OpenDefinitionsDocument active)
          Called when the selection in the navigator changes the active document.
 void activeDocumentRefreshed(OpenDefinitionsDocument active)
          Called when the active document is refreshed.
 void browserChanged()
          Called when the a region is added to the browswing history.
 boolean canAbandonFile(OpenDefinitionsDocument doc)
          Called to ask the listeners if it is OK to abandon the current document.
 void classFileError(ClassFileError e)
          Called when trying to test an illegal class file.
 void compileAborted(Exception e)
          Called if a compile is aborted.
 void compileBeforeJUnit(CompilerListener cl)
          Called before attempting unit testing if tested class files are out of sync, to give the user a chance to save.
 void compileEnded(File workDir, List<? extends File> excludedFiles)
          Called when a compile has finished running.
 void compileStarted()
          Called after a compile is started by the GlobalModel.
 void consoleReset()
          Called when the console window is reset.
 void currentDirectoryChanged(File dir)
          Called when the selection in the navigator changes the current directory without changing the active document.
 void documentNotFound(OpenDefinitionsDocument d, File f)
          Called when the a document, already opened, is brought back into the cache, and it no longer exists on disk or cannot be accessed.
<P,R> void
executeAsyncTask(AsyncTask<P,R> task, P param, boolean showProgress, boolean lockUI)
          Called when an asynchronous task must be run in the model
 void fileClosed(OpenDefinitionsDocument doc)
          Called after a document is closed.
 void fileOpened(OpenDefinitionsDocument doc)
          Called after a file is opened and read into the current document.
 void filePathContainsPound()
          Notifies the view that the current file path contains a #.
 void fileReverted(OpenDefinitionsDocument doc)
          Called after a document is reverted.
 void fileSaved(OpenDefinitionsDocument doc)
          Called after the current document is saved.
 void filesNotFound(File... f)
          Called when trying to open one or more files that do not exist.
 File[] filesReadOnly(File... f)
          Called when trying to write one or more files that are read-only.
 void focusOnDefinitionsPane()
          Called to shift the focus to the Definitions Pane.
 void focusOnLastFocusOwner()
          Called to shift the focus to the last focus owner among the main frame panes.
 void handleAlreadyOpenDocument(OpenDefinitionsDocument doc)
          Performs any UI related steps to handle the case in which a file is being opened that is already open and modified.
 void interactionEnded()
          Called when an interaction has finished running.
 void interactionErrorOccurred(int offset, int length)
          Called when the interactions window generates a syntax error.
 void interactionIncomplete()
          Notifies the view that the current interaction is incomplete.
 void interactionStarted()
          Called after an interaction is started by the GlobalModel.
 void interpreterChanged(boolean inProgress)
          Called when the active interpreter is changed.
 void interpreterExited(int status)
          Called when the interactions JVM was closed by System.exit or by being aborted.
 void interpreterReady(File wd)
          Called when the interactions window is reset.
 void interpreterResetFailed(Throwable t)
          Called if the interpreter reset failed.
 void interpreterResetting()
          Called when the interactionsJVM has begun resetting.
 void javadocEnded(boolean success, File destDir, boolean allDocs)
          Called after Javadoc is finished.
 void javadocStarted()
          Called after Javadoc is started by the GlobalModel.
 void junitClassesStarted()
          Called when testing specific list of classes.
 void junitEnded()
          Called after JUnit is finished running tests.
 void junitStarted()
          Called after JUnit is started by the GlobalModel.
 void junitSuiteStarted(int numTests)
          Called to indicate that a suite of tests has started running.
 void junitTestEnded(String name, boolean wasSuccessful, boolean causedError)
          Called when a particular test has ended.
 void junitTestStarted(String name)
          Called when a particular test is started.
 void newFileCreated(OpenDefinitionsDocument doc)
          Called after a new document is created.
 void nonTestCase(boolean isTestAll)
          Called when trying to test a non-TestCase class.
 void notifyListeners(GlobalEventNotifier.Notifier n)
          Lets the listeners know some event has taken place.
 void openProject(File pfile, FileOpenSelector files)
          Called while the project is being opened.
 boolean pollListeners(GlobalEventNotifier.Poller p)
          Deprecated. Use listener methods directly instead.
 void prepareForRun(OpenDefinitionsDocument doc)
          Called when a file's main method is about to be run.
 void projectBuildDirChanged()
          Called when the build directory is modified in the model.
 void projectClosed()
          Called when the project is being closed.
 void projectModified()
          Called if the project's modified state has changed.
 void projectRunnableChanged()
          Called when the project runnability changed (ie, when the main file is set/unset).
 void projectWorkDirChanged()
          Called when the working directory is modified in the model.
 boolean quitFile(OpenDefinitionsDocument doc)
          Called to ask the listeners save the file before quitting at the user's option.
 void saveBeforeCompile()
          Called to demand that all files be saved before compiling.
 void saveBeforeJavadoc()
          Called before attempting Javadoc, to give the user a chance to save.
 void saveUntitled()
          Called to demand that the active document, which is untitled, is saved before compiling.
 boolean shouldRevertFile(OpenDefinitionsDocument doc)
          Called to ask the listeners if it is OK to revert the current document to the version saved on disk.
 void slaveJVMUsed()
          Called when the slave JVM is used by the interpreter or unit testing.
 void undoableEditHappened()
          Called when an undoable edit occurs.
 
Methods inherited from class edu.rice.cs.drjava.model.EventNotifier
addListener, removeAllListeners, removeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GlobalEventNotifier

public GlobalEventNotifier()
Method Detail

executeAsyncTask

public <P,R> void executeAsyncTask(AsyncTask<P,R> task,
                                   P param,
                                   boolean showProgress,
                                   boolean lockUI)
Description copied from interface: GlobalModelListener
Called when an asynchronous task must be run in the model

Specified by:
executeAsyncTask in interface GlobalModelListener

filesNotFound

public void filesNotFound(File... f)
Description copied from interface: GlobalModelListener
Called when trying to open one or more files that do not exist.

Specified by:
filesNotFound in interface GlobalModelListener

filesReadOnly

public File[] filesReadOnly(File... f)
Description copied from interface: GlobalModelListener
Called when trying to write one or more files that are read-only.

Specified by:
filesReadOnly in interface GlobalModelListener
Parameters:
f - files that are read-only
Returns:
the intersection of all the return values from the listeners.

handleAlreadyOpenDocument

public void handleAlreadyOpenDocument(OpenDefinitionsDocument doc)
Performs any UI related steps to handle the case in which a file is being opened that is already open and modified. The two choices are to revert to the copy on disk, or to keep the current changes.

Specified by:
handleAlreadyOpenDocument in interface GlobalModelListener
Parameters:
doc - true if the user wishes to revert the document, false to ignore

openProject

public void openProject(File pfile,
                        FileOpenSelector files)
Description copied from interface: GlobalModelListener
Called while the project is being opened.

Specified by:
openProject in interface GlobalModelListener
Parameters:
pfile - the location of the project file
files - The files the gui should open for the model

projectClosed

public void projectClosed()
Description copied from interface: GlobalModelListener
Called when the project is being closed.

Specified by:
projectClosed in interface GlobalModelListener

projectModified

public void projectModified()
Description copied from interface: GlobalModelListener
Called if the project's modified state has changed.

Specified by:
projectModified in interface GlobalModelListener

projectBuildDirChanged

public void projectBuildDirChanged()
Description copied from interface: GlobalModelListener
Called when the build directory is modified in the model.

Specified by:
projectBuildDirChanged in interface GlobalModelListener

projectWorkDirChanged

public void projectWorkDirChanged()
Description copied from interface: GlobalModelListener
Called when the working directory is modified in the model.

Specified by:
projectWorkDirChanged in interface GlobalModelListener

projectRunnableChanged

public void projectRunnableChanged()
Description copied from interface: GlobalModelListener
Called when the project runnability changed (ie, when the main file is set/unset).

Specified by:
projectRunnableChanged in interface GlobalModelListener

notifyListeners

public void notifyListeners(GlobalEventNotifier.Notifier n)
Lets the listeners know some event has taken place.

Parameters:
n - tells the listener what happened.

pollListeners

@Deprecated
public boolean pollListeners(GlobalEventNotifier.Poller p)
Deprecated. Use listener methods directly instead.

Allows the GlobalModel to ask its listeners a yes/no question and receive a response.

Parameters:
p - the question being asked of the listeners
Returns:
the listeners' responses ANDed together, true if they all agree, false if some disagree

prepareForRun

public void prepareForRun(OpenDefinitionsDocument doc)
Called when a file's main method is about to be run.

Specified by:
prepareForRun in interface GlobalModelListener

newFileCreated

public void newFileCreated(OpenDefinitionsDocument doc)
Called after a new document is created.

Specified by:
newFileCreated in interface GlobalModelListener

consoleReset

public void consoleReset()
Called when the console window is reset.

Specified by:
consoleReset in interface GlobalModelListener

fileSaved

public void fileSaved(OpenDefinitionsDocument doc)
Called after the current document is saved.

Specified by:
fileSaved in interface GlobalModelListener

fileOpened

public void fileOpened(OpenDefinitionsDocument doc)
Called after a file is opened and read into the current document.

Specified by:
fileOpened in interface GlobalModelListener

fileClosed

public void fileClosed(OpenDefinitionsDocument doc)
Called after a document is closed.

Specified by:
fileClosed in interface GlobalModelListener

fileReverted

public void fileReverted(OpenDefinitionsDocument doc)
Called after a document is reverted.

Specified by:
fileReverted in interface GlobalModelListener

undoableEditHappened

public void undoableEditHappened()
Called when an undoable edit occurs.

Specified by:
undoableEditHappened in interface GlobalModelListener

canAbandonFile

public boolean canAbandonFile(OpenDefinitionsDocument doc)
Called to ask the listeners if it is OK to abandon the current document.

Specified by:
canAbandonFile in interface GlobalModelListener

quitFile

public boolean quitFile(OpenDefinitionsDocument doc)
Called to ask the listeners save the file before quitting at the user's option.

Specified by:
quitFile in interface GlobalModelListener
Returns:
true if quitting should continue, false if the user cancelled

shouldRevertFile

public boolean shouldRevertFile(OpenDefinitionsDocument doc)
Called to ask the listeners if it is OK to revert the current document to the version saved on disk.

Specified by:
shouldRevertFile in interface GlobalModelListener

currentDirectoryChanged

public void currentDirectoryChanged(File dir)
Called when the selection in the navigator changes the current directory without changing the active document.

Specified by:
currentDirectoryChanged in interface GlobalModelListener

activeDocumentChanged

public void activeDocumentChanged(OpenDefinitionsDocument active)
Called when the selection in the navigator changes the active document.

Specified by:
activeDocumentChanged in interface GlobalModelListener

activeDocumentRefreshed

public void activeDocumentRefreshed(OpenDefinitionsDocument active)
Called when the active document is refreshed.

Specified by:
activeDocumentRefreshed in interface GlobalModelListener

focusOnDefinitionsPane

public void focusOnDefinitionsPane()
Called to shift the focus to the Definitions Pane.

Specified by:
focusOnDefinitionsPane in interface GlobalModelListener

focusOnLastFocusOwner

public void focusOnLastFocusOwner()
Called to shift the focus to the last focus owner among the main frame panes.

Specified by:
focusOnLastFocusOwner in interface GlobalModelListener

interactionStarted

public void interactionStarted()
Called after an interaction is started by the GlobalModel.

Specified by:
interactionStarted in interface InteractionsListener

interactionEnded

public void interactionEnded()
Called when an interaction has finished running.

Specified by:
interactionEnded in interface InteractionsListener

interactionErrorOccurred

public void interactionErrorOccurred(int offset,
                                     int length)
Called when the interactions window generates a syntax error.

Specified by:
interactionErrorOccurred in interface InteractionsListener
Parameters:
offset - the error's offset into the InteractionsDocument.
length - the length of the error.

interpreterResetting

public void interpreterResetting()
Called when the interactionsJVM has begun resetting.

Specified by:
interpreterResetting in interface InteractionsListener

interpreterReady

public void interpreterReady(File wd)
Called when the interactions window is reset.

Specified by:
interpreterReady in interface InteractionsListener

interpreterResetFailed

public void interpreterResetFailed(Throwable t)
Called if the interpreter reset failed.

Specified by:
interpreterResetFailed in interface InteractionsListener
Parameters:
t - Throwable explaining why the reset failed. (Subclasses must maintain listeners.)

interpreterExited

public void interpreterExited(int status)
Called when the interactions JVM was closed by System.exit or by being aborted. Immediately after this the interactions will be reset.

Specified by:
interpreterExited in interface InteractionsListener
Parameters:
status - the exit code

interpreterChanged

public void interpreterChanged(boolean inProgress)
Called when the active interpreter is changed.

Specified by:
interpreterChanged in interface InteractionsListener
Parameters:
inProgress - Whether the new interpreter is processing an interaction (i.e,. whether an interactionEnded event will be fired)

compileStarted

public void compileStarted()
Called after a compile is started by the GlobalModel.

Specified by:
compileStarted in interface CompilerListener

compileEnded

public void compileEnded(File workDir,
                         List<? extends File> excludedFiles)
Called when a compile has finished running.

Specified by:
compileEnded in interface CompilerListener

compileAborted

public void compileAborted(Exception e)
Called if a compile is aborted.

Specified by:
compileAborted in interface CompilerListener

saveBeforeCompile

public void saveBeforeCompile()
Called to demand that all files be saved before compiling. It is up to the caller of this method to check if the documents have been saved, using IGetDocuments.hasModifiedDocuments().

Specified by:
saveBeforeCompile in interface CompilerListener

saveUntitled

public void saveUntitled()
Called to demand that the active document, which is untitled, is saved before compiling.

Specified by:
saveUntitled in interface CompilerListener

activeCompilerChanged

public void activeCompilerChanged()
Called after the active compiler has been changed.

Specified by:
activeCompilerChanged in interface CompilerListener

nonTestCase

public void nonTestCase(boolean isTestAll)
Called when trying to test a non-TestCase class.

Specified by:
nonTestCase in interface JUnitListener
Parameters:
isTestAll - whether or not it was a use of the test all button

classFileError

public void classFileError(ClassFileError e)
Called when trying to test an illegal class file.

Specified by:
classFileError in interface JUnitListener
Parameters:
e - the ClassFileError thrown when DrJava attempted to load the offending file

compileBeforeJUnit

public void compileBeforeJUnit(CompilerListener cl)
Called before attempting unit testing if tested class files are out of sync, to give the user a chance to save. Do not continue with JUnit if the user doesn't recompile!

Specified by:
compileBeforeJUnit in interface JUnitListener

junitStarted

public void junitStarted()
Called after JUnit is started by the GlobalModel.

Specified by:
junitStarted in interface JUnitListener

junitClassesStarted

public void junitClassesStarted()
Called when testing specific list of classes.

Specified by:
junitClassesStarted in interface JUnitListener

junitSuiteStarted

public void junitSuiteStarted(int numTests)
Called to indicate that a suite of tests has started running.

Specified by:
junitSuiteStarted in interface JUnitListener
Parameters:
numTests - The number of tests in the suite to be run.

junitTestStarted

public void junitTestStarted(String name)
Called when a particular test is started.

Specified by:
junitTestStarted in interface JUnitListener
Parameters:
name - The name of the test being started.

junitTestEnded

public void junitTestEnded(String name,
                           boolean wasSuccessful,
                           boolean causedError)
Called when a particular test has ended.

Specified by:
junitTestEnded in interface JUnitListener
Parameters:
name - the name of the test that has ended
wasSuccessful - whether the test passed or not
causedError - if not successful, whether the test caused an error or simply failed

junitEnded

public void junitEnded()
Called after JUnit is finished running tests.

Specified by:
junitEnded in interface JUnitListener

javadocStarted

public void javadocStarted()
Called after Javadoc is started by the GlobalModel.

Specified by:
javadocStarted in interface JavadocListener

javadocEnded

public void javadocEnded(boolean success,
                         File destDir,
                         boolean allDocs)
Called after Javadoc is finished.

Specified by:
javadocEnded in interface JavadocListener
Parameters:
success - whether the Javadoc operation generated proper output
destDir - if (success) the location where the output was generated, otherwise undefined (possibly null)
allDocs - Whether Javadoc was run for all open documents

saveBeforeJavadoc

public void saveBeforeJavadoc()
Called before attempting Javadoc, to give the user a chance to save. Do not continue with Javadoc if the user doesn't save!

Specified by:
saveBeforeJavadoc in interface JavadocListener

interactionIncomplete

public void interactionIncomplete()
Notifies the view that the current interaction is incomplete.

Specified by:
interactionIncomplete in interface InteractionsListener

slaveJVMUsed

public void slaveJVMUsed()
Description copied from interface: InteractionsListener
Called when the slave JVM is used by the interpreter or unit testing.

Specified by:
slaveJVMUsed in interface InteractionsListener

filePathContainsPound

public void filePathContainsPound()
Notifies the view that the current file path contains a #.

Specified by:
filePathContainsPound in interface GlobalModelListener

documentNotFound

public void documentNotFound(OpenDefinitionsDocument d,
                             File f)
Description copied from interface: GlobalModelListener
Called when the a document, already opened, is brought back into the cache, and it no longer exists on disk or cannot be accessed.

Specified by:
documentNotFound in interface GlobalModelListener

browserChanged

public void browserChanged()
Description copied from interface: GlobalModelListener
Called when the a region is added to the browswing history.

Specified by:
browserChanged in interface GlobalModelListener