use of org.eclipse.core.commands.operations.IUndoableOperation in project polymap4-core by Polymap4.
the class OperationSupport method undo.
public void undo() throws ExecutionException {
IUndoableOperation op = getUndoOperation();
assert op != null && op.canUndo();
OperationJob job = new OperationJob(op) {
protected void run() throws Exception {
// try to preset task name without beginTask()
monitor.setTaskName(op.getLabel());
history.undo(context, monitor, null);
}
};
run(job, true, true);
}
use of org.eclipse.core.commands.operations.IUndoableOperation in project hale by halestudio.
the class AlignmentServiceUndoSupport method replaceCells.
/**
* @see eu.esdihumboldt.hale.ui.service.align.AlignmentService#replaceCells(java.util.Map)
*/
@Override
public void replaceCells(Map<? extends Cell, MutableCell> cells) {
BiMap<MutableCell, MutableCell> map = HashBiMap.create(cells.size());
for (Entry<? extends Cell, MutableCell> e : cells.entrySet()) {
if (e.getKey() instanceof MutableCell && e.getValue() != null && getAlignment().getCells().contains(e.getKey()))
map.put((MutableCell) e.getKey(), e.getValue());
else {
log.warn("Replaced cells contains at least one cell which " + "is either not mutable or not in the alignment. " + "No undo/redo possible.");
super.replaceCells(cells);
return;
}
}
IUndoableOperation operation = new ReplaceOperation(map);
executeOperation(operation);
}
use of org.eclipse.core.commands.operations.IUndoableOperation in project hale by halestudio.
the class AlignmentServiceUndoSupport method setCellProperty.
/**
* @see eu.esdihumboldt.hale.ui.service.align.AlignmentService#setCellProperty(java.lang.String,
* java.lang.String, java.lang.Object)
*/
@Override
public void setCellProperty(String cellId, String propertyName, Object property) {
if (Cell.PROPERTY_DISABLE_FOR.equals(propertyName) || Cell.PROPERTY_ENABLE_FOR.equals(propertyName)) {
IUndoableOperation operation = new DisableCellOperation(Cell.PROPERTY_DISABLE_FOR.equals(propertyName), cellId, (Cell) property);
executeOperation(operation);
} else if (Cell.PROPERTY_PRIORITY.equals(propertyName)) {
if (property instanceof Priority) {
Priority newPriority = (Priority) property;
Cell cell = getAlignment().getCell(cellId);
Priority oldPriority = cell.getPriority();
IUndoableOperation operation = new SetCellPropertyOperation(cellId, propertyName, oldPriority, newPriority);
executeOperation(operation);
}
} else if (Cell.PROPERTY_TRANSFORMATION_MODE.equals(propertyName)) {
Cell cell = getAlignment().getCell(cellId);
Object oldValue = cell.getTransformationMode();
IUndoableOperation operation = new SetCellPropertyOperation(cellId, propertyName, oldValue, property);
executeOperation(operation);
} else {
log.warn("An unknown cell property is set. No undo support.");
alignmentService.setCellProperty(cellId, propertyName, property);
}
}
use of org.eclipse.core.commands.operations.IUndoableOperation in project hale by halestudio.
the class AlignmentServiceUndoSupport method replaceCell.
/**
* @see AlignmentServiceDecorator#replaceCell(Cell, MutableCell)
*/
@Override
public synchronized void replaceCell(Cell oldCell, MutableCell newCell) {
if (oldCell != null && newCell != null) {
if (oldCell != newCell) {
boolean contains = getAlignment().getCells().contains(oldCell);
if (!contains) {
/*
* Cell must be contained in the current alignment, else the
* redo would do something unexpected (reading a cell that
* was not previously there).
*/
addCell(newCell);
} else {
if (oldCell instanceof MutableCell) {
/*
* As long as there is no copy constructor in
* DefaultCell, undo only supported for MutableCells to
* be replaced.
*/
IUndoableOperation operation = new ReplaceOperation((MutableCell) oldCell, newCell);
executeOperation(operation);
} else {
super.replaceCell(oldCell, newCell);
}
}
}
} else if (newCell != null) {
addCell(newCell);
} else if (oldCell != null) {
removeCells(oldCell);
}
}
use of org.eclipse.core.commands.operations.IUndoableOperation in project eclipse.platform.text by eclipse.
the class TextViewerUndoManagerTest method internalTestTransferNonTextOp.
// --- DocumentUndoManager only ---
public void internalTestTransferNonTextOp(final boolean isUndoable) throws Exception {
Object context = new Object();
DocumentUndoManager tempUndoManager = new DocumentUndoManager(new Document());
tempUndoManager.connect(context);
IUndoableOperation operation = new AbstractOperation("") {
@Override
public boolean canUndo() {
return isUndoable;
}
@Override
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
@Override
public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
@Override
public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
};
operation.addContext(tempUndoManager.getUndoContext());
OperationHistoryFactory.getOperationHistory().add(operation);
assertEquals(isUndoable, tempUndoManager.undoable());
final DocumentUndoManager undoManager = new DocumentUndoManager(new Document());
Object newContext = new Object();
undoManager.connect(newContext);
undoManager.addDocumentUndoListener(new IDocumentUndoListener() {
@Override
public void documentUndoNotification(DocumentUndoEvent event) {
fail();
}
});
undoManager.transferUndoHistory(tempUndoManager);
tempUndoManager.disconnect(context);
assertEquals(isUndoable, undoManager.undoable());
undoManager.undo();
assertEquals(false, undoManager.undoable());
undoManager.disconnect(newContext);
}
Aggregations