use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.
the class TextSearchVisitor method processFile.
/**
// * @return returns a map from IFile to IDocument for all open, dirty editors
// */
// private Map evalNonFileBufferDocuments() {
// Map result = new HashMap();
// IWorkbench workbench = SearchPlugin.getDefault().getWorkbench();
// IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
// for (int i = 0; i < windows.length; i++) {
// IWorkbenchPage[] pages = windows[i].getPages();
// for (int x = 0; x < pages.length; x++) {
// IEditorReference[] editorRefs = pages[x].getEditorReferences();
// for (int z = 0; z < editorRefs.length; z++) {
// IEditorPart ep = editorRefs[z].getEditor(false);
// if (ep instanceof ITextEditor && ep.isDirty()) { // only dirty editors
// evaluateTextEditor(result, ep);
// }
// }
// }
// }
// return result;
// }
// private void evaluateTextEditor(Map result, IEditorPart ep) {
// IEditorInput input= ep.getEditorInput();
// if (input instanceof IFileEditorInput) {
// IFile file= ((IFileEditorInput) input).getFile();
// if (!result.containsKey(file)) { // take the first editor found
// ITextFileBufferManager bufferManager= FileBuffers.getTextFileBufferManager();
// ITextFileBuffer textFileBuffer= bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
// if (textFileBuffer != null) {
// // file buffer has precedence
// result.put(file, textFileBuffer.getDocument());
// } else {
// // use document provider
// IDocument document= ((ITextEditor) ep).getDocumentProvider().getDocument(input);
// if (document != null) {
// result.put(file, document);
// }
// }
// }
// }
// }
public boolean processFile(IFile file, Map documentsInEditors) {
try {
if (!fCollector.acceptFile(file) || fMatcher == null) {
return true;
}
IDocument document = getOpenDocument(file, documentsInEditors);
if (document != null) {
DocumentCharSequence documentCharSequence = new DocumentCharSequence(document);
// assume all documents are non-binary
locateMatches(file, documentCharSequence);
} else {
CharSequence seq = null;
try {
seq = fFileCharSequenceProvider.newCharSequence(file);
if (hasBinaryContent(seq, file) && !fCollector.reportBinaryFile(file)) {
return true;
}
locateMatches(file, seq);
} catch (FileCharSequenceProvider.FileCharSequenceException e) {
e.throwWrappedException();
} finally {
if (seq != null) {
try {
fFileCharSequenceProvider.releaseCharSequence(seq);
} catch (IOException e) {
SearchPlugin.log(e);
}
}
}
}
} catch (UnsupportedCharsetException e) {
String[] args = { getCharSetName(file), file.getFullPath().makeRelative().toString() };
String message = Messages.format(SearchMessages.TextSearchVisitor_unsupportedcharset, args);
fStatus.add(new Status(IStatus.ERROR, NewSearchUI.PLUGIN_ID, IStatus.ERROR, message, e));
} catch (IllegalCharsetNameException e) {
String[] args = { getCharSetName(file), file.getFullPath().makeRelative().toString() };
String message = Messages.format(SearchMessages.TextSearchVisitor_illegalcharset, args);
fStatus.add(new Status(IStatus.ERROR, NewSearchUI.PLUGIN_ID, IStatus.ERROR, message, e));
} catch (IOException e) {
String[] args = { getExceptionMessage(e), file.getFullPath().makeRelative().toString() };
String message = Messages.format(SearchMessages.TextSearchVisitor_error, args);
fStatus.add(new Status(IStatus.ERROR, NewSearchUI.PLUGIN_ID, IStatus.ERROR, message, e));
} catch (CoreException e) {
String[] args = { getExceptionMessage(e), file.getFullPath().makeRelative().toString() };
String message = Messages.format(SearchMessages.TextSearchVisitor_error, args);
fStatus.add(new Status(IStatus.ERROR, NewSearchUI.PLUGIN_ID, IStatus.ERROR, message, e));
} catch (StackOverflowError e) {
String message = SearchMessages.TextSearchVisitor_patterntoocomplex0;
fStatus.add(new Status(IStatus.ERROR, NewSearchUI.PLUGIN_ID, IStatus.ERROR, message, e));
return false;
} finally {
fNumberOfScannedFiles++;
}
if (fProgressMonitor.isCanceled())
throw new OperationCanceledException(SearchMessages.TextSearchVisitor_canceled);
return true;
}
use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.
the class WorkspaceModifyOperation method run.
/**
* The <code>WorkspaceModifyOperation</code> implementation of this
* <code>IRunnableWithProgress</code> method initiates a batch of changes by
* invoking the <code>execute</code> method as a workspace runnable
* (<code>IWorkspaceRunnable</code>).
*/
public final synchronized void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
final InvocationTargetException[] iteHolder = new InvocationTargetException[1];
try {
IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {
public void run(IProgressMonitor pm) throws CoreException {
try {
execute(pm);
} catch (InvocationTargetException e) {
// Pass it outside the workspace runnable
iteHolder[0] = e;
} catch (InterruptedException e) {
// caught and re-thrown as InterruptedException below.
throw new OperationCanceledException(e.getMessage());
}
// CoreException and OperationCanceledException are propagated
}
};
ResourcesPlugin.getWorkspace().run(workspaceRunnable, rule, IResource.NONE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
} catch (OperationCanceledException e) {
throw new InterruptedException(e.getMessage());
}
// Re-throw the InvocationTargetException, if any occurred
if (iteHolder[0] != null) {
throw iteHolder[0];
}
}
use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.
the class FileUndoState method createExistentResourceFromHandle.
public void createExistentResourceFromHandle(IResource resource, IProgressMonitor monitor) throws CoreException {
Assert.isLegal(resource instanceof IFile);
if (resource.exists()) {
return;
}
IFile fileHandle = (IFile) resource;
//$NON-NLS-1$
monitor.beginTask("", 200);
monitor.setTaskName(RefactoringCoreMessages.FileDescription_NewFileProgress);
try {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
if (location != null) {
fileHandle.createLink(location, IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 200));
} else {
InputStream contents = new ByteArrayInputStream(RefactoringCoreMessages.FileDescription_ContentsCouldNotBeRestored.getBytes());
// object and are restored in #restoreResourceAttributes
if (fileContentDescription != null && fileContentDescription.exists()) {
contents = fileContentDescription.getContents();
}
fileHandle.create(contents, false, new SubProgressMonitor(monitor, 100));
fileHandle.setCharset(charset, new SubProgressMonitor(monitor, 100));
}
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
} catch (CoreException e) {
if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED) {
fileHandle.refreshLocal(IResource.DEPTH_ZERO, null);
} else {
throw e;
}
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.
the class FileDescription method createExistentResourceFromHandle.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.internal.ide.undo.ResourceDescription#createExistentResourceFromHandle(org.eclipse.core.resources.IResource,
* org.eclipse.core.runtime.IProgressMonitor)
*/
public void createExistentResourceFromHandle(IResource resource, IProgressMonitor monitor) throws CoreException {
Assert.isLegal(resource instanceof IFile);
if (resource.exists()) {
return;
}
IFile fileHandle = (IFile) resource;
//$NON-NLS-1$
monitor.beginTask("", 200);
monitor.setTaskName(UndoMessages.FileDescription_NewFileProgress);
try {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
if (location != null) {
fileHandle.createLink(location, IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 200));
} else {
InputStream contents = new ByteArrayInputStream(UndoMessages.FileDescription_ContentsCouldNotBeRestored.getBytes());
// object and are restored in #restoreResourceAttributes
if (fileContentDescription != null && fileContentDescription.exists()) {
contents = fileContentDescription.getContents();
}
fileHandle.create(contents, false, new SubProgressMonitor(monitor, 100));
fileHandle.setCharset(charset, new SubProgressMonitor(monitor, 100));
}
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
} catch (CoreException e) {
if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED) {
fileHandle.refreshLocal(IResource.DEPTH_ZERO, null);
} else {
throw e;
}
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.
the class FolderDescription method createExistentResourceFromHandle.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.internal.ide.undo.ResourceDescription#createExistentResourceFromHandle(org.eclipse.core.resources.IResource,
* org.eclipse.core.runtime.IProgressMonitor)
*/
public void createExistentResourceFromHandle(IResource resource, IProgressMonitor monitor) throws CoreException {
Assert.isLegal(resource instanceof IFolder);
if (resource.exists()) {
return;
}
IFolder folderHandle = (IFolder) resource;
try {
//$NON-NLS-1$
monitor.beginTask("", 200);
monitor.setTaskName(UndoMessages.FolderDescription_NewFolderProgress);
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
if (filters != null) {
for (int i = 0; i < filters.length; i++) {
folderHandle.createFilter(filters[i].getType(), filters[i].getFileInfoMatcherDescription(), 0, new SubProgressMonitor(monitor, 100));
}
}
if (location != null) {
folderHandle.createLink(location, IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 100));
} else {
folderHandle.create(virtual ? IResource.VIRTUAL : 0, true, new SubProgressMonitor(monitor, 100));
}
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
createChildResources(folderHandle, monitor, 100);
} finally {
monitor.done();
}
}
Aggregations