Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » xwt databinding trouble
xwt databinding trouble [message #902220] Thu, 16 August 2012 12:21 Go to next message
Jürgen Weinberger is currently offline Jürgen WeinbergerFriend
Messages: 42
Registered: August 2012
Member
Hey!
Sorry this may be a stupid question but i can't see what i am doing wrong.

I have a simple testcase to experiment with the databinding of xwt.
I just try to bind a textbox to a string in my class in both ways. At the startup the textbox is filled with the text set by the attribute. But when i change the text in the text field the attribute in my object won't be updated. Also the otherway around when i press the button the event is called but the textbox will not change.

Maybe anyone has an idea. By the way i am using eclipse 3.6

package helloWorld;

import java.net.URL;

import org.eclipse.e4.xwt.IConstants;
import org.eclipse.e4.xwt.XWT;

public class Main {
	private static TestMe testme = new TestMe();
	
	public static void main(String args[]) throws Exception {
		URL url = TestMe.class.getResource(TestMe.class.getSimpleName()
				+ IConstants.XWT_EXTENSION_SUFFIX);
		XWT.open(url,testme);
	}
	
	
}


package helloWorld;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import org.eclipse.swt.widgets.Event;


public class TestMe {

	private String testText;
	
	private PropertyChangeSupport support = new PropertyChangeSupport(this);
	
	public void addPropertyChangeListener(String propertyName,PropertyChangeListener listener) {
		support.addPropertyChangeListener(propertyName, listener);
	}
	
	public void removePropertyChangeListener(String propertyName,PropertyChangeListener listener) {
		support.removePropertyChangeListener(listener);
	}

	public TestMe() {
		setTestText("This is a Test");
	}
	
	public String getTestText() {
		return testText;
	}

	public void setTestText(String testText) {
		support.firePropertyChange("testText", this.testText, testText);
		this.testText = testText;
	}

	public void onSelection(Event event) {
		System.out.println(testText);
		setTestText("Hello World");
	}

}


<Composite xmlns="http://www.eclipse.org/xwt/presentation" 
		   xmlns:x="http://www.eclipse.org/xwt"
		   xmlns:y="clr-namespace:helloWorld"
		   x:Class="helloWorld.TestMe">
	
	<Composite.layout>
		<RowLayout/>
	</Composite.layout>
	
	<Text x:Style="BORDER" text="{Binding path=testText}"/>
	
	<Button text="New Button" SelectionEvent="onSelection"/>
</Composite>
Re: xwt databinding trouble [message #902243 is a reply to message #902220] Thu, 16 August 2012 13:53 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
I think your property change support code is wrong, it should be:

public void addPropertyChangeListener(PropertyChangeListener listener) {
		support.addPropertyChangeListener(propertyName, listener);
	}
	
	public void removePropertyChangeListener(PropertyChangeListener listener) {
		support.removePropertyChangeListener(listener);
	}


(Just add a breakpoint in add/removePropertyChangeListener.)
Re: xwt databinding trouble [message #902292 is a reply to message #902243] Thu, 16 August 2012 20:05 Go to previous message
Jürgen Weinberger is currently offline Jürgen WeinbergerFriend
Messages: 42
Registered: August 2012
Member
Hey! thanks for the fast reply Smile

Now i had time to try out your proposal and changed the code to
package helloworld;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import org.eclipse.swt.widgets.Event;


public class TestMe {

	private String testText;
	
	private PropertyChangeSupport support = new PropertyChangeSupport(this);
	
	public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
		support.addPropertyChangeListener(propertyName, listener);
	}
	
	public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
		support.removePropertyChangeListener(propertyName, listener);
	}

	public void addPropertyChangeListener(PropertyChangeListener listener) {
		support.addPropertyChangeListener(listener);
	}
	
	public void removePropertyChangeListener(PropertyChangeListener listener) {
		support.removePropertyChangeListener(listener);
	}

	public TestMe() {
		setTestText("This is a Test");
	}
	
	public String getTestText() {
		return testText;
	}

	public void setTestText(String testText) {
		support.firePropertyChange("testText", this.testText, testText);
		this.testText = testText;
	}

	public void onSelection(Event event) {
		System.out.println(testText);
		setTestText("Hello World");
	}

}


I found the propertyChange code from an old tutorial with jface databinding and there it worked. Also the breakpoint at addSupportListener(..,..) is reached (with propertyName="testText" and a BeanValueProperty. But unfortunately i got still the same results.
Thanks for the help Smile. Maybe you have any other suggestion? (maybe some class or jar i forgot, but there's no error message).
Could this be a problem with the realms. I don't looked into that topic in details.

What i don't understand is, why the data- and eventbinding works at the startup but the data doesn't get updated later.

Is there any documentation about xwt, i can't find something realy usefull?

regards weinma

[Updated on: Thu, 16 August 2012 20:12]

Report message to a moderator

Previous Topic:How to change tab color?
Next Topic:XWTException by adding Listener to Button
Goto Forum:
  


Current Time: Wed Apr 24 19:30:36 GMT 2024

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

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

Back to the top