Search in sources :

Example 11 with IUndoableOperation

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);
}
Also used : IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation)

Example 12 with IUndoableOperation

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);
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation)

Example 13 with IUndoableOperation

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);
    }
}
Also used : IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) Priority(eu.esdihumboldt.hale.common.align.model.Priority) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell)

Example 14 with IUndoableOperation

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);
    }
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation)

Example 15 with IUndoableOperation

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);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractOperation(org.eclipse.core.commands.operations.AbstractOperation) DocumentUndoEvent(org.eclipse.text.undo.DocumentUndoEvent) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) IDocumentUndoListener(org.eclipse.text.undo.IDocumentUndoListener) DocumentUndoManager(org.eclipse.text.undo.DocumentUndoManager) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

IUndoableOperation (org.eclipse.core.commands.operations.IUndoableOperation)27 ExecutionException (org.eclipse.core.commands.ExecutionException)7 IAdaptable (org.eclipse.core.runtime.IAdaptable)5 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 GridData (org.eclipse.swt.layout.GridData)4 IOperationHistory (org.eclipse.core.commands.operations.IOperationHistory)3 CoreException (org.eclipse.core.runtime.CoreException)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 FormToolkit (org.eclipse.ui.forms.widgets.FormToolkit)3 Section (org.eclipse.ui.forms.widgets.Section)3 CreateMarkersOperation (org.eclipse.ui.ide.undo.CreateMarkersOperation)3 ServerEditorSection (org.eclipse.wst.server.ui.editor.ServerEditorSection)3 Cell (eu.esdihumboldt.hale.common.align.model.Cell)2 AbstractRemoveResourcesOperation (eu.esdihumboldt.hale.ui.service.project.internal.AbstractRemoveResourcesOperation)2 HashMap (java.util.HashMap)2