Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF databinding + undo/redo
EMF databinding + undo/redo [message #426739] Mon, 19 January 2009 21:40 Go to next message
Kai Schlamp is currently offline Kai SchlampFriend
Messages: 344
Registered: July 2009
Senior Member
Hello.

Inspired by the Blog entry "Eclipse Databinding + Validation +
Decoration" (http://toedter.com/blog/?p=36), I wanted to have this for
all my views and dialogs of my RCP application, as I already use EMF for
my models cause of the CDO support.
But let's assume a dialog with an "Ok" and "Cancel" button. When the
user presses the "Cancel" button all modifications to the model have to
be undone.
So I looked further how to solve this problem an came over the EMF Edit
framework and especially the "Datacentric RCP Applications" presentation
by Tom Schindl.
( https://www.gpublication.com/eclipse/#requestedContent=conte ntID://EclipseConferences/ESE2008/48).
This also has the advantage of full undo/redo support that I like to
have in one of my views.
But even after reading this and looking through many newsgroup messages,
there are still many questions open.

Tom has the following code in his presentation:

Text widget = new Text(parent,SWT.BORDER)
IObservableValue uiObs = SWTObservables.observeText(widget,SWT.Modify);
Person p = getPersons();
EditingDomain domain = getEditingDomain();
EStructuralFeature feature = MyPackage.Literals.SURNAME;
IObservableValue mObs = EMFEditObservables.observeValue(domain,p,feature);
EMFDatabindingContext dbc = new EMFDataBindingContext();
dbc.bind(uiObs,mObs,null,null);

But where does the EditingDomain come from?

Do I have to create it myself like on Tom's "Setting up an EditingDomain
by hand" slide?:

ResourceSet set = new ResourceSetImpl();
set.getPackageRegistry().put(MyPackage.eNS_URI,MyPackage.eIN STANCE);
ComposedAdapterFactory af = new ComposedAdapterFactory(
ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
BasicCommandStack cs = new BasicCommandStack();
AdapterFactoryEditingDomain ed = new AdapterFactoryEditingDomain(af, cs,
set);
Resource res = resourceSet.getResource(....);

And how do I undo all changes from a specific point?
For example ... I pass a "Person" eObject to a dialog that edits the
already set "age" and "name" attributes.
How do I undo all the changes that where done by that dialog when the
user presses "Cancel"?
Get the CommandStack und use undo() method as long as it canUndo()? So
do I have to create a new CommandStack for every Dialog (I think so)? By
creating a new EditingDomain for every dialog, right?
And when I use this Edit Framework, do I have to "Generate Edit Code" of
my GenModel. And if yes, where do I have to use those generated providers?
I hope that someone can enlighten me a bit ... this undo/redo task seems
to be quite complex to me.

Kai
Re: EMF databinding + undo/redo [message #426742 is a reply to message #426739] Mon, 19 January 2009 21:59 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi Kai,

Kai Schlamp schrieb:
> Hello.
>
> Inspired by the Blog entry "Eclipse Databinding + Validation +
> Decoration" (http://toedter.com/blog/?p=36), I wanted to have this for
> all my views and dialogs of my RCP application, as I already use EMF for
> my models cause of the CDO support.
> But let's assume a dialog with an "Ok" and "Cancel" button. When the
> user presses the "Cancel" button all modifications to the model have to
> be undone.
> So I looked further how to solve this problem an came over the EMF Edit
> framework and especially the "Datacentric RCP Applications" presentation
> by Tom Schindl.
> ( https://www.gpublication.com/eclipse/#requestedContent=conte ntID://EclipseConferences/ESE2008/48).
> This also has the advantage of full undo/redo support that I like to
> have in one of my views.
> But even after reading this and looking through many newsgroup messages,
> there are still many questions open.
>
> Tom has the following code in his presentation:
>
> Text widget = new Text(parent,SWT.BORDER)
> IObservableValue uiObs = SWTObservables.observeText(widget,SWT.Modify);
> Person p = getPersons();
> EditingDomain domain = getEditingDomain();
> EStructuralFeature feature = MyPackage.Literals.SURNAME;
> IObservableValue mObs = EMFEditObservables.observeValue(domain,p,feature);
> EMFDatabindingContext dbc = new EMFDataBindingContext();
> dbc.bind(uiObs,mObs,null,null);
>
> But where does the EditingDomain come from?

If you browse my example code you'll see that you'll have to create it
your own [2] :-)

>
> Do I have to create it myself like on Tom's "Setting up an EditingDomain
> by hand" slide?:
>
> ResourceSet set = new ResourceSetImpl();
> set.getPackageRegistry().put(MyPackage.eNS_URI,MyPackage.eIN STANCE);
> ComposedAdapterFactory af = new ComposedAdapterFactory(
> ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
> BasicCommandStack cs = new BasicCommandStack();
> AdapterFactoryEditingDomain ed = new AdapterFactoryEditingDomain(af, cs,
> set);
> Resource res = resourceSet.getResource(....);
>
> And how do I undo all changes from a specific point?

Well undo/redo is done with the CommandStack. Take a look at my example
code (referenced from the slides [1]) [3] it does exactly what you want.
Opening a dialog and undo all changes if cancel is pressed.

Another possibility is to use IPolicy.ON_REQUEST for your bindings so
and only update your model on press of OK.

> For example ... I pass a "Person" eObject to a dialog that edits the
> already set "age" and "name" attributes.
> How do I undo all the changes that where done by that dialog when the
> user presses "Cancel"?
> Get the CommandStack und use undo() method as long as it canUndo()? So
> do I have to create a new CommandStack for every Dialog (I think so)? By
> creating a new EditingDomain for every dialog, right?

Yes see above but not necessarily until you canUndo doesn't return any
more because if your model was already dirty before you'll undo too many
things :-) I already thought about wrapping this and providing a command
stack which allows to set an SQL-Like Savepoint where you can rollback to.

> And when I use this Edit Framework, do I have to "Generate Edit Code" of
> my GenModel. And if yes, where do I have to use those generated providers?
> I hope that someone can enlighten me a bit ... this undo/redo task seems
> to be quite complex to me.
>

I'm not using any generated editing code in my example but all is coded
by hand.

> Kai

Tom

[1] https://www.gpublication.com/eclipse/#requestedContent=conte ntID://EclipseConferences/ESE2008/48
[2] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/
[3] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/at.bestsolution.soccer.ui.playeradmin/src/at/bestso lution/soccer/ui/playeradmin/command/EditPlayerCommandHandle r.java


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: EMF databinding + undo/redo [message #426744 is a reply to message #426742] Mon, 19 January 2009 22:03 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
By the way its quite likely that my UFaceKit-Project [1] will provide
such an undo/redo feature for EMF-Based-Model-Objects without the need
to understand how all this works internally but wrapped in a very
simplistic API :-)

Tom

[1]http://wiki.eclipse.org/UFaceKit

Tom Schindl schrieb:
> Hi Kai,
>
> Kai Schlamp schrieb:
>> Hello.
>>
>> Inspired by the Blog entry "Eclipse Databinding + Validation +
>> Decoration" (http://toedter.com/blog/?p=36), I wanted to have this for
>> all my views and dialogs of my RCP application, as I already use EMF for
>> my models cause of the CDO support.
>> But let's assume a dialog with an "Ok" and "Cancel" button. When the
>> user presses the "Cancel" button all modifications to the model have to
>> be undone.
>> So I looked further how to solve this problem an came over the EMF Edit
>> framework and especially the "Datacentric RCP Applications" presentation
>> by Tom Schindl.
>> ( https://www.gpublication.com/eclipse/#requestedContent=conte ntID://EclipseConferences/ESE2008/48).
>> This also has the advantage of full undo/redo support that I like to
>> have in one of my views.
>> But even after reading this and looking through many newsgroup messages,
>> there are still many questions open.
>>
>> Tom has the following code in his presentation:
>>
>> Text widget = new Text(parent,SWT.BORDER)
>> IObservableValue uiObs = SWTObservables.observeText(widget,SWT.Modify);
>> Person p = getPersons();
>> EditingDomain domain = getEditingDomain();
>> EStructuralFeature feature = MyPackage.Literals.SURNAME;
>> IObservableValue mObs = EMFEditObservables.observeValue(domain,p,feature);
>> EMFDatabindingContext dbc = new EMFDataBindingContext();
>> dbc.bind(uiObs,mObs,null,null);
>>
>> But where does the EditingDomain come from?
>
> If you browse my example code you'll see that you'll have to create it
> your own [2] :-)
>
>> Do I have to create it myself like on Tom's "Setting up an EditingDomain
>> by hand" slide?:
>>
>> ResourceSet set = new ResourceSetImpl();
>> set.getPackageRegistry().put(MyPackage.eNS_URI,MyPackage.eIN STANCE);
>> ComposedAdapterFactory af = new ComposedAdapterFactory(
>> ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
>> BasicCommandStack cs = new BasicCommandStack();
>> AdapterFactoryEditingDomain ed = new AdapterFactoryEditingDomain(af, cs,
>> set);
>> Resource res = resourceSet.getResource(....);
>>
>> And how do I undo all changes from a specific point?
>
> Well undo/redo is done with the CommandStack. Take a look at my example
> code (referenced from the slides [1]) [3] it does exactly what you want.
> Opening a dialog and undo all changes if cancel is pressed.
>
> Another possibility is to use IPolicy.ON_REQUEST for your bindings so
> and only update your model on press of OK.
>
>> For example ... I pass a "Person" eObject to a dialog that edits the
>> already set "age" and "name" attributes.
>> How do I undo all the changes that where done by that dialog when the
>> user presses "Cancel"?
>> Get the CommandStack und use undo() method as long as it canUndo()? So
>> do I have to create a new CommandStack for every Dialog (I think so)? By
>> creating a new EditingDomain for every dialog, right?
>
> Yes see above but not necessarily until you canUndo doesn't return any
> more because if your model was already dirty before you'll undo too many
> things :-) I already thought about wrapping this and providing a command
> stack which allows to set an SQL-Like Savepoint where you can rollback to.
>
>> And when I use this Edit Framework, do I have to "Generate Edit Code" of
>> my GenModel. And if yes, where do I have to use those generated providers?
>> I hope that someone can enlighten me a bit ... this undo/redo task seems
>> to be quite complex to me.
>>
>
> I'm not using any generated editing code in my example but all is coded
> by hand.
>
>> Kai
>
> Tom
>
> [1] https://www.gpublication.com/eclipse/#requestedContent=conte ntID://EclipseConferences/ESE2008/48
> [2] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/
> [3] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/at.bestsolution.soccer.ui.playeradmin/src/at/bestso lution/soccer/ui/playeradmin/command/EditPlayerCommandHandle r.java
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: EMF databinding + undo/redo [message #426787 is a reply to message #426742] Tue, 20 January 2009 15:33 Go to previous messageGo to next message
Kai Schlamp is currently offline Kai SchlampFriend
Messages: 344
Registered: July 2009
Senior Member
Thanks for all those explanations, Tom. I think for my dialogs I stick
to the ON_REQUEST or better CONVERT policy (as I can still validate the
input then) of the databinding framework, and only use the undo/redo
functionality for the view that really needs this.

I just looked at the source code of your application, as I wanted to
find out what the best place is to create the EditingDomain.

In your code it seems to happen in the initializeEditingDomain() method
of the PersistanceServicesRegistry class.

ComposedAdapterFactory adapterFactory = new
ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Reg istry.INSTANCE);
adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
// adapterFactory.addAdapterFactory(new
SoccerItemProviderAdapterFactory());
adapterFactory.addAdapterFactory(new
ReflectiveItemProviderAdapterFactory());

The last three lines (.*addAdapterFactory.*) are not mentioned in your
presentation. Are those required? Why did you comment the second line
(the one with SoccerItemProviderAdapterFactory) out?

Kai



Tom Schindl schrieb:
> Hi Kai,
>
> Kai Schlamp schrieb:
>> Hello.
>>
>> Inspired by the Blog entry "Eclipse Databinding + Validation +
>> Decoration" (http://toedter.com/blog/?p=36), I wanted to have this for
>> all my views and dialogs of my RCP application, as I already use EMF for
>> my models cause of the CDO support.
>> But let's assume a dialog with an "Ok" and "Cancel" button. When the
>> user presses the "Cancel" button all modifications to the model have to
>> be undone.
>> So I looked further how to solve this problem an came over the EMF Edit
>> framework and especially the "Datacentric RCP Applications" presentation
>> by Tom Schindl.
>> ( https://www.gpublication.com/eclipse/#requestedContent=conte ntID://EclipseConferences/ESE2008/48).
>> This also has the advantage of full undo/redo support that I like to
>> have in one of my views.
>> But even after reading this and looking through many newsgroup messages,
>> there are still many questions open.
>>
>> Tom has the following code in his presentation:
>>
>> Text widget = new Text(parent,SWT.BORDER)
>> IObservableValue uiObs = SWTObservables.observeText(widget,SWT.Modify);
>> Person p = getPersons();
>> EditingDomain domain = getEditingDomain();
>> EStructuralFeature feature = MyPackage.Literals.SURNAME;
>> IObservableValue mObs = EMFEditObservables.observeValue(domain,p,feature);
>> EMFDatabindingContext dbc = new EMFDataBindingContext();
>> dbc.bind(uiObs,mObs,null,null);
>>
>> But where does the EditingDomain come from?
>
> If you browse my example code you'll see that you'll have to create it
> your own [2] :-)
>
>> Do I have to create it myself like on Tom's "Setting up an EditingDomain
>> by hand" slide?:
>>
>> ResourceSet set = new ResourceSetImpl();
>> set.getPackageRegistry().put(MyPackage.eNS_URI,MyPackage.eIN STANCE);
>> ComposedAdapterFactory af = new ComposedAdapterFactory(
>> ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
>> BasicCommandStack cs = new BasicCommandStack();
>> AdapterFactoryEditingDomain ed = new AdapterFactoryEditingDomain(af, cs,
>> set);
>> Resource res = resourceSet.getResource(....);
>>
>> And how do I undo all changes from a specific point?
>
> Well undo/redo is done with the CommandStack. Take a look at my example
> code (referenced from the slides [1]) [3] it does exactly what you want.
> Opening a dialog and undo all changes if cancel is pressed.
>
> Another possibility is to use IPolicy.ON_REQUEST for your bindings so
> and only update your model on press of OK.
>
>> For example ... I pass a "Person" eObject to a dialog that edits the
>> already set "age" and "name" attributes.
>> How do I undo all the changes that where done by that dialog when the
>> user presses "Cancel"?
>> Get the CommandStack und use undo() method as long as it canUndo()? So
>> do I have to create a new CommandStack for every Dialog (I think so)? By
>> creating a new EditingDomain for every dialog, right?
>
> Yes see above but not necessarily until you canUndo doesn't return any
> more because if your model was already dirty before you'll undo too many
> things :-) I already thought about wrapping this and providing a command
> stack which allows to set an SQL-Like Savepoint where you can rollback to.
>
>> And when I use this Edit Framework, do I have to "Generate Edit Code" of
>> my GenModel. And if yes, where do I have to use those generated providers?
>> I hope that someone can enlighten me a bit ... this undo/redo task seems
>> to be quite complex to me.
>>
>
> I'm not using any generated editing code in my example but all is coded
> by hand.
>
>> Kai
>
> Tom
>
> [1] https://www.gpublication.com/eclipse/#requestedContent=conte ntID://EclipseConferences/ESE2008/48
> [2] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/
> [3] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/at.bestsolution.soccer.ui.playeradmin/src/at/bestso lution/soccer/ui/playeradmin/command/EditPlayerCommandHandle r.java
>
>
Re: EMF databinding + undo/redo [message #426790 is a reply to message #426744] Tue, 20 January 2009 15:50 Go to previous messageGo to next message
Kai Schlamp is currently offline Kai SchlampFriend
Messages: 344
Registered: July 2009
Senior Member
Tom Schindl schrieb:
> By the way its quite likely that my UFaceKit-Project [1] will provide
> such an undo/redo feature for EMF-Based-Model-Objects without the need
> to understand how all this works internally but wrapped in a very
> simplistic API :-)

Simplistic sounds great ;-)

I wonder a bit why to bother with EditingDomains, AdapterFactories and
so on.
Wouldn't something like an improved ChangeRecorder do the trick?

I am thinking of something like:

UndoRecorder recorder = new UndoRecorder(Person);
recorder.beginRecording();
// do something with EObject Person
recorder.endRecording();

And now (or even before the recording ended) use some methods like:
recorder.undo();
recorder.redo();
recorder.undoAll();
recorder.redoAll();

But perhaps I am thinking a bit too simplistic. Or does this work with
the current ChangeRecorder implementation without extending it much?

Kai
Re: EMF databinding + undo/redo [message #426792 is a reply to message #426790] Tue, 20 January 2009 16:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Kai,

The change recorder has applyAndReverse for undo/redo support. There's
also ChangeCommand which is based on using it...


Kai Schlamp wrote:
> Tom Schindl schrieb:
>> By the way its quite likely that my UFaceKit-Project [1] will provide
>> such an undo/redo feature for EMF-Based-Model-Objects without the need
>> to understand how all this works internally but wrapped in a very
>> simplistic API :-)
>
> Simplistic sounds great ;-)
>
> I wonder a bit why to bother with EditingDomains, AdapterFactories and
> so on.
> Wouldn't something like an improved ChangeRecorder do the trick?
>
> I am thinking of something like:
>
> UndoRecorder recorder = new UndoRecorder(Person);
> recorder.beginRecording();
> // do something with EObject Person
> recorder.endRecording();
>
> And now (or even before the recording ended) use some methods like:
> recorder.undo();
> recorder.redo();
> recorder.undoAll();
> recorder.redoAll();
>
> But perhaps I am thinking a bit too simplistic. Or does this work with
> the current ChangeRecorder implementation without extending it much?
>
> Kai


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF databinding + undo/redo [message #426795 is a reply to message #426790] Tue, 20 January 2009 17:49 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi Kai,

Kai Schlamp schrieb:
> Tom Schindl schrieb:
>> By the way its quite likely that my UFaceKit-Project [1] will provide
>> such an undo/redo feature for EMF-Based-Model-Objects without the need
>> to understand how all this works internally but wrapped in a very
>> simplistic API :-)
>
> Simplistic sounds great ;-)
>
> I wonder a bit why to bother with EditingDomains, AdapterFactories and
> so on.
> Wouldn't something like an improved ChangeRecorder do the trick?
>

