Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » XWT: DataContext change --> Change UI
XWT: DataContext change --> Change UI [message #636167] Fri, 29 October 2010 14:07 Go to next message
Missing name Missing name is currently offline Missing name Missing nameFriend
Messages: 57
Registered: September 2009
Member
Hello,

I have a XWT file UI description, containing a button btn1. It's a simple example of my aim.

<Composite xmlns="http://www.eclipse.org/xwt/presentation"
	xmlns:x="http://www.eclipse.org/xwt" xmlns:css="http://www.eclipse.org/css"
	xmlns:c="clr-namespace:myproject.ui" xmlns:j="clr-namespace:myproject.ui"
	x:Class="myproject.ui.Essai" >
	<Composite.layout>
		<GridLayout numColumns="2" />
	</Composite.layout>
	<Composite.layoutData>
		<GridData grabExcessHorizontalSpace="true"
			horizontalAlignment="SWT.FILL" />
	</Composite.layoutData>

	<Label text="Name" css:id="LabelUnBold"></Label>
	<Text name="name"
		text="{Binding path=name, updateSourceTrigger=PropertyChanged}">
		<Text.layoutData>
			<GridData grabExcessHorizontalSpace="true" widthHint="150"
				horizontalIndent="40" />
		</Text.layoutData>
	</Text>
	<Button name="btn" text="btn1" selectionEvent="changeFirstNamet"></Button>

	<Button name="btn" text="btn2"></Button>

	<Label text="Firstname" css:id="LabelUnBold"></Label>
	<Text name="firstName"
		text="{Binding path=firstName, updateSourceTrigger=PropertyChanged}">
		<Text.layoutData>
			<GridData grabExcessHorizontalSpace="true" widthHint="150"
				horizontalIndent="40" />
		</Text.layoutData>
	</Text>

	<Label text="Namet" css:id="LabelUnBold"></Label>
	<Text name="namet" text="{Binding path=name}">
		<Text.layoutData>
			<GridData grabExcessHorizontalSpace="true" widthHint="150"
				horizontalIndent="40" />
		</Text.layoutData>
	</Text>

	<Label text="Firstnamet" css:id="LabelUnBold"></Label>
	<Text name="firstNamet" text="{Binding path=firstName,updateSourceTrigger=PropertyChanged}">
		<Text.layoutData>
			<GridData grabExcessHorizontalSpace="true" widthHint="150"
				horizontalIndent="40" />
		</Text.layoutData>
	</Text>
</Composite>


On clicking on th button btn1, an event is called in the java class in order to change a value of the datacontext.

public class Essai extends Composite{

    /**
     * @param _parent
     * @param _style
     */
    public Essai(Composite _parent, int _style) {
        super(_parent, _style);
    }
    
    public void changeFirstNamet(Event _event){
        Person data = (Person)XWT.getDataContext(this);
        data.setFirstName("hello");
        
    }
}


On clicking on the btn1 button, this value (hello) must be displayed in the firstNamet widget (and firstName too) in the xwt file (a Text). But it doesn't work.
Why ?

Thank you.
Re: XWT: DataContext change --> Change UI [message #636693 is a reply to message #636167] Tue, 02 November 2010 13:35 Go to previous message
Missing name Missing name is currently offline Missing name Missing nameFriend
Messages: 57
Registered: September 2009
Member
Hello,

I found a solution. A lot of people saw my question, so I give you the solution that can help someone.

In the Essai class, I add:

public class Essai extends Composite{

    /**
     * @param _parent
     * @param _style
     */
    public Essai(Composite _parent, int _style) {
        super(_parent, _style);
    }
    
    public void changeFirstNamet(Event _event){
        Person data = (Person)XWT.getDataContext(this);
       // data.setFirstName("hello"); not used now
        IObservable obs = XWT.findObservableValue(this, data, "firstName");  //"firstName" is an attribute of Person
        obs.setValue("TheNewFirstname");
    }
}


The last parameter of findObservableValue can be a composite object (for example: Company class that contains an adress as String).
If the adress is displayed in the XWT like
<Text text="{Binding path=company.adress}">

it will be updated.


Previous Topic:Dynamically creating Parts (updated from the E4/Snippets) / Passing around IEclipseContext
Next Topic:RCP (Eclipse 3.6) into E4
Goto Forum:
  


Current Time: Tue Apr 16 15:47:58 GMT 2024

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

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

Back to the top