use of org.eclipse.core.runtime.jobs.Job in project bndtools by bndtools.
the class ResolutionView method executeAnalysis.
void executeAnalysis() {
if (inputLocked)
return;
outOfDate = false;
synchronized (this) {
Job oldJob = analysisJob;
if (oldJob != null && oldJob.getState() != Job.NONE)
oldJob.cancel();
if (!loaders.isEmpty()) {
final AnalyseBundleResolutionJob job = new AnalyseBundleResolutionJob("importExportAnalysis", loaders);
job.setSystem(true);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void aboutToRun(IJobChangeEvent event) {
if (display != null && !display.isDisposed()) {
Runnable update = new Runnable() {
@Override
public void run() {
setContentDescription("Working...");
}
};
if (display.getThread() == Thread.currentThread())
update.run();
else
display.asyncExec(update);
}
}
@Override
public void done(IJobChangeEvent event) {
IStatus result = job.getResult();
if (result != null && result.isOK()) {
if (display != null && !display.isDisposed())
display.asyncExec(new Runnable() {
@Override
public void run() {
setInput(loaders, job.getCapabilities(), job.getRequirements());
}
});
}
}
});
analysisJob = job;
analysisJob.schedule(500);
} else {
analysisJob = null;
}
}
}
use of org.eclipse.core.runtime.jobs.Job in project bndtools by bndtools.
the class RepositoryTreeContentProvider method getRepositoryBundles.
Object[] getRepositoryBundles(final RepositoryPlugin repoPlugin) {
Object[] result = null;
if (requirementFilter != null) {
if (repoPlugin instanceof Repository) {
result = searchR5Repository(repoPlugin, (Repository) repoPlugin);
} else if (repoPlugin instanceof WorkspaceRepository) {
try {
WorkspaceR5Repository workspaceRepo = Central.getWorkspaceR5Repository();
result = searchR5Repository(repoPlugin, workspaceRepo);
} catch (Exception e) {
logger.logError("Error querying workspace repository", e);
}
}
return result;
}
/*
* We can't directly call repoPlugin.list() since we are on the UI thread
* so the plan is to first check to see if we have cached the list results
* already from a previous job, if so, return those results directly
* If not, then we need to create a background job that will call list()
* and once it is finished, we tell the Viewer to refresh this node and the
* next time this method gets called the 'results' will be available in the cache
*/
Map<String, Object[]> listResults = repoPluginListResults.get(repoPlugin);
if (listResults == null) {
listResults = new HashMap<>();
repoPluginListResults.put(repoPlugin, listResults);
}
result = listResults.get(wildcardFilter);
if (result == null) {
Job job = new Job("Loading " + repoPlugin.getName() + " content...") {
@Override
protected IStatus run(IProgressMonitor monitor) {
IStatus status = Status.OK_STATUS;
Object[] jobresult;
List<String> bsns = null;
try {
bsns = repoPlugin.list(wildcardFilter);
} catch (Exception e) {
String message = MessageFormat.format("Error querying repository {0}.", repoPlugin.getName());
logger.logError(message, e);
status = new Status(IStatus.ERROR, Plugin.PLUGIN_ID, message, e);
}
if (bsns != null) {
Collections.sort(bsns);
jobresult = new RepositoryBundle[bsns.size()];
int i = 0;
for (String bsn : bsns) {
jobresult[i++] = new RepositoryBundle(repoPlugin, bsn);
}
Map<String, Object[]> listResults = repoPluginListResults.get(repoPlugin);
listResults.put(wildcardFilter, jobresult);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
structuredViewer.refresh(repoPlugin, true);
}
});
}
return status;
}
};
job.schedule();
// wait 100 ms and see if the job will complete fast (likely already cached)
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
IStatus status = job.getResult();
if (status != null && status.isOK()) {
Map<String, Object[]> fastResults = repoPluginListResults.get(repoPlugin);
result = fastResults.get(wildcardFilter);
} else {
Object[] loading = new Object[] { new LoadingContentElement() };
listResults.put(wildcardFilter, loading);
result = loading;
}
}
return result;
}
use of org.eclipse.core.runtime.jobs.Job in project bndtools by bndtools.
the class JAREntryPart method loadContent.
protected void loadContent() {
if (displayJob != null && displayJob.getState() != Job.NONE)
displayJob.cancel();
if (zipEntry != null && !zipEntry.isDirectory()) {
IEditorInput input = editor.getEditorInput();
final Display display = text.getDisplay();
final URI uri = URIHelper.retrieveFileURI(input);
if (uri != null) {
displayJob = new Job("Load zip content") {
@Override
protected IStatus run(IProgressMonitor monitor) {
File ioFile = new File(uri);
try (ZipFile zipFile = new ZipFile(ioFile)) {
final StringWriter writer = new StringWriter();
if (showAsText)
readAsText(zipFile, zipEntry, charsets[selectedCharset], writer, 1024 * 20, monitor);
else
readAsHex(zipFile, zipEntry, writer, 1024 * 20, 2, monitor);
display.asyncExec(new Runnable() {
@Override
public void run() {
setContent(writer.toString());
}
});
return Status.OK_STATUS;
} catch (IOException e) {
Status status = new Status(IStatus.ERROR, PluginConstants.PLUGIN_ID, 0, "I/O error reading JAR file contents", e);
// ErrorDialog.openError(getManagedForm().getForm().getShell(), "Error", null, status);
return status;
}
}
};
displayJob.schedule();
}
} else {
setContent("");
}
}
use of org.eclipse.core.runtime.jobs.Job in project eclipse.platform.text by eclipse.
the class LockJob method setUp.
@Before
public void setUp() throws Exception {
IFolder folder = ResourceHelper.createFolder("FileDocumentProviderTestProject/test");
file = (File) ResourceHelper.createFile(folder, "file.txt", "");
assertTrue(file.exists());
fsManager = file.getLocalManager();
assertTrue(fsManager.fastIsSynchronized(file));
stopLockingFlag = new AtomicBoolean(false);
stoppedByTest = new AtomicBoolean(false);
fileProvider = new FileDocumentProviderMock();
lockJob = new LockJob("Locking workspace", file, stopLockingFlag, stoppedByTest);
// We need the editor only to get the default editor status line manager
IWorkbench workbench = PlatformUI.getWorkbench();
page = workbench.getActiveWorkbenchWindow().getActivePage();
editor = IDE.openEditor(page, file);
TestUtil.runEventLoop();
IStatusLineManager statusLineManager = editor.getEditorSite().getActionBars().getStatusLineManager();
// This is default monitor which almost all editors are using
IProgressMonitor progressMonitor = statusLineManager.getProgressMonitor();
assertNotNull(progressMonitor);
assertFalse(progressMonitor instanceof NullProgressMonitor);
assertFalse(progressMonitor instanceof EventLoopProgressMonitor);
assertTrue(progressMonitor instanceof IProgressMonitorWithBlocking);
// Because this monitor is not EventLoopProgressMonitor, it will not
// process UI events while waiting on workspace lock
fileProvider.setProgressMonitor(progressMonitor);
TestUtil.waitForJobs(500, 5000);
Job[] jobs = Job.getJobManager().find(null);
String jobsList = Arrays.toString(jobs);
System.out.println("Still running jobs: " + jobsList);
if (!Job.getJobManager().isIdle()) {
jobs = Job.getJobManager().find(null);
for (Job job : jobs) {
System.out.println("Going to cancel: " + job.getName() + " / " + job);
job.cancel();
}
}
}
use of org.eclipse.core.runtime.jobs.Job in project eclipse.platform.text by eclipse.
the class FileBufferOperationAction method doRun.
protected final void doRun(final IFile[] files, final IPath location, final IFileBufferOperation fileBufferOperation) {
Job job = new Job(fileBufferOperation.getOperationName()) {
@Override
protected IStatus run(IProgressMonitor monitor) {
IStatus status;
try {
int ticks = 100;
SubMonitor subMonitor = SubMonitor.convert(monitor, fFileBufferOperation.getOperationName(), ticks);
IPath[] locations;
if (files != null) {
ticks -= 30;
locations = generateLocations(files, subMonitor.split(30));
} else
locations = new IPath[] { location };
if (locations != null && locations.length > 0) {
FileBufferOperationRunner runner = new FileBufferOperationRunner(FileBuffers.getTextFileBufferManager(), getShell());
runner.execute(locations, fileBufferOperation, subMonitor.split(ticks));
}
status = Status.OK_STATUS;
} catch (OperationCanceledException e) {
// $NON-NLS-1$
status = new Status(IStatus.CANCEL, EditorsUI.PLUGIN_ID, IStatus.OK, "", null);
} catch (CoreException e) {
// $NON-NLS-1$
status = new Status(IStatus.ERROR, EditorsUI.PLUGIN_ID, IStatus.OK, "", e);
}
return status;
}
};
job.setUser(true);
job.schedule();
}
Aggregations