use of org.eclipse.jface.operation.IRunnableWithProgress in project linuxtools by eclipse.
the class StapNewWizard 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.
*/
@Override
public boolean performFinish() {
final String containerName = page.getContainerName();
final String fileName = page.getFileName();
IRunnableWithProgress op = monitor -> {
try {
doFinish(containerName, fileName, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
};
try {
getContainer().run(true, false, op);
} catch (InterruptedException e) {
// $NON-NLS-1$
MessageDialog.openError(getShell(), "Error", e.getLocalizedMessage());
return false;
} catch (InvocationTargetException e) {
Throwable realException = e.getTargetException();
// $NON-NLS-1$
MessageDialog.openError(getShell(), "Error", realException.getMessage());
return false;
}
return true;
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project linuxtools by eclipse.
the class SpecfileNewWizard 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.
*/
@Override
public boolean performFinish() {
final String containerName = page.getProjectName();
final String fileName = page.getFileName();
final InputStream contentInputStream = openContentStream();
IRunnableWithProgress op = monitor -> {
try {
doFinish(containerName, fileName, contentInputStream, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
};
try {
getContainer().run(true, false, op);
} catch (InterruptedException e) {
return false;
} catch (InvocationTargetException e) {
SpecfileLog.logError(e);
Throwable realException = e.getTargetException();
MessageDialog.openError(getShell(), Messages.SpecfileNewWizard_0, realException.getMessage());
return false;
}
return true;
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project linuxtools by eclipse.
the class PrepareChangeLogAction method doRun.
/**
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
protected void doRun() {
IRunnableWithProgress code = monitor -> {
// $NON-NLS-1$
monitor.beginTask(Messages.getString("ChangeLog.PrepareChangeLog"), 1000);
prepareChangeLog(monitor);
monitor.done();
};
ProgressMonitorDialog pd = new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
try {
pd.run(false, /* fork */
false, /* cancelable */
code);
} catch (InvocationTargetException e) {
ChangelogPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
return;
} catch (InterruptedException e) {
ChangelogPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project linuxtools by eclipse.
the class ContainerCopyToPage method setupSelectionsBasedOnSelectedTypes.
/**
* Update the tree to only select those elements that match the selected
* types
*/
@SuppressWarnings("rawtypes")
@Override
protected void setupSelectionsBasedOnSelectedTypes() {
ProgressMonitorDialog dialog = new ProgressMonitorDialog(getContainer().getShell());
final Map selectionMap = new Hashtable();
final IElementFilter filter = new IElementFilter() {
@Override
public void filterElements(Collection files, IProgressMonitor monitor) throws InterruptedException {
if (files == null) {
throw new InterruptedException();
}
Iterator filesList = files.iterator();
while (filesList.hasNext()) {
if (monitor.isCanceled()) {
throw new InterruptedException();
}
checkFile(filesList.next());
}
}
@Override
public void filterElements(Object[] files, IProgressMonitor monitor) throws InterruptedException {
if (files == null) {
throw new InterruptedException();
}
for (int i = 0; i < files.length; i++) {
if (monitor.isCanceled()) {
throw new InterruptedException();
}
checkFile(files[i]);
}
}
@SuppressWarnings("unchecked")
private void checkFile(Object fileElement) {
MinimizedFileSystemElement file = (MinimizedFileSystemElement) fileElement;
if (isExportableExtension(file.getFileNameExtension())) {
List elements = new ArrayList();
FileSystemElement parent = file.getParent();
if (selectionMap.containsKey(parent)) {
elements = (List) selectionMap.get(parent);
}
elements.add(file);
selectionMap.put(parent, elements);
}
}
};
IRunnableWithProgress runnable = monitor -> {
monitor.beginTask(CopyToContainerMessages.ImportPage_filterSelections, IProgressMonitor.UNKNOWN);
getSelectedResources(filter, monitor);
};
try {
dialog.run(true, true, runnable);
} catch (InvocationTargetException exception) {
// Couldn't start. Do nothing.
return;
} catch (InterruptedException exception) {
// Got interrupted. Do nothing.
return;
}
// make sure that all paint operations caused by closing the progress
// dialog get flushed, otherwise extra pixels will remain on the screen
// until
// updateSelections is completed
getShell().update();
// a new process.
if (selectionMap != null) {
updateSelections(selectionMap);
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project knime-core by knime.
the class NodeDescriptionConverter method buildDocumentationWithProgress.
/**
* @param plugins the plugin names
*/
public void buildDocumentationWithProgress(final String[] plugins) {
Display display = Display.getDefault();
Shell shell = new Shell(display);
m_dialog = new ProgressMonitorDialog(shell);
m_dialog.setCancelable(true);
m_monitor = m_dialog.getProgressMonitor();
m_monitor.setTaskName("Retrieving information from repository...");
m_nrPlugins = plugins.length;
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
m_first = true;
monitor.beginTask("Building documentation", m_nrPlugins);
for (String s : plugins) {
if (m_monitor.isCanceled()) {
m_canceled = true;
return;
}
buildDocumentationFor(s);
m_currentPlugin++;
monitor.worked(m_currentPlugin);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
try {
m_dialog.run(true, true, op);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
m_monitor.done();
}
}
Aggregations