Auto-refreshing ViewPart by using Job [message #820977] |
Wed, 14 March 2012 16:23  |
Eclipse User |
|
|
|
Hello,
I have an issue updating a view. It's just a label that I am hoping to present the current time.
public class TestView extends ViewPart {
private Label label;
private String jobId;
private Display display;
public TestView() {
System.out.println("TestView.TestView()");
}
@Override
public void createPartControl(Composite parent) {
this.setContentDescription("This is just a test.");
GridLayoutFactory.fillDefaults().applyTo(parent);
label = new Label(parent, SWT.BOLD | SWT.BORDER);
jobId = UUID.randomUUID().toString();
System.out.println("Job ID: " + jobId);
display = parent.getDisplay();
Job job = new Job(jobId) {
protected IStatus run(IProgressMonitor monitor) {
// Assume this getTime() method takes a long time
final String newString = GregorianCalendar.getInstance()
.getTime().toString();
System.out.println("new Time: " + newString);
display.asyncExec(new Runnable() {
public void run() {
// Updating UI has to happen in a thread that is called
// by display.asyncExec.
updateLabel(newString);
}
});
return Status.OK_STATUS;
}
};
job.schedule();
}
@Override
public void setFocus() {
System.out.println("TestView.setFocus()");
label.setFocus();
}
private void updateLabel(String newString) {
System.out.println("TestView.updateLabel()");
if (!label.isDisposed()) {
label.setText(newString);
}
}
}
The current time stamp will show up fine initially, but it will never get updated anymore. How do I
1) Update this label with the current time continuously? I know I can use UICallBack but I think the Job should handle this for me automagically.
2) Update this label when user gets to the page (pull model instead of push).
Thank you,
Ronald
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.24894 seconds