Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Undo/Redo functionality with EMF resources
Undo/Redo functionality with EMF resources [message #1010797] Mon, 18 February 2013 09:02 Go to next message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
Hi,

I'm not sure, whether this is the right forum or the EMF forum is the better choice. But I thought, this could be more of an Eclipse 4 topic.
I'm creating a Eclipse 4 RCP that uses EMF resources as input. Now I want to implement undo/redo functionality. In Eclipse 3.x the EMF generated editor used an EditingDomain that includes a CommandStack. I thought maybe I could use this EditingDomain in the Eclipse 4 RCP, too. So I created the EditingDomain like in the EMF Editor:
adapterFactory = new ComposedAdapterFactory(
				ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
		adapterFactory
				.addAdapterFactory(new ResourceItemProviderAdapterFactory());
		adapterFactory
				.addAdapterFactory(new IdentifiableItemProviderAdapterFactory());
		adapterFactory
				.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());

		BasicCommandStack commandStack = new BasicCommandStack();
		commandStack.addCommandStackListener(new CommandStackListener() {

			@Override
			public void commandStackChanged(EventObject event) {
				eventBroker.post(UIEvents.Dirtyable.DIRTY, dirtyable);

			}
		});

		editingDomain = new AdapterFactoryEditingDomain(adapterFactory,
				commandStack, new HashMap<Resource, Boolean>());
		editingDomain.getResourceSet().getResources().add(resource);


Unfortunately the CommandStack is always empty. Does anabody have an idea what else I have to do, to get the CommandStack filled, if an action on the resource is permormed?

Best regards
Bastian
Re: Undo/Redo functionality with EMF resources [message #1010804 is a reply to message #1010797] Mon, 18 February 2013 09:11 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi

I don't know about e4, but concerning the editing domain and the command
stack: are you using the same resource set of the editing domain to load
your EMF resource?

cheers
Lorenzo

On 02/18/2013 10:02 AM, Bastian Wagenfeld wrote:
> Hi,
>
> I'm not sure, whether this is the right forum or the EMF forum is the
> better choice. But I thought, this could be more of an Eclipse 4 topic.
> I'm creating a Eclipse 4 RCP that uses EMF resources as input. Now I
> want to implement undo/redo functionality. In Eclipse 3.x the EMF
> generated editor used an EditingDomain that includes a CommandStack. I
> thought maybe I could use this EditingDomain in the Eclipse 4 RCP, too.
> So I created the EditingDomain like in the EMF Editor:
> adapterFactory = new ComposedAdapterFactory(
> ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
> adapterFactory
> .addAdapterFactory(new
> ResourceItemProviderAdapterFactory());
> adapterFactory
> .addAdapterFactory(new
> IdentifiableItemProviderAdapterFactory());
> adapterFactory
> .addAdapterFactory(new
> ReflectiveItemProviderAdapterFactory());
>
> BasicCommandStack commandStack = new BasicCommandStack();
> commandStack.addCommandStackListener(new CommandStackListener() {
>
> @Override
> public void commandStackChanged(EventObject event) {
> eventBroker.post(UIEvents.Dirtyable.DIRTY, dirtyable);
>
> }
> });
>
> editingDomain = new AdapterFactoryEditingDomain(adapterFactory,
> commandStack, new HashMap<Resource, Boolean>());
> editingDomain.getResourceSet().getResources().add(resource);
>
> Unfortunately the CommandStack is always empty. Does anabody have an
> idea what else I have to do, to get the CommandStack filled, if an
> action on the resource is permormed?
> Best regards
> Bastian


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it


Re: Undo/Redo functionality with EMF resources [message #1010810 is a reply to message #1010804] Mon, 18 February 2013 09:27 Go to previous messageGo to next message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
Hi Lorenzo,

I'm not quite sure, if I understand your question correctly. Firt I load the Resource via Texo, then I call the code above and afterwards set editingDomain.getResourceSet().getResources().get(0) as the TreeViewer's input.

Bastian
Re: Undo/Redo functionality with EMF resources [message #1010861 is a reply to message #1010810] Mon, 18 February 2013 11:05 Go to previous message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
Hey,

I think I misunderstood the behaviour of the command stack. I thought, the EditingDomain would automatically create and add the Commands to the CommandStack, if I add or remove contents. This doesn't seem to be what happens, so when I manually create the commands, it works. For example: editingDomain.getCommandStack().execute(RemoveCommand.create(editingDomain, obj));.

So, it was my fault and also the wrong forum Smile Sorry for that!

Best regards
Bastian
Previous Topic:Hide View Tab
Next Topic:Problems with CompatibilityView
Goto Forum:
  


Current Time: Fri Apr 26 04:06:04 GMT 2024

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

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

Back to the top