edu.rice.cs.drjava.ui
Class MainFrame.ModelListener

java.lang.Object
  extended by edu.rice.cs.drjava.ui.MainFrame.ModelListener
All Implemented Interfaces:
CompilerListener, GlobalModelListener, JavadocListener, JUnitListener, InteractionsListener
Enclosing class:
MainFrame

private class MainFrame.ModelListener
extends Object
implements GlobalModelListener

Inner class to listen to all events in the model.


Field Summary
private  int _fnfCount
           
 
Constructor Summary
private MainFrame.ModelListener()
           
 
Method Summary
private  void _compileBeforeProceeding(String message, BooleanOption option, String checkMsg, CompilerListener afterCompile)
          Helper method shared by all "compileBeforeX" methods.
private  void _fileClosed(OpenDefinitionsDocument doc)
          Does the work of closing a file
private  void _fileOpened(OpenDefinitionsDocument doc)
           
private  boolean _fileSaveHelper(OpenDefinitionsDocument doc, int paneOption)
           
private  void _saveAllBeforeProceeding(String message, BooleanOption option, String checkMsg)
          Helper method shared by all "saveBeforeX" methods.
 void activeCompilerChanged()
          Called after the active compiler has been changed.
 void activeDocumentChanged(OpenDefinitionsDocument active)
          Called when a new active document is selected
 void activeDocumentRefreshed(OpenDefinitionsDocument active)
          Called when the active document is refreshed
 void allFilesClosed()
          Called when all open files are closed.
 void browserChanged()
          Called when the a region is added to the browswing history.
 boolean canAbandonFile(OpenDefinitionsDocument doc)
          Check if the specified document has been modified.
 void classFileError(ClassFileError e)
          Event that is fired when testing encounters an illegal class file.
 void compileAborted(Exception e)
          Called if a compilation is aborted.
 void compileBeforeJavadoc(CompilerListener afterCompile)
          Called before attempting Javadoc, to give the user a chance to compile.
 void compileBeforeJUnit(CompilerListener testAfterCompile, List<OpenDefinitionsDocument> outOfSync)
          Compile all open source files if this option is configured or running as a unit test.
 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)
          Only callable from within the event-handling thread
 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()
          Called when saving a file whose path contains a '#' symbol.
 void fileReverted(OpenDefinitionsDocument doc)
          Called after a document is reverted.
 void fileSaved(OpenDefinitionsDocument doc)
          Called after the current document is saved.
 void filesNotFound(File... files)
          Called when trying to open one or more files that do not exist.
 File[] filesReadOnly(File... files)
          Called when trying to write one or more files that are read-only.
 void focusOnDefinitionsPane()
          Moves focus in MainFrame to the definitions pane.
 void focusOnLastFocusOwner()
          Restores the focus in the main frame to the last focus owner.
 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 ended.
 void interactionErrorOccurred(int offset, int length)
          Called when an interaction results in a syntax error.
 void interactionIncomplete()
          Called when enter was typed in the interactions pane but the interaction was incomplete.
 void interactionStarted()
          Called when an interaction has started.
 void interpreterChanged(boolean inProgress)
          Called when the active interpreter is changed.
 void interpreterExited(int status)
          Called when the interpreter exits unexpectedly.
 void interpreterReady(File wd)
          Called when the interpreter is ready to use.
 void interpreterResetFailed(Throwable t)
          Called if the interpreter could not be reset.
 void interpreterResetting()
          Called when the interpreter has begun resetting.
 void javadocEnded(boolean success, File destDir, boolean allDocs)
          Called after Javadoc is finished.
 void javadocStarted()
          Fire just before javadoc asynchronous thread is started.
 void junitClassesStarted()
          We are junit'ing a specific list of classes given their source files.
 void junitEnded()
          Called after JUnit is finished running tests.
 void junitStarted()
          Only runs in event thread.
 void junitSuiteStarted(int numTests)
          Called to indicate that a suite of tests has started running.
 void junitTestEnded(String name, boolean succeeded, 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, boolean didCompileFail)
          Event that is fired with there is nothing to test.
 void openProject(File projectFile, FileOpenSelector files)
          Called while the project is being opened.
 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)
          Check if the current document has been modified.
