Search in sources :

Example 1 with FileBufferOperationRunner

use of org.eclipse.core.filebuffers.manipulation.FileBufferOperationRunner in project eclipse.platform.text by eclipse.

the class FileBufferOperationAction method doRun.

protected final void doRun(final IFile[] files, final IPath location, final IFileBufferOperation fileBufferOperation) {
    Job job = new Job(fileBufferOperation.getOperationName()) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            IStatus status;
            try {
                int ticks = 100;
                SubMonitor subMonitor = SubMonitor.convert(monitor, fFileBufferOperation.getOperationName(), ticks);
                IPath[] locations;
                if (files != null) {
                    ticks -= 30;
                    locations = generateLocations(files, subMonitor.split(30));
                } else
                    locations = new IPath[] { location };
                if (locations != null && locations.length > 0) {
                    FileBufferOperationRunner runner = new FileBufferOperationRunner(FileBuffers.getTextFileBufferManager(), getShell());
                    runner.execute(locations, fileBufferOperation, subMonitor.split(ticks));
                }
                status = Status.OK_STATUS;
            } catch (OperationCanceledException e) {
                // $NON-NLS-1$
                status = new Status(IStatus.CANCEL, EditorsUI.PLUGIN_ID, IStatus.OK, "", null);
            } catch (CoreException e) {
                // $NON-NLS-1$
                status = new Status(IStatus.ERROR, EditorsUI.PLUGIN_ID, IStatus.OK, "", e);
            }
            return status;
        }
    };
    job.setUser(true);
    job.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) FileBufferOperationRunner(org.eclipse.core.filebuffers.manipulation.FileBufferOperationRunner) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Example 2 with FileBufferOperationRunner

use of org.eclipse.core.filebuffers.manipulation.FileBufferOperationRunner in project eclipse.platform.text by eclipse.

the class FileBufferOperationHandler method doRun.

/**
 * Runs the given operation.
 *
 * @param files the file on which to run this operation
 * @param location the file buffer location
 * @param fileBufferOperation the operation to run
 */
protected final void doRun(final IFile[] files, final IPath location, final IFileBufferOperation fileBufferOperation) {
    Job job = new Job(fileBufferOperation.getOperationName()) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            IStatus status;
            try {
                int ticks = 100;
                SubMonitor subMonitor = SubMonitor.convert(monitor, fFileBufferOperation.getOperationName(), ticks);
                IPath[] locations;
                if (files != null) {
                    ticks -= 30;
                    locations = generateLocations(files, subMonitor.split(30));
                } else
                    locations = new IPath[] { location };
                if (locations != null && locations.length > 0) {
                    FileBufferOperationRunner runner = new FileBufferOperationRunner(FileBuffers.getTextFileBufferManager(), getShell());
                    runner.execute(locations, fileBufferOperation, subMonitor.split(ticks));
                }
                status = Status.OK_STATUS;
            } catch (OperationCanceledException e) {
                // $NON-NLS-1$
                status = new Status(IStatus.CANCEL, EditorsUI.PLUGIN_ID, IStatus.OK, "", null);
            } catch (CoreException e) {
                // $NON-NLS-1$
                status = new Status(IStatus.ERROR, EditorsUI.PLUGIN_ID, IStatus.OK, "", e);
            }
            return status;
        }
    };
    job.setUser(true);
    job.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) FileBufferOperationRunner(org.eclipse.core.filebuffers.manipulation.FileBufferOperationRunner) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

FileBufferOperationRunner (org.eclipse.core.filebuffers.manipulation.FileBufferOperationRunner)2 CoreException (org.eclipse.core.runtime.CoreException)2 IPath (org.eclipse.core.runtime.IPath)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 Status (org.eclipse.core.runtime.Status)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2