Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Undo/Redo with TextViewers and Dirty State Handling(Dirty State Handling for TextViewer Objects in the Context of Undo/Redo in an Editor)
Undo/Redo with TextViewers and Dirty State Handling [message #1693338] Thu, 23 April 2015 10:10 Go to next message
Adalbert Perbandt is currently offline Adalbert PerbandtFriend
Messages: 4
Registered: March 2014
Junior Member
Hi there

some time ago I posted a problem I'm facing with Undo/Redo behavior in conjunction with dirty state handling in a multipage editor using Eclipse forms in the Eclipse Community forum for newcomers. Unfortunately I got no response on my posting and so I assume that this was not the proper place to publish my problem. I just discovered the JFace forum so I'd like to publish my issue here in the hope someone can provide some helpful information.

I'm implementing an editor plugin. The editor is constructed in the form of a multi-page editor with the pages implemented using Eclipse Forms. It looks a little bit similar to Eclipse's plugin.xml editor in the sense that each page is structured in sections (extending SectionPart). The sections contain several different GUI components, e.g. TextViewers, TableViewers and TreeViewers. Whenever in any of the GUI components belonging to the editor a change is made, the editor
becomes dirty.
I'm now in the process of implementing Undo/Redo for my editor. For the TreeViewers and TableViewers I made this work already. So addition or removal of objects in a TreeViewer or TableViewer can be undone and in case the editor's dirty state before the respective operation was clean, then after undoing the operation the editor becomes clean again. I achieved this by caching the editor's dirty state in the respective operation so that when undo is executed on it the previous dirty state is restored again in the editor.
But with undo/redo of changes made in TextViewer objects I couldn't figure out yet how to achieve this behavior. The problem for me is that the TextViewer already has undo/redo implemented in a helper class called TextViewerUndoManager. I only needed to create an instance of this class, set it into the TextViewer and connect it with this TextViewer instance. Besides this I created a context menu for the TextViewer. And I managed to make the editor's undo context match the undo context provided by the TextViewer's undo manager. The code that does all that looks as follows:

fText = new TextViewer(parent, styles);
fTextModel = new Document("");
fText.setDocument(fTextModel);
int MAX_UNDO_LEVEL = 99;
TextViewerUndoManager undoMgr = new TextViewerUndoManager(MAX_UNDO_LEVEL);	
fText.setUndoManager(undoMgr);
fText.getUndoManager().connect(fText);
ObjectUndoContext context = (ObjectUndoContext) undoMgr.getUndoContext();
MyEditor editor = (MyEditor) site.getPart();
context.addMatch(editor.getUndoContext());
MenuManager manager = new MenuManager(null, "#PopupMenu");
Menu menu = manager.createContextMenu(ftext.getControl());
ftext.getControl().setMenu(menu);
site.registerContextMenu(manager, ftext);


I assumed that the TextViewer's document should somehow already support the concept of a dirty state or that the UndoManager would provide some API for dirty state handling but could not find anything.

Any helpful hint would be very welcome!

Regards,

Adalbert.
Re: Undo/Redo with TextViewers and Dirty State Handling [message #1693718 is a reply to message #1693338] Mon, 27 April 2015 20:25 Go to previous message
Maria Finkelstein is currently offline Maria FinkelsteinFriend
Messages: 8
Registered: January 2014
Junior Member
If i understand your problem, you need to use command stack. I am not sure what editor you are using but there is Emf and GEF command stack



it's very easy to use and you don't need TextViewerUndoManager
Previous Topic:Single Selection ViewerProperties Databinding with Converter
Next Topic:How toHow to draw lines between jface tree items
Goto Forum:
  


Current Time: Thu Apr 25 19:33:49 GMT 2024

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

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

Back to the top