use of org.eclipse.core.runtime.IProgressMonitor in project che by eclipse.
the class JavaProjectHelper method delete.
/**
* Removes an IJavaElement's resource. Retries if deletion failed (e.g. because the indexer
* still locks the file).
*
* @param elem the element to delete
* @throws CoreException if operation failed
* @see #ASSERT_NO_MIXED_LINE_DELIMIERS
*/
public static void delete(final IJavaElement elem) throws CoreException {
// MixedLineDelimiterDetector.assertNoMixedLineDelimiters(elem);
if (elem instanceof JavaProject) {
((JavaProject) elem).close();
JavaModelManager.getJavaModelManager().removePerProjectInfo((JavaProject) elem, true);
}
JavaModelManager.getJavaModelManager().resetTemporaryCache();
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
// performDummySearch();
if (elem instanceof IJavaProject) {
IJavaProject jproject = (IJavaProject) elem;
jproject.setRawClasspath(new IClasspathEntry[0], jproject.getProject().getFullPath(), null);
}
delete(elem.getResource());
}
};
ResourcesPlugin.getWorkspace().run(runnable, null);
// emptyDisplayLoop();
}
use of org.eclipse.core.runtime.IProgressMonitor in project che by eclipse.
the class InlineMethodRefactoring method checkFinalConditions.
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
//$NON-NLS-1$
pm.beginTask("", 20);
fChangeManager = new TextChangeManager();
RefactoringStatus result = new RefactoringStatus();
fSourceProvider.initialize();
fTargetProvider.initialize();
pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_searching);
RefactoringStatus searchStatus = new RefactoringStatus();
String binaryRefsDescription = Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description, BasicElementLabels.getJavaElementName(fSourceProvider.getMethodName()));
ReferencesInBinaryContext binaryRefs = new ReferencesInBinaryContext(binaryRefsDescription);
ICompilationUnit[] units = fTargetProvider.getAffectedCompilationUnits(searchStatus, binaryRefs, new SubProgressMonitor(pm, 1));
binaryRefs.addErrorIfNecessary(searchStatus);
if (searchStatus.hasFatalError()) {
result.merge(searchStatus);
return result;
}
IFile[] filesToBeModified = getFilesToBeModified(units);
result.merge(Checks.validateModifiesFiles(filesToBeModified, getValidationContext()));
if (result.hasFatalError())
return result;
result.merge(ResourceChangeChecker.checkFilesToBeChanged(filesToBeModified, new SubProgressMonitor(pm, 1)));
checkOverridden(result, new SubProgressMonitor(pm, 4));
IProgressMonitor sub = new SubProgressMonitor(pm, 15);
//$NON-NLS-1$
sub.beginTask("", units.length * 3);
for (int c = 0; c < units.length; c++) {
ICompilationUnit unit = units[c];
sub.subTask(Messages.format(RefactoringCoreMessages.InlineMethodRefactoring_processing, BasicElementLabels.getFileName(unit)));
CallInliner inliner = null;
try {
boolean added = false;
MultiTextEdit root = new MultiTextEdit();
CompilationUnitChange change = (CompilationUnitChange) fChangeManager.get(unit);
change.setEdit(root);
BodyDeclaration[] bodies = fTargetProvider.getAffectedBodyDeclarations(unit, new SubProgressMonitor(pm, 1));
if (bodies.length == 0)
continue;
inliner = new CallInliner(unit, (CompilationUnit) bodies[0].getRoot(), fSourceProvider);
for (int b = 0; b < bodies.length; b++) {
BodyDeclaration body = bodies[b];
inliner.initialize(body);
RefactoringStatus nestedInvocations = new RefactoringStatus();
ASTNode[] invocations = removeNestedCalls(nestedInvocations, unit, fTargetProvider.getInvocations(body, new SubProgressMonitor(sub, 2)));
for (int i = 0; i < invocations.length; i++) {
ASTNode invocation = invocations[i];
result.merge(inliner.initialize(invocation, fTargetProvider.getStatusSeverity()));
if (result.hasFatalError())
break;
if (result.getSeverity() < fTargetProvider.getStatusSeverity()) {
added = true;
TextEditGroup group = new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_inline);
change.addTextEditGroup(group);
result.merge(inliner.perform(group));
} else {
fDeleteSource = false;
}
}
// to generate the modifications.
if (!nestedInvocations.isOK()) {
result.merge(nestedInvocations);
fDeleteSource = false;
}
}
if (!added) {
fChangeManager.remove(unit);
} else {
root.addChild(inliner.getModifications());
ImportRewrite rewrite = inliner.getImportEdit();
if (rewrite.hasRecordedChanges()) {
TextEdit edit = rewrite.rewriteImports(null);
if (edit instanceof MultiTextEdit ? ((MultiTextEdit) edit).getChildrenSize() > 0 : true) {
root.addChild(edit);
change.addTextEditGroup(new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_import, new TextEdit[] { edit }));
}
}
}
} finally {
if (inliner != null)
inliner.dispose();
}
sub.worked(1);
if (sub.isCanceled())
throw new OperationCanceledException();
}
result.merge(searchStatus);
sub.done();
pm.done();
return result;
}
use of org.eclipse.core.runtime.IProgressMonitor in project che by eclipse.
the class RefactoringHistoryManager method removeIndexTree.
/**
* Removes the refactoring history index tree spanned by the specified file
* store.
*
* @param store
* the file store spanning the history index tree
* @param monitor
* the progress monitor to use
* @param task
* the task label to use
* @throws CoreException
* if an error occurs while removing the index tree
*/
private static void removeIndexTree(final IFileStore store, final IProgressMonitor monitor, final String task) throws CoreException {
try {
monitor.beginTask(task, 16);
final IFileInfo info = store.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
if (info.isDirectory()) {
if (info.getName().equalsIgnoreCase(RefactoringHistoryService.NAME_HISTORY_FOLDER))
return;
final IFileStore[] stores = store.childStores(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
final IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL);
try {
subMonitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_updating_history, stores.length);
for (int index = 0; index < stores.length; index++) {
final IFileInfo current = stores[index].fetchInfo(EFS.NONE, new SubProgressMonitor(subMonitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
if (current.isDirectory()) {
final char[] characters = stores[index].getName().toCharArray();
for (int offset = 0; offset < characters.length; offset++) {
if (Character.isDigit(characters[offset]))
return;
else
continue;
}
}
}
} finally {
subMonitor.done();
}
}
final IFileStore parent = store.getParent();
store.delete(0, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
removeIndexTree(parent, new SubProgressMonitor(monitor, 12, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL), task);
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.
the class MultiSchemasUI method fetchCodes.
@SuppressWarnings("restriction")
private void fetchCodes() {
try {
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
dialog.run(true, false, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Fetch...", IProgressMonitor.UNKNOWN);
monitor.setCanceled(false);
final CsvArray csvArray = processor.getCsvArray();
Display.getDefault().syncExec(new Runnable() {
public void run() {
SchemasKeyData schemasModel = null;
boolean checked = (csvArray != null && csvArray.getRows().size() > 0);
CSVArrayAndSeparator uniqueCsvArray = null;
if (useMultiSaparators.getSelection()) {
getMultiSchemaManager().setKeyValues(keyValuesText.getText());
}
if (multiSchemasFilePreview.getSelectColumnIndex() < 0 && multiSchemaManager.getSelectedColumnIndex() != 0) {
uniqueCsvArray = getMultiSchemaManager().retrieveCsvArrayInUniqueModel(getProcessDescription(), checked, multiSchemaManager.getSelectedColumnIndex(), useMultiSaparators.getSelection());
schemasModel = getMultiSchemaManager().createSchemasTree(uniqueCsvArray, multiSchemaManager.getSelectedColumnIndex());
} else {
uniqueCsvArray = getMultiSchemaManager().retrieveCsvArrayInUniqueModel(getProcessDescription(), checked, multiSchemasFilePreview.getSelectColumnIndex(), useMultiSaparators.getSelection());
schemasModel = getMultiSchemaManager().createSchemasTree(uniqueCsvArray, multiSchemasFilePreview.getSelectColumnIndex());
getMultiSchemaManager().setSelectedColumnIndex(multiSchemasFilePreview.getSelectColumnIndex());
schemaTreeViewer.setInput(schemasModel);
getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
clearSchemaDetail();
checkDialog();
}
}
});
monitor.done();
}
});
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.
the class ThreadDumpEditor method parseDumpFile.
/**
* Parses the dump file.
*
* @param filePath The file path
*/
private void parseDumpFile(final String filePath) {
Job job = new Job(Messages.parseThreadDumpFileJobLabel) {
@Override
protected IStatus run(IProgressMonitor monitor) {
final ThreadDumpParser parser = new ThreadDumpParser(new File(filePath), threadListElements, monitor);
try {
parser.parse();
} catch (ParserConfigurationException e) {
//$NON-NLS-1$
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not load thread dump file.", e);
} catch (SAXException e) {
//$NON-NLS-1$
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not load thread dump file.", e);
} catch (IOException e) {
//$NON-NLS-1$
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not load thread dump file.", e);
}
setProfileInfo(parser.getProfileInfo());
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (threadSashForm != null) {
threadSashForm.refresh();
}
}
});
return Status.OK_STATUS;
}
};
job.schedule();
}
Aggregations