private  boolean resetFNFCount()
           
 void saveBeforeCompile()
          Called to demand that all open source files be saved before compiling.
 void saveBeforeJavadoc()
          Called to demand that all files be saved before generating Javadoc.
 void saveUntitled()
          Saves the active document which is untitled.
 boolean shouldRevertFile(OpenDefinitionsDocument doc)
          Called to ask the listener if it is OK to revert the current document to a newer version saved on file.
private  boolean someFilesNotFound()
           
 void undoableEditHappened()
          Called when an undoable edit occurs.
 void updateCurrentLocationInDoc()
          Called when the current location in the document needs to be synchronized to the actual location displayed in the view.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_fnfCount

private volatile int _fnfCount
Constructor Detail

MainFrame.ModelListener

private MainFrame.ModelListener()
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

handleAlreadyOpenDocument

public void handleAlreadyOpenDocument(OpenDefinitionsDocument doc)
Description copied from interface: GlobalModelListener
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

newFileCreated

public void newFileCreated(OpenDefinitionsDocument doc)
Description copied from interface: GlobalModelListener
Called after a new document is created.

Specified by:
newFileCreated in interface GlobalModelListener

resetFNFCount

private boolean resetFNFCount()

someFilesNotFound

private boolean someFilesNotFound()

filesNotFound

public void filesNotFound(File... files)
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... files)
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:
files - files that are read-only
Returns:
the files that should be attempted to be rewritten

fileSaved

public void fileSaved(OpenDefinitionsDocument doc)
Description copied from interface: GlobalModelListener
Called after the current document is saved.

Specified by:
fileSaved in interface GlobalModelListener

fileOpened

public void fileOpened(OpenDefinitionsDocument doc)
Description copied from interface: GlobalModelListener
Called after a file is opened and read into the current document.

Specified by:
fileOpened in interface GlobalModelListener

_fileOpened

private void _fileOpened(OpenDefinitionsDocument doc)

fileClosed

public void fileClosed(OpenDefinitionsDocument doc)
Description copied from interface: GlobalModelListener
Called after a document is closed.

Specified by:
fileClosed in interface GlobalModelListener

_fileClosed

private void _fileClosed(OpenDefinitionsDocument doc)
Does the work of closing a file


fileReverted

public void fileReverted(OpenDefinitionsDocument doc)
Description copied from interface: GlobalModelListener
Called after a document is reverted.

Specified by:
fileReverted in interface GlobalModelListener

undoableEditHappened

public void undoableEditHappened()
Description copied from interface: GlobalModelListener
Called when an undoable edit occurs.

Specified by:
undoableEditHappened in interface GlobalModelListener

activeDocumentRefreshed

public void activeDocumentRefreshed(OpenDefinitionsDocument active)
Description copied from interface: GlobalModelListener
Called when the active document is refreshed

Specified by:
activeDocumentRefreshed in interface GlobalModelListener

activeDocumentChanged

public void activeDocumentChanged(OpenDefinitionsDocument active)
Description copied from interface: GlobalModelListener
Called when a new active document is selected

Specified by:
activeDocumentChanged in interface GlobalModelListener

focusOnLastFocusOwner

public void focusOnLastFocusOwner()
Description copied from interface: GlobalModelListener
Restores the focus in the main frame to the last focus owner.

Specified by:
focusOnLastFocusOwner in interface GlobalModelListener

focusOnDefinitionsPane

public void focusOnDefinitionsPane()
Moves focus in MainFrame to the definitions pane.

Specified by:
focusOnDefinitionsPane in interface GlobalModelListener

interactionStarted

public void interactionStarted()
Description copied from interface: InteractionsListener
Called when an interaction has started.

Specified by:
interactionStarted in interface InteractionsListener

interactionEnded

public void interactionEnded()
Description copied from interface: InteractionsListener
Called when an interaction has ended.

