Search in sources :

Example 21 with IUndoableOperation

use of org.eclipse.core.commands.operations.IUndoableOperation in project tdq-studio-se by Talend.

the class TdDialogMarkerProperties method saveChanges.

/**
 * Saves the changes made in the dialog if needed. Creates a new marker if needed. Updates the existing marker only
 * if there have been changes.
 */
@SuppressWarnings("unchecked")
private void saveChanges() {
    Map attrs = getMarkerAttributes();
    IUndoableOperation op = null;
    if (marker == null) {
        if (resource == null)
            return;
        op = new CreateMarkersOperation(type, attrs, resource, getCreateOperationTitle());
    } else {
        if (isDirty()) {
            op = new UpdateMarkersOperation(marker, attrs, getModifyOperationTitle(), true);
        }
    }
    if (op != null) {
        try {
            PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, null, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
        } catch (ExecutionException e) {
            if (e.getCause() instanceof CoreException) {
                ErrorDialog.openError(getShell(), MarkerMessages.Error, null, ((CoreException) e.getCause()).getStatus());
            } else {
                IDEWorkbenchPlugin.log(e.getMessage(), e);
            }
        }
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) UpdateMarkersOperation(org.eclipse.ui.ide.undo.UpdateMarkersOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) HashMap(java.util.HashMap) Map(java.util.Map) CreateMarkersOperation(org.eclipse.ui.ide.undo.CreateMarkersOperation)

Example 22 with IUndoableOperation

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

the class SchemaServiceImpl method clearSchemas.

/**
 * @see SchemaService#clearSchemas(SchemaSpaceID)
 */
@Override
public void clearSchemas(final SchemaSpaceID spaceID) {
    Preconditions.checkNotNull(spaceID);
    IUndoableOperation operation = new AbstractRemoveResourcesOperation("Clear " + (spaceID == SchemaSpaceID.SOURCE ? "source" : "target") + " schema", spaceID == SchemaSpaceID.SOURCE ? ACTION_READ_SOURCE : ACTION_READ_TARGET) {

        /**
         * @see eu.esdihumboldt.hale.ui.service.project.internal.AbstractRemoveResourcesOperation#execute(org.eclipse.core.runtime.IProgressMonitor,
         *      org.eclipse.core.runtime.IAdaptable)
         */
        @Override
        public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            synchronized (spaces) {
                spaces.remove(spaceID);
            }
            notifySchemasCleared(spaceID);
            return super.execute(monitor, info);
        }
    };
    IWorkbenchOperationSupport operationSupport = PlatformUI.getWorkbench().getOperationSupport();
    operation.addContext(operationSupport.getUndoContext());
    try {
        operationSupport.getOperationHistory().execute(operation, null, null);
    } catch (ExecutionException e) {
        log.error("Error executing operation on schema service", e);
    }
}
Also used : AbstractRemoveResourcesOperation(eu.esdihumboldt.hale.ui.service.project.internal.AbstractRemoveResourcesOperation) IAdaptable(org.eclipse.core.runtime.IAdaptable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) IWorkbenchOperationSupport(org.eclipse.ui.operations.IWorkbenchOperationSupport) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 23 with IUndoableOperation

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

the class OrientInstanceService method clearInstances.

/**
 * @see InstanceService#clearInstances()
 */
@Override
public void clearInstances() {
    IUndoableOperation operation = new AbstractRemoveResourcesOperation("Clear source data", InstanceService.ACTION_READ_SOURCEDATA) {

        /**
         * @see eu.esdihumboldt.hale.ui.service.project.internal.AbstractRemoveResourcesOperation#execute(org.eclipse.core.runtime.IProgressMonitor,
         *      org.eclipse.core.runtime.IAdaptable)
         */
        @Override
        public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            notifyDatasetAboutToChange(null);
            source.clear();
            transformed.clear();
            notifyDatasetChanged(null);
            return super.execute(monitor, info);
        }
    };
    IWorkbenchOperationSupport operationSupport = PlatformUI.getWorkbench().getOperationSupport();
    operation.addContext(operationSupport.getUndoContext());
    try {
        operationSupport.getOperationHistory().execute(operation, null, null);
    } catch (ExecutionException e) {
        log.error("Error executing operation on instance service", e);
    }
}
Also used : AbstractRemoveResourcesOperation(eu.esdihumboldt.hale.ui.service.project.internal.AbstractRemoveResourcesOperation) IAdaptable(org.eclipse.core.runtime.IAdaptable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) IWorkbenchOperationSupport(org.eclipse.ui.operations.IWorkbenchOperationSupport) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 24 with IUndoableOperation

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

the class AlignmentServiceUndoSupport method removeCells.

/**
 * @see AlignmentServiceDecorator#removeCells(Cell[])
 */
@Override
public synchronized void removeCells(Cell... cells) {
    if (cells == null || cells.length == 0) {
        return;
    }
    List<MutableCell> contained = new ArrayList<MutableCell>();
    for (Cell cell : cells) {
        if (cell instanceof MutableCell && getAlignment().getCells().contains(cell)) {
            contained.add((MutableCell) cell);
        }
    }
    if (!contained.isEmpty()) {
        /*
			 * Cells must be contained in the current alignment, else the redo
			 * would do something unexpected (readding a cell that was not
			 * previously there).
			 * 
			 * Also, as long as there is no copy constructor in DefaultCell,
			 * undo only for removing MutableCells supported.
			 */
        IUndoableOperation operation = new RemoveCellOperation(contained);
        executeOperation(operation);
    } else {
        super.removeCells(cells);
    }
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) ArrayList(java.util.ArrayList) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell)

Example 25 with IUndoableOperation

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

the class AlignmentServiceUndoSupport method clean.

/**
 * @see AlignmentServiceDecorator#clean()
 */
@Override
public synchronized void clean() {
    // XXX problem: what about cleans that should not be undone? e.g. when
    // the schemas have changed
    // XXX -> currently on project clean the workbench history is reset
    Alignment alignment = getAlignment();
    if (alignment.getCells().isEmpty()) {
        return;
    }
    if (alignment instanceof MutableAlignment) {
        /*
			 * As long as there is no copy constructor in DefaultAlignment, undo
			 * only supported if the current alignment is a MutableAlignment.
			 */
        IUndoableOperation operation = new CleanOperation((MutableAlignment) alignment);
        executeOperation(operation);
    } else {
        super.clean();
    }
}
Also used : Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment)

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