Search in sources :

Example 1 with IUndoableOperation

use of org.eclipse.core.commands.operations.IUndoableOperation in project che by eclipse.

the class UndoManager2 method performRedo.

public void performRedo(IValidationCheckResultQuery query, IProgressMonitor pm) throws CoreException {
    IUndoableOperation redo = fOperationHistory.getRedoOperation(RefactoringCorePlugin.getUndoContext());
    UndoableOperation2ChangeAdapter changeOperation = getUnwrappedOperation(redo);
    if (changeOperation == null)
        throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IStatus.ERROR, RefactoringCoreMessages.UndoManager2_no_change, null));
    if (query == null)
        query = new NullQuery();
    try {
        fOperationHistory.redoOperation(redo, pm, new QueryAdapter(query));
    } catch (ExecutionException e) {
        handleException(e);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) CoreException(org.eclipse.core.runtime.CoreException) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 2 with IUndoableOperation

use of org.eclipse.core.commands.operations.IUndoableOperation in project che by eclipse.

the class UndoManager2 method aboutToPerformChange.

public void aboutToPerformChange(Change change) {
    IUndoableOperation operation = new UndoableOperation2ChangeAdapter(change);
    operation.addContext(RefactoringCorePlugin.getUndoContext());
    fActiveOperation = new TriggeredOperations(operation, fOperationHistory);
    fActiveOperation.addContext(RefactoringCorePlugin.getUndoContext());
    fOperationHistory.openOperation(fActiveOperation, IOperationHistory.EXECUTE);
    fIsOpen = true;
}
Also used : IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) TriggeredOperations(org.eclipse.core.commands.operations.TriggeredOperations)

Example 3 with IUndoableOperation

use of org.eclipse.core.commands.operations.IUndoableOperation in project che by eclipse.

the class UndoManager2 method performUndo.

public void performUndo(IValidationCheckResultQuery query, IProgressMonitor pm) throws CoreException {
    IUndoableOperation undo = fOperationHistory.getUndoOperation(RefactoringCorePlugin.getUndoContext());
    UndoableOperation2ChangeAdapter changeOperation = getUnwrappedOperation(undo);
    if (changeOperation == null)
        throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IStatus.ERROR, RefactoringCoreMessages.UndoManager2_no_change, null));
    if (query == null)
        query = new NullQuery();
    try {
        fOperationHistory.undoOperation(undo, pm, new QueryAdapter(query));
    } catch (ExecutionException e) {
        handleException(e);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) CoreException(org.eclipse.core.runtime.CoreException) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 4 with IUndoableOperation

use of org.eclipse.core.commands.operations.IUndoableOperation in project eclipse.platform.text by eclipse.

the class DocumentUndoManager method transferUndoHistory.

@Override
public void transferUndoHistory(IDocumentUndoManager manager) {
    IUndoContext oldUndoContext = manager.getUndoContext();
    // Get the history for the old undo context.
    IUndoableOperation[] operations = OperationHistoryFactory.getOperationHistory().getUndoHistory(oldUndoContext);
    for (IUndoableOperation operation : operations) {
        // First replace the undo context
        IUndoableOperation op = operation;
        if (op instanceof IContextReplacingOperation) {
            ((IContextReplacingOperation) op).replaceContext(oldUndoContext, getUndoContext());
        } else {
            op.addContext(getUndoContext());
            op.removeContext(oldUndoContext);
        }
        // Now update the manager that owns the text edit.
        if (op instanceof UndoableTextChange) {
            ((UndoableTextChange) op).fDocumentUndoManager = this;
        }
    }
    IUndoableOperation op = OperationHistoryFactory.getOperationHistory().getUndoOperation(getUndoContext());
    if (op != null && !(op instanceof UndoableTextChange))
        return;
    // Record the transfer itself as an undoable change.
    // If the transfer results from some open operation, recording this change will
    // cause our undo context to be added to the outer operation.  If there is no
    // outer operation, there will be a local change to signify the transfer.
    // This also serves to synchronize the modification stamps with the documents.
    UndoableTextChange cmd = new UndoableTextChange(this);
    cmd.fStart = cmd.fEnd = 0;
    // $NON-NLS-1$
    cmd.fText = cmd.fPreservedText = "";
    if (fDocument instanceof IDocumentExtension4) {
        cmd.fRedoModificationStamp = ((IDocumentExtension4) fDocument).getModificationStamp();
        if (op != null)
            cmd.fUndoModificationStamp = ((UndoableTextChange) op).fRedoModificationStamp;
    }
    addToOperationHistory(cmd);
}
Also used : IContextReplacingOperation(org.eclipse.core.commands.operations.IContextReplacingOperation) IUndoContext(org.eclipse.core.commands.operations.IUndoContext) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation)

Example 5 with IUndoableOperation

use of org.eclipse.core.commands.operations.IUndoableOperation in project eclipse.platform.text by eclipse.

the class AddMarkerAction method run.

@Override
public void run() {
    IResource resource = getResource();
    if (resource == null)
        return;
    Map<String, Object> attributes = getInitialAttributes();
    if (fAskForLabel) {
        if (!askForLabel(attributes))
            return;
    }
    String name = getToolTipText();
    name = name == null ? TextEditorMessages.AddMarkerAction_addMarker : name;
    final Shell shell = getTextEditor().getSite().getShell();
    IAdaptable context = new IAdaptable() {

        @SuppressWarnings("unchecked")
        @Override
        public <T> T getAdapter(Class<T> adapter) {
            if (adapter == Shell.class)
                return (T) shell;
            return null;
        }
    };
    IUndoableOperation operation = new CreateMarkersOperation(fMarkerType, attributes, resource, name);
    IOperationHistory operationHistory = PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
    try {
        operationHistory.execute(operation, null, context);
    } catch (ExecutionException x) {
        Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
        ILog log = Platform.getLog(bundle);
        // $NON-NLS-2$ //$NON-NLS-1$
        String msg = getString(fBundle, fPrefix + "error.dialog.message", fPrefix + "error.dialog.message");
        log.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, msg, x));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IAdaptable(org.eclipse.core.runtime.IAdaptable) ResourceBundle(java.util.ResourceBundle) Bundle(org.osgi.framework.Bundle) CreateMarkersOperation(org.eclipse.ui.ide.undo.CreateMarkersOperation) Shell(org.eclipse.swt.widgets.Shell) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) ILog(org.eclipse.core.runtime.ILog) ExecutionException(org.eclipse.core.commands.ExecutionException) IResource(org.eclipse.core.resources.IResource)

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