use of org.eclipse.core.runtime.jobs.Job in project linuxtools by eclipse.
the class ShowInWebBrowserCommandHandler method execute.
@Override
public Object execute(final ExecutionEvent event) {
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
final List<IDockerPortMapping> portMappings = getSelectedPortMappings(activePart);
if (portMappings == null || portMappings.isEmpty()) {
return null;
}
final Job job = new Job(// $NON-NLS-1$
CommandMessages.getString("command.showIn.webBrowser")) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
try {
final IDockerConnection currentConnection = getCurrentConnection(activePart);
final IDockerPortMapping selectedPort = portMappings.get(0);
final URI connectionURI = new URI(currentConnection.getUri());
if (// $NON-NLS-1$
"tcp".equalsIgnoreCase(connectionURI.getScheme()) || // $NON-NLS-1$
"unix".equalsIgnoreCase(connectionURI.getScheme()) || // $NON-NLS-1$
"http".equalsIgnoreCase(connectionURI.getScheme()) || // $NON-NLS-1$
"https".equalsIgnoreCase(connectionURI.getScheme())) {
final String host = // $NON-NLS-1$
"unix".equalsIgnoreCase(connectionURI.getScheme()) ? "127.0.0.1" : // $NON-NLS-1$
connectionURI.getHost();
final URL location = new // $NON-NLS-1$
URL(// $NON-NLS-1$
"http", // $NON-NLS-1$
host, selectedPort.getPublicPort(), // $NON-NLS-1$
"/");
openLocationInWebBrowser(location);
}
} catch (URISyntaxException | MalformedURLException e) {
Activator.logErrorMessage(CommandMessages.getString(// $NON-NLS-1$
"command.showIn.webBrowser.failure"), e);
}
monitor.done();
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
return null;
}
use of org.eclipse.core.runtime.jobs.Job in project knime-core by knime.
the class Bug_4423_saveDuringResetDeadlock method runTest.
private void runTest(final Pointer<Exception> throwablePointer) throws Exception {
final Display currentDisplay = Display.getCurrent();
final Thread displayThread = currentDisplay.getThread();
final Thread currentThread = Thread.currentThread();
// reset and save are getting called from UI thread - replicate it here.
assertTrue("Not executing in display thread: " + currentThread, currentThread == displayThread);
final WorkflowManager workflowManager = getManager();
executeAllAndWait();
final NodeContainer nc = findNodeContainer(m_tableView2);
final AtomicReference<Progress> saveProgressPointer = new AtomicReference<>(Progress.NotStarted);
NodeContext.pushContext(nc);
try {
AbstractNodeView<?> view = ((NativeNodeContainer) nc).getNode().getView(0, "Programmatically opened in test flow");
Node.invokeOpenView(view, "Programmatically opened in test flow");
} finally {
NodeContext.removeLastContext();
}
final NodeLogger logger = NodeLogger.getLogger(getClass());
Runnable saveRunnable = new Runnable() {
@Override
public void run() {
// in the full application (and as part of the bug report) this job is scheduled while the reset is
// ongoing; note, it's not possible to replicate the exact behavior here as the whole test case is
// run in the display thread - we have to schedule the job up-front
Job saveJob = new Job("Workflow Save") {
@Override
protected IStatus run(final IProgressMonitor monitor) {
saveProgressPointer.set(Progress.Ongoing);
try {
logger.info("Calling save");
workflowManager.save(m_workflowDirTemp, new ExecutionMonitor(), true);
logger.info("Called save");
} catch (Exception e) {
throwablePointer.set(e);
} finally {
saveProgressPointer.set(Progress.Done);
}
return Status.OK_STATUS;
}
};
saveJob.schedule();
long wait = 5000;
while ((saveJob.getResult() == null) && (wait > 0)) {
try {
Thread.sleep(250);
wait -= 250;
} catch (InterruptedException e) {
throwablePointer.set(e);
}
}
if (saveJob.getResult() == null) {
saveJob.cancel();
throwablePointer.set(new IllegalStateException("Workflow save job has not finished within 5 secs, very likely because we have a deadlock"));
}
}
};
// doesn't actually run as this thread is the display thread
currentDisplay.asyncExec(saveRunnable);
// this is the display thread, cannot execute async scheduled tasks
assertEquals(Progress.NotStarted, saveProgressPointer.get());
logger.info("Calling reset");
reset(m_dataGenerator1);
logger.info("Called reset");
// this might change in the future so we let the test case do its job:
while (!Progress.Done.equals(saveProgressPointer.get())) {
if (!currentDisplay.readAndDispatch()) {
currentDisplay.sleep();
}
}
}
use of org.eclipse.core.runtime.jobs.Job in project bndtools by bndtools.
the class TemplateSelectionWizardPage method setTemplate.
public void setTemplate(final Template template) {
Template old = this.selected;
this.selected = template;
propSupport.firePropertyChange(PROP_TEMPLATE, old, template);
if (template != null) {
txtDescription.setText(String.format("<form>Loading help content for template '%s'...</form>", template.getName()));
Job updateDescJob = new UpdateDescriptionJob(template, txtDescription);
updateDescJob.setSystem(true);
updateDescJob.schedule();
} else {
txtDescription.setText(NO_HELP_CONTENT);
}
}
use of org.eclipse.core.runtime.jobs.Job in project yamcs-studio by yamcs.
the class PlayWavFileAction method run.
@Override
public void run() {
Job job = new Job("Play wave file") {
@Override
protected IStatus run(IProgressMonitor monitor) {
IPath path = getAbsolutePath();
monitor.beginTask("Connecting to " + path, IProgressMonitor.UNKNOWN);
try {
// a better way to play wav.
URL url;
if (ResourceUtil.isExistingWorkspaceFile(path))
url = new File(ResourceUtil.workspacePathToSysPath(path).toOSString()).toURI().toURL();
else if (ResourceUtil.isExistingLocalFile(path))
url = new File(path.toOSString()).toURI().toURL();
else
url = new URL(path.toString());
Applet.newAudioClip(url).play();
// final InputStream in = ResourceUtil.pathToInputStream(
// getAbsolutePath(), false);
//
// UIJob playWavJob = new UIJob(getDescription()) {
// @Override
// public IStatus runInUIThread(IProgressMonitor monitor) {
// try {
// final BufferedInputStream bis;
// if (!(in instanceof BufferedInputStream))
// bis = new BufferedInputStream(in);
// else
// bis = (BufferedInputStream) in;
//
// final AudioInputStream stream = AudioSystem
// .getAudioInputStream(bis);
// Clip clip = AudioSystem.getClip();
// clip.open(stream);
//
// clip.addLineListener(new LineListener() {
// public void update(LineEvent event) {
// if (event.getType() == LineEvent.Type.STOP) {
// try {
// stream.close();
// bis.close();
// if (in != bis)
// in.close();
// } catch (IOException e) {
// OPIBuilderPlugin
// .getLogger()
// .log(Level.WARNING,
// "audio close error", e); //$NON-NLS-1$
// }
// }
// }
// });
// clip.start();
// } catch (Exception e) {
// final String message = "Failed to play wave file " + getPath(); //$NON-NLS-1$
// OPIBuilderPlugin.getLogger().log(Level.WARNING,
// message, e);
// ConsoleService.getInstance().writeError(
// message + "\n" + e.getMessage()); //$NON-NLS-1$
// }
// return Status.OK_STATUS;
// }
// };
// playWavJob.schedule();
} catch (Exception e) {
String message = "Failed to connect to wave file " + getPath();
OPIBuilderPlugin.getLogger().log(Level.WARNING, message, e);
ConsoleService.getInstance().writeError(message + "\n" + e.getMessage());
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
job.schedule();
}
use of org.eclipse.core.runtime.jobs.Job in project yamcs-studio by yamcs.
the class OPIRuntimeDelegate method fillDisplayModelInJob.
private void fillDisplayModelInJob(final IEditorInput input, final Display display, final IWorkbenchPartSite site) {
Job job = new Job("Loading OPI...") {
@Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask("Connecting to " + input, IProgressMonitor.UNKNOWN);
try {
display.asyncExec(new Runnable() {
@Override
public void run() {
if (viewer != null) {
viewer.getControl().addPaintListener(loadingMessagePaintListener);
viewer.getControl().redraw();
}
}
});
final InputStream stream = ((IRunnerInput) input).getInputStream();
display.asyncExec(new Runnable() {
@Override
public void run() {
try {
if (viewer != null) {
viewer.getControl().removePaintListener(loadingMessagePaintListener);
}
MacrosInput macrosInput = ((IRunnerInput) input).getMacrosInput();
XMLUtil.fillDisplayModelFromInputStream(stream, displayModel, null, macrosInput);
displayModel.setOpiRuntime(opiRuntime);
displayModelFilled = true;
addRunnerInputMacros(input);
if (viewer != null) {
viewer.setContents(displayModel);
displayModel.setViewer(viewer);
}
updateEditorTitle();
hideCloseButton(site);
} catch (Exception e) {
ErrorHandlerUtil.handleError("Failed to load widget from " + input, e, true, true);
}
}
});
} catch (final Exception e) {
display.asyncExec(new Runnable() {
@Override
public void run() {
if (viewer != null && viewer.getControl() != null) {
viewer.getControl().removePaintListener(loadingMessagePaintListener);
viewer.getControl().addPaintListener(errorMessagePaintListener);
viewer.getControl().redraw();
}
ErrorHandlerUtil.handleError("Failed to open opi file: " + input, e, true, true);
}
});
}
monitor.done();
return Status.OK_STATUS;
}
};
job.setPriority(Job.INTERACTIVE);
job.schedule();
}
Aggregations