Home » Modeling » EMF » Building a UI on EMF - UPDATED(How to extend EMF generated code to add combo boxes, etc.)
Building a UI on EMF - UPDATED [message #1262233] |
Mon, 03 March 2014 11:57 |
Greg Dart Messages: 17 Registered: September 2013 |
Junior Member |
|
|
Update to the below...
If I use this code for my binding
DataBindingContext ctx = new DataBindingContext();
IObservableValue widgetValue = WidgetProperties.selection().observe(cmbSubject);
IObservableValue modelValue = EMFProperties.value(xxxxPackage.Literals.CONTRACT__BUSINESS_PURPOSE).observe(contract);
ctx.bindValue(widgetValue, modelValue);
This kind of works as follows:
When I first create the file it is in the unsaved state. If I change the combo selection and hit save, the combo selection change is included in the underlying XML. However, once the user has hit the save button, any subsequent combo selection changes do not cause the file to appear as "unsaved", so no further changes are recorded.
How do I force the UI to recognise a combo selection change as something that needs saving....?
Thanks,
Greg
--------------
Hi,
I've been working on this project for sometime and have already had some great help from people on this forum. Feel I'm getting close, but still not quite there! I'm a beginner to EMF so your patience with me is much appreciated!
What I'm trying to do is to take the EMF generated code and create my own UI that manipulates the EMF model - ultimately I want a user to be able to create an XML file, according to the EMF model, using my UI interface. GMF is too much, I want to be able to manipulate EMF from a UI of my design.
So I have defined my Ecore model and generated the code. I believe I need to make changes in xxxxxxxEditor.java in order to create my UI. I have added code into createModel() to pre-populate the model with some base elements, using the AddCommand.Create function. This works fine.
Then in createPages() I have added code to create a combo box. This works - in that the combo box appears in the UI and has a list of items. What I want, is that when a user selects an item from that combo box, a corresponding item in the model is changed and the "save" option becomes active (i.e. isDirty), click save then writes the change to the underlying XML file (as per the additional items I added in createModel). I am trying to do this via EMF-JFace data-binding. I have read all the tutorials (Vogella, Koegel, Tomsondev, etc) and many forum posts.
The code below runs without error... but does nothing... Any hints, tips, help, much appreciated...
Thanks,
Greg
DataBindingContext ctx = new DataBindingContext();
IViewerObservableValue widgetValue = ViewersObservables.observeSingleSelection(cmbSubjectViewer);
IObservableValue modelValue = EMFProperties.value(ContractSpecEditorPackage.Literals.NODE__NAME).observe(subject);
ctx.bindValue(widgetValue, modelValue);
cmbSubjectViewer is...
cmbSubjectViewer = new ComboViewer(cmbSubject);
setCurrentViewer(cmbSubjectViewer);
My EMF model includes a Subject element, it extends NODE. NODE__Name is an attribute of Node.
The variable "subject" above is a global (protected) variable I declare in xxxxEditor.java and initialise in createModel() thus:
subject = xxxxxxxxFactory.eINSTANCE.createSubject();
What am I doing wrong.....!
[Updated on: Mon, 03 March 2014 19:36] Report message to a moderator
|
|
|
Re: Building a UI on EMF [message #1263335 is a reply to message #1262233] |
Tue, 04 March 2014 11:37 |
Christophe Bouhier Messages: 937 Registered: July 2009 |
Senior Member |
|
|
Hi Greg,
See below.
On 03-03-14 12:57, Greg Dart wrote:
> Hi,
>
> I've been working on this project for sometime and have already had some
> great help from people on this forum. Feel I'm getting close, but still
> not quite there! I'm a beginner to EMF so your patience with me is much
> appreciated!
>
> What I'm trying to do is to take the EMF generated code and create my
> own UI that manipulates the EMF model - ultimately I want a user to be
> able to create an XML file, according to the EMF model, using my UI
> interface. GMF is too much, I want to be able to manipulate EMF from a
> UI of my design.
>
> So I have defined my Ecore model and generated the code. I believe I
> need to make changes in xxxxxxxEditor.java in order to create my UI. I
> have added code into createModel() to pre-populate the model with some
> base elements, using the AddCommand.Create function. This works fine.
>
> Then in createPages() I have added code to create a combo box. This
> works - in that the combo box appears in the UI and has a list of items.
> What I want, is that when a user selects an item from that combo box, a
> corresponding item in the model is changed and the "save" option becomes
> active (i.e. isDirty), click save then writes the change to the
> underlying XML file (as per the additional items I added in
> createModel). I am trying to do this via EMF-JFace data-binding. I have
> read all the tutorials (Vogella, Koegel, Tomsondev, etc) and many forum
> posts.
>
> The code below runs without error... but does nothing... Any hints,
> tips, help, much appreciated...
> Thanks,
> Greg
>
>
>
> DataBindingContext ctx = new DataBindingContext();
Perhaps use an EMFDatabindingContext
> IViewerObservableValue widgetValue =
> ViewersObservables.observeSingleSelection(cmbSubjectViewer);
>
> IObservableValue modelValue =
> EMFProperties.value(ContractSpecEditorPackage.Literals.NODE__NAME).observe(subject);
>
I would recommend an 'EMFEditProperties' variant, as the requrired
editing domain, will execute a command on the command stack which will
notify your viewpart that it's dirty enabling the save button.
>
> ctx.bindValue(widgetValue, modelValue);
Apparently you don't need object type conversion (Your EAttribute is of
type String?).
>
>
>
> cmbSubjectViewer is...
>
>
> cmbSubjectViewer = new ComboViewer(cmbSubject);
> setCurrentViewer(cmbSubjectViewer);
you don;t show how the combo is populated, but I guess you put the
subject object in there....
>
>
> My EMF model includes a Subject element, it extends NODE. NODE__Name is
> an attribute of Node.
>
> The variable "subject" above is a global (protected) variable I declare
> in xxxxEditor.java and initialise in createModel() thus:
>
>
> subject = xxxxxxxxFactory.eINSTANCE.createSubject();
mmmh... where is this object contained?
>
>
> What am I doing wrong.....!
>
|
|
| | |
Goto Forum:
Current Time: Sat Apr 27 01:57:17 GMT 2024
Powered by FUDForum. Page generated in 0.02961 seconds
|