edu.rice.cs.drjava.plugins.eclipse.repl
Class EclipseInteractionsModel

java.lang.Object
  extended by edu.rice.cs.drjava.model.repl.InteractionsModel
      extended by edu.rice.cs.drjava.model.repl.RMIInteractionsModel
          extended by edu.rice.cs.drjava.plugins.eclipse.repl.EclipseInteractionsModel
All Implemented Interfaces:
InteractionsModelCallback

public class EclipseInteractionsModel
extends RMIInteractionsModel

Interactions model which can notify GlobalModelListeners on events.

Version:
$Id: EclipseInteractionsModel.java 4698 2008-12-09 15:25:10Z dlsmith $

Field Summary
protected  LinkedList<InteractionsListener> _listeners
          List of listeners to this document.
protected  boolean _warnedToReset
          Whether we have already warned the user to reset after a compilation occurs.
protected static int HISTORY_SIZE
          Number of lines to remember in the history
static File WORKING_DIR
           
protected static int WRITE_DELAY
          Milliseconds to wait after each println
 
Fields inherited from class edu.rice.cs.drjava.model.repl.RMIInteractionsModel
_jvm
 
Fields inherited from class edu.rice.cs.drjava.model.repl.InteractionsModel
_cDoc, _document, _inputListener, _lastError, _notifier, _pane, _secondToLastError, _waitingForFirstInterpreter, _workingDirectory, _writerLock, BANNER_PREFIX
 
Constructor Summary
EclipseInteractionsModel(MainJVM control, SWTDocumentAdapter adapter)
          Creates a new InteractionsModel.
EclipseInteractionsModel(SWTDocumentAdapter adapter)
          Creates a new InteractionsModel with a new MainJVM.
 
Method Summary
protected  void _addChangeListener()
          Adds a listener to Eclipse for any changes to Java projects.
protected  void _interpreterResetFailed(Throwable t)
          Any extra action to perform (beyond notifying listeners) when the interpreter fails to reset.
protected  boolean _isCompilationUnit(org.eclipse.jdt.core.IJavaElement element)
          Returns whether the given element is a compilation unit and not a working copy.
protected  void _notifyInteractionEnded()
          Notifies listeners that an interaction has ended.
protected  void _notifyInteractionIncomplete()
          Notifies the view that the current interaction is incomplete.
 void _notifyInteractionStarted()
          Notifies listeners that an interaction has started.
protected  void _notifyInterpreterChanged(boolean inProgress)
          Notifies listeners that the interpreter has changed.
protected  void _notifyInterpreterExited(int status)
          Notifies listeners that the interpreter has exited unexpectedly.
 void _notifyInterpreterReady(File wd)
          Notifies listeners that the interpreter is ready.
protected  void _notifyInterpreterResetFailed(Throwable t)
          Notifies listeners that the interpreter reset failed.
protected  void _notifyInterpreterResetting()
          Notifies listeners that the interpreter is resetting.
protected  void _notifySlaveJVMUsed()
          Notifies listeners that the slave JVM has been used.
protected  void _notifySyntaxErrorOccurred(int offset, int length)
          Notifies listeners that an error was present in the interaction.
protected  void _resetInteractionsClasspath()
          Adds each project's classpath to the Interactions pane.
protected  void _resetInterpreter(File wd)
          Resets the warning flag after the Interactions Pane is reset.
protected  void _visitDelta(org.eclipse.jdt.core.IJavaElementDelta delta, int depth)
          Walks the tree of deltas, looking for changes to the classpath or compilation units.
protected  void _warnUserToReset()
          Prints a message warning the user to reset the Interactions Pane once a compilation has occurred.
 void addBuildDirectoryClassPath(String path)
           
 void addInteractionsListener(InteractionsListener l)
          Adds a listener to this model.
 void addProjectFilesClassPath(String path)
           
 void addToClassPath(String path)
           
 void dispose()
          Cleans up any resources this model created, including the Interactions JVM.
 Iterable<File> getClassPath()
          Gets the interpreter classpath from the interpreter jvm.
 ConsoleDocument getConsoleDocument()
          Gets the console tab document for this interactions model
 void interpreterReady(File wd)
          Called when the Java interpreter is ready to use.
 void removeAllInteractionsListeners()
          Removes all listeners from this model.
 void removeInteractionsListener(InteractionsListener l)
          Removes the given listener from this model.
 void setOptionArgs(String optionArgString)
          Sets the optional command-line arguments to the interpreter JVM.
 void setPrivateAccessible(boolean allow)
          Sets whether to allow access to private members in the interactions pane.
 URL toURL(String path)
           
 
