Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EditingSupport and EditingDomain
EditingSupport and EditingDomain [message #1248977] Mon, 17 February 2014 21:22 Go to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Hello,

I have implemented a UI which shows various structural features of an underlying EMF model. There is a table viewer in this UI to be able to edit these features. After initializing the data binding based on EMF, I have implemented the cell editors for the table viewer's specific column that shows the values of the selected attributes.

I call this specific editing support class of mine, which overrides the getValue() and setValue() methods, from the view as follows:

tableViewerColumn.setEditingSupport(new MyEditingSupport(tableViewer));


The editing works so far good, but there are two issues:

1.) The other editors (one being a tree viewer in the same implemented UI view and other e.g. the reflective Ecore editor) are not getting dirty, even though the table editors columns show the changed values after giving the new values of the attributes. So the save options of the Eclipse are not being activated.

2.) I also want to add the support for Undo/Redo by implementing the EditingDomain. But I don't exactly know how to combine these two aspects, the EditingSupport for JFace and the EditingDomain for EMF. Alone getting the EditingDomain doesn't work. I guess I need to implement the functions of my EditingSupport methods as Actions which I then register into the EditingDomain. Or is there a simpler way two let these two aspects interact together?

Every help will be appreciated, thanks a lot!
Re: EditingSupport and EditingDomain [message #1249267 is a reply to message #1248977] Tue, 18 February 2014 04:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30679
Registered: July 2009
Senior Member
On 17/02/2014 10:22 PM, Emre T wrote:
> Hello,
> I have implemented a UI which shows various structural features of an
> underlying EMF model. There is a table viewer in this UI to be able to
> edit these features. After initializing the data binding based on EMF,
> I have implemented the cell editors for the table viewer's specific
> column that shows the values of the selected attributes.
>
> I call this specific editing support class of mine, which overrides
> the getValue() and setValue() methods, from the view as follows:
>
> tableViewerColumn.setEditingSupport(new MyEditingSupport(tableViewer));
>
> The editing works so far good, but there are two issues:
>
> 1.) The other editors (one being a tree viewer in the same implemented
> UI view and other e.g. the reflective Ecore editor) are not getting
> dirty, even though the table editors columns show the changed values
> after giving the new values of the attributes. So the save options of
> the Eclipse are not being activated.
Are you using org.eclipse.emf.databinding.edit.EMFEditObservables or
org.eclipse.emf.databinding.edit.EMFEditProperties?
>
> 2.) I also want to add the support for Undo/Redo by implementing the
> EditingDomain. But I don't exactly know how to combine these two
> aspects, the EditingSupport for JFace and the EditingDomain for EMF.
All changes to the model must be done via commands executed on the
editing domain's command stack.
> Alone getting the EditingDomain doesn't work. I guess I need to
> implement the functions of my EditingSupport methods as Actions which
> I then register into the EditingDomain. Or is there a simpler way two
> let these two aspects interact together?
You said you use data binding, but it's not clear how. Generally I'd
expect your cell editor to do something like what you see in
org.eclipse.emf.edit.provider.ItemPropertyDescriptor.setPropertyValue(Object,
Object), though your case is probably simpler because you know exactly
which feature of which type of object you're editing.
>
> Every help will be appreciated, thanks a lot!
>
Re: EditingSupport and EditingDomain [message #1249626 is a reply to message #1249267] Tue, 18 February 2014 12:59 Go to previous messageGo to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Hello Ed, thanks for the quick reply.

I am using EMFProperties at the detail-part. Like this:

IObservableValue value = EMFProperties.value(attribute).observeDetail(view.getMaster());


I have implemented the setValue()-method in my MyEditingSupport as follows:

EAttribute attr = (EAttribute) ((IEMFObservable) element).getStructuralFeature();
Object obj = ((EObject) ((IEMFObservable) element).getObserved()).eGet(attr);
if (obj instanceof String)
((EObject) ((IEMFObservable) element).getObserved()).eSet(attr, value);


And no, I don't know at compile time exactly, what features my UI needs to show and can be edited. I observe them and collect them into a list as a master, which later is put into the table viewer as Input.

Best regards,
Emre
Re: EditingSupport and EditingDomain [message #1249658 is a reply to message #1249626] Tue, 18 February 2014 13:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30679
Registered: July 2009
Senior Member
Emre,

Comments below.

On 18/02/2014 1:59 PM, Emre T wrote:
> Hello Ed, thanks for the quick reply.
> I am using EMFProperties at the detail-part. Like this:
>
> IObservableValue value =
> EMFProperties.value(attribute).observeDetail(view.getMaster());
Didn't I suggest you use EMFEditProperties?
>
> I have implemented the setValue()-method in my MyEditingSupport as
> follows:
>
>
> EAttribute attr = (EAttribute) ((IEMFObservable)
> element).getStructuralFeature();
> Object obj = ((EObject) ((IEMFObservable)
> element).getObserved()).eGet(attr);
> if (obj instanceof String)
> ((EObject) ((IEMFObservable) element).getObserved()).eSet(attr, value);
This has to be done with a command. Did you look at
org.eclipse.emf.edit.provider.ItemPropertyDescriptor.setPropertyValue(Object,
Object)?

I also get the sense that this is all overly complex, bypassing what
data binding should be doing for you. I.e., shouldn't you just be using
org.eclipse.core.databinding.property.value.IValueProperty.setValue(Object,
Object)?
>
> And no, I don't know at compile time exactly, what features my UI
> needs to show and can be edited. I observe them and collect them into
> a list as a master, which later is put into the table viewer as Input.
>
> Best regards,
> Emre
>
Re: EditingSupport and EditingDomain [message #1249668 is a reply to message #1249658] Tue, 18 February 2014 13:56 Go to previous messageGo to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Hello Ed,

yes, indeed you have. And I have changed the line to the following:

IObservableValue value = EMFEditProperties.value(editingDomain, attribute).observeDetail(view.getMaster());


Where I try to get the editingDomain like this:
	private EditingDomain editingDomain;
	
	public void setActivePart(IAction action, IWorkbenchPart workbenchPart) {
	    if (workbenchPart instanceof IEditingDomainProvider) {
	        editingDomain = ((IEditingDomainProvider) workbenchPart).getEditingDomain();
	    }
	}


Though it is a null. First I just wanted to test, whether EMFEditProperties would work my approach, but of course now I need to provide a real EditingDomain instance.

Furthermore I don't understand what you mean by "I also get the sense that this is all overly complex, bypassing what
data binding should be doing for you. I.e., shouldn't you just be using
org.eclipse.core.databinding.property.value.IValueProperty.setValue(Object,
Object)?"

Is my databinding somehow wrong? I need to use the IObservableValue which is my master from a listened treeviewer.

Thanks again.

Emre

[Updated on: Tue, 18 February 2014 13:59]

Report message to a moderator

Re: EditingSupport and EditingDomain [message #1249670 is a reply to message #1248977] Tue, 18 February 2014 13:56 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 17-02-14 22:22, Emre T wrote:
> Hello,
> I have implemented a UI which shows various structural features of an
> underlying EMF model. There is a table viewer in this UI to be able to
> edit these features. After initializing the data binding based on EMF, I
> have implemented the cell editors for the table viewer's specific column
> that shows the values of the selected attributes.
>
> I call this specific editing support class of mine, which overrides the
> getValue() and setValue() methods, from the view as follows:
>
> tableViewerColumn.setEditingSupport(new MyEditingSupport(tableViewer));
>
> The editing works so far good, but there are two issues:
>
> 1.) The other editors (one being a tree viewer in the same implemented
> UI view and other e.g. the reflective Ecore editor) are not getting
> dirty, even though the table editors columns show the changed values
> after giving the new values of the attributes. So the save options of
> the Eclipse are not being activated.
Typically various editors will have their own editing domain, so will
not know about a dirty command stack. (Which triggers the dirtyness of
the Editor for ISaveablePart2).
>
> 2.) I also want to add the support for Undo/Redo by implementing the
> EditingDomain. But I don't exactly know how to combine these two
> aspects, the EditingSupport for JFace and the EditingDomain for EMF.
> Alone getting the EditingDomain doesn't work. I guess I need to
> implement the functions of my EditingSupport methods as Actions which I
> then register into the EditingDomain. Or is there a simpler way two let
> these two aspects interact together?
You said you implemented EditingSupport get/setValue() but how?

What I do is update the viewer (viewer.update(element,value). because
the viewer is bound with EMFDatabinding, the
change is applied. (Note EMF Databinding has two options, with or
without EditingDomain. You should use the one which includes
EditingDOmain).


>
> Every help will be appreciated, thanks a lot!
>
Re: EditingSupport and EditingDomain [message #1249683 is a reply to message #1249670] Tue, 18 February 2014 14:12 Go to previous messageGo to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Hello,

Christophe Bouhier wrote on Tue, 18 February 2014 08:56

Typically various editors will have their own editing domain, so will
not know about a dirty command stack. (Which triggers the dirtyness of
the Editor for ISaveablePart2).


Oh, so the dirtyness must be implemented using the ISaveablePart2 in the UI? The databinding actually happens in my UI, which has a treeviewer(master) and a tableeditor(detail). That my UI implements the ISaveablePart2 was going to be one of my futere tasks. But I guess, I will be doing it sooner.

Christophe Bouhier wrote on Tue, 18 February 2014 08:56


You said you implemented EditingSupport get/setValue() but how?

What I do is update the viewer (viewer.update(element,value). because
the viewer is bound with EMFDatabinding, the
change is applied. (Note EMF Databinding has two options, with or
without EditingDomain. You should use the one which includes
EditingDOmain).


I have implemented the getValue and setValue as follows:

	@Override
	protected Object getValue(Object element) {

	EAttribute attr = (EAttribute) ((IEMFObservable) element).getStructuralFeature();
        Object obj = ((EObject) ((IEMFObservable) element).getObserved()).eGet(attr);
	return obj.toString();
	}


and

	@Override
	protected void setValue(Object element, Object value) {
		EAttribute attr = (EAttribute) ((IEMFObservable) element).getStructuralFeature();
	        Object obj = ((EObject) ((IEMFObservable) element).getObserved()).eGet(attr);
	        if (obj instanceof String) {
		        ((EObject) ((IEMFObservable) element).getObserved()).eSet(attr, value);
			} else if (obj instanceof Integer) {
		        ((EObject) ((IEMFObservable) element).getObserved()).eSet(attr, Integer.valueOf((String) value));
			} else {
				// for further types
			}
		viewer.update(element, null);
	}


Yes, the update method works. The new values are indeed set. I can see it in the tableeditor and also in the underlying .xmi instance of the model. But I can't save it, the editors (treeviewer from my own UI and the standard ecore editor) are not getting dirty or starred, so that the save option is not active. When I close and reopen the model instance, the changes are then gone.

Best regards,
Emre
Re: EditingSupport and EditingDomain [message #1249699 is a reply to message #1249683] Tue, 18 February 2014 14:31 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 18-02-14 15:12, Emre T wrote:
> Hello,
>
> Christophe Bouhier wrote on Tue, 18 February 2014 08:56
>> Typically various editors will have their own editing domain, so will
>> not know about a dirty command stack. (Which triggers the dirtyness of
>> the Editor for ISaveablePart2).
>
>
> Oh, so the dirtyness must be implemented using the ISaveablePart2 in the
> UI? The databinding actually happens in my UI, which has a
> treeviewer(master) and a tableeditor(detail). That my UI implements the
> ISaveablePart2 was going to be one of my futere tasks. But I guess, I
> will be doing it sooner.
>
I don't know about the containers (Parts) for your viewers, is
IEditorPart or IViewerPart or...? and are there multiple? Perhaps each
with their own EditingDOmain?

IEditorPart implements ISaveablePart which is what the default generated
EMF editor uses...You shouldn't need to do anything here.

If you put your viewers in an IViewerPart, you would need explicitly
implement the ISavablePart (or ISavablePart2). Simply look at the
generated EMF editor, you can see how it's done. (The command stack
listener is the interresting bit, it fires a propertychange ).


> Christophe Bouhier wrote on Tue, 18 February 2014 08:56
>> You said you implemented EditingSupport get/setValue() but how?
>>
>> What I do is update the viewer (viewer.update(element,value). because
>> the viewer is bound with EMFDatabinding, the
>> change is applied. (Note EMF Databinding has two options, with or
>> without EditingDomain. You should use the one which includes
>> EditingDOmain).
>
>
> I have implemented the getValue and setValue as follows:
>
> @Override
> protected Object getValue(Object element) {
>
> EAttribute attr = (EAttribute) ((IEMFObservable)
> element).getStructuralFeature();
> Object obj = ((EObject) ((IEMFObservable)
> element).getObserved()).eGet(attr);
> return obj.toString();
> }
>
> and
>
> @Override
> protected void setValue(Object element, Object value) {
> EAttribute attr = (EAttribute) ((IEMFObservable)
> element).getStructuralFeature();
> Object obj = ((EObject) ((IEMFObservable)
> element).getObserved()).eGet(attr);
> if (obj instanceof String) {
> ((EObject) ((IEMFObservable)
> element).getObserved()).eSet(attr, value);
> } else if (obj instanceof Integer) {
> ((EObject) ((IEMFObservable)
> element).getObserved()).eSet(attr, Integer.valueOf((String) value));
> } else {
> // for further types
> }
> viewer.update(element, null);
> }
>
> Yes, the update method works. The new values are indeed set. I can see
> it in the tableeditor and also in the underlying .xmi instance of the
> model. But I can't save it, the editors (treeviewer from my own UI and
> the standard ecore editor) are not getting dirty or starred, so that the
> save option is not active.
When I close and reopen the model instance,
> the changes are then gone.
>
> Best regards,
> Emre
>
Re: EditingSupport and EditingDomain [message #1249711 is a reply to message #1249699] Tue, 18 February 2014 14:46 Go to previous messageGo to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
My UI extends the ViewPart and in createPartControl() I initialize my tree and table viewer. So I need to implement ISaveablePart2 implicitly, right?

What about the Undo/Redo functionality? How can I integrate my EditingSupport with the EditingDomain, so the actions made in getValue/setValue() methods bevome undoalbe/redoable? Any tips regarding this?

Best regards,
Emre
Re: EditingSupport and EditingDomain [message #1249724 is a reply to message #1249711] Tue, 18 February 2014 15:04 Go to previous message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 18-02-14 15:46, Emre T wrote:
> My UI extends the ViewPart and in createPartControl() I initialize my
> tree and table viewer. So I need to implement ISaveablePart2 implicitly,
> right?

Yes it seems.

>
> What about the Undo/Redo functionality? How can I integrate my
> EditingSupport with the EditingDomain, so the actions made in
> getValue/setValue() methods bevome undoalbe/redoable? Any tips regarding
> this?

When your viewer is bound with an EditingDomain. (Your observable uses
EMFEditProperties as Ed explained), then simply updating the value in
the viewer should let the observable use a command on the editing domain
command stack, hence making it dirty, undoable etc..

But, as you use a ViewPart, I don't know how the EMF Edit Actions are
tight to this ViewPart, which they need to be. Have a look at i.e. the
UndoAction, the part should implement IEditingDomainProvider so it can
deal with the cmmand stack.

Basically, your challenge is to replicate the stuff generated by EMF on
an IEditorPart with a ViewPart. A ViewPart has no
EditorActionBarContributor which EMF extends, so you need to work harder
for this.

As an alternative, you could work directly on e4. EMF doesn't generate
pure e4 code, but there is an example which could prove useful here:

https://github.com/dzonekl/e4mf

Cheers Christophe

>
> Best regards,
> Emre
Previous Topic:[cdo] how several CDO transactions can commit their changes using one durable view?
Next Topic:[Xcore] problems with "Converting a GenModel to an Xcore Model"
Goto Forum:
  


Current Time: Thu Dec 05 18:02:29 GMT 2019

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

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

Back to the top