Data binding between SWT and Xtext - data-binding

I am building a plugin for eclipse that provides a graphical editor.
In this editor, I want to bind some data between an XText model and the SWT widgets. How can I do this while updating the XTextDocument automatically?
Are there existing tools that help with this, or do code generation for this?
By now, I have created with window builder plugin JFace Automatic Databinding with controller class.
it seem that whenever I change the text field which the xtext data model (JString) is bind to, the binding put null/new instance of JString into the JString instance.
so the document isn't familiar with the new JString instance and it is not updated with the new data.

I extended AbstractObservableValue to work with simple xtext models as string boolean and numbers. which help me to bind between swt model and my xtext model.

Dana, FYI I've done some work on this front in https://github.com/vorburger/xtext-sandbox/tree/master/XtextDocumentBinding (demo video on http://www.youtube.com/watch?v=7RThXRyo3ik).. basically working, except for lists - patches & pull requests most welcome! ;-)

Related

binding devexpress xtrareport EFdatasource at runtime

I'm trying to bind a xtraReport-EFdatasource to a list, i have done this in designer mode quickly using the wizard, but i cant bind its datasource at runtime.
DataSource = Services.CoursesList();
I tryed this code in the report constructor, also in the XtraReport1_DataSourceDemanded event with no luck. the devexpress website show an example using bindingsource, but im using EFdatasource. Can you help me with a code sample please?
I suggest you refer this - How to use Entity Framework with Xtrareports
The best way to accomplish your task is to place your Report class and
Entity objects into a separate class library. In this case, you will
be able to bind the Report to a custom object at design time and
provide data at run time.
To pass data to your Report instance, handle the
XtraReport.DataSourceDemanded event, create your Entity objects,
and pass them to the XtraReport.DataSource property.
More References:
How to use the XtraReport with the Entity Framework

Executing an item in the package as a Dreamweaver Template

Does anybody know if it is possible in a compound template to use a string item in the package and execute it as if were a dreamweaver template? And whether you apply the same method to other mediators (like razor)?
Thanks
Mark
I suspect this is not possible.
Package.EvaluateExpression may be useful, but as the name suggests it'll only work on expressions, not large snippets of code with embedded expressions (i.e. TEL)
Engine.GetMediator expects a Template and returns the appropriate Mediator for it. Your problem then is that the IMediator interface only defines the Transform method, which requires an Engine, a Template and a Package.
I can't think of any elegant ways around these. Maybe write your own Mediator, but that would still expect a Package, not a string, so you'd have to first store the string based Item from another TBB.
My advice: Sounds like you need to go back to the drawing board and find an alternative solution to your problem.
I'm afraid that won't be possible on just any item in the Package, since the Engine expects Templates to be based on Tridion items.
If your Template Item is based on a Tridion Item you can probably get pretty far by starting at the Engine.GetMediator method. If it isn't, you'll have to find some way to turn it into a valid Template object.
Template template = ...
IMediator mediator = engine.GetMediator(template);
mediator.Transform(engine, template, package);
When I have to create a Component object from a Tridion-based Item in the Package, I normally do something like this:
Component component = new Component(item.GetAsXmlDocument().DocumentElement,
engine.GetSession);
I haven't tried, but expect that you can do the same for a Template - given that you start with a valid Item from the Package representing a Template to begin with. You can probably clone the XML from an existing Item or find some other way to fake it.
If you get this to work, it will work across all registered template types. The Engine provides no special treatment for the types that come with Tridion.

What is a good approach to bind an entityproxy to a UI component?

I'm currently working on a GWT project. The thing is, I find very hard to believe that I need to repeat some boilerplate over and over to bind the data from an EntityProxy (say a getSomeData() method) to a UI component (say a TextBox).
How do you guys overcome this issue? For now I have to create a method to read from the TextBox and set it to the EntityProxy, and a method to write to the TextBox after reading from the EntityProxy.
Basically, it's always the same! i.e.:
// Update the text box
T someData = entity.getSomeData();
textBox.setText(someData);
// Update the entity
String value = textBox.getText();
entity.setSomeData(value);
You get my point? I'm aware there is no Reflection at client side. I could use deffered binding but I'm not sure how or if it is a good approach with RequestFactory's EntityProxys.
Thank you
I use the technique you have defined in your question to push and collect data from my controls. Recently I have found out that there is a built-in feature of GWT called Editors. I didn't have a chance to try it myself yet but perhaps you want to check it out it seems promising. Also here is another useful link from Thomas Broyer's blog about Editors