No because CDO changes (in case you are using passive-update) would be
recorded too by a ChangeRecorder and then you are in trouble :-)

Tom

> I am thinking of something like:
>
> UndoRecorder recorder = new UndoRecorder(Person);
> recorder.beginRecording();
> // do something with EObject Person
> recorder.endRecording();
>
> And now (or even before the recording ended) use some methods like:
> recorder.undo();
> recorder.redo();
> recorder.undoAll();
> recorder.redoAll();
>
> But perhaps I am thinking a bit too simplistic. Or does this work with
> the current ChangeRecorder implementation without extending it much?
>
> Kai


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: EMF databinding + undo/redo [message #426796 is a reply to message #426787] Tue, 20 January 2009 17:51 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Kai Schlamp schrieb:
> Thanks for all those explanations, Tom. I think for my dialogs I stick
> to the ON_REQUEST or better CONVERT policy (as I can still validate the
> input then) of the databinding framework, and only use the undo/redo
> functionality for the view that really needs this.
>
> I just looked at the source code of your application, as I wanted to
> find out what the best place is to create the EditingDomain.
>
> In your code it seems to happen in the initializeEditingDomain() method
> of the PersistanceServicesRegistry class.
>
> ComposedAdapterFactory adapterFactory = new
> ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Reg istry.INSTANCE);
>
> adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
> // adapterFactory.addAdapterFactory(new
> SoccerItemProviderAdapterFactory());
> adapterFactory.addAdapterFactory(new
> ReflectiveItemProviderAdapterFactory());
>
> The last three lines (.*addAdapterFactory.*) are not mentioned in your
> presentation. Are those required? Why did you comment the second line
> (the one with SoccerItemProviderAdapterFactory) out?
>

