Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » ChangeCommand Test(How it works, is it in working condition ?)
ChangeCommand Test [message #648556] Thu, 13 January 2011 14:03 Go to next message
tenor  is currently offline tenor Friend
Messages: 57
Registered: October 2010
Member
http://dev.eclipse.org/newslists/news.eclipse.platform/msg69 415.html

how to run it ?

As facing error at imports ie

import org.eclipse.emf.test.models.ref.E;
import org.eclipse.emf.test.models.ref.RefFactory;
import org.eclipse.emf.test.models.ref.RefPackage;
import org.eclipse.emf.test.models.ref.provider.RefItemProviderAdap terFactory;



How it uses ChangeRecorder internally ?

Re: ChangeCommand Test [message #648640 is a reply to message #648556] Thu, 13 January 2011 18:09 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
You could try to install the unit test by extracting them from CVS:
http://wiki.eclipse.org/EMF/Getting_Source

tenor wrote:
> http://dev.eclipse.org/newslists/news.eclipse.platform/msg69 415.html
>
> how to run it ?
>
> As facing error at imports ie
> import org.eclipse.emf.test.models.ref.E;
> import org.eclipse.emf.test.models.ref.RefFactory;
> import org.eclipse.emf.test.models.ref.RefPackage;
> import org.eclipse.emf.test.models.ref.provider.RefItemProviderAdap
> terFactory;
>
>
>
> How it uses ChangeRecorder internally ?
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ChangeCommand Test [message #648682 is a reply to message #648640] Fri, 14 January 2011 01:53 Go to previous messageGo to next message
tenor  is currently offline tenor Friend
Messages: 57
Registered: October 2010
Member
i get errors at import after i have checked out through cvs.

import org.eclipse.emf.test.models.ref.E;
import org.eclipse.emf.test.models.ref.RefFactory;
import org.eclipse.emf.test.models.ref.RefPackage;
import org.eclipse.emf.test.models.ref.provider.RefItemProviderAdap terFactory;

i put in MANIFEST.MF

org.eclipse.emf.test.common;resolution:=optional,
org.eclipse.emf.common,
org.eclipse.emf.edit,
org.eclipse.emf.transaction;resolution:=optional,
org.eclipse.emf.validation;resolution:=optional,
org.eclipse.emf.edit.ui

first one ie test one was red, as fix it suggested to be optional.

where i am going wrong as unable to run ChangeCommand.
Re: ChangeCommand Test [message #648692 is a reply to message #648682] Fri, 14 January 2011 03:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
I do the same thing but don't get errors. Those tests don't depend on
transaction nor validation.

tenor wrote:
> i get errors at import after i have checked out through cvs.
>
> import org.eclipse.emf.test.models.ref.E;
> import org.eclipse.emf.test.models.ref.RefFactory;
> import org.eclipse.emf.test.models.ref.RefPackage;
> import org.eclipse.emf.test.models.ref.provider.RefItemProviderAdap
> terFactory;
>
> i put in MANIFEST.MF
>
> org.eclipse.emf.test.common;resolution:=optional,
> org.eclipse.emf.common,
> org.eclipse.emf.edit,
> org.eclipse.emf.transaction;resolution:=optional,
> org.eclipse.emf.validation;resolution:=optional,
> org.eclipse.emf.edit.ui
>
> first one ie test one was red, as fix it suggested to be optional.
>
> where i am going wrong as unable to run ChangeCommand.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ChangeCommand Test [message #648753 is a reply to message #648692] Fri, 14 January 2011 12:25 Go to previous messageGo to next message
tenor  is currently offline tenor Friend
Messages: 57
Registered: October 2010
Member
i get at the time of import only!!! Sad
Re: ChangeCommand Test [message #648821 is a reply to message #648753] Fri, 14 January 2011 16:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Your sentences are short.

tenor wrote:
> i get at the time of import only!!! :(


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ChangeCommand Test [message #648856 is a reply to message #648556] Fri, 14 January 2011 18:19 Go to previous messageGo to next message
tenor  is currently offline tenor Friend
Messages: 57
Registered: October 2010
Member
Right at the checkout level, those imports are having red mark.

I have not run the test yet as unable to run.
Re: ChangeCommand Test [message #648887 is a reply to message #648856] Fri, 14 January 2011 22:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
What exactly have you all checked out?

PS. Don't expect me to spend more time answering your questions than you
spend asking them.


tenor wrote:
> Right at the checkout level, those imports are having red mark.
>
> I have not run the test yet as unable to run.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ChangeCommand Test [message #648969 is a reply to message #648887] Sun, 16 January 2011 22:40 Go to previous messageGo to next message
tenor  is currently offline tenor Friend
Messages: 57
Registered: October 2010
Member
Merks.Thanks.

These were missing in the check out.

org.eclipse.emf.test.common
org.eclipse.emf.test.edit

NOW, it runs fine. Smile

But, i want to know

1) Does doing applyAndReverse again and again will result in undo ? but i did two times, and pressed undo button in my app, it resulted as it was!!![ ie using ChangeRecorder]

2) using ChangeCommand vs ChangeRecorder, who scores over and why?

Much Thanks.
Re: ChangeCommand Test [message #648970 is a reply to message #648969] Sun, 16 January 2011 22:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Comments below.

tenor wrote:
> Merks.Thanks.
>
> These were missing in the check out.
>
> org.eclipse.emf.test.common
> org.eclipse.emf.test.edit
>
> NOW, it runs fine. :)
>
> But, i want to know
>
> 1) Does doing applyAndReverse again and again will result in undo ?
> but i did two times, and pressed undo button in my app, it resulted as
> it was!!![ ie using ChangeRecorder]
Calling applyAndReverse applies the changes and reverses the change
description such that calling applyAndReverse a second time will be the
same as not calling it at all. I.e., it helps implement undo and redo.
>
> 2) using ChangeCommand vs ChangeRecorder, who scores over and why?
A ChangeCommand uses a ChangeRecorder to keep track of all changes made
when executing the command. The resulting ChangeDescription is then
used by ChangeCommand to implement undo/redo.
>
> Much Thanks.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ChangeCommand Test [message #649170 is a reply to message #648970] Tue, 18 January 2011 00:35 Go to previous messageGo to next message
tenor  is currently offline tenor Friend
Messages: 57
Registered: October 2010
Member
Vide in the book.

Notice that calling applyAndReverse() repeatedly provides a convenient undo/redo capability for a change description.

I was under impression, it can lead me to undo the "Each Step Changes" back to original state, but it does NOT!!

It goes in one shot to original.

So, Merks, my Q is

1) How i can write for before press of OK button, it should call startRecording and on press of OK button, it should call endRecording, and save changes happened in between, to a stack. And if user presses undo , at this point of time, it should revert the change, to last sequential value. if again pressed undo, again till last value from this reverted back value, ie journey back and tracing back.

2)if so, any close example?


Thanks.
Re: ChangeCommand Test [message #649171 is a reply to message #649170] Tue, 18 January 2011 00:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Comments below.

tenor wrote:
> Vide in the book.
>
> Notice that calling applyAndReverse() repeatedly provides a convenient
> undo/redo capability for a change description.
Yes, call it once is undo, call it twice is redo, call it three times is
undo again...
>
> I was under impression, it can lead me to undo the "Each Step Changes"
> back to original state, but it does NOT!!
No, that's what a command stack does.
>
> It goes in one shot to original.
>
> So, Merks, my Q is
>
> 1) How i can write for before press of OK button, it should call
> startRecording and on press of OK button, it should call endRecording,
> and save changes happened in between, to a stack. And if user presses
> undo , at this point of time, it should revert the change, to last
> sequential value. if again pressed undo, again till last value from
> this reverted back value, ie journey back and tracing back.
Are you writing a wizard or dialog? It's best that such a thing make no
changes to the actual model until you press OK. When you press OK, you
should execute a command that makes all the changes.
>
> 2)if so, any close example?
The problem is if you make changes to the actual objects before pressing
okay, the rest of the editor will see those changes.
>
>
> Thanks.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ChangeCommand Test [message #649173 is a reply to message #649171] Tue, 18 January 2011 01:24 Go to previous messageGo to next message
tenor  is currently offline tenor Friend
Messages: 57
Registered: October 2010
Member
Are you writing a wizard or dialog? It's best that such a thing make no
changes to the actual model until you press OK. When you press OK, you
should execute a command that makes all the changes.


We will have UI with N tabs , each tab having say X fields.
we are not saving to model.

you
should execute a command that makes all the changes.


Which command i should execute? ChangeCommand? Does it do incremental undo?


Thanks.
Re: ChangeCommand Test [message #649320 is a reply to message #649173] Tue, 18 January 2011 17:49 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Tenor,

Comments below.

tenor wrote:
> Are you writing a wizard or dialog? It's best that such a thing make
> no changes to the actual model until you press OK. When you press OK,
> you should execute a command that makes all the changes.
>
> We will have UI with N tabs , each tab having say X fields.
So how does the OK button fit into the picture.
> we are not saving to model.
The data being edited is completely transient?
>
> you should execute a command that makes all the changes.
>
> Which command i should execute?
Whatever works well for you. It sounds like changing individual fields
is just like editing properties in the properties view and can make use
of things like SetCommand
> ChangeCommand?
If that works best.
> Does it do incremental undo?
It will undo whatever is done during execute.
>
>
> Thanks.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ChangeCommand Test [message #649352 is a reply to message #649320] Tue, 18 January 2011 21:16 Go to previous messageGo to next message
tenor  is currently offline tenor Friend
Messages: 57
Registered: October 2010
Member
yes, data is transient.

Based on ChangeCommandTest, i tried to replicate the test but i could not meet any success!!


protected void doExecute() {
service = Proxy.getManagementService();
List<Name> names = service.getAllNames);
for (Name name : namess) {

AggregateKey ak = DomainFactory.eINSTANCE
.createAggregateKey();
ak.setClassifier(mult.eClass().getClassifierID());
ak.setId(EcoreUtil.getID(mult));

resource.getContents().add(mult);
keyList.add(ak);
}

And then

editingDomain.getCommandStack().execute(changeCommand);
editingDomain.getCommandStack().undo();
}

How to achieve incremental undo ie at each step like Unit of Work with ChangeCommand?

Re: ChangeCommand Test [message #649365 is a reply to message #649352] Tue, 18 January 2011 21:40 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Comments below.

tenor wrote:
> yes, data is transient.
>
> Based on ChangeCommandTest, i tried to replicate the test but i could
> not meet any success!!
>
>
> protected void doExecute() {
> service = Proxy.getManagementService();
> List<Name> names = service.getAllNames);
> for (Name name : namess) {
>
> AggregateKey ak = DomainFactory.eINSTANCE
> .createAggregateKey();
> ak.setClassifier(mult.eClass().getClassifierID());
> ak.setId(EcoreUtil.getID(mult));
>
> resource.getContents().add(mult);
> keyList.add(ak);
> }
>
Have you specified suitable notifiers such that all the above changes
will be recorded?
> And then
>
> editingDomain.getCommandStack().execute(changeCommand);
> editingDomain.getCommandStack().undo();
> }
>
> How to achieve incremental undo ie at each step like Unit of Work with
> ChangeCommand?
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ChangeCommand Test [message #649369 is a reply to message #649365] Tue, 18 January 2011 23:02 Go to previous messageGo to next message
tenor  is currently offline tenor Friend
Messages: 57
Registered: October 2010
Member
Merks,

What are those suitable Notifers as i am unable to find them in ChangeCommandTest.

AND

MOST FUNDAMENTALLY, Can i get undo capability for each of Change? step back , one step at a time?

If so, how to achieve this with ChangeCommand?
Re: ChangeCommand Test [message #649373 is a reply to message #649369] Wed, 19 January 2011 00:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Comments below.

tenor wrote:
> Merks,
>
> What are those suitable Notifers as i am unable to find them in
> ChangeCommandTest.
You'll see that there are three tests that test changes made to an
EObject, a Resource, and a ResourceSet.
>
> AND
>
> MOST FUNDAMENTALLY, Can i get undo capability for each of Change? step
> back , one step at a time?
It will undo exactly the things you did during doExecute. If you do
only one thing, it will undo only one thing. If you do many things, it
will undo them all...
> If so, how to achieve this with ChangeCommand?
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ChangeCommand Test [message #649838 is a reply to message #649373] Thu, 20 January 2011 17:38 Go to previous messageGo to next message
tenor  is currently offline tenor Friend
Messages: 57
Registered: October 2010
Member
1.Do we necessarily have to generate the Editor code if we are going for EMF.edit approach?
Can we mimic redo/undo of EMF.edit without code generation? How i can have EditingDomain and other classes which are generated
out of code generation.

2.And can we use the "org.eclipse.emf.common.command.BasicCommandStack" for redo/undo.

Thanks.
Re: ChangeCommand Test [message #649856 is a reply to message #649838] Thu, 20 January 2011 18:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Tenor,

Comments below.

tenor wrote:
> 1.Do we necessarily have to generate the Editor code if we are going
> for EMF.edit approach?
No.
> Can we mimic redo/undo of EMF.edit without code generation?
Yes.
> How i can have EditingDomain and other classes which are generated
> out of code generation.
Do by hand what you see in the generated editor.
>
> 2.And can we use the
> "org.eclipse.emf.common.command.BasicCommandStack" for redo/undo.
Yes.
>
> Thanks.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ChangeCommand Test [message #650096 is a reply to message #649856] Fri, 21 January 2011 17:39 Go to previous messageGo to next message
tenor  is currently offline tenor Friend
Messages: 57
Registered: October 2010
Member
Merks

I have generated editor code.

During debug of redo/undo of library editor code, [i set up break point at setName], i found that this line ie ((BasicCommandStack)editingDomain.getCommandStack()).saveIsD one(); is touched
and then
it goes in the BasicCommandStack.class

As i have to redo/undo on screen(UI) not attached to viewer etc.
I should bind button at UI to
A) DomainEditor.doSave(IProgressMonitor progressMonitor) ie i want to know which piece of code i should bind to?

B)if so, what can be passed as progressMonitor from UI side?

Thanks.
Re: ChangeCommand Test [message #650121 is a reply to message #650096] Fri, 21 January 2011 19:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Comments below.

tenor wrote:
> Merks
>
> I have generated editor code.
>
> During debug of redo/undo of library editor code, [i set up break
> point at setName], i found that this line ie
> ((BasicCommandStack)editingDomain.getCommandStack()).saveIsD one(); is
> touched and then
> it goes in the BasicCommandStack.class
> As i have to redo/undo on screen(UI) not attached to viewer etc.
> I should bind button at UI to
> A) DomainEditor.doSave(IProgressMonitor progressMonitor) ie i want to
> know which piece of code i should bind to?
I really can't make sense out of the above comments. I know you said
you didn't need to persist any data so I'm not sure how save is coming up.
>
> B)if so, what can be passed as progressMonitor from UI side?
The platform has classes to create a progress monitor. They're not that
hard to find.
>
> Thanks.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ChangeCommand Test [message #650143 is a reply to message #650121] Fri, 21 January 2011 22:32 Go to previous messageGo to next message
tenor  is currently offline tenor Friend
Messages: 57
Registered: October 2010
Member
I am NOT saving any of changes, but only till SAVE button is clicked.

Which piece governs the undo/redo in editor code?

I thought
((BasicCommandStack)editingDomain.getCommandStack()).saveIsD one() , as that leads to BasicCommandStack in debug.

Re: ChangeCommand Test [message #650191 is a reply to message #650143] Sat, 22 January 2011 17:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
You seem to have an endless stream of questions that are starting to
feel a little circular. Surely you've noticed that BasicCommandStack
has undo/redo methods and you're certainly capable of setting a
breakpoint in those methods. In addition, you have a fully functional
editor that supports undo/redo and a feature rich debugger than can help
answer any question you could possibly ask about how it works. Use
those tools and try to ask questions that demonstrate you've done your
own homework first.

tenor wrote:
> I am NOT saving any of changes, but only till SAVE button is clicked.
>
> Which piece governs the undo/redo in editor code?
>
> I thought ((BasicCommandStack)editingDomain.getCommandStack()).saveIsD
> one() , as that leads to BasicCommandStack in debug.
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ChangeCommand Test [message #650398 is a reply to message #650191] Mon, 24 January 2011 17:47 Go to previous messageGo to next message
tenor  is currently offline tenor Friend
Messages: 57
Registered: October 2010
Member
Dont despair on me.
I am trying to get it right, but miss basics.
I had a look at following generated editor class. ie
LibraryEditor
LibraryActionBarContributor

And
public class LibraryActionBarContributor
extends EditingDomainActionBarContributor
And i notice , that there is following method in the EditingDomainActionBarContributor
protected UndoAction createUndoAction()
{
return new UndoAction();
}

Now in UndoAction.class, i set bp here, it breakspoint here

@Override
public void run()
{
domain.getCommandStack().undo();
}

Further debugging, takes to BasicCommandStack class.

So i need domain, as domain has commandstack.
First set of questions
1. If LibraryEditor.java can be subclassed to provide redo/undo functionality?
2. How to put button there, if LibraryEditor is to do calling for redo/undo ?

And as in the link
http://www.eclipsezone.com/eclipse/forums/t115960.html
the last part ie
Furthermore EMF global undo/redo etc actions are only added to the actual
Actions in eclipse via the ActionHandler mechanism, which is called from
the EditorActionBar.init function or from the shareGlobalActions function
if you are attaching them via a View such as an Outline or PropertySheet.
The shareGlobalActions function is in turn called from setActionBars on
the Page class, which you will have in your View? If you look at how the
generated Editor's ContentOutlinePage and PropertySheetPage handle these
things, you could incorporate this into your code, bearing in mind that
you need to be an EditorPart to use the EMF ActionBarContributor as is.
Second set of Qs
1. Where to hook for redo/undo button, if i have NOTHING to do with Property sheet, as i will have my own view.
So, in this view, if i place a button which bit of piece i should hook to ?
2. As above, EditorPart is MUST ? if so,
menuManager.add(new ActionContributionItem(undoAction)); is one of means to achieve a button on my view?

3. Unrelated to this, in the copy by EMF.edit, does it copy contained references?





Re: ChangeCommand Test [message #650416 is a reply to message #650398] Mon, 24 January 2011 18:38 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Tenor,

Comments below.

tenor wrote:
> Dont despair on me.
I'm not generally a patient person despite appearances to the contrary.
> I am trying to get it right, but miss basics.
> I had a look at following generated editor class. ie
> LibraryEditor
> LibraryActionBarContributor
> And
> public class LibraryActionBarContributor
> extends EditingDomainActionBarContributor
> And i notice , that there is following method in the
> EditingDomainActionBarContributor
> protected UndoAction createUndoAction()
> {
> return new UndoAction();
> }
>
> Now in UndoAction.class, i set bp here, it breakspoint here
>
> @Override
> public void run()
> {
> domain.getCommandStack().undo();
> }
>
> Further debugging, takes to BasicCommandStack class.
>
> So i need domain, as domain has commandstack.
> First set of questions
> 1. If LibraryEditor.java can be subclassed to provide redo/undo
> functionality?
It already directly supports it.
> 2. How to put button there, if LibraryEditor is to do calling for
> redo/undo ?
There's a menu action in the edit menu. Ho to provide button for the
same thing isn't an EMF question.
>
> And as in the link http://www.eclipsezone.com/eclipse/forums/t115960.html
> the last part ie
> Furthermore EMF global undo/redo etc actions are only added to the
> actual Actions in eclipse via the ActionHandler mechanism, which is
> called from the EditorActionBar.init function or from the
> shareGlobalActions function if you are attaching them via a View such
> as an Outline or PropertySheet. The shareGlobalActions function is in
> turn called from setActionBars on the Page class, which you will have
> in your View? If you look at how the generated Editor's
> ContentOutlinePage and PropertySheetPage handle these things, you
> could incorporate this into your code, bearing in mind that you need
> to be an EditorPart to use the EMF ActionBarContributor as is. Second
> set of Qs
> 1. Where to hook for redo/undo button, if i have NOTHING to do
> with Property sheet, as i will have my own view.
> So, in this view, if i place a button which bit of piece i should hook
> to ?
You can see that the action just calls undo on the command stack so you
can do the same thing from any button you decide to put anywhere.
> 2. As above, EditorPart is MUST ?
No.
> if so, menuManager.add(new ActionContributionItem(undoAction)); is one
> of means to achieve a button on my view?
Make the button any way you want (it's not an EMF question) and invoke
undo on the command stack (simple).
>
> 3. Unrelated to this, in the copy by EMF.edit, does it copy
> contained references?
Yes it does.
>
>
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[EEF] Absolute paths in components model
Next Topic:[EEF] RAP Support
Goto Forum:
  


Current Time: Fri Apr 19 10:00:50 GMT 2024

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

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

Back to the top