Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Need help on implementing Undo-Redo feature for eclipse Form Editor.
Need help on implementing Undo-Redo feature for eclipse Form Editor. [message #996536] Wed, 02 January 2013 10:10 Go to next message
akhil gupta is currently offline akhil guptaFriend
Messages: 13
Registered: November 2012
Junior Member
Hello,

I am developing a multipage FormEditor to edit/create a customized XML file.
1.Implementation class is MyXMLFormEditor which extends FormEditor.
2.Each page of FormEditor extends FormPage (i.e. MyXMLFormPage extends FormPage).
3.Between FormEditor and actual XML file I am maintaining JDOM model.
4.Also I implemented dirty flag handling. So user's inputs into form editor gets saved into JDOM till the time user presses Save button. When user presses save button JDOM is written/serialized into XML file.

In an editor with above functionality I would like to implement undo/redo functionality as follow:
-When editor is dirty (user changed something into form editor and it is not saved) undo operation should revert back the changes in form editor as well as JDOM to its original state (i.e. the state when editor was non-dirty) and redo operation should again bring back the changes into FormEditor as well as JDOM and editor should become dirty.

Can anyone provide me pointer/samples on how to implement undo/redo functionality into FormEditor?
It would be good if the approach make use of existing undo/redo framework of Eclipse PDE or workbench.

Here is code snippt:

MyXMLFormEditor.java

public class MyXMLFormEditor extends FormEditor {

MyXMLFormEditor(){
super();
}

@Override
protected FormToolkit createToolkit(Display display) {
// Create a toolkit that shares colors between editors.
return new FormToolkit(Activator.getDefault().getFormColors(display));
}

@Override
public void init(IEditorSite site, IEditorInput editorInput) {
setSite(site);
mSite = site;
setInput(editorInput);
try {
super.init(site, editorInput);
} catch (PartInitException e1) {
e1.printStackTrace();
}
if (!(editorInput instanceof IFileEditorInput))
try {
throw new PartInitException("Invalid Input: Must be IFileEditorInput");
} catch (PartInitException e) {
e.printStackTrace();
}
setPartName(fileName);
}
public void setUpProgFile(IEditorSite site, IEditorInput editorInput){
IFileEditorInput fileInput = ((IFileEditorInput) editorInput);

//create document builder and prepare JDom model for xml file.
}


@Override
protected void addPages() {
try {
//add 'Main' page
objMyXMLFormPage = new MyXMLFormPage (this, "FirstPage","Main");
//set rootNode of MyXMLFormPage
objMyXMLFormPage.rootNode = getRootNode();
objMyXMLFormPage.filePath = filePath;
objMyXMLFormPage.document = document;
addPage(objMyXMLFormPage);

} catch (PartInitException e) {
e.printStackTrace();
}
}

@Override
public void doSave(IProgressMonitor monitor) {
System.out.println("MyXMLFormEditor: doSave");

//logic to write jdom contents into xml file.
objMyXMLFormPage.setDirty(false);
}

@Override
public void doSaveAs() {
System.out.println("MyXMLFormEditor: doSaveAs");
}
@Override
public boolean isSaveAsAllowed() {
System.out.println("MyXMLFormEditor: isSaveAsAllowed");
return true;
}

}


MyXMLFormPage .java

public class MyXMLFormPage extends FormPage{

//private members declaration.

public MyXMLFormPage (MyXMLFormEditor editor,String title, String id) {
// initialize the editor and set its title and name.
super(editor,title,id );
}

@Override
public void createFormContent(IManagedForm managedForm) {
// Set page title
super.createFormContent(managedForm);

FormToolkit mMyXMLFormPage Toolkit = managedForm.getToolkit();

//Logic to creat UI and populating its contents from JDom

}


private void makeEditorDirty() {
updateJdom = true;
setDirty(true);
}

private void updateJDom() {
if(updateJdom){
System.out.println("*** Jdom updated ***");
updateJdom = false;
}
}

@Override
public boolean isDirty() {
return isDirtyFlag;
}

protected void setDirty(boolean value) {
isDirtyFlag = value;
dirtyStateChanged();
}

public void dirtyStateChanged() {
getEditor().editorDirtyStateChanged();

}

@Override
public boolean isSaveAsAllowed() {
System.out.println("MyXMLFormPage .isSaveAsAllowed");
return false;
}

@Override
public void doSave(IProgressMonitor monitor) {
System.out.println("MyXMLFormPage .doSave");
}

}


Thanks in Advance!
Regards,
Akhil

[Updated on: Wed, 02 January 2013 10:55]

Report message to a moderator

Re: Need help on implementing Undo-Redo feature for eclipse Form Editor. [message #996548 is a reply to message #996536] Wed, 02 January 2013 10:52 Go to previous messageGo to next message
akhil gupta is currently offline akhil guptaFriend
Messages: 13
Registered: November 2012
Junior Member
No Message Body

[Updated on: Wed, 02 January 2013 10:54]

Report message to a moderator

Re: Need help on implementing Undo-Redo feature for eclipse Form Editor. [message #996549 is a reply to message #996548] Wed, 02 January 2013 10:52 Go to previous messageGo to next message
akhil gupta is currently offline akhil guptaFriend
Messages: 13
Registered: November 2012
Junior Member
No Message Body

[Updated on: Wed, 02 January 2013 10:54]

Report message to a moderator

Re: Need help on implementing Undo-Redo feature for eclipse Form Editor. [message #1688803 is a reply to message #996549] Sat, 21 March 2015 20:00 Go to previous message
Atish kumar is currently offline Atish kumarFriend
Messages: 1
Registered: March 2015
Junior Member
hi Akhil,

How u r populating the data from model to xml?
Previous Topic:Problem building a new C/C++ project
Next Topic:Lost edit ability in my eclipe Java developer
Goto Forum:
  


Current Time: Tue Mar 09 06:48:08 GMT 2021

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

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

Back to the top