Search in sources :

Example 6 with IWorkbenchOperationSupport

use of org.eclipse.ui.operations.IWorkbenchOperationSupport in project hale by halestudio.

the class ProjectServiceImpl method internalClean.

private boolean internalClean() {
    if (!changeCheck()) {
        return false;
    }
    // reset current session descriptor
    ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class);
    repService.updateCurrentSessionDescription();
    // clean
    final IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            ATransaction trans = log.begin("Clean project");
            CleanupService cs = HalePlatform.getService(CleanupService.class);
            if (cs != null) {
                cs.triggerProjectCleanup();
            }
            monitor.beginTask("Clean project", IProgressMonitor.UNKNOWN);
            try {
                synchronized (this) {
                    main = createDefaultProject();
                    projectFile = null;
                    projectLocation = null;
                    changed = false;
                    projectLoadContentType = null;
                    temporarySettings.clear();
                }
                updateWindowTitle();
                notifyClean();
                // schemas aren't valid anymore, clear property resolver
                // cache
                PropertyResolver.clearCache();
            } finally {
                monitor.done();
                trans.end();
            }
            // clean workbench history AFTER other cleans since they can
            // create operations
            IWorkbenchOperationSupport os = PlatformUI.getWorkbench().getOperationSupport();
            os.getOperationHistory().dispose(os.getUndoContext(), true, true, false);
            // suppress the status being set to changed by the clean
            synchronized (ProjectServiceImpl.this) {
                changed = false;
            }
            updateWindowTitle();
        }
    };
    try {
        ThreadProgressMonitor.runWithProgressDialog(op, false);
    } catch (Exception e) {
        log.error("Error cleaning the project.", e);
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ReportService(eu.esdihumboldt.hale.ui.service.report.ReportService) CleanupService(eu.esdihumboldt.hale.common.core.service.cleanup.CleanupService) IWorkbenchOperationSupport(org.eclipse.ui.operations.IWorkbenchOperationSupport) ATransaction(de.fhg.igd.slf4jplus.ATransaction) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 7 with IWorkbenchOperationSupport

use of org.eclipse.ui.operations.IWorkbenchOperationSupport 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)

Aggregations

IWorkbenchOperationSupport (org.eclipse.ui.operations.IWorkbenchOperationSupport)7 ExecutionException (org.eclipse.core.commands.ExecutionException)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 AbstractRemoveResourcesOperation (eu.esdihumboldt.hale.ui.service.project.internal.AbstractRemoveResourcesOperation)2 IUndoableOperation (org.eclipse.core.commands.operations.IUndoableOperation)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 ATransaction (de.fhg.igd.slf4jplus.ATransaction)1 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 CleanupService (eu.esdihumboldt.hale.common.core.service.cleanup.CleanupService)1 ReportService (eu.esdihumboldt.hale.ui.service.report.ReportService)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ICompositeOperation (org.eclipse.core.commands.operations.ICompositeOperation)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1