Better way to update UI with a job [message #629920] |
Wed, 29 September 2010 23:54 |
Luiz E. Messages: 100 Registered: September 2010 |
Senior Member |
|
|
hi all
i have a job (and a uijob) that update my UI. but i was thinking if there's a better wat to do this.
actually, i'm doing like this:
public class CarregarMapaJob extends Job
{
private Location loc;
private Image img;
private AhmCastView view;
public CarregarMapaJob(String name, Location loc, AhmCastView view) {
super(name);
this.loc = loc;
this.view = view;
}
@Override
protected IStatus run(IProgressMonitor monitor)
{
try
{
monitor.beginTask("Criando URL e baixando mapa", -1);
String center = loc.getLatitude()+","+loc.getLongitude();
String def = "http://maps.google.com/staticmap?center="+center+"&zoom=12&" +
"size=800x800&key="+DataUtils.GMAP_KEY+"&sensor=true";
URL url = new URL(def);
img = ImageDescriptor.createFromURL(url).createImage();
monitor.done();
} catch (Exception e)
{
e.printStackTrace();
}
finally {
UIJob uiCarregarMapa = new UIJob("Carregando mapa") {
public IStatus runInUIThread(IProgressMonitor monitor)
{
try
{
monitor.beginTask("Adicionando mapa", -1);
view.addMapaLabel(img);
monitor.done();
} catch (Exception e)
{
e.printStackTrace();
}
return Status.OK_STATUS;
}
};
uiCarregarMapa.setUser(true);
uiCarregarMapa.schedule();
}
return Status.OK_STATUS;
}
as you can see, i'm passing the view as a parameter to the constructor, and inside the UIJob, I update her (the ui, of course)
is this a good approach?
sorry for the english.
thanks
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02990 seconds