Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Does EMFObservables provide undo/redo functionality?
Does EMFObservables provide undo/redo functionality? [message #420402] Sat, 28 June 2008 09:50 Go to next message
Al B is currently offline Al BFriend
Messages: 130
Registered: July 2009
Senior Member
Hi,

I am using EMFObservables.observeValue((EObject) object, feature), but
undo/redo functionality is not working.

AdapterFactoryEditingDomain.getEditingDomainFor(target) is returning an
EditingDoamin and domain.getCommandStack() is returning a CommandStack as
well.

So, does EMFObservables support the undo/redo functionality?

Thanks!
Re: Does EMFObservables provide undo/redo functionality? [message #420403 is a reply to message #420402] Sat, 28 June 2008 10:17 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You'll need to use the EMFObservableEditingDomain for this kind of thing
this is an extra plugin.

Tom

AJ schrieb:
> Hi,
>
> I am using EMFObservables.observeValue((EObject) object, feature), but
> undo/redo functionality is not working.
> AdapterFactoryEditingDomain.getEditingDomainFor(target) is returning an
> EditingDoamin and domain.getCommandStack() is returning a CommandStack
> as well.
>
> So, does EMFObservables support the undo/redo functionality?
>
> Thanks!
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Does EMFObservables provide undo/redo functionality? [message #420406 is a reply to message #420403] Sat, 28 June 2008 10:50 Go to previous messageGo to next message
Cristi Angheluta is currently offline Cristi AnghelutaFriend
Messages: 25
Registered: July 2009
Junior Member
You mean EMFEditObservables from org.eclipse.emf.databinding.edit plugin?

Cristi Angheluta


On Sat, 28 Jun 2008 13:17:45 +0300, Tom Schindl
<tom.schindl@bestsolution.at> wrote:

> You'll need to use the EMFObservableEditingDomain for this kind of thing
> this is an extra plugin.
>
> Tom
>
> AJ schrieb:
>> Hi,
>> I am using EMFObservables.observeValue((EObject) object, feature), but
>> undo/redo functionality is not working.
>> AdapterFactoryEditingDomain.getEditingDomainFor(target) is returning an
>> EditingDoamin and domain.getCommandStack() is returning a CommandStack
>> as well.
>> So, does EMFObservables support the undo/redo functionality?
>> Thanks!
>>
>
>
Re: Does EMFObservables provide undo/redo functionality? [message #420407 is a reply to message #420406] Sat, 28 June 2008 10:53 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Sure :-)

Tom

Cristi Angheluta schrieb:
> You mean EMFEditObservables from org.eclipse.emf.databinding.edit plugin?
>
> Cristi Angheluta
>
>
> On Sat, 28 Jun 2008 13:17:45 +0300, Tom Schindl
> <tom.schindl@bestsolution.at> wrote:
>
>> You'll need to use the EMFObservableEditingDomain for this kind of
>> thing this is an extra plugin.
>>
>> Tom
>>
>> AJ schrieb:
>>> Hi,
>>> I am using EMFObservables.observeValue((EObject) object, feature),
>>> but undo/redo functionality is not working.
>>> AdapterFactoryEditingDomain.getEditingDomainFor(target) is returning
>>> an EditingDoamin and domain.getCommandStack() is returning a
>>> CommandStack as well.
>>> So, does EMFObservables support the undo/redo functionality?
>>> Thanks!
>>>
>>
>>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Does EMFObservables provide undo/redo functionality? [message #420409 is a reply to message #420406] Sat, 28 June 2008 13:45 Go to previous messageGo to next message
Al B is currently offline Al BFriend
Messages: 130
Registered: July 2009
Senior Member
Cristi / Tom,

Thank you both. It works with EMFEditObservables

However, there is an undesired behavior. By default, all change events
generated by keystrokes are triggering a SetCommand. Is there a way to
make EMFEditObservables to store the keystrokes into a CompoundCommand for
all event within the same binding and execute it when the text field lost
focus?

Thanks again!
Re: Does EMFObservables provide undo/redo functionality? [message #420412 is a reply to message #420409] Sun, 29 June 2008 07:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
AJ,

In my opinion this is something that should be done on the other side of
the fence. I.e., each key stroke should not commit a change to the
underlying model because the model itself doesn't know anything about
what the GUI or user is doing.

AJ wrote:
> Cristi / Tom,
>
> Thank you both. It works with EMFEditObservables
>
> However, there is an undesired behavior. By default, all change events
> generated by keystrokes are triggering a SetCommand. Is there a way
> to make EMFEditObservables to store the keystrokes into a
> CompoundCommand for all event within the same binding and execute it
> when the text field lost focus?
>
> Thanks again!
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Does EMFObservables provide undo/redo functionality? [message #420416 is a reply to message #420412] Sat, 28 June 2008 21:14 Go to previous messageGo to next message
Al B is currently offline Al BFriend
Messages: 130
Registered: July 2009
Senior Member
Ed,

When you say "it is something that should be done on the other side of the
fence", are you referring to my side of the fence where I need to extend
the EMFEditObservables functionality or the JFace/Platform side of the
fence?

Thanks!
Re: Does EMFObservables provide undo/redo functionality? [message #420417 is a reply to message #420416] Sat, 28 June 2008 21:55 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
AJ,

Yes, I don't think each key stroke should change the model and only
JFace knows what's happening in the UI.


AJ wrote:
> Ed,
>
> When you say "it is something that should be done on the other side of
> the fence", are you referring to my side of the fence where I need to
> extend the EMFEditObservables functionality or the JFace/Platform side
> of the fence?
>
> Thanks!
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Does EMFObservables provide undo/redo functionality? [message #420419 is a reply to message #420417] Sun, 29 June 2008 10:50 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
What Ed means is that the Text-Observable is created with SWT.FocusOut
instead of SWT.Modify. Special care has to be taken when doing this on OS-X!

Tom

Ed Merks schrieb:
> AJ,
>
> Yes, I don't think each key stroke should change the model and only
> JFace knows what's happening in the UI.
>
>
> AJ wrote:
>> Ed,
>>
>> When you say "it is something that should be done on the other side of
>> the fence", are you referring to my side of the fence where I need to
>> extend the EMFEditObservables functionality or the JFace/Platform side
>> of the fence?
>>
>> Thanks!
>>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Does EMFObservables provide undo/redo functionality? [message #420420 is a reply to message #420419] Sun, 29 June 2008 12:14 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
On the other hand Ed, do you think the Command-Framework could be able
to create a "CombinedCommand" from a list of single ones?

Tom

Tom Schindl schrieb:
> What Ed means is that the Text-Observable is created with SWT.FocusOut
> instead of SWT.Modify. Special care has to be taken when doing this on
> OS-X!
>
> Tom
>
> Ed Merks schrieb:
>> AJ,
>>
>> Yes, I don't think each key stroke should change the model and only
>> JFace knows what's happening in the UI.
>>
>>
>> AJ wrote:
>>> Ed,
>>>
>>> When you say "it is something that should be done on the other side
>>> of the fence", are you referring to my side of the fence where I need
>>> to extend the EMFEditObservables functionality or the JFace/Platform
>>> side of the fence?
>>>
>>> Thanks!
>>>
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Does EMFObservables provide undo/redo functionality? [message #420422 is a reply to message #420420] Sun, 29 June 2008 14:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Tom,

There are composite commands already, but the tricky part is it would
somehow have to merge a new command with an already executed command and
know when that's appropriate. I think the UI side of things has the
best idea of when a change should really be committed to the model...
Committing for every key stroke is a little much...


Tom Schindl wrote:
> On the other hand Ed, do you think the Command-Framework could be able
> to create a "CombinedCommand" from a list of single ones?
>
> Tom
>
> Tom Schindl schrieb:
>> What Ed means is that the Text-Observable is created with
>> SWT.FocusOut instead of SWT.Modify. Special care has to be taken when
>> doing this on OS-X!
>>
>> Tom
>>
>> Ed Merks schrieb:
>>> AJ,
>>>
>>> Yes, I don't think each key stroke should change the model and only
>>> JFace knows what's happening in the UI.
>>>
>>>
>>> AJ wrote:
>>>> Ed,
>>>>
>>>> When you say "it is something that should be done on the other side
>>>> of the fence", are you referring to my side of the fence where I
>>>> need to extend the EMFEditObservables functionality or the
>>>> JFace/Platform side of the fence?
>>>>
>>>> Thanks!
>>>>
>>
>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Does EMFObservables provide undo/redo functionality? [message #420423 is a reply to message #420422] Sun, 29 June 2008 15:18 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
But on focus out is also :-( because you can't rely on it on all
platforms (OS-X doesn't has a focus lost when you hit the save button
because buttons don't receive focus which is nice because you can hit
save and are immediately back at the position you left of). The same is
true for if your hit CTRL+S, ... .

Is there a user defined way of creating a composite command from single
change commands?

This way an UI-Logic could be:
- Change Model on ever key-stroke
- On FocusOut look at the executed commands and replace them through one
CompositeCommand

Tom

Ed Merks schrieb:
> Tom,
>
> There are composite commands already, but the tricky part is it would
> somehow have to merge a new command with an already executed command and
> know when that's appropriate. I think the UI side of things has the
> best idea of when a change should really be committed to the model...
> Committing for every key stroke is a little much...
>
>
> Tom Schindl wrote:
>> On the other hand Ed, do you think the Command-Framework could be able
>> to create a "CombinedCommand" from a list of single ones?
>>
>> Tom
>>
>> Tom Schindl schrieb:
>>> What Ed means is that the Text-Observable is created with
>>> SWT.FocusOut instead of SWT.Modify. Special care has to be taken when
>>> doing this on OS-X!
>>>
>>> Tom
>>>
>>> Ed Merks schrieb:
>>>> AJ,
>>>>
>>>> Yes, I don't think each key stroke should change the model and only
>>>> JFace knows what's happening in the UI.
>>>>
>>>>
>>>> AJ wrote:
>>>>> Ed,
>>>>>
>>>>> When you say "it is something that should be done on the other side
>>>>> of the fence", are you referring to my side of the fence where I
>>>>> need to extend the EMFEditObservables functionality or the
>>>>> JFace/Platform side of the fence?
>>>>>
>>>>> Thanks!
>>>>>
>>>
>>>
>>
>>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Does EMFObservables provide undo/redo functionality? [message #420425 is a reply to message #420419] Sun, 29 June 2008 15:23 Go to previous messageGo to next message
Al B is currently offline Al BFriend
Messages: 130
Registered: July 2009
Senior Member
Tom,

I am glad you mentioned the SWT.FocusOut because I was actually using
SWT.Modify.

So, when I changed my code to use SWTObservables.observeText(aText,
SWT.FocusOut), then everything started working a desired (i.e. the
SetCommnad is only executed when the widget loses the focus).

So, unless I am missing something here, there is not a problem and EMF +
databinding is the way to go (at least in my case) since EMF already takes
care of the undo/redo functionality.

Thanks guys!

**PS: Tom, my final score prediction is: SPAIN 3 - GERMANY 1 :-)
Re: Does EMFObservables provide undo/redo functionality? [message #420426 is a reply to message #420423] Sun, 29 June 2008 15:45 Go to previous messageGo to next message
Al B is currently offline Al BFriend
Messages: 130
Registered: July 2009
Senior Member
Tom,

I am also running on OS/X. However, I don't understand the problem you are
now trying to highlight. Here is an snap-shot of code I using that
resolved my problem.

protected Binding createWidgetsForAttribute(Composite parent,
Object object, EStructuralFeature feature,
String featureDisplayName, boolean editable) {
IObservableValue observeModel;
IObservableValue observeTarget;
EMFUpdateValueStrategy targetStrategy = new EMFUpdateValueStrategy(
EMFUpdateValueStrategy.POLICY_UPDATE);
EMFUpdateValueStrategy modelStrategy;
TableWrapData labelData = new TableWrapData(TableWrapData.LEFT,
TableWrapData.MIDDLE);
TableWrapData valueData = new TableWrapData(TableWrapData.LEFT,
TableWrapData.MIDDLE);

Label label = toolkit.createLabel(parent,
((featureDisplayName != null) ? featureDisplayName :
feature.getName()) + ": ");
label.setLayoutData(labelData);

if (target instanceof EObject) {
observeModel = EMFEditObservables.observeValue(
AdapterFactoryEditingDomain.getEditingDomainFor(object), (EObject) object,
feature);
} else if (target instanceof IObservableValue) {
observeModel = EMFObservables.observeDetailValue(Realm.getDefault(),
(IObservableValue) object, feature);
valueData.rowspan = 2;
} else {
throw new IllegalArgumentException("Invalid value for Object
parameter: " + target + ". Must be an EObject or IObservableValue.");
}

toolkit.setBorderStyle(SWT.BORDER);
Text value = toolkit.createText(parent, null);
value.setLayoutData(valueData);
observeTarget = SWTObservables.observeText(value, SWT.FocusOut);
modelStrategy = new EMFUpdateValueStrategy(
EMFUpdateValueStrategy.POLICY_UPDATE);

return dbctx.bindValue(observeTarget, observeModel, modelStrategy,
targetStrategy);
}
Re: Does EMFObservables provide undo/redo functionality? [message #420427 is a reply to message #420425] Sun, 29 June 2008 15:55 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
AJ schrieb:
> Tom,
>
> I am glad you mentioned the SWT.FocusOut because I was actually using
> SWT.Modify.

The problem is that when you are relying on FocusOut there are
situations where your model is not updated because no FocusOut-Event
occurs (A hit on the Save-Button is such a case).

Before doing any save action you'll need to ensure that the field
holding the current focus is updating the model programmatically by
calling updateTargetToModel().


Tom

--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Does EMFObservables provide undo/redo functionality? [message #420428 is a reply to message #420423] Sun, 29 June 2008 16:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Tom,

There's currently nothing that would allow commands to be merged once
executed. The issues you mention sound like yet more things that ought
to be handled at the UI level, i.e., some type of commit pending changes
on the widget with focus, otherwise what good is a focus out approach in
general...


Tom Schindl wrote:
> But on focus out is also :-( because you can't rely on it on all
> platforms (OS-X doesn't has a focus lost when you hit the save button
> because buttons don't receive focus which is nice because you can hit
> save and are immediately back at the position you left of). The same
> is true for if your hit CTRL+S, ... .
>
> Is there a user defined way of creating a composite command from
> single change commands?
>
> This way an UI-Logic could be:
> - Change Model on ever key-stroke
> - On FocusOut look at the executed commands and replace them through one
> CompositeCommand
>
> Tom
>
> Ed Merks schrieb:
>> Tom,
>>
>> There are composite commands already, but the tricky part is it would
>> somehow have to merge a new command with an already executed command
>> and know when that's appropriate. I think the UI side of things has
>> the best idea of when a change should really be committed to the
>> model... Committing for every key stroke is a little much...
>>
>>
>> Tom Schindl wrote:
>>> On the other hand Ed, do you think the Command-Framework could be
>>> able to create a "CombinedCommand" from a list of single ones?
>>>
>>> Tom
>>>
>>> Tom Schindl schrieb:
>>>> What Ed means is that the Text-Observable is created with
>>>> SWT.FocusOut instead of SWT.Modify. Special care has to be taken
>>>> when doing this on OS-X!
>>>>
>>>> Tom
>>>>
>>>> Ed Merks schrieb:
>>>>> AJ,
>>>>>
>>>>> Yes, I don't think each key stroke should change the model and
>>>>> only JFace knows what's happening in the UI.
>>>>>
>>>>>
>>>>> AJ wrote:
>>>>>> Ed,
>>>>>>
>>>>>> When you say "it is something that should be done on the other
>>>>>> side of the fence", are you referring to my side of the fence
>>>>>> where I need to extend the EMFEditObservables functionality or
>>>>>> the JFace/Platform side of the fence?
>>>>>>
>>>>>> Thanks!
>>>>>>
>>>>
>>>>
>>>
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Does EMFObservables provide undo/redo functionality? [message #420437 is a reply to message #420427] Mon, 30 June 2008 15:12 Go to previous messageGo to next message
Al B is currently offline Al BFriend
Messages: 130
Registered: July 2009
Senior Member
Tom,

In my case, I am using a form-based view so the Save menu option triggers
the FocusOut event.

Eric Rizzo encountered the problem you described if the editor is closed
via X button. To resolve it, he suggests to override
EditorPart.isSaveOnCloseNeeded() like this:

@Override
public boolean isSaveOnCloseNeeded() {
// If one of this editor's widgets has focus, make sure it fires change
notification to
// update the model before asking if save is needed.

Control focusedChild =
EclipseUIUtils.getFocusedChild(getActivePageInstance().getMa nagedForm().getForm());
if (focusedChild != null) {
focusedChild.notifyListeners(SWT.FocusOut, null);
}

return super.isSaveOnCloseNeeded();
}
Re: Does EMFObservables provide undo/redo functionality? [message #420438 is a reply to message #420437] Mon, 30 June 2008 15:17 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
This doesn't solve the CTRL+S problem so I'm forcing a ui-model-update
explicitly.

Tom

AJ schrieb:
> Tom,
>
> In my case, I am using a form-based view so the Save menu option
> triggers the FocusOut event.
>
> Eric Rizzo encountered the problem you described if the editor is closed
> via X button. To resolve it, he suggests to override
> EditorPart.isSaveOnCloseNeeded() like this:
>
> @Override
> public boolean isSaveOnCloseNeeded() {
> // If one of this editor's widgets has focus, make sure it fires change
> notification to
> // update the model before asking if save is needed.
>
> Control focusedChild =
> EclipseUIUtils.getFocusedChild(getActivePageInstance().getMa nagedForm().getForm());
>
> if (focusedChild != null) {
> focusedChild.notifyListeners(SWT.FocusOut, null);
> }
>
> return super.isSaveOnCloseNeeded();
> }
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Does EMFObservables provide undo/redo functionality? [message #420453 is a reply to message #420438] Mon, 30 June 2008 18:03 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Sometimes one misses the the simple things:

SWTObservables.observeDelayedValue(400, myObservable)

Thanks for Chris point this out at his blog.

Tom

Tom Schindl schrieb:
> This doesn't solve the CTRL+S problem so I'm forcing a ui-model-update
> explicitly.
>
> Tom
>
> AJ schrieb:
>> Tom,
>>
>> In my case, I am using a form-based view so the Save menu option
>> triggers the FocusOut event.
>>
>> Eric Rizzo encountered the problem you described if the editor is
>> closed via X button. To resolve it, he suggests to override
>> EditorPart.isSaveOnCloseNeeded() like this:
>>
>> @Override
>> public boolean isSaveOnCloseNeeded() {
>> // If one of this editor's widgets has focus, make sure it fires
>> change
>> notification to
>> // update the model before asking if save is needed.
>>
>> Control focusedChild =
>> EclipseUIUtils.getFocusedChild(getActivePageInstance().getMa nagedForm().getForm());
>>
>> if (focusedChild != null) {
>> focusedChild.notifyListeners(SWT.FocusOut, null);
>> }
>>
>> return super.isSaveOnCloseNeeded();
>> }
>>
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Previous Topic:EMF databinding Recipe
Next Topic:ID and IDREF 1 to 1 link
Goto Forum:
  


Current Time: Fri Apr 19 14:50:38 GMT 2024

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

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

Back to the top