Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Undo/Redo for tree item editing
Undo/Redo for tree item editing [message #465057] Thu, 22 March 2007 12:42
sunny is currently offline sunnyFriend
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
Previous Topic:CellEditors in Tree + TreeColumn
Next Topic:SashForm in Forms..
Goto Forum:
  


Current Time: Mon Oct 07 17:55:33 GMT 2024

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

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

Back to the top