[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: How to monitor all Events handled by an SWT app

On Fri, 25 Jul 2003 14:42:28 +0000, ktdal wrote:


> We're extending an existing AWT testing framework- Abbot- for use with
> SWT, so look to http://abbot.sourceforge.net/ for info.  And I'll post
> here once we have something up and running.


Cool. I hadn't seen that before (and wasn't familiar with the
java.awt.Toolkit.addAWTEventListener()).

It strikes me that one could essentially the same functionality as the
abbot SemanticRecording and such by using AspectJ. I was playing around
with it last night to learn about AspectJ and to see how I would be able
to add listeners to every AWT component as it's created. Turns out it's
really easy.

Using it for SWT shouldn't be too bad, either.

Here's some skeleton code for the aspect (and it works as you might
expect, i.e., a JFrame matches both predicates shown so Component and
Window listeners are added to any JFrame that's constructed:

public aspect Recorder {
	pointcut anyConstructor(): call(*.new(..));
	pointcut theseListeners(): call(void aspecttest.Recorder.addListeners(..));


	public void addListeners(Component c) {
		c.addComponentListener(new MyRecordingComponentListener());
		...
	}

	public void addListeners(Window w) {
		w.addWindowListener(new MyRecordingWindowListener());
		...
	}
	...

	after() returning (Component c): anyConstructor(){
		addListeners(c);
	}
	
	after() returning (Window w): anyConstructor() {
		addListeners(w);
	}
	
	...

	//Just to see that the above advices are woven...
	before(): theseListeners() {
		System.out.println("calling: "+thisJoinPoint);
	}
	
	after() returning: theseListeners() {
		System.out.println("completed: "+thisJoinPoint);
	}
}


-- 
http://zclipse.org