Undo/Redo for tree item editing [message #465057] |
Thu, 22 March 2007 12:42 |
sunny Messages: 15 Registered: July 2009 |
Junior Member |
|
|
Hi,
I have written EditTreeOperation to handle the editing of tree item
on mouse double click.And I want to add Undo/Redo facility to this
operation...Here is the code I have written..Undo is working well but Redo
is not working ...Please tell me am I missing anything?
DoubleClick event Code: Where customerView is the instance of my customer
view
IUndoableOperation treeOperation = new EditTreeOperation();
workbench = customerView.getSite().getWorkbenchWindow().getWorkbench();
IOperationHistory operHistory = workbench.getOperationSupport()
.getOperationHistory();
IUndoContext myContext = workbench.getOperationSupport()
.getUndoContext();
treeOperation.addContext(myContext);
try
{
operHistory.execute(treeOperation, null, null);
} catch (Exception e1)
{
e1.printStackTrace();
}
Here is the EditTreeOperation code:
package com.sequenom.everest.ui.project;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.AbstractOperation;
import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.widgets.TreeItem;
/**
* An operation that makes tree item editable
* * */
public class EditTreeOperation extends AbstractOperation implements
IUndoableOperation
{
TreeItem treeItem;
String text;
public EditTreeOperation()
{
super("Edit tree");
}
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
throws ExecutionException
{
treeItem = customerView.tree
.getTree().getSelection()[0];
text = treeItem.getText().trim();
// handleEdit() contains the actual logic of editing of tree item
customerView.handleEdit();
return Status.OK_STATUS;
}
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
throws ExecutionException
{
return undo(monitor, info);
}
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
throws ExecutionException
{
treeItem.setText(text);
return Status.OK_STATUS;
}
}
Thnaks in advance,
Swetha
|
|
|
Powered by
FUDForum. Page generated in 0.03264 seconds