Qt equivalent of .NET data binding?

Is there an equivalent of .NET's data binding in Qt?
I want to populate some combo boxes and other widgets with QStrings that refer to specific entities in my database. However, it would be cleaner if I could bind the data to these strings rather than either querying the database again based off of a new combobox selection or some other scheme based off of building my own index of entities that would be searched with the QStrings.
The best I've come up with is to derive these entities from QString and pushing them into the widgets this way, but I've yet to actually try it. I'm not sure if it will work the way I want it to, and it seems like a nasty hack.
If there is no data binding, what do you suggest?
Thank you.
As the user nonchalant mentioned in a comment you can use the QDataWidgetMapper class.
This is quite an easy way of binding arbitrary widgets to data that is stored in a QAbstractItemModel.
The example on the linked page shows in a few lines of code, how you can link your data model to common used input widgets:
QDataWidgetMapper *mapper = new QDataWidgetMapper;
mapper->setModel(model);
mapper->addMapping(mySpinBox, 0);
mapper->addMapping(myLineEdit, 1);
mapper->addMapping(myCountryChooser, 2);
mapper->toFirst();
One way is using Qt Model/View Classes (with base at QAbstractItemModel), but they need that you widget inherits QAbstractItemView (this is widgets like QTableView etc.).
If you want map Qt model to set of widgets, which haven't nothing common with QAbstractItemView you can use QDataWidgetMapper, which maps separate widget to Qt Model/View indexes. But anyway, as said Aaron Digulla, you must write some boiler plate code...
Well, for combobox specifically, you can set a model. For QObjects in general you can use the notify signal for properties to connect or other non-property related signals. I think there is another way to do it but I can't recall.

XtraGrid doesn't display properly newly added line

I'm using XtraGrid of DevExpress 2.9.5 to display a blotter of dynamic set of lines. The blotter is integrated into another application, this is why it has to be based on UserControl class and also implement a couple of custom interfaces.
public partial class BlotterForm : UserControl, ISMMdiEmbeddable, ISMAssociatedMFCWindow
{
private BindingList<BlotterTrade> fDeals;
....
}
As the data is binded to control using BindedList, any change should be reflected in the form automatically. And if I try to add new line to fDeals like follows:
public void AddDeal()
{
fDeals.Add(new BlotterTrade(1,2,3));
}
... i can see the line, but it's content is rubbish.
I tried to do the same in a small test application. It works ok with only difference that the blotter in test application is based on DevExpress.XtraEditors.XtraForm. To me it looks now that the form of original blotter doesn't overload some method or miss some event. But I cannot find out what exactly is missed.
Can somebody tell me what I do wrong or don't do?
Thanks.
A couple of things:
BindingList doesn't always work too well with DevExpress, and it's suggested to use XPCollection instead.
Do you have any more info about how you setup your columns in the xtragrid? If you use incorrect field names in the column, then they won't show what you're looking for.
If the params you're using (1, 2, 3) are ids stored as fkeys to other objects (not sure if you're using xpo or not) then they won't show up correctly either (there'll likely be a '+' in the cell instead of any values).
[aside] be sure that blottertrade implements INotifyPropertyChanged for better interaction with the grid.
Thanks to everybody for the answers and comments. I think I sorted out the problem. It was actually related to interaction between native C++ and C# layers in my application. The object that was supposed to be displayed in XtraGrid was created in C++ layer, the grid was displayed asynchronously with object construction/deconstruction, that's why at the moment when the grid was ready to display it, the object itself didn't exist. Hence the rubbish. It's good the grid itself was not crashing or firing exceptions.

Resources