use of org.eclipse.jface.operation.IRunnableWithProgress in project xtext-eclipse by eclipse.
the class XtextNewProjectWizard method performFinish.
@Override
public boolean performFinish() {
final IProjectInfo projectInfo = getProjectInfo();
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException {
try {
doFinish(projectInfo, monitor);
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
};
try {
getContainer().run(true, false, op);
} catch (InterruptedException e) {
return false;
} catch (InvocationTargetException e) {
logger.error(e.getMessage(), e);
Throwable realException = e.getTargetException();
MessageDialog.openError(getShell(), Messages.XtextNewProjectWizard_ErrorDialog_Title, realException.getMessage());
return false;
}
return true;
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project archi by archimatetool.
the class ExportJasperReportsWizard method performFinish.
@Override
public boolean performFinish() {
fPage1.storePreferences();
final File mainTemplateFile = fPage2.getMainTemplateFile();
// Check this exists
if (mainTemplateFile == null || !mainTemplateFile.exists()) {
MessageDialog.openError(getShell(), Messages.ExportJasperReportsWizard_1, Messages.ExportJasperReportsWizard_2);
return false;
}
final Locale locale = fPage2.getLocale();
final File exportFolder = fPage1.getExportFolder();
final String exportFileName = fPage1.getExportFilename();
final String reportTitle = fPage1.getReportTitle();
final int exportOptions = fPage1.getExportOptions();
// Check valid dir and file name
try {
File exportFile = new File(exportFolder, exportFileName);
exportFile.getCanonicalPath();
exportFolder.mkdirs();
} catch (Exception ex) {
MessageDialog.openError(getShell(), Messages.ExportJasperReportsWizard_3, Messages.ExportJasperReportsWizard_4);
return false;
}
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
try {
dialog.run(false, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
JasperReportsExporter exporter = new JasperReportsExporter(fModel, exportFolder, exportFileName, mainTemplateFile, reportTitle, locale, exportOptions);
exporter.export(monitor);
} catch (Exception ex) {
ex.printStackTrace();
MessageDialog.openError(getShell(), Messages.ExportJasperReportsWizard_5, ex.getMessage());
} finally {
monitor.done();
}
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
return true;
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project xtext-eclipse by eclipse.
the class MultiOrganizeImportsHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
MultiOrganizeImportAction javaDelegate = new MultiOrganizeImportAction(activeSite);
ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
if (currentSelection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
if (shouldRunJavaOrganizeImports()) {
ICompilationUnit[] compilationUnits = javaDelegate.getCompilationUnits(structuredSelection);
if (compilationUnits.length > 0) {
javaDelegate.run(structuredSelection);
}
}
final Multimap<IProject, IFile> files = collectFiles(structuredSelection);
Shell shell = activeSite.getShell();
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor mon) throws InvocationTargetException, InterruptedException {
mon.beginTask(Messages.OrganizeImports, files.size() * 2);
mon.setTaskName(Messages.OrganizeImports + " - Calculating Import optimisations for " + files.size() + " Xtend files");
final List<Change> organizeImports = importOrganizerProvider.get().organizeImports(files, mon);
for (int i = 0; !mon.isCanceled() && i < organizeImports.size(); i++) {
Change change = organizeImports.get(i);
mon.setTaskName("Performing changes - Xtend " + (i + 1) + " of " + files.size() + "");
try {
mon.subTask(change.getName());
change.perform(SubMonitor.convert(mon, 1));
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
if (mon.isCanceled()) {
throw new InterruptedException();
}
}
}
};
try {
new ProgressMonitorDialog(shell).run(true, true, op);
} catch (InvocationTargetException e) {
handleException(e);
} catch (InterruptedException e) {
// user cancelled, ok
}
}
return event.getApplicationContext();
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project xtext-eclipse by eclipse.
the class JvmImplementationOpener method openImplementations.
/**
* Main parts of the logic is taken from {@link org.eclipse.jdt.internal.ui.javaeditor.JavaElementImplementationHyperlink}
*
* @param element - Element to show implementations for
* @param textviewer - Viewer to show hierarchy view on
* @param region - Region where to show hierarchy view
*/
public void openImplementations(final IJavaElement element, ITextViewer textviewer, IRegion region) {
if (element instanceof IMethod) {
ITypeRoot typeRoot = ((IMethod) element).getTypeRoot();
CompilationUnit ast = SharedASTProvider.getAST(typeRoot, SharedASTProvider.WAIT_YES, null);
if (ast == null) {
openQuickHierarchy(textviewer, element, region);
return;
}
try {
ISourceRange nameRange = ((IMethod) element).getNameRange();
ASTNode node = NodeFinder.perform(ast, nameRange);
ITypeBinding parentTypeBinding = null;
if (node instanceof SimpleName) {
ASTNode parent = node.getParent();
if (parent instanceof MethodInvocation) {
Expression expression = ((MethodInvocation) parent).getExpression();
if (expression == null) {
parentTypeBinding = Bindings.getBindingOfParentType(node);
} else {
parentTypeBinding = expression.resolveTypeBinding();
}
} else if (parent instanceof SuperMethodInvocation) {
// Directly go to the super method definition
openEditor(element);
return;
} else if (parent instanceof MethodDeclaration) {
parentTypeBinding = Bindings.getBindingOfParentType(node);
}
}
final IType type = parentTypeBinding != null ? (IType) parentTypeBinding.getJavaElement() : null;
if (type == null) {
openQuickHierarchy(textviewer, element, region);
return;
}
final String earlyExitIndicator = "EarlyExitIndicator";
final ArrayList<IJavaElement> links = Lists.newArrayList();
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
try {
String methodLabel = JavaElementLabels.getElementLabel(element, JavaElementLabels.DEFAULT_QUALIFIED);
monitor.beginTask(Messages.format("Searching for implementors of ''{0}''", methodLabel), 100);
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
if (match.getAccuracy() == SearchMatch.A_ACCURATE) {
IJavaElement element = (IJavaElement) match.getElement();
if (element instanceof IMethod && !JdtFlags.isAbstract((IMethod) element)) {
links.add(element);
if (links.size() > 1) {
throw new OperationCanceledException(earlyExitIndicator);
}
}
}
}
};
int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
SearchPattern pattern = SearchPattern.createPattern(element, limitTo);
Assert.isNotNull(pattern);
SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
SearchEngine engine = new SearchEngine();
engine.search(pattern, participants, SearchEngine.createHierarchyScope(type), requestor, SubMonitor.convert(monitor, 100));
if (monitor.isCanceled()) {
throw new InterruptedException();
}
} catch (OperationCanceledException e) {
throw new InterruptedException(e.getMessage());
} catch (CoreException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
} catch (InvocationTargetException e) {
IStatus status = new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, Messages.format("An error occurred while searching for implementations of method ''{0}''. See error log for details.", element.getElementName()), e.getCause());
JavaPlugin.log(status);
ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Open Implementation", "Problems finding implementations.", status);
} catch (InterruptedException e) {
if (e.getMessage() != earlyExitIndicator) {
return;
}
}
if (links.size() == 1) {
openEditor(links.get(0));
} else {
openQuickHierarchy(textviewer, element, region);
}
} catch (JavaModelException e) {
log.error("An error occurred while searching for implementations", e.getCause());
} catch (PartInitException e) {
log.error("An error occurred while searching for implementations", e.getCause());
}
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project xtext-eclipse by eclipse.
the class RenameRefactoringController method startLinkedEditing.
protected void startLinkedEditing() throws InterruptedException {
if (activeLinkedMode != null)
startRefactoring(RefactoringType.REFACTORING_DIALOG);
try {
final XtextEditor xtextEditor = getXtextEditor();
if (xtextEditor != null) {
workbench.getProgressService().run(true, true, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
final Provider<LinkedPositionGroup> provider = linkedPositionGroupCalculator.getLinkedPositionGroup(renameElementContext, monitor);
Display display = workbench.getDisplay();
display.syncExec(new Runnable() {
@Override
public void run() {
RenameLinkedMode newLinkedMode = renameLinkedModeProvider.get();
if (newLinkedMode.start(renameElementContext, provider, monitor)) {
activeLinkedMode = newLinkedMode;
undoSupport = undoSupportProvider.get();
undoSupport.startRecording(xtextEditor);
}
}
});
} catch (OperationCanceledException e) {
throw new InterruptedException();
}
}
});
if (activeLinkedMode == null) {
startRefactoring(RefactoringType.REFACTORING_DIALOG);
}
}
} catch (InterruptedException e) {
throw e;
} catch (Exception exc) {
// unwrap invocation target exceptions
if (exc.getCause() instanceof RuntimeException)
throw (RuntimeException) exc.getCause();
if (exc instanceof RuntimeException)
throw (RuntimeException) exc;
throw new WrappedException(exc);
}
}
Aggregations