Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Eclipse 4 undo/redo mechanism
Eclipse 4 undo/redo mechanism [message #1573542] Mon, 19 January 2015 20:15 Go to next message
Vladimir D is currently offline Vladimir DFriend
Messages: 22
Registered: January 2013
Junior Member
Hi all,

I was wondering if anyone has some information or useful links on how to implement undo/redo mechanism in the eclipse4-based editor.

I developed a set of plugins that extends Eclipse IDE with some drawing views (mainly drawing lines between two element trees). I've used e4 tools to develop the tool so far, but now I need to implement undo/redo mechanism. I could develop my own command stack and introduce my own undo and redo buttons in my tool, but I was wondering if there is some tutorial on how to integrate this with existing Eclipse IDE mechanism. I found some instructions for previous eclipse versions (one is present in the official eclipse rpc help). However I was not able to replicate this in the current version.

I must stress out that I'm a beginner to e4 rpc development and any comment, suggestion, or a link that you may give me would be greatly appreciated.

Best regards.

Re: Eclipse 4 undo/redo mechanism [message #1574395 is a reply to message #1573542] Tue, 20 January 2015 07:40 Go to previous messageGo to next message
Mihael Schmidt is currently offline Mihael SchmidtFriend
Messages: 81
Registered: August 2010
Member
Hi,

I had the same "problem". My situation: I have a JFace SourceViewer based editor which needs undo/redo functionality.

I have created my own commands and handlers, f. e.:

import javax.inject.Inject;
import javax.inject.Named;

import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.services.adapter.Adapter;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.text.ITextOperationTarget;

public class UndoHandler {
	
	@Inject
	private Adapter _adapter;

	@Execute
	public void execute(@Named(IServiceConstants.ACTIVE_PART) final MPart part) {
		final ITextOperationTarget opTarget = _adapter.adapt(part.getObject(),
				ITextOperationTarget.class);

		opTarget.doOperation(ITextOperationTarget.UNDO);
	}

	@CanExecute
	public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) final MPart part) {
		final ITextOperationTarget opTarget = _adapter.adapt(part.getObject(),
				ITextOperationTarget.class);
		if (opTarget == null)
			return false;
		boolean canDoOperation = opTarget.canDoOperation(ITextOperationTarget.UNDO);
		return canDoOperation;
	}
}
Re: Eclipse 4 undo/redo mechanism [message #1574450 is a reply to message #1574395] Tue, 20 January 2015 08:18 Go to previous messageGo to next message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
Hello,

Depending on your needs, you could also use the commands framework from EMF Edit. A very nice presentation of EMF can be found here : http://fr.slideshare.net/dmsteinberg/eclipsecon-2007-effective-use-of-the-eclipse-modeling-framework
Re: Eclipse 4 undo/redo mechanism [message #1586219 is a reply to message #1574450] Mon, 26 January 2015 18:40 Go to previous message
Vladimir D is currently offline Vladimir DFriend
Messages: 22
Registered: January 2013
Junior Member
Hi all,

thank you for your suggestions. In the end I choose Mihael's solution. As a do not use SourceViewer or other JFace components, I created my own commands and command stack within a custom-made view component. However, this handler was of great help, and I just changed it a little bit to suit my needs.

Kind ragards.
Previous Topic:A lot of elements kept in UISynchronizer.pendingStartup attribute
Next Topic:Compile and Run a Class.Java File
Goto Forum:
  


Current Time: Wed Apr 24 22:55:31 GMT 2024

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

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

Back to the top