Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Undo/Redo
Undo/Redo [message #465601] Tue, 03 April 2007 05:12
Swetha is currently offline SwethaFriend
Messages: 68
Registered: July 2009
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;
}

}

Can anyone please help me , it is pretty urgent....


Thanks in advance,
Swetha
Previous Topic:Synchronizing editors
Next Topic:Dynamic Help in RCP
Goto Forum:
  


Current Time: Thu Apr 18 10:19:03 GMT 2024

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

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

Back to the top