Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Correct way to use Listeners
Correct way to use Listeners [message #636886] Wed, 03 November 2010 08:55 Go to next message
Peter J. Kranz is currently offline Peter J. KranzFriend
Messages: 10
Registered: November 2010
Junior Member

currently i'm refactoring some code at work, and i'm not sure if everything is correct. Also, i'm new to programming Eclipse RCP, but have experience with Java/Swing.

import org.eclipse.swt.widgets.Text;

public class TestClass implements ModifyListener {
	private Text textField;
	public TestClass() {
		// init fields
	public void update() {
// toggle visibilty of elements or change data
		if (textField.getText().equals("someString")) {
	public void modifyText(ModifyEvent e) {
		if (e.getSource() == textField) {
		// update all fields etc.

i don't like removing the modifylistener and add it afterwards. Is there some better way?
Re: Correct way to use Listeners [message #636948 is a reply to message #636886] Wed, 03 November 2010 14:04 Go to previous message
David Wegener is currently offline David WegenerFriend
Messages: 1437
Registered: July 2009
Senior Member
Add a private boolean updateInProgress instance variable to the class and initialize it to false.

Add a check of the variable to the if statement in the update method.

Set the field to true just before calling setText on the text field.

Set the field back to false after the setText method.
Previous Topic:Drawing to a GC through an external native library
Next Topic:Use Menu with Combo?
Goto Forum:

Current Time: Thu May 28 11:08:05 GMT 2020

Powered by FUDForum. Page generated in 0.01706 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top