No I don't think they are needed but at the time I wrote the code I
wasn't sure.

Tom

--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: EMF databinding + undo/redo [message #426797 is a reply to message #426795] Tue, 20 January 2009 18:04 Go to previous messageGo to next message
Kai Schlamp is currently offline Kai SchlampFriend
Messages: 344
Registered: July 2009
Senior Member
Tom Schindl schrieb:
> Hi Kai,
>
> Kai Schlamp schrieb:
>> Tom Schindl schrieb:
>>> By the way its quite likely that my UFaceKit-Project [1] will provide
>>> such an undo/redo feature for EMF-Based-Model-Objects without the need
>>> to understand how all this works internally but wrapped in a very
>>> simplistic API :-)
>> Simplistic sounds great ;-)
>>
>> I wonder a bit why to bother with EditingDomains, AdapterFactories and
>> so on.
>> Wouldn't something like an improved ChangeRecorder do the trick?
>>
>
> No because CDO changes (in case you are using passive-update) would be
> recorded too by a ChangeRecorder and then you are in trouble :-)
>
> Tom
>

Thats a striking argument. I didn't even think about that. So it seems
the best way for me is to get a bit more involved regarding those
EditingDomains. At least until your cool UFaceKit project has some more
straightforward databind options :-) Thanks a lot again.

And regarding the SQL-Like Savepoint you mentioned in your earlier post.
I too think that this would be a nice idea.
How about methods like: setSavepoint(String id), hasSavepoint(String
id), removeSavepoint(String id), rollback(String id). So one can
rollback to different save points?

Kai
Re: EMF databinding + undo/redo [message #426798 is a reply to message #426795] Tue, 20 January 2009 18:05 Go to previous messageGo to next message
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
Tom are you sure about the following ?

> No because CDO changes (in case you are using passive-update) would be
> recorded too by a ChangeRecorder and then you are in trouble :-)

CDO will make changed not through the EMF API but only underneath
(CDORevision). I will be surprised if the ChangeRecorder knows about that.


But if ChangeSubscriptionPolicy is turned on... that could be possibly
errors... but I never tried.

Simon

Tom Schindl wrote:
> Hi Kai,
>
> Kai Schlamp schrieb:
>> Tom Schindl schrieb:
>>> By the way its quite likely that my UFaceKit-Project [1] will provide
>>> such an undo/redo feature for EMF-Based-Model-Objects without the need
>>> to understand how all this works internally but wrapped in a very
>>> simplistic API :-)
>> Simplistic sounds great ;-)
>>
>> I wonder a bit why to bother with EditingDomains, AdapterFactories and
>> so on.
>> Wouldn't something like an improved ChangeRecorder do the trick?
>>
>
> No because CDO changes (in case you are using passive-update) would be
> recorded too by a ChangeRecorder and then you are in trouble :-)
>
> Tom
>
>> I am thinking of something like:
>>
>> UndoRecorder recorder = new UndoRecorder(Person);
>> recorder.beginRecording();
>> // do something with EObject Person
>> recorder.endRecording();
>>
>> And now (or even before the recording ended) use some methods like:
>> recorder.undo();
>> recorder.redo();
>> recorder.undoAll();
>> recorder.redoAll();
>>
>> But perhaps I am thinking a bit too simplistic. Or does this work with
>> the current ChangeRecorder implementation without extending it much?
>>
>> Kai
>
>
Re: EMF databinding + undo/redo [message #426799 is a reply to message #426798] Tue, 20 January 2009 22:00 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Simon McDuff schrieb:
> Tom are you sure about the following ?
>
>> No because CDO changes (in case you are using passive-update) would be
>> recorded too by a ChangeRecorder and then you are in trouble :-)
>
> CDO will make changed not through the EMF API but only underneath
> (CDORevision). I will be surprised if the ChangeRecorder knows about that.
>
>
> But if ChangeSubscriptionPolicy is turned on... that could be possibly
> errors... but I never tried.
>