Methods inherited from class edu.rice.cs.drjava.model.repl.RMIInteractionsModel
_interpret, addBuildDirectoryClassPath, addExternalFilesClassPath, addExtraClassPath, addInterpreter, addProjectClassPath, addProjectFilesClassPath, enableRestart, getVariableToString, getVariableType, removeInterpreter, setActiveInterpreter, setToDefaultInterpreter
 
Methods inherited from class edu.rice.cs.drjava.model.repl.InteractionsModel
_addNewline, _createNewDebugPort, _deleteSemiColon, _getHistoryText, _interactionIsOver, _removeSeparators, _testClassCall, _writerDelay, addListener, append, changeInputListener, getBanner, getBanner, getConsoleInput, getDebugPort, getDocument, getLastError, getSecondToLastError, getStartUpBanner, getWorkingDirectory, interactionContinues, interpret, interpretCurrentInteraction, interpreterResetFailed, interpreterResetting, loadHistory, loadHistoryAsScript, removeAllInteractionListeners, removeLastFromHistory, removeListener, replCalledSystemExit, replReturnedResult, replReturnedSyntaxError, replReturnedVoid, replSystemErrPrint, replSystemOutPrint, replThrewException, resetInterpreter, resetLastErrors, scrollToCaret, setDebugPort, setInputListener, setUpPane, setWaitingForFirstInterpreter, slaveJVMUsed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HISTORY_SIZE

protected static final int HISTORY_SIZE
Number of lines to remember in the history

See Also:
Constant Field Values

WRITE_DELAY

protected static final int WRITE_DELAY
Milliseconds to wait after each println

See Also:
Constant Field Values

WORKING_DIR

public static final File WORKING_DIR

_listeners

protected final LinkedList<InteractionsListener> _listeners
List of listeners to this document.


_warnedToReset

protected boolean _warnedToReset
Whether we have already warned the user to reset after a compilation occurs.

Constructor Detail

EclipseInteractionsModel

public EclipseInteractionsModel(SWTDocumentAdapter adapter)
Creates a new InteractionsModel with a new MainJVM.

Parameters:
adapter - SWTDocumentAdapter to use for the document

EclipseInteractionsModel

public EclipseInteractionsModel(MainJVM control,
                                SWTDocumentAdapter adapter)
Creates a new InteractionsModel.

Parameters:
control - RMI interface to the Interpreter JVM
adapter - SWTDocumentAdapter to use for the document
Method Detail

dispose

public void dispose()
Cleans up any resources this model created, including the Interactions JVM.


getClassPath

public Iterable<File> getClassPath()
Description copied from class: RMIInteractionsModel
Gets the interpreter classpath from the interpreter jvm.

Overrides:
getClassPath in class RMIInteractionsModel
Returns:
a vector of classpath elements

addInteractionsListener

public void addInteractionsListener(InteractionsListener l)
Adds a listener to this model.


removeInteractionsListener

public void removeInteractionsListener(InteractionsListener l)
Removes the given listener from this model.


removeAllInteractionsListeners

public void removeAllInteractionsListeners()
Removes all listeners from this model.


_interpreterResetFailed

protected void _interpreterResetFailed(Throwable t)
Any extra action to perform (beyond notifying listeners) when the interpreter fails to reset.

Specified by:
_interpreterResetFailed in class InteractionsModel
Parameters:
t - The Throwable thrown by System.exit

interpreterReady

public void interpreterReady(File wd)
Called when the Java interpreter is ready to use. Adds any open documents to the classpath.

Specified by:
interpreterReady in interface InteractionsModelCallback
Overrides:
interpreterReady in class InteractionsModel

_resetInterpreter

protected void _resetInterpreter(File wd)
Resets the warning flag after the Interactions Pane is reset.

Overrides:
_resetInterpreter in class RMIInteractionsModel

_notifyInteractionStarted

public void _notifyInteractionStarted()
Notifies listeners that an interaction has started.

Specified by:
_notifyInteractionStarted in class InteractionsModel

