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);
}
}
}
}
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);
}
}
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);
}
}
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);
}
}
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();
}
}
Aggregations