Sorry I meant ChangeDescription [1] :-( but one needs this to let
Databinding do the work it is supposed to do (updating the UI when the
underlying model changes).

Then the above is correct because a ChangeRecorder (it simply attaches
an adapter to the EObjects) would record changes made and you will undo
changes you made didn't made yourself which is not what we want right :-)

When using EditingDomain and Commands this is not the case because the
the undo/redo is done on the CommandStack which is not affected by the
change-subscription.

Sorry if I caused confusion by using the wrong term passive-update when
I meant change-subscription.

Tom


[1] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/at.bestsolution.soccer.core.datasource.cdo/src/at/b estsolution/soccer/core/datasource/cdo/CDODatasource.java

--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: EMF databinding + undo/redo [message #426800 is a reply to message #426744] Wed, 21 January 2009 00:11 Go to previous messageGo to next message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
FWIW this could be quite interesting for us. We are reworking our system
around EMF based domain models. We have a large Swing GUI that we will
evolve over time, not replace so anything that makes the Swing / EMF
integration easier will be very attractive for us.

Tom Schindl wrote:

> By the way its quite likely that my UFaceKit-Project [1] will provide
> such an undo/redo feature for EMF-Based-Model-Objects without the need
> to understand how all this works internally but wrapped in a very
> simplistic API :-)

> Tom

> [1]http://wiki.eclipse.org/UFaceKit

> Tom Schindl schrieb:
>> Hi Kai,
>>
>> Kai Schlamp schrieb:
>>> Hello.
>>>
>>> Inspired by the Blog entry "Eclipse Databinding + Validation +
>>> Decoration" (http://toedter.com/blog/?p=36), I wanted to have this for
>>> all my views and dialogs of my RCP application, as I already use EMF for
>>> my models cause of the CDO support.
>>> But let's assume a dialog with an "Ok" and "Cancel" button. When the
>>> user presses the "Cancel" button all modifications to the model have to
>>> be undone.
>>> So I looked further how to solve this problem an came over the EMF Edit
>>> framework and especially the "Datacentric RCP Applications" presentation
>>> by Tom Schindl.
>>>
( https://www.gpublication.com/eclipse/#requestedContent=conte ntID://EclipseConferences/ESE2008/48).
>>> This also has the advantage of full undo/redo support that I like to
>>> have in one of my views.
>>> But even after reading this and looking through many newsgroup messages,
>>> there are still many questions open.
>>>
>>> Tom has the following code in his presentation:
>>>
>>> Text widget = new Text(parent,SWT.BORDER)
>>> IObservableValue uiObs = SWTObservables.observeText(widget,SWT.Modify);
>>> Person p = getPersons();
>>> EditingDomain domain = getEditingDomain();
>>> EStructuralFeature feature = MyPackage.Literals.SURNAME;
>>> IObservableValue mObs = EMFEditObservables.observeValue(domain,p,feature);
>>> EMFDatabindingContext dbc = new EMFDataBindingContext();
>>> dbc.bind(uiObs,mObs,null,null);
>>>
>>> But where does the EditingDomain come from?
>>
>> If you browse my example code you'll see that you'll have to create it
>> your own [2] :-)
>>
>>> Do I have to create it myself like on Tom's "Setting up an EditingDomain
>>> by hand" slide?:
>>>
>>> ResourceSet set = new ResourceSetImpl();
>>> set.getPackageRegistry().put(MyPackage.eNS_URI,MyPackage.eIN STANCE);
>>> ComposedAdapterFactory af = new ComposedAdapterFactory(
>>> ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
>>> BasicCommandStack cs = new BasicCommandStack();
>>> AdapterFactoryEditingDomain ed = new AdapterFactoryEditingDomain(af, cs,
>>> set);
>>> Resource res = resourceSet.getResource(....);
>>>
>>> And how do I undo all changes from a specific point?
>>
>> Well undo/redo is done with the CommandStack. Take a look at my example
>> code (referenced from the slides [1]) [3] it does exactly what you want.
>> Opening a dialog and undo all changes if cancel is pressed.
>>
>> Another possibility is to use IPolicy.ON_REQUEST for your bindings so
>> and only update your model on press of OK.
>>
>>> For example ... I pass a "Person" eObject to a dialog that edits the
>>> already set "age" and "name" attributes.
>>> How do I undo all the changes that where done by that dialog when the
>>> user presses "Cancel"?
>>> Get the CommandStack und use undo() method as long as it canUndo()? So
>>> do I have to create a new CommandStack for every Dialog (I think so)? By
>>> creating a new EditingDomain for every dialog, right?
>>
>> Yes see above but not necessarily until you canUndo doesn't return any
>> more because if your model was already dirty before you'll undo too many
>> things :-) I already thought about wrapping this and providing a command
>> stack which allows to set an SQL-Like Savepoint where you can rollback to.
>>
>>> And when I use this Edit Framework, do I have to "Generate Edit Code" of
>>> my GenModel. And if yes, where do I have to use those generated providers?
>>> I hope that someone can enlighten me a bit ... this undo/redo task seems
>>> to be quite complex to me.
>>>
>>
>> I'm not using any generated editing code in my example but all is coded
>> by hand.
>>
>>> Kai
>>
>> Tom
>>
>>
[1] https://www.gpublication.com/eclipse/#requestedContent=conte ntID://EclipseConferences/ESE2008/48
>> [2] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/
>>
[3] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/at.bestsolution.soccer.ui.playeradmin/src/at/bestso lution/soccer/ui/playeradmin/command/EditPlayerCommandHandle r.java
>>
>>
Re: EMF databinding + undo/redo [message #426801 is a reply to message #426800] Wed, 21 January 2009 00:32 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi Andrew,

The first thing you can already use from UFaceKit are the
SwingObservables [1] we provide. So you could write native Swing-UI and
use EMF-Databinding and the SwingObservables to bind Model and UI just
like you do it nowadays with SWT/JFace and EMF.

If you have in depth knowledge about Swing I'd be happy to get your
comments because none of us (the UFaceKit-Team) is Swing-Guru.

Tom

[1] http://dev.eclipse.org/svnroot/eclipse/org.eclipse.ufacekit/ bundles/proper/org.eclipse.ufacekit/org.eclipse.ufacekit.ui. swing/org.eclipse.ufacekit.ui.swing.databinding/

Andrew H schrieb:
> FWIW this could be quite interesting for us. We are reworking our system
> around EMF based domain models. We have a large Swing GUI that we will
> evolve over time, not replace so anything that makes the Swing / EMF
> integration easier will be very attractive for us.
>
> Tom Schindl wrote:
>
>> By the way its quite likely that my UFaceKit-Project [1] will provide
>> such an undo/redo feature for EMF-Based-Model-Objects without the need
>> to understand how all this works internally but wrapped in a very
>> simplistic API :-)
>
>> Tom
>
>> [1]http://wiki.eclipse.org/UFaceKit
>
>> Tom Schindl schrieb:
>>> Hi Kai,
>>>
>>> Kai Schlamp schrieb:
>>>> Hello.
>>>>
>>>> Inspired by the Blog entry "Eclipse Databinding + Validation +
>>>> Decoration" (http://toedter.com/blog/?p=36), I wanted to have this for
>>>> all my views and dialogs of my RCP application, as I already use EMF
>>>> for
>>>> my models cause of the CDO support.
>>>> But let's assume a dialog with an "Ok" and "Cancel" button. When the
>>>> user presses the "Cancel" button all modifications to the model have to
>>>> be undone.
>>>> So I looked further how to solve this problem an came over the EMF Edit
>>>> framework and especially the "Datacentric RCP Applications"
>>>> presentation
>>>> by Tom Schindl.
>>>>
> ( https://www.gpublication.com/eclipse/#requestedContent=conte ntID://EclipseConferences/ESE2008/48).
>
>>>> This also has the advantage of full undo/redo support that I like to
>>>> have in one of my views.
>>>> But even after reading this and looking through many newsgroup
>>>> messages,
>>>> there are still many questions open.
>>>>
>>>> Tom has the following code in his presentation:
>>>>
>>>> Text widget = new Text(parent,SWT.BORDER)
>>>> IObservableValue uiObs = SWTObservables.observeText(widget,SWT.Modify);
>>>> Person p = getPersons();
>>>> EditingDomain domain = getEditingDomain();
>>>> EStructuralFeature feature = MyPackage.Literals.SURNAME;
>>>> IObservableValue mObs =
>>>> EMFEditObservables.observeValue(domain,p,feature);
>>>> EMFDatabindingContext dbc = new EMFDataBindingContext();
>>>> dbc.bind(uiObs,mObs,null,null);
>>>>
>>>> But where does the EditingDomain come from?
>>>
>>> If you browse my example code you'll see that you'll have to create it
>>> your own [2] :-)
>>>
>>>> Do I have to create it myself like on Tom's "Setting up an
>>>> EditingDomain
>>>> by hand" slide?:
>>>>
>>>> ResourceSet set = new ResourceSetImpl();
>>>> set.getPackageRegistry().put(MyPackage.eNS_URI,MyPackage.eIN STANCE);
>>>> ComposedAdapterFactory af = new ComposedAdapterFactory(
>>>> ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
>>>> BasicCommandStack cs = new BasicCommandStack();
>>>> AdapterFactoryEditingDomain ed = new AdapterFactoryEditingDomain(af,
>>>> cs,
>>>> set);
>>>> Resource res = resourceSet.getResource(....);
>>>>
>>>> And how do I undo all changes from a specific point?
>>>
>>> Well undo/redo is done with the CommandStack. Take a look at my example
>>> code (referenced from the slides [1]) [3] it does exactly what you want.
>>> Opening a dialog and undo all changes if cancel is pressed.
>>>
>>> Another possibility is to use IPolicy.ON_REQUEST for your bindings so
>>> and only update your model on press of OK.
>>>
>>>> For example ... I pass a "Person" eObject to a dialog that edits the
>>>> already set "age" and "name" attributes.
>>>> How do I undo all the changes that where done by that dialog when the
>>>> user presses "Cancel"?
>>>> Get the CommandStack und use undo() method as long as it canUndo()? So
>>>> do I have to create a new CommandStack for every Dialog (I think
>>>> so)? By
>>>> creating a new EditingDomain for every dialog, right?
>>>
>>> Yes see above but not necessarily until you canUndo doesn't return any
>>> more because if your model was already dirty before you'll undo too many
>>> things :-) I already thought about wrapping this and providing a command
>>> stack which allows to set an SQL-Like Savepoint where you can
>>> rollback to.
>>>
>>>> And when I use this Edit Framework, do I have to "Generate Edit
>>>> Code" of
>>>> my GenModel. And if yes, where do I have to use those generated
>>>> providers?
>>>> I hope that someone can enlighten me a bit ... this undo/redo task
>>>> seems
>>>> to be quite complex to me.
>>>>
>>>
>>> I'm not using any generated editing code in my example but all is coded
>>> by hand.
>>>
>>>> Kai
>>>
>>> Tom
>>>
>>>
> [1] https://www.gpublication.com/eclipse/#requestedContent=conte ntID://EclipseConferences/ESE2008/48
>
>>> [2] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/
>>>
> [3] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/at.bestsolution.soccer.ui.playeradmin/src/at/bestso lution/soccer/ui/playeradmin/command/EditPlayerCommandHandle r.java
>
>>>
>>>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: EMF databinding + undo/redo [message #426804 is a reply to message #426796] Wed, 21 January 2009 08:19 Go to previous messageGo to next message
Matthias Treitler is currently offline Matthias TreitlerFriend
Messages: 117
Registered: July 2009
Senior Member
Hi,

You only need the ComposedAdapterFactory.Descriptor.Registry.INSTANCE,
because this registry holds all XXXItemProviders that have been registred
with the "org.eclipse.emf.edit.itemProviderAdapterFactories" extension in
your generated .edit plug-ins (if you have not turned this feature off in
your genmodel).

The ResourceItemProviderAdapterFactory and
ReflectiveItemProviderAdapterFactory are only needed if you want to show a
resource + its content in a *Viewer and for dynamic classes.

I also think about the problems issued from time to time because I am
facing the same use cases in my project.
Normally you have one EditingDomain in your application (there are some
few posts in this newsgroup where it has been disadvised to use several
editing domains).
But now it is not likely (as it is in the generated .editor plug-in) that
you edit your big EMF model within one editor but your GUI is seperated
into different editors and probably saveable views. So the the undo and
redo buttons should be editor or view aware. If you look at the Eclipse
IDE the undo and redo always depends on the current selected view or
editor.

Up to now I have not found a way to solve this issue. But I think its an
interesting topic with very less best practices...

Bye,
matthias
Re: EMF databinding + undo/redo [message #426805 is a reply to message #426804] Wed, 21 January 2009 08:47 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi Matthias,

Matthias Treitler schrieb:
> Hi,
>
> You only need the ComposedAdapterFactory.Descriptor.Registry.INSTANCE,
> because this registry holds all XXXItemProviders that have been
> registred with the "org.eclipse.emf.edit.itemProviderAdapterFactories"
> extension in your generated .edit plug-ins (if you have not turned this
> feature off in your genmodel).
>

I don't use any generated .edit-code (no item providers, ...) so I don't
think I need it at all. All my code is written by hand
(ContentProviders, LabelProviders, ...).

> The ResourceItemProviderAdapterFactory and
> ReflectiveItemProviderAdapterFactory are only needed if you want to show
> a resource + its content in a *Viewer and for dynamic classes.
>

See above.

> I also think about the problems issued from time to time because I am
> facing the same use cases in my project. Normally you have one
> EditingDomain in your application (there are some few posts in this
> newsgroup where it has been disadvised to use several editing domains).
> But now it is not likely (as it is in the generated .editor plug-in)
> that you edit your big EMF model within one editor but your GUI is
> seperated into different editors and probably saveable views. So the the
> undo and redo buttons should be editor or view aware. If you look at the
> Eclipse IDE the undo and redo always depends on the current selected
> view or editor.
>

Yes. I also faced the problem you are describing but on the other hand I
don't think what you describe here is possible because only a complete
model graph can be saved because items can refrence each other inside
the graph (none containments).The same applies to undo/redo.

Take the following example:

View A:
- Administration of a List of Countries

View B:
- Person-Form which let you select from a list of countries.

Now let's try the following:

- Open View A
- Add a new country (Austria)
- Open View B
- Create a new person
- Select the country (Austria)
- Open View A
- Undo the addition of countries
- Open View B
- Save (big crash :-)

So how can we solve this? Well this is something that just came to my
mind. Couldn't we use CDO for this?

View A and View B have their own CDO-Session and so you'll only see the
newly added country after it has been persisted using the Session in
View A.

The question is still what happens if the country value is removed from
the persisted model while your are editing in View B? At least the above
saves you from the problem that you see values in View B which are not
persisted already which doesn't work if you use a single model instance.

Tom
Re: EMF databinding + undo/redo [message #426806 is a reply to message #426805] Wed, 21 January 2009 09:41 Go to previous messageGo to next message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
Tom Schindl wrote:
> Take the following example:
>
> View A:
> - Administration of a List of Countries
>
> View B:
> - Person-Form which let you select from a list of countries.
>
> Now let's try the following:
>
> - Open View A
> - Add a new country (Austria)
> - Open View B
> - Create a new person
> - Select the country (Austria)
> - Open View A
> - Undo the addition of countries
> - Open View B
> - Save (big crash :-)
>
> So how can we solve this? Well this is something that just came to my
> mind. Couldn't we use CDO for this?

Hi, stupid question: Can CDO be used for more than "distributed shared
EMF models and a fast server-based O/R mapping"? I've been always
ignoring the CDO stuff, as I thought I won't need. I assume from your
statement that CDO can do much more for me...

Sebastian
[CDO] EditingDomain and multiple-editors - can CDO be a solution [ was Re: EMF databinding + undo/re [message #426807 is a reply to message #426806] Wed, 21 January 2009 09:59 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Well yes CDO can do much more even if you don't have a 3-tier setup! One
of this big strenghts is its clever memory concept [1].

Though there are issues in the current JFace-Implementation which make
it not as powerful as they could be [2].

CDO has an in JVM-Connection implementation (there was a recent thread
about it) Simon and/or Eike can tell you more about it but I think its
quite straight forward you simply start the server and client inside the
same JVM (e.g. your RCP-Application) and choose the appropriate NET4J
implementation.

Tom

[1] http://thegordian.blogspot.com/2008/11/how-scalable-are-my-m odels.html
[2] http://tom-eclipse-dev.blogspot.com/2009/01/where-do-you-go- jface.html

Sebastian Paul schrieb:
> Tom Schindl wrote:
>> Take the following example:
>>
>> View A:
>> - Administration of a List of Countries
>>
>> View B:
>> - Person-Form which let you select from a list of countries.
>>
>> Now let's try the following:
>>
>> - Open View A
>> - Add a new country (Austria)
>> - Open View B
>> - Create a new person
>> - Select the country (Austria)
>> - Open View A
>> - Undo the addition of countries
>> - Open View B
>> - Save (big crash :-)
>>
>> So how can we solve this? Well this is something that just came to my
>> mind. Couldn't we use CDO for this?
>
> Hi, stupid question: Can CDO be used for more than "distributed shared
> EMF models and a fast server-based O/R mapping"? I've been always
> ignoring the CDO stuff, as I thought I won't need. I assume from your
> statement that CDO can do much more for me...
>
> Sebastian
Re: EMF databinding + undo/redo [message #426826 is a reply to message #426801] Wed, 21 January 2009 23:55 Go to previous messageGo to next message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
Hi Tom

Unfortunately, I have the opposite problem as I have no idea about
SWT/JFace. I do have a fair bit of Swing experience but its pretty rusty
now. A colleague here has much more current experience if you have any
particular questions.

I had a quick look at the code from the link. It looks like you create
Observables from Swing widgets which I presume are then used to integrate
in with EMF models somehow?

When I initially evaluated EMF I had it in the back of my mind that the UI
models generated by EMF (i.e. EMF.edit) looked fairly generic and not
terribly SWT centric. So I had thought it should be possible to write
custom implementations of the Swing models that wrap these somehow. I
didn't look into it further.

Custom model implementations tends to be how I have gone about adapting
other model frameworks into Swing in the past. These days there are a
bunch of binding api's for Swing so that would likely be the way I would
go now.

Our GUI rework is probably a few months off so I will check in with you
then on the status of the UFaceKit work. In the meantime, I'm happy to
provide input if that helps.

cheers
Andrew

Tom Schindl wrote:

> Hi Andrew,

> The first thing you can already use from UFaceKit are the
> SwingObservables [1] we provide. So you could write native Swing-UI and
> use EMF-Databinding and the SwingObservables to bind Model and UI just
> like you do it nowadays with SWT/JFace and EMF.

> If you have in depth knowledge about Swing I'd be happy to get your
> comments because none of us (the UFaceKit-Team) is Swing-Guru.

> Tom

>
[1] http://dev.eclipse.org/svnroot/eclipse/org.eclipse.ufacekit/ bundles/proper/org.eclipse.ufacekit/org.eclipse.ufacekit.ui. swing/org.eclipse.ufacekit.ui.swing.databinding/

> Andrew H schrieb:
>> FWIW this could be quite interesting for us. We are reworking our system
>> around EMF based domain models. We have a large Swing GUI that we will
>> evolve over time, not replace so anything that makes the Swing / EMF
>> integration easier will be very attractive for us.
>>
>> Tom Schindl wrote:
>>
>>> By the way its quite likely that my UFaceKit-Project [1] will provide
>>> such an undo/redo feature for EMF-Based-Model-Objects without the need
>>> to understand how all this works internally but wrapped in a very
>>> simplistic API :-)
>>
>>> Tom
>>
>>> [1]http://wiki.eclipse.org/UFaceKit
>>
>>> Tom Schindl schrieb:
>>>> Hi Kai,
>>>>
>>>> Kai Schlamp schrieb:
>>>>> Hello.
>>>>>
>>>>> Inspired by the Blog entry "Eclipse Databinding + Validation +
>>>>> Decoration" (http://toedter.com/blog/?p=36), I wanted to have this for
>>>>> all my views and dialogs of my RCP application, as I already use EMF
>>>>> for
>>>>> my models cause of the CDO support.
>>>>> But let's assume a dialog with an "Ok" and "Cancel" button. When the
>>>>> user presses the "Cancel" button all modifications to the model have to
>>>>> be undone.
>>>>> So I looked further how to solve this problem an came over the EMF Edit
>>>>> framework and especially the "Datacentric RCP Applications"
>>>>> presentation
>>>>> by Tom Schindl.
>>>>>
>>
( https://www.gpublication.com/eclipse/#requestedContent=conte ntID://EclipseConferences/ESE2008/48).
>>
>>>>> This also has the advantage of full undo/redo support that I like to
>>>>> have in one of my views.
>>>>> But even after reading this and looking through many newsgroup
>>>>> messages,
>>>>> there are still many questions open.
>>>>>
>>>>> Tom has the following code in his presentation:
>>>>>
>>>>> Text widget = new Text(parent,SWT.BORDER)
>>>>> IObservableValue uiObs = SWTObservables.observeText(widget,SWT.Modify);
>>>>> Person p = getPersons();
>>>>> EditingDomain domain = getEditingDomain();
>>>>> EStructuralFeature feature = MyPackage.Literals.SURNAME;
>>>>> IObservableValue mObs =
>>>>> EMFEditObservables.observeValue(domain,p,feature);
>>>>> EMFDatabindingContext dbc = new EMFDataBindingContext();
>>>>> dbc.bind(uiObs,mObs,null,null);
>>>>>
>>>>> But where does the EditingDomain come from?
>>>>
>>>> If you browse my example code you'll see that you'll have to create it
>>>> your own [2] :-)
>>>>
>>>>> Do I have to create it myself like on Tom's "Setting up an
>>>>> EditingDomain
>>>>> by hand" slide?:
>>>>>
>>>>> ResourceSet set = new ResourceSetImpl();
>>>>> set.getPackageRegistry().put(MyPackage.eNS_URI,MyPackage.eIN STANCE);
>>>>> ComposedAdapterFactory af = new ComposedAdapterFactory(
>>>>> ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
>>>>> BasicCommandStack cs = new BasicCommandStack();
>>>>> AdapterFactoryEditingDomain ed = new AdapterFactoryEditingDomain(af,
>>>>> cs,
>>>>> set);
>>>>> Resource res = resourceSet.getResource(....);
>>>>>
>>>>> And how do I undo all changes from a specific point?
>>>>
>>>> Well undo/redo is done with the CommandStack. Take a look at my example
>>>> code (referenced from the slides [1]) [3] it does exactly what you want.
>>>> Opening a dialog and undo all changes if cancel is pressed.
>>>>
>>>> Another possibility is to use IPolicy.ON_REQUEST for your bindings so
>>>> and only update your model on press of OK.
>>>>
>>>>> For example ... I pass a "Person" eObject to a dialog that edits the
>>>>> already set "age" and "name" attributes.
>>>>> How do I undo all the changes that where done by that dialog when the
>>>>> user presses "Cancel"?
>>>>> Get the CommandStack und use undo() method as long as it canUndo()? So
>>>>> do I have to create a new CommandStack for every Dialog (I think
>>>>> so)? By
>>>>> creating a new EditingDomain for every dialog, right?
>>>>
>>>> Yes see above but not necessarily until you canUndo doesn't return any
>>>> more because if your model was already dirty before you'll undo too many
>>>> things :-) I already thought about wrapping this and providing a command
>>>> stack which allows to set an SQL-Like Savepoint where you can
>>>> rollback to.
>>>>
>>>>> And when I use this Edit Framework, do I have to "Generate Edit
>>>>> Code" of
>>>>> my GenModel. And if yes, where do I have to use those generated
>>>>> providers?
>>>>> I hope that someone can enlighten me a bit ... this undo/redo task
>>>>> seems
>>>>> to be quite complex to me.
>>>>>
>>>>
>>>> I'm not using any generated editing code in my example but all is coded
>>>> by hand.
>>>>
>>>>> Kai
>>>>
>>>> Tom
>>>>
>>>>
>>
[1] https://www.gpublication.com/eclipse/#requestedContent=conte ntID://EclipseConferences/ESE2008/48
>>
>>>> [2] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/
>>>>
>>
[3] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/at.bestsolution.soccer.ui.playeradmin/src/at/bestso lution/soccer/ui/playeradmin/command/EditPlayerCommandHandle r.java
>>
>>>>
>>>>
>>
Re: EMF databinding + undo/redo [message #426827 is a reply to message #426826] Thu, 22 January 2009 01:23 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Andrew H schrieb:
> Hi Tom
>
> Unfortunately, I have the opposite problem as I have no idea about
> SWT/JFace. I do have a fair bit of Swing experience but its pretty rusty
> now. A colleague here has much more current experience if you have any
> particular questions.
>
> I had a quick look at the code from the link. It looks like you create
> Observables from Swing widgets which I presume are then used to
> integrate in with EMF models somehow?

Yes you draw the connection between them by creating an Observable for
your EMF-Attribute and connect it to your UI-Observable using
Eclipse-Databinding.

>
> When I initially evaluated EMF I had it in the back of my mind that the
> UI models generated by EMF (i.e. EMF.edit) looked fairly generic and not
> terribly SWT centric. So I had thought it should be possible to write
> custom implementations of the Swing models that wrap these somehow. I
> didn't look into it further.
>

Sure you could simply customized the JET-Templates and create Swing-UI
instead of SWT/JFace.

> Custom model implementations tends to be how I have gone about adapting
> other model frameworks into Swing in the past. These days there are a
> bunch of binding api's for Swing so that would likely be the way I would
> go now.

You talk about BeanBinding and their friends right. I'm not sure they
integrate as good with EMFs notifications as Eclipse-Databinding does.

Tom

--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: EMF databinding + undo/redo [message #426837 is a reply to message #426827] Thu, 22 January 2009 11:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010800080209060403040504
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Guys,

Comments below.

Tom Schindl wrote:
> Andrew H schrieb:
>
>> Hi Tom
>>
>> Unfortunately, I have the opposite problem as I have no idea about
>> SWT/JFace. I do have a fair bit of Swing experience but its pretty rusty
>> now. A colleague here has much more current experience if you have any
>> particular questions.
>>
>> I had a quick look at the code from the link. It looks like you create
>> Observables from Swing widgets which I presume are then used to
>> integrate in with EMF models somehow?
>>
>
> Yes you draw the connection between them by creating an Observable for
> your EMF-Attribute and connect it to your UI-Observable using
> Eclipse-Databinding.
>
Data binding is a general concept that could be used to bind any data
"model' to any UI "model".
>
>> When I initially evaluated EMF I had it in the back of my mind that the
>> UI models generated by EMF (i.e. EMF.edit) looked fairly generic and not
>> terribly SWT centric.
Absolutely it's designed to be UI technology agnostic so it can be
applied in many different contexts. For example, getImage returns an
Object and in the implementation a URL.
>> So I had thought it should be possible to write
>> custom implementations of the Swing models that wrap these somehow. I
>> didn't look into it further.
>>
The EMF.Edit layer is designed to be wrapped by something like the
EMF.Edit.UI layer, which is Eclipse specific. I could imagine
EMF.Edit.Swing and I know folks have done exactly that type of thing in
the past.
>>
>
> Sure you could simply customized the JET-Templates and create Swing-UI
> instead of SWT/JFace.
>
Most of the work is likely generic and requires nothing that is specific
to any particular instance model. Even the generated EMF Editor has
almost no model-specific dependencies (and even the ones it has, like
the item provider adapter factory is redundant now that these are
available from the registry).
>
>> Custom model implementations tends to be how I have gone about adapting
>> other model frameworks into Swing in the past. These days there are a
>> bunch of binding api's for Swing so that would likely be the way I would
>> go now.
>>
>
> You talk about BeanBinding and their friends right. I'm not sure they
> integrate as good with EMFs notifications as Eclipse-Databinding does.
>
EMF's data model is so much more powerful and functionally completely
that crappy old beans. A great demonstration of the power/completeness
of EMF's notifications is the fact that they can be used to implement
undo...
> Tom
>
>

--------------010800080209060403040504
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Guys,<br>
<br>
Comments below.<br>
<br>
Tom Schindl wrote:
<blockquote cite="mid:gl8hq3$v7e$1@build.eclipse.org" type="cite">
<pre wrap="">Andrew H schrieb:
</pre>
<blockquote type="cite">
<pre wrap="">Hi Tom

Unfortunately, I have the opposite problem as I have no idea about
SWT/JFace. I do have a fair bit of Swing experience but its pretty rusty
now. A colleague here has much more current experience if you have any
particular questions.

I had a quick look at the code from the link. It looks like you create
Observables from Swing widgets which I presume are then used to
integrate in with EMF models somehow?
</pre>
</blockquote>
<pre wrap=""><!---->
Yes you draw the connection between them by creating an Observable for
your EMF-Attribute and connect it to your UI-Observable using
Eclipse-Databinding.
</pre>
</blockquote>
Data binding is a general concept that could be used to bind any data
"model' to any UI "model".<br>
<blockquote cite="mid:gl8hq3$v7e$1@build.eclipse.org" type="cite">
<pre wrap="">
</pre>
<blockquote type="cite">
<pre wrap="">When I initially evaluated EMF I had it in the back of my mind that the
UI models generated by EMF (i.e. EMF.edit) looked fairly generic and not
terribly SWT centric. </pre>
</blockquote>
</blockquote>
Absolutely it's designed to be UI technology agnostic so it can be
applied in many different contexts.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF databinding + undo/redo [message #426868 is a reply to message #426806] Thu, 22 January 2009 20:32 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Sebastian, Tom,

Comments inline...


Sebastian Paul schrieb:
> Tom Schindl wrote:
>> Take the following example:
>>
>> View A:
>> - Administration of a List of Countries
>>
>> View B:
>> - Person-Form which let you select from a list of countries.
>>
>> Now let's try the following:
>>
>> - Open View A
>> - Add a new country (Austria)
>> - Open View B
>> - Create a new person
>> - Select the country (Austria)
>> - Open View A
>> - Undo the addition of countries
>> - Open View B
>> - Save (big crash :-)
>>
>> So how can we solve this? Well this is something that just came to my
>> mind. Couldn't we use CDO for this?
>
> Hi, stupid question: Can CDO be used for more than "distributed shared
> EMF models and a fast server-based O/R mapping"? I've been always
> ignoring the CDO stuff, as I thought I won't need.
That was obviously not a wise decision :P

> I assume from your statement that CDO can do much more for me...
I think CDO can already do something here and it's still my dream that
somebody starts work on a file system or workspace based CDO repository
implementation that brings all (or at least many of) the transactional
features of CDO to the otherwise undistributed XML clients. Model
distribution would even be optionally included then. I'm waiting here to
offer my assistence ;-)

In your case it seems as if you would only need a single CDOSession and
then open multiple CDOTransactions on it. In this case you'd even get
transparent data sharing between the same objects in different transactions.

Cheers
/Eike

----
http://thegordian.blogspot.com


Re: EMF databinding + undo/redo [message #426876 is a reply to message #426868] Fri, 23 January 2009 08:48 Go to previous messageGo to next message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
> In your case it seems as if you would only need a single CDOSession and
> then open multiple CDOTransactions on it. In this case you'd even get
> transparent data sharing between the same objects in different
> transactions.

Hi,
what about EMF Model Transaction
( http://www.eclipse.org/modeling/emf/?project=transaction#tra nsaction).
Is CDO based on it? Or are there major differences regarding transactions?

Cheers, Sebastian
Re: EMF databinding + undo/redo [message #426881 is a reply to message #426876] Fri, 23 January 2009 09:44 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Sebastian,

CDO is not based on EMF Transaction. I think the major difference is
that EMF Transaction transactions are built on top of the command stack
of an editing domain while CDOTransactions are integrated with EMF on a
lower level (no edit dependency). As a consequence CDO transactions are
not relying on the client cooperation and allow a somewhat stronger
statement about transactional isolation. In other words, CDO
Transactions are more transparent to the editor. An editor using CDO
transactions does not need to be modified, but usually you will want to
react to certain events like objects becoming dirty, transaction is
committed or rolled back etc. Our generic CDOEditor demonstrates some
nice ideas like coloring dirty objects.

Cheers
/Eike

----
http://thegordian.blogspot.com



Sebastian Paul schrieb:
>
>> In your case it seems as if you would only need a single CDOSession
>> and then open multiple CDOTransactions on it. In this case you'd even
>> get transparent data sharing between the same objects in different
>> transactions.
>
> Hi,
> what about EMF Model Transaction
> ( http://www.eclipse.org/modeling/emf/?project=transaction#tra nsaction).
> Is CDO based on it? Or are there major differences regarding
> transactions?
>
> Cheers, Sebastian


Re: EMF databinding + undo/redo [message #426958 is a reply to message #426837] Mon, 26 January 2009 23:36 Go to previous messageGo to next message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
Hi Ed / Tom

See inline

Ed Merks wrote:

> Guys,

> Comments below.

> Tom Schindl wrote:
>> Andrew H schrieb:
>>
>>> Hi Tom
>>>
>>> Unfortunately, I have the opposite problem as I have no idea about
>>> SWT/JFace. I do have a fair bit of Swing experience but its pretty rusty
>>> now. A colleague here has much more current experience if you have any
>>> particular questions.
>>>
>>> I had a quick look at the code from the link. It looks like you create
>>> Observables from Swing widgets which I presume are then used to
>>> integrate in with EMF models somehow?
>>>
>>
>> Yes you draw the connection between them by creating an Observable for
>> your EMF-Attribute and connect it to your UI-Observable using
>> Eclipse-Databinding.
>>
> Data binding is a general concept that could be used to bind any data
> "model' to any UI "model".

Yeah I think there are a few different binding frameworks that bind
(normally JavaBeans) models into swing UI models. I can't remember their
names.

>>
>>> When I initially evaluated EMF I had it in the back of my mind that the
>>> UI models generated by EMF (i.e. EMF.edit) looked fairly generic and not
>>> terribly SWT centric.
> Absolutely it's designed to be UI technology agnostic so it can be
> applied in many different contexts. For example, getImage returns an
> Object and in the implementation a URL.

Glad to hear you confirm that cause it certainly appeared that way and
that will make our life much easier.

>>> So I had thought it should be possible to write
>>> custom implementations of the Swing models that wrap these somehow. I
>>> didn't look into it further.
>>>
> The EMF.Edit layer is designed to be wrapped by something like the
> EMF.Edit.UI layer, which is Eclipse specific. I could imagine
> EMF.Edit.Swing and I know folks have done exactly that type of thing in
> the past.

That's pretty much what I was hoping. I was thinking along the lines of
for example in order to bind an EMF attribute into a text field
(JTextField in swing) I would create a custom implementation of Document
(the MVC model interface behind a JTextField) which adapts some model that
is part of the EMF.Edit layer, or something along those lines.

Similar tricks for combo's, tabs, lists etc.

>>>
>>
>> Sure you could simply customized the JET-Templates and create Swing-UI
>> instead of SWT/JFace.
>>
> Most of the work is likely generic and requires nothing that is specific
> to any particular instance model. Even the generated EMF Editor has
> almost no model-specific dependencies (and even the ones it has, like
> the item provider adapter factory is redundant now that these are
> available from the registry).

That was what I was thinking too unless there was something useful UI wise
that we could generate. Actually there probably is. We are thinking along
the lines of creating a set of what we are calling application models that
will be EMF models aligning with the user interaction we wish to create.
They will relate to the true domain model we have been creating.

The thought was that we might be able to generate useful UI stuff for
these. For example we might create widgets for all the attributes and add
them to a panel, leaving largely just the layout needed as custom code.

Not sure how that will turn out, but that was the basic idea.

>>
>>> Custom model implementations tends to be how I have gone about adapting
>>> other model frameworks into Swing in the past. These days there are a
>>> bunch of binding api's for Swing so that would likely be the way I would
>>> go now.
>>>
>>
>> You talk about BeanBinding and their friends right. I'm not sure they
>> integrate as good with EMFs notifications as Eclipse-Databinding does.
>>
> EMF's data model is so much more powerful and functionally completely
> that crappy old beans. A great demonstration of the power/completeness
> of EMF's notifications is the fact that they can be used to implement
> undo...

Yes, and this is something I look forward to benefiting from. Over the
years (dating back many years before EMF was conceived of) I have done
things to add some of the things that EMF has in it to JavaBeans models.
e.g. the stuff like lower & upper bounds, plus other constraints like
integer bounds, regexp etc.

Our UI layers would then know about this meta data and made use of it,
e.g. validating etc. We even used it to generate html & java script based
constraints.

It used to be particularly awkward, but Java 5 annotations improved this
somewhat.

However, EMF provides a much cleaner and more comprehensive answer to this
problem, so I am more than happy to no longer need to write that sort of
stuff.

And having the extra stuff in EMF.edit makes this even more convenient,
even for a Swing based product like ours.

cheers

Andy
Re: EMF databinding + undo/redo [message #426960 is a reply to message #426958] Tue, 27 January 2009 10:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030201090809020209090402
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Andrew,

Both these proposals are likely to be of some interest:

http://www.eclipse.org/proposals/pmf/
http://www.eclipse.org/proposals/eef/


Andrew H wrote:
> Hi Ed / Tom
>
> See inline
>
> Ed Merks wrote:
>
>> Guys,
>
>> Comments below.
>
>> Tom Schindl wrote:
>>> Andrew H schrieb:
>>>
>>>> Hi Tom
>>>>
>>>> Unfortunately, I have the opposite problem as I have no idea about
>>>> SWT/JFace. I do have a fair bit of Swing experience but its pretty
>>>> rusty
>>>> now. A colleague here has much more current experience if you have any
>>>> particular questions.
>>>>
>>>> I had a quick look at the code from the link. It looks like you create
>>>> Observables from Swing widgets which I presume are then used to
>>>> integrate in with EMF models somehow?
>>>>
>>>
>>> Yes you draw the connection between them by creating an Observable for
>>> your EMF-Attribute and connect it to your UI-Observable using
>>> Eclipse-Databinding.
>>>
>> Data binding is a general concept that could be used to bind any data
>> "model' to any UI "model".
>
> Yeah I think there are a few different binding frameworks that bind
> (normally JavaBeans) models into swing UI models. I can't remember
> their names.
>
>>>
>>>> When I initially evaluated EMF I had it in the back of my mind that
>>>> the
>>>> UI models generated by EMF (i.e. EMF.edit) looked fairly generic
>>>> and not
>>>> terribly SWT centric.
>> Absolutely it's designed to be UI technology agnostic so it can be
>> applied in many different contexts. For example, getImage returns an
>> Object and in the implementation a URL.
>
> Glad to hear you confirm that cause it certainly appeared that way and
> that will make our life much easier.
>
>>>> So I had thought it should be possible to write
>>>> custom implementations of the Swing models that wrap these somehow. I
>>>> didn't look into it further.
>>>>
>> The EMF.Edit layer is designed to be wrapped by something like the
>> EMF.Edit.UI layer, which is Eclipse specific. I could imagine
>> EMF.Edit.Swing and I know folks have done exactly that type of thing
>> in the past.
>
> That's pretty much what I was hoping. I was thinking along the lines
> of for example in order to bind an EMF attribute into a text field
> (JTextField in swing) I would create a custom implementation of
> Document (the MVC model interface behind a JTextField) which adapts
> some model that is part of the EMF.Edit layer, or something along
> those lines.
>
> Similar tricks for combo's, tabs, lists etc.
>
>>>>
>>>
>>> Sure you could simply customized the JET-Templates and create Swing-UI
>>> instead of SWT/JFace.
>>>
>> Most of the work is likely generic and requires nothing that is
>> specific to any particular instance model. Even the generated EMF
>> Editor has almost no model-specific dependencies (and even the ones
>> it has, like the item provider adapter factory is redundant now that
>> these are available from the registry).
>
> That was what I was thinking too unless there was something useful UI
> wise that we could generate. Actually there probably is. We are
> thinking along the lines of creating a set of what we are calling
> application models that will be EMF models aligning with the user
> interaction we wish to create. They will relate to the true domain
> model we have been creating.
>
> The thought was that we might be able to generate useful UI stuff for
> these. For example we might create widgets for all the attributes and
> add them to a panel, leaving largely just the layout needed as custom
> code.
>
> Not sure how that will turn out, but that was the basic idea.
>
>>>
>>>> Custom model implementations tends to be how I have gone about
>>>> adapting
>>>> other model frameworks into Swing in the past. These days there are a
>>>> bunch of binding api's for Swing so that would likely be the way I
>>>> would
>>>> go now.
>>>>
>>>
>>> You talk about BeanBinding and their friends right. I'm not sure they
>>> integrate as good with EMFs notifications as Eclipse-Databinding does.
>>>
>> EMF's data model is so much more powerful and functionally completely
>> that crappy old beans. A great demonstration of the
>> power/completeness of EMF's notifications is the fact that they can
>> be used to implement undo...
>
> Yes, and this is something I look forward to benefiting from. Over the
> years (dating back many years before EMF was conceived of) I have done
> things to add some of the things that EMF has in it to JavaBeans
> models. e.g. the stuff like lower & upper bounds, plus other
> constraints like integer bounds, regexp etc.
>
> Our UI layers would then know about this meta data and made use of it,
> e.g. validating etc. We even used it to generate html & java script
> based constraints.
>
> It used to be particularly awkward, but Java 5 annotations improved
> this somewhat.
>
> However, EMF provides a much cleaner and more comprehensive answer to
> this problem, so I am more than happy to no longer need to write that
> sort of stuff.
>
> And having the extra stuff in EMF.edit makes this even more
> convenient, even for a Swing based product like ours.
>
> cheers
>
> Andy
>

--------------030201090809020209090402
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Andrew,<br>
<br>
Both these proposals are likely to be of some interest:<br>
<blockquote><a href="http://www.eclipse.org/proposals/pmf/">http://www.eclipse.org/proposals/pmf/</a><br>
<a href="http://www.eclipse.org/proposals/eef/">http://www.eclipse.org/proposals/eef/</a><br>
</blockquote>
<br>
Andrew H wrote:
<blockquote
cite="mid:7de35d48683c909c571d8cb8db64e15e$1@www.eclipse.org"
type="cite">Hi Ed / Tom
<br>
<br>
See inline
<br>
<br>
Ed Merks wrote:
<br>
<br>
<blockquote type="cite">Guys,
<br>
</blockquote>
<br>
<blockquote type="cite">Comments below.
<br>
</blockquote>
<br>
<blockquote type="cite">Tom Schindl wrote:
<br>
<blockquote type="cite">Andrew H schrieb:
<br>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF databinding + undo/redo [message #427007 is a reply to message #426960] Tue, 27 January 2009 23:42 Go to previous messageGo to next message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
Yes they do sound interesting (at least as far as I can tell from the
proposals). Pity they won't happen within our timelines.

I assume there will be some relationship between the two?

Ed Merks wrote:

> Andrew,

> Both these proposals are likely to be of some interest:

> http://www.eclipse.org/proposals/pmf/
> http://www.eclipse.org/proposals/eef/


> Andrew H wrote:
>> Hi Ed / Tom
>>
>> See inline
>>
>> Ed Merks wrote:
>>
>>> Guys,
>>
>>> Comments below.
>>
>>> Tom Schindl wrote:
>>>> Andrew H schrieb:
>>>>
>>>>> Hi Tom
>>>>>
>>>>> Unfortunately, I have the opposite problem as I have no idea about
>>>>> SWT/JFace. I do have a fair bit of Swing experience but its pretty
>>>>> rusty
>>>>> now. A colleague here has much more current experience if you have any
>>>>> particular questions.
>>>>>
>>>>> I had a quick look at the code from the link. It looks like you create
>>>>> Observables from Swing widgets which I presume are then used to
>>>>> integrate in with EMF models somehow?
>>>>>
>>>>
>>>> Yes you draw the connection between them by creating an Observable for
>>>> your EMF-Attribute and connect it to your UI-Observable using
>>>> Eclipse-Databinding.
>>>>
>>> Data binding is a general concept that could be used to bind any data
>>> "model' to any UI "model".
>>
>> Yeah I think there are a few different binding frameworks that bind
>> (normally JavaBeans) models into swing UI models. I can't remember
>> their names.
>>
>>>>
>>>>> When I initially evaluated EMF I had it in the back of my mind that
>>>>> the
>>>>> UI models generated by EMF (i.e. EMF.edit) looked fairly generic
>>>>> and not
>>>>> terribly SWT centric.
>>> Absolutely it's designed to be UI technology agnostic so it can be
>>> applied in many different contexts. For example, getImage returns an
>>> Object and in the implementation a URL.
>>
>> Glad to hear you confirm that cause it certainly appeared that way and
>> that will make our life much easier.
>>
>>>>> So I had thought it should be possible to write
>>>>> custom implementations of the Swing models that wrap these somehow. I
>>>>> didn't look into it further.
>>>>>
>>> The EMF.Edit layer is designed to be wrapped by something like the
>>> EMF.Edit.UI layer, which is Eclipse specific. I could imagine
>>> EMF.Edit.Swing and I know folks have done exactly that type of thing
>>> in the past.
>>
>> That's pretty much what I was hoping. I was thinking along the lines
>> of for example in order to bind an EMF attribute into a text field
>> (JTextField in swing) I would create a custom implementation of
>> Document (the MVC model interface behind a JTextField) which adapts
>> some model that is part of the EMF.Edit layer, or something along
>> those lines.
>>
>> Similar tricks for combo's, tabs, lists etc.
>>
>>>>>
>>>>
>>>> Sure you could simply customized the JET-Templates and create Swing-UI
>>>> instead of SWT/JFace.
>>>>
>>> Most of the work is likely generic and requires nothing that is
>>> specific to any particular instance model. Even the generated EMF
>>> Editor has almost no model-specific dependencies (and even the ones
>>> it has, like the item provider adapter factory is redundant now that
>>> these are available from the registry).
>>
>> That was what I was thinking too unless there was something useful UI
>> wise that we could generate. Actually there probably is. We are
>> thinking along the lines of creating a set of what we are calling
>> application models that will be EMF models aligning with the user
>> interaction we wish to create. They will relate to the true domain
>> model we have been creating.
>>
>> The thought was that we might be able to generate useful UI stuff for
>> these. For example we might create widgets for all the attributes and
>> add them to a panel, leaving largely just the layout needed as custom
>> code.
>>
>> Not sure how that will turn out, but that was the basic idea.
>>
>>>>
>>>>> Custom model implementations tends to be how I have gone about
>>>>> adapting
>>>>> other model frameworks into Swing in the past. These days there are a
>>>>> bunch of binding api's for Swing so that would likely be the way I
>>>>> would
>>>>> go now.
>>>>>
>>>>
>>>> You talk about BeanBinding and their friends right. I'm not sure they
>>>> integrate as good with EMFs notifications as Eclipse-Databinding does.
>>>>
>>> EMF's data model is so much more powerful and functionally completely
>>> that crappy old beans. A great demonstration of the
>>> power/completeness of EMF's notifications is the fact that they can
>>> be used to implement undo...
>>
>> Yes, and this is something I look forward to benefiting from. Over the
>> years (dating back many years before EMF was conceived of) I have done
>> things to add some of the things that EMF has in it to JavaBeans
>> models. e.g. the stuff like lower & upper bounds, plus other
>> constraints like integer bounds, regexp etc.
>>
>> Our UI layers would then know about this meta data and made use of it,
>> e.g. validating etc. We even used it to generate html & java script
>> based constraints.
>>
>> It used to be particularly awkward, but Java 5 annotations improved
>> this somewhat.
>>
>> However, EMF provides a much cleaner and more comprehensive answer to
>> this problem, so I am more than happy to no longer need to write that
>> sort of stuff.
>>
>> And having the extra stuff in EMF.edit makes this even more
>> convenient, even for a Swing based product like ours.
>>
>> cheers
>>
>> Andy
>>
Re: EMF databinding + undo/redo [message #427010 is a reply to message #427007] Wed, 28 January 2009 03:06 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Andrew,

They have a bit different time lines as well with EEF being more
immediately short term. I'm sure it will all converge though...


Andrew H wrote:
> Yes they do sound interesting (at least as far as I can tell from the
> proposals). Pity they won't happen within our timelines.
>
> I assume there will be some relationship between the two?
> Ed Merks wrote:
>
>> Andrew,
>
>> Both these proposals are likely to be of some interest:
>
>> http://www.eclipse.org/proposals/pmf/
>> http://www.eclipse.org/proposals/eef/
>
>
>> Andrew H wrote:
>>> Hi Ed / Tom
>>>
>>> See inline
>>>
>>> Ed Merks wrote:
>>>
>>>> Guys,
>>>
>>>> Comments below.
>>>
>>>> Tom Schindl wrote:
>>>>> Andrew H schrieb:
>>>>>
>>>>>> Hi Tom
>>>>>>
>>>>>> Unfortunately, I have the opposite problem as I have no idea about
>>>>>> SWT/JFace. I do have a fair bit of Swing experience but its
>>>>>> pretty rusty
>>>>>> now. A colleague here has much more current experience if you
>>>>>> have any
>>>>>> particular questions.
>>>>>>
>>>>>> I had a quick look at the code from the link. It looks like you
>>>>>> create
>>>>>> Observables from Swing widgets which I presume are then used to
>>>>>> integrate in with EMF models somehow?
>>>>>>
>>>>>
>>>>> Yes you draw the connection between them by creating an Observable
>>>>> for
>>>>> your EMF-Attribute and connect it to your UI-Observable using
>>>>> Eclipse-Databinding.
>>>>>
>>>> Data binding is a general concept that could be used to bind any
>>>> data "model' to any UI "model".
>>>
>>> Yeah I think there are a few different binding frameworks that bind
>>> (normally JavaBeans) models into swing UI models. I can't remember
>>> their names.
>>>
>>>>>
>>>>>> When I initially evaluated EMF I had it in the back of my mind
>>>>>> that the
>>>>>> UI models generated by EMF (i.e. EMF.edit) looked fairly generic
>>>>>> and not
>>>>>> terribly SWT centric.
>>>> Absolutely it's designed to be UI technology agnostic so it can be
>>>> applied in many different contexts. For example, getImage returns
>>>> an Object and in the implementation a URL.
>>>
>>> Glad to hear you confirm that cause it certainly appeared that way
>>> and that will make our life much easier.
>>>
>>>>>> So I had thought it should be possible to write
>>>>>> custom implementations of the Swing models that wrap these
>>>>>> somehow. I
>>>>>> didn't look into it further.
>>>>>>
>>>> The EMF.Edit layer is designed to be wrapped by something like the
>>>> EMF.Edit.UI layer, which is Eclipse specific. I could imagine
>>>> EMF.Edit.Swing and I know folks have done exactly that type of
>>>> thing in the past.
>>>
>>> That's pretty much what I was hoping. I was thinking along the lines
>>> of for example in order to bind an EMF attribute into a text field
>>> (JTextField in swing) I would create a custom implementation of
>>> Document (the MVC model interface behind a JTextField) which adapts
>>> some model that is part of the EMF.Edit layer, or something along
>>> those lines.
>>>
>>> Similar tricks for combo's, tabs, lists etc.
>>>
>>>>>>
>>>>>
>>>>> Sure you could simply customized the JET-Templates and create
>>>>> Swing-UI
>>>>> instead of SWT/JFace.
>>>>>
>>>> Most of the work is likely generic and requires nothing that is
>>>> specific to any particular instance model. Even the generated EMF
>>>> Editor has almost no model-specific dependencies (and even the ones
>>>> it has, like the item provider adapter factory is redundant now
>>>> that these are available from the registry).
>>>
>>> That was what I was thinking too unless there was something useful
>>> UI wise that we could generate. Actually there probably is. We are
>>> thinking along the lines of creating a set of what we are calling
>>> application models that will be EMF models aligning with the user
>>> interaction we wish to create. They will relate to the true domain
>>> model we have been creating.
>>>
>>> The thought was that we might be able to generate useful UI stuff
>>> for these. For example we might create widgets for all the
>>> attributes and add them to a panel, leaving largely just the layout
>>> needed as custom code.
>>>
>>> Not sure how that will turn out, but that was the basic idea.
>>>
>>>>>
>>>>>> Custom model implementations tends to be how I have gone about
>>>>>> adapting
>>>>>> other model frameworks into Swing in the past. These days there
>>>>>> are a
>>>>>> bunch of binding api's for Swing so that would likely be the way
>>>>>> I would
>>>>>> go now.
>>>>>>
>>>>>
>>>>> You talk about BeanBinding and their friends right. I'm not sure they
>>>>> integrate as good with EMFs notifications as Eclipse-Databinding
>>>>> does.
>>>>>
>>>> EMF's data model is so much more powerful and functionally
>>>> completely that crappy old beans. A great demonstration of the
>>>> power/completeness of EMF's notifications is the fact that they can
>>>> be used to implement undo...
>>>
>>> Yes, and this is something I look forward to benefiting from. Over
>>> the years (dating back many years before EMF was conceived of) I
>>> have done things to add some of the things that EMF has in it to
>>> JavaBeans models. e.g. the stuff like lower & upper bounds, plus
>>> other constraints like integer bounds, regexp etc.
>>>
>>> Our UI layers would then know about this meta data and made use of
>>> it, e.g. validating etc. We even used it to generate html & java
>>> script based constraints.
>>>
>>> It used to be particularly awkward, but Java 5 annotations improved
>>> this somewhat.
>>>
>>> However, EMF provides a much cleaner and more comprehensive answer
>>> to this problem, so I am more than happy to no longer need to write
>>> that sort of stuff.
>>>
>>> And having the extra stuff in EMF.edit makes this even more
>>> convenient, even for a Swing based product like ours.
>>>
>>> cheers
>>>
>>> Andy
>>>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Create genmodel from ecore programmatically
Next Topic:[CDO-EMF] request for help with new model design
Goto Forum:
  


Current Time: Fri Apr 26 20:59:04 GMT 2024

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

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

Back to the top