Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Building a UI on EMF - UPDATED(How to extend EMF generated code to add combo boxes, etc.)
icon5.gif  Building a UI on EMF - UPDATED [message #1262233] Mon, 03 March 2014 11:57 Go to next message
Greg Dart is currently offline Greg DartFriend
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 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
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.....!
>
icon7.gif  Re: Building a UI on EMF - UPDATED - RESOLVED [message #1264887 is a reply to message #1262233] Wed, 05 March 2014 15:30 Go to previous messageGo to next message
Greg Dart is currently offline Greg DartFriend
Messages: 17
Registered: September 2013
Junior Member
Christophe,

You star! Thanks very much, that resolved it - in particular using the EMFEditProperties to pull in the editingDomain resolved the issue of the change not being picked up. Obvious now with hindsight, but I didn't even know it existed.

Thanks again,
Greg
Re: Building a UI on EMF - UPDATED - RESOLVED [message #1265694 is a reply to message #1264887] Thu, 06 March 2014 12:34 Go to previous message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 05-03-14 16:30, Greg Dart wrote:
> Christophe,
>
> You star! Thanks very much, that resolved it - in particular using the
> EMFEditProperties to pull in the editingDomain resolved the issue of the
> change not being picked up. Obvious now with hindsight, but I didn't
> even know it existed.
I think it's discussed here:

http://tomsondev.bestsolution.at/2009/06/06/galileo-emf-databinding-part-1/

>
> Thanks again,
> Greg
Previous Topic:Creating a new plugin EMF
Next Topic:CDO Revisions not Persisting in HSQLDB
Goto Forum:
  


Current Time: Sat Apr 27 01:57:17 GMT 2024

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

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

Back to the top