_notifyInteractionEnded

protected void _notifyInteractionEnded()
Notifies listeners that an interaction has ended.

Specified by:
_notifyInteractionEnded in class InteractionsModel

_notifySyntaxErrorOccurred

protected void _notifySyntaxErrorOccurred(int offset,
                                          int length)
Notifies listeners that an error was present in the interaction.

Specified by:
_notifySyntaxErrorOccurred in class InteractionsModel
Parameters:
offset - the first character of the error in the InteractionsDocument
length - the length of the error.

_notifyInterpreterResetting

protected void _notifyInterpreterResetting()
Notifies listeners that the interpreter is resetting.

Specified by:
_notifyInterpreterResetting in class InteractionsModel

_notifyInterpreterReady

public void _notifyInterpreterReady(File wd)
Notifies listeners that the interpreter is ready.

Specified by:
_notifyInterpreterReady in class InteractionsModel

_notifyInterpreterExited

protected void _notifyInterpreterExited(int status)
Notifies listeners that the interpreter has exited unexpectedly.

Specified by:
_notifyInterpreterExited in class InteractionsModel
Parameters:
status - Status code of the dead process

_notifyInterpreterResetFailed

protected void _notifyInterpreterResetFailed(Throwable t)
Notifies listeners that the interpreter reset failed.

Specified by:
_notifyInterpreterResetFailed in class InteractionsModel
Parameters:
t - Throwable explaining why the reset failed.

_notifyInterpreterChanged

protected void _notifyInterpreterChanged(boolean inProgress)
Notifies listeners that the interpreter has changed.

Specified by:
_notifyInterpreterChanged in class RMIInteractionsModel
Parameters:
inProgress - Whether the new interpreter is currently in progress.

_notifyInteractionIncomplete

protected void _notifyInteractionIncomplete()
Notifies the view that the current interaction is incomplete.

Specified by:
_notifyInteractionIncomplete in class InteractionsModel

_notifySlaveJVMUsed

protected void _notifySlaveJVMUsed()
Notifies listeners that the slave JVM has been used.

Specified by:
_notifySlaveJVMUsed in class InteractionsModel

_resetInteractionsClasspath

protected void _resetInteractionsClasspath()
Adds each project's classpath to the Interactions pane.


_warnUserToReset

protected void _warnUserToReset()
Prints a message warning the user to reset the Interactions Pane once a compilation has occurred. The warning is only printed if the Interactions Pane has been used.


_addChangeListener

protected void _addChangeListener()
Adds a listener to Eclipse for any changes to Java projects. The listener will warn the user to reset the Interactions Pane if new class files are generated. Note: We'd also like to dynamically add elements to the classpath if the classpath of a project changes. (This is tricky to identify.)


toURL

public URL toURL(String path)

addBuildDirectoryClassPath

public void addBuildDirectoryClassPath(String path)

addProjectFilesClassPath

public void addProjectFilesClassPath(String path)

addToClassPath

public void addToClassPath(String path)

_visitDelta

protected void _visitDelta(org.eclipse.jdt.core.IJavaElementDelta delta,
                           int depth)
Walks the tree of deltas, looking for changes to the classpath or compilation units.

Parameters:
delta - Tree to search
depth - Current depth of original tree. Pass 0 on the first call.

_isCompilationUnit

protected boolean _isCompilationUnit(org.eclipse.jdt.core.IJavaElement element)
Returns whether the given element is a compilation unit and not a working copy. Useful to determine whether class files have actually changed or not. Note: ICompilationUnit extends IWorkingCopy, but WorkingCopy extends CompilationUnit. (?!?) This means that we can't just ask whether element is an ICompilationUnit; we have to also make sure it is not also an IWorkingCopy.

Parameters:
element - JavaElement in question

setPrivateAccessible

public void setPrivateAccessible(boolean allow)
Sets whether to allow access to private members in the interactions pane.

Overrides:
setPrivateAccessible in class RMIInteractionsModel
Parameters:
allow - true iff access should be allowed

setOptionArgs

public void setOptionArgs(String optionArgString)
Sets the optional command-line arguments to the interpreter JVM.


getConsoleDocument

public ConsoleDocument getConsoleDocument()
Gets the console tab document for this interactions model

Specified by:
getConsoleDocument in class InteractionsModel