classpathhelper.eclipse.jdt.listener
Class JavaProjectClassPathListener

java.lang.Object
  extended byclasspathhelper.eclipse.ui.AbstractClassPathModel
      extended byclasspathhelper.eclipse.jdt.listener.JavaProjectClassPathListener
All Implemented Interfaces:
IClassPathModel, IFileChangeListener
Direct Known Subclasses:
NotOnClassPathListener

public class JavaProjectClassPathListener
extends AbstractClassPathModel
implements IFileChangeListener

Class that listens to the IJavaProject and notifies an instance of IClassPathChangeListener if anything occurs that would cause a change to the classpath.

Implementation Notes

This listener caches classpaths/classloaders for each project this prevents the constant reloading of projects when clicking around Package Explorer as it simply returns the already existing classloader. It clears its cache if another listener is selected as the primary listener.

This class has two different strategies for locating the selected IJavaProject. These two strategies are selected by the user and stored as preferences. The two strategies implement the IProjectSelectionStrategy interface.

Since:
1.0
Author:
bharris

Constructor Summary
JavaProjectClassPathListener()
           
 
Method Summary
protected static void addSourcesToFileMonitor(FileChangeMonitor fileMonitor, java.lang.String cp)
          Internal method that adds elements from the classpath to the file monitor.
protected  java.lang.String determineClassPath(IJavaProject javaProject)
          Internal method for determining the classpath of a JDT JavaProject.
 void fileChanged(FileChangeMonitor monitor, FileChangedEvent[] evts)
          Callback method indicating file(s) have changed.
protected  void fireNewClassPathEvent(IJavaProject javaProject)
          Internal method to notify listeners that the classpath has changed.
protected  CGClassLoader getCurrentClassLoader()
          Internal method used to obtain the current classloader for AbstractClassPathModel.addClassPathChangeListener(IClassPathChangeListener).
 void propertyChange(PropertyChangeEvent evt)
           
 void startClassPathListening()
          Method called to indicate that this model is the selected model and should start sending classpath change events.
 void stopClassPathListening()
          Method called to indicate that this model is nolonger the selected model and can clean up any listeners it has started (as well as any caching.
 
Methods inherited from class classpathhelper.eclipse.ui.AbstractClassPathModel
addClassPathChangeListener, fireClassPathChangeEvent, getNumberOfListeners, removeClassPathChangeListener, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaProjectClassPathListener

public JavaProjectClassPathListener()
Since:
1.0
Method Detail

fireNewClassPathEvent

protected void fireNewClassPathEvent(IJavaProject javaProject)
Internal method to notify listeners that the classpath has changed.

Parameters:
javaProject - The javaProject to pull the classpath from.
Since:
1.0

addSourcesToFileMonitor

protected static void addSourcesToFileMonitor(FileChangeMonitor fileMonitor,
                                              java.lang.String cp)
Internal method that adds elements from the classpath to the file monitor.

Parameters:
fileMonitor - The monitor that will watch files on the classpath for changes.
cp - The classpath.
Since:
1.0

determineClassPath

protected java.lang.String determineClassPath(IJavaProject javaProject)
Internal method for determining the classpath of a JDT JavaProject.

Parameters:
javaProject - The javaProject to pull the classpath from.
Returns:
A string representation of the classpath.
Since:
1.0

getCurrentClassLoader

protected CGClassLoader getCurrentClassLoader()
Description copied from class: AbstractClassPathModel
Internal method used to obtain the current classloader for AbstractClassPathModel.addClassPathChangeListener(IClassPathChangeListener). If not class loader exists, this method should return null.

Specified by:
getCurrentClassLoader in class AbstractClassPathModel
Returns:
The current class loader.

startClassPathListening

public void startClassPathListening()
Description copied from interface: IClassPathModel

Method called to indicate that this model is the selected model and should start sending classpath change events. If a model needs to attach any listeners this is a good point to do so.

A model should also use this call send its initial class loader via its IClassPathChangeListener objects.

Specified by:
startClassPathListening in interface IClassPathModel

stopClassPathListening

public void stopClassPathListening()
Description copied from interface: IClassPathModel
Method called to indicate that this model is nolonger the selected model and can clean up any listeners it has started (as well as any caching.

Specified by:
stopClassPathListening in interface IClassPathModel

fileChanged

public void fileChanged(FileChangeMonitor monitor,
                        FileChangedEvent[] evts)
Description copied from interface: IFileChangeListener
Callback method indicating file(s) have changed.

Specified by:
fileChanged in interface IFileChangeListener
Parameters:
monitor - The monitor these changes are from.
evts - An array of the events representing all the file changes.

propertyChange

public void propertyChange(PropertyChangeEvent evt)