use of org.eclipse.jface.operation.IRunnableWithProgress in project sling by apache.
the class ExportWizard method performFinish.
@Override
public boolean performFinish() {
try {
getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
final ResourceChangeCommandFactory factory = new ResourceChangeCommandFactory(Activator.getDefault().getSerializationManager(), Activator.getDefault().getPreferences().getIgnoredFileNamesForSync());
final Repository[] selectedServer = new Repository[1];
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
try {
selectedServer[0] = ServerUtil.getConnectedRepository(exportPage.getServer(), monitor);
} catch (CoreException e) {
throw new RuntimeException(e);
}
}
});
try {
syncStartPoint.accept(new IResourceVisitor() {
@Override
public boolean visit(IResource resource) throws CoreException {
Command<?> command = factory.newCommandForAddedOrUpdated(selectedServer[0], resource);
if (command == null) {
return true;
}
Result<?> result = command.execute();
if (!result.isSuccess()) {
throw new CoreException(new Status(Status.ERROR, Activator.PLUGIN_ID, "Failed exporting: " + result.toString()));
}
return true;
}
});
} catch (CoreException e) {
throw new InvocationTargetException(e);
} catch (Throwable t) {
t.printStackTrace();
throw new InvocationTargetException(t);
}
}
});
return true;
} catch (RuntimeException | InterruptedException e) {
exportPage.setErrorMessage(e.getMessage());
return false;
} catch (InvocationTargetException e) {
exportPage.setErrorMessage(e.getCause().getMessage());
return false;
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project sling by apache.
the class AbstractNewSlingApplicationWizard method performFinish.
/**
* This method is called when 'Finish' button is pressed in the wizard. We will create an operation and run it using
* wizard as execution context.
*/
public boolean performFinish() {
try {
// create projects
final List<IProject> createdProjects = new ArrayList<>();
getContainer().run(false, true, new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
createdProjects.addAll(createProjects(monitor));
}
});
// configure projects
final Projects[] projects = new Projects[1];
getContainer().run(false, true, new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
projects[0] = configureCreatedProjects(createdProjects, monitor);
}
});
// deploy the projects on server
getContainer().run(false, true, new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
deployProjectsOnServer(projects[0], monitor);
}
});
// ensure server is started and all modules are published
getContainer().run(false, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
publishModules(createdProjects, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
} catch (InvocationTargetException e) {
reportError(e.getTargetException());
return false;
}
return true;
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project azure-tools-for-java by Microsoft.
the class SrvPriCreationStatusDialog method createServicePrincipalAsync.
private void createServicePrincipalAsync() {
try {
class StatusTask implements IRunnableWithProgress, IListener<Status> {
IProgressMonitor progressIndicator = null;
@Override
public void listen(Status status) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (progressIndicator != null) {
progressIndicator.setTaskName(status.getAction());
}
// if only action was set in the status - the info for progress indicator only - igonre for table
if (status.getResult() != null) {
TableItem item = new TableItem(table, SWT.NULL);
item.setText(new String[] { status.getAction(), status.getResult().toString(), status.getDetails() });
}
}
});
}
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
progressIndicator = monitor;
monitor.beginTask("Creating Service Principal...", IProgressMonitor.UNKNOWN);
for (String tid : tidSidsMap.keySet()) {
if (monitor.isCanceled()) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
TableItem item = new TableItem(table, SWT.NULL);
item.setText(new String[] { "!!! Canceled by user" });
}
});
return;
}
List<String> sidList = tidSidsMap.get(tid);
if (!sidList.isEmpty()) {
try {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
TableItem item = new TableItem(table, SWT.NULL);
item.setText(new String[] { "tenant ID: " + tid + " ===" });
}
});
Date now = new Date();
String suffix = new SimpleDateFormat("yyyyMMddHHmmss").format(now);
;
String authFilepath = SrvPriManager.createSp(tid, sidList, suffix, this, destinationFolder);
if (authFilepath != null) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
listCreatedFiles.add(authFilepath);
listCreatedFiles.setSelection(0);
}
});
}
} catch (Exception ex) {
ex.printStackTrace();
LOG.log(new org.eclipse.core.runtime.Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@createServicePrincipalAsync@SrvPriCreationStatusDialog", ex));
}
}
}
}
}
new ProgressMonitorDialog(this.getShell()).run(true, true, new StatusTask());
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method internalInit.
/**
* Implements the <code>init</code> method of <code>IEditorPart</code>.
* Subclasses replacing <code>init</code> may choose to call this method in
* their implementation.
*
* @param window the workbench window
* @param site the editor's site
* @param input the editor input for the editor being created
* @throws PartInitException if {@link #doSetInput(IEditorInput)} fails or gets canceled
*
* @see org.eclipse.ui.IEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
* @since 2.1
*/
protected final void internalInit(IWorkbenchWindow window, final IEditorSite site, final IEditorInput input) throws PartInitException {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
if (getDocumentProvider() instanceof IDocumentProviderExtension2) {
IDocumentProviderExtension2 extension = (IDocumentProviderExtension2) getDocumentProvider();
extension.setProgressMonitor(monitor);
}
doSetInput(input);
} catch (CoreException x) {
throw new InvocationTargetException(x);
} finally {
if (getDocumentProvider() instanceof IDocumentProviderExtension2) {
IDocumentProviderExtension2 extension = (IDocumentProviderExtension2) getDocumentProvider();
extension.setProgressMonitor(null);
}
}
}
};
try {
// When using the progress service always a modal dialog pops up. The site should be asked for a runnable context
// which could be the workbench window or the progress service, depending on what the site represents.
// getSite().getWorkbenchWindow().getWorkbench().getProgressService().run(false, true, runnable);
getSite().getWorkbenchWindow().run(false, true, runnable);
} catch (InterruptedException x) {
} catch (InvocationTargetException x) {
Throwable t = x.getTargetException();
if (t instanceof CoreException) {
/*
/* XXX: Remove unpacking of CoreException once the following bug is
* fixed: https://bugs.eclipse.org/bugs/show_bug.cgi?id=81640
*/
CoreException e = (CoreException) t;
IStatus status = e.getStatus();
if (status.getException() != null)
throw new PartInitException(status);
throw new PartInitException(new Status(status.getSeverity(), status.getPlugin(), status.getCode(), status.getMessage(), t));
}
throw new PartInitException(new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, IStatus.OK, EditorMessages.Editor_error_init, t));
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project linuxtools by eclipse.
the class Oprofile method getModelData.
/**
* Return a list of all the Samples in the given session.
*
* @param session
* the session for which to get samples
* @param shell
* the composite shell to use for the progress dialog
*/
public static OpModelImage getModelData(String eventName, String sessionName) {
OpModelImage image = new OpModelImage();
final IRunnableWithProgress opxml;
try {
opxml = OprofileCorePlugin.getDefault().getOpxmlProvider().modelData(eventName, sessionName, image);
opxml.run(null);
} catch (InvocationTargetException | InterruptedException e) {
}
return image;
}
Aggregations