Specified by:
interactionEnded in interface InteractionsListener

interactionErrorOccurred

public void interactionErrorOccurred(int offset,
                                     int length)
Description copied from interface: InteractionsListener
Called when an interaction results in a syntax error.

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

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 currently in progress with an interaction (i.e., whether an interactionEnded event will be fired)

compileStarted

public void compileStarted()
Description copied from interface: CompilerListener
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)
Description copied from interface: CompilerListener
Called when a compile has finished running.

Specified by:
compileEnded in interface CompilerListener

compileAborted

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

Specified by:
compileAborted in interface CompilerListener

activeCompilerChanged

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

Specified by:
activeCompilerChanged in interface CompilerListener

prepareForRun

public void prepareForRun(OpenDefinitionsDocument doc)
Description copied from interface: GlobalModelListener
Called when a file's main method is about to be run.

Specified by:
prepareForRun in interface GlobalModelListener

junitStarted

public void junitStarted()
Only runs in event thread.

Specified by:
junitStarted in interface JUnitListener

junitClassesStarted

public void junitClassesStarted()
We are junit'ing a specific list of classes given their source files.

Specified by:
junitClassesStarted in interface JUnitListener

junitSuiteStarted

public void junitSuiteStarted(int numTests)
Description copied from interface: JUnitListener
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)
Description copied from interface: JUnitListener
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 succeeded,
                           boolean causedError)
Description copied from interface: JUnitListener
Called when a particular test has ended.

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

junitEnded

public void junitEnded()
Description copied from interface: JUnitListener
Called after JUnit is finished running tests.

Specified by:
junitEnded in interface JUnitListener

javadocStarted

public void javadocStarted()
Fire just before javadoc asynchronous thread is started. Only runs in the event thread.

Specified by:
javadocStarted in interface JavadocListener

javadocEnded

public void javadocEnded(boolean success,
                         File destDir,
                         boolean allDocs)
Description copied from interface: JavadocListener
Called after Javadoc is finished.

Specified by:
javadocEnded in interface JavadocListener
Parameters:
success - whether the Javadoc operation generated proper output
destDir - if (success == true) the location where the output was generated, otherwise undefined (null?)
allDocs - Whether we are running over all open documents

interpreterExited

public void interpreterExited(int status)
Description copied from interface: InteractionsListener
Called when the interpreter exits unexpectedly.

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

interpreterResetFailed

public void interpreterResetFailed(Throwable t)
Description copied from interface: InteractionsListener
Called if the interpreter could not be reset.

Specified by:
interpreterResetFailed in interface InteractionsListener
Parameters:
t - Throwable explaining why the reset failed.

interpreterResetting

public void interpreterResetting()
Description copied from interface: InteractionsListener
Called when the interpreter has begun resetting.

Specified by:
interpreterResetting in interface InteractionsListener

interpreterReady

public void interpreterReady(File wd)
Description copied from interface: InteractionsListener
Called when the interpreter is ready to use.

Specified by:
interpreterReady in interface InteractionsListener

consoleReset

public void consoleReset()
Description copied from interface: GlobalModelListener
Called when the console window is reset.

Specified by:
consoleReset in interface GlobalModelListener

saveBeforeCompile

public void saveBeforeCompile()
Description copied from interface: CompilerListener
Called to demand that all open source files be saved before compiling.

Specified by:
saveBeforeCompile in interface CompilerListener

compileBeforeJUnit

public void compileBeforeJUnit(CompilerListener testAfterCompile,
                               List<OpenDefinitionsDocument> outOfSync)
Compile all open source files if this option is configured or running as a unit test. Otherwise, pop up a dialog to ask if all open source files should be compiled in order to test the program.

Specified by:
compileBeforeJUnit in interface JUnitListener

saveBeforeJavadoc

public void saveBeforeJavadoc()
Description copied from interface: JavadocListener
Called to demand that all files be saved before generating Javadoc. It is up to the caller of this method to check if the documents have been saved, using IGetDocuments.hasModifiedDocuments(). Do not continue with Javadoc if the user doesn't save!

Specified by:
saveBeforeJavadoc in interface JavadocListener

_saveAllBeforeProceeding

private void _saveAllBeforeProceeding(String message,
                                      BooleanOption option,
                                      String checkMsg)
Helper method shared by all "saveBeforeX" methods. In JUnit tests, YES option is automatically selected

Parameters:
message - a prompt message to be displayed to the user
option - the BooleanOption for the prompt dialog checkbox
checkMsg - the description of the checkbox ("Always save before X")

compileBeforeJavadoc

public void compileBeforeJavadoc(CompilerListener afterCompile)
Description copied from interface: JavadocListener
Called before attempting Javadoc, to give the user a chance to compile. Do not continue with Javadoc if the user doesn't comoile!

Specified by:
compileBeforeJavadoc in interface JavadocListener

_compileBeforeProceeding

private void _compileBeforeProceeding(String message,
                                      BooleanOption option,
                                      String checkMsg,
                                      CompilerListener afterCompile)
Helper method shared by all "compileBeforeX" methods.

Parameters:
message - a prompt message to be displayed to the user
option - the BooleanOption for the prompt dialog checkbox
checkMsg - the description of the checkbox ("Always compile before X")

saveUntitled

public void saveUntitled()
Saves the active document which is untitled.

Specified by:
saveUntitled in interface CompilerListener

filePathContainsPound

public void filePathContainsPound()
Description copied from interface: GlobalModelListener
Called when saving a file whose path contains a '#' symbol.

Specified by:
filePathContainsPound in interface GlobalModelListener

nonTestCase

public void nonTestCase(boolean isTestAll,
                        boolean didCompileFail)
Event that is fired with there is nothing to test. JUnit is never started.

Specified by:
nonTestCase in interface JUnitListener
Parameters:
isTestAll - whether or not it was a use of the test all button
didCompileFail - whether or not a compile before this JUnit attempt failed

classFileError

public void classFileError(ClassFileError e)
Event that is fired when testing encounters an illegal class file. JUnit is never started.

Specified by:
classFileError in interface JUnitListener
Parameters:
e - the error or exception thrown by loading and resolving f.

currentDirectoryChanged

public void currentDirectoryChanged(File dir)
Only callable from within the event-handling thread

Specified by:
currentDirectoryChanged in interface GlobalModelListener

canAbandonFile

public boolean canAbandonFile(OpenDefinitionsDocument doc)
Check if the specified document has been modified. If it has, ask the user if he would like to save it and save the document if yes. Also give the user a "cancel" option to cancel doing the operation that got us here in the first place.

Specified by:
canAbandonFile in interface GlobalModelListener
Returns:
A boolean indicating whether the user cancelled the save process. False means cancel.

_fileSaveHelper

private boolean _fileSaveHelper(OpenDefinitionsDocument doc,
                                int paneOption)

quitFile

public boolean quitFile(OpenDefinitionsDocument doc)
Check if the current document has been modified. If it has, ask the user if he would like to save it and save the document if yes.

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 listener if it is OK to revert the current document to a newer version saved on file.

Specified by:
shouldRevertFile in interface GlobalModelListener

interactionIncomplete

public void interactionIncomplete()
Description copied from interface: InteractionsListener
Called when enter was typed in the interactions pane but the interaction was incomplete.

Specified by:
interactionIncomplete in interface InteractionsListener

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

projectModified

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

Specified by:
projectModified in interface GlobalModelListener

projectClosed

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

Specified by:
projectClosed in interface GlobalModelListener

allFilesClosed

public void allFilesClosed()
Description copied from interface: GlobalModelListener
Called when all open files are closed.

Specified by:
allFilesClosed in interface GlobalModelListener

openProject

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

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

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

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

updateCurrentLocationInDoc

public void updateCurrentLocationInDoc()
Description copied from interface: GlobalModelListener
Called when the current location in the document needs to be synchronized to the actual location displayed in the view.

Specified by:
updateCurrentLocationInDoc in interface GlobalModelListener