private NewsCounter countAll() {
final NewsCounter newsCounter = new NewsCounter();
final long start = System.currentTimeMillis();
final Collection<IFeed> feeds = DynamicDAO.loadAll(IFeed.class);
final ProgressMonitorDialog dialog = new NewsServiceProgressMonitorDialog(new Shell(Display.getDefault(), SWT.NONE));
dialog.setOpenOnRun(false);
/* Runnable will open the Dialog after SHOW_PROGRESS_THRESHOLD ms */
IRunnableWithProgress runnable = new IRunnableWithProgress() {
private boolean fDialogOpened;
public void run(IProgressMonitor monitor) {
int worked = 0;
for (IFeed feed : feeds) {
newsCounter.put(feed.getLink(), count(feed));
/* Open the Dialog if exceeded SHOW_PROGRESS_THRESHOLD ms */
if (System.currentTimeMillis() - start > SHOW_PROGRESS_THRESHOLD && !fDialogOpened) {
dialog.open();
monitor.beginTask("RSSOwl was not shutdown properly. Restoring data, please wait...", feeds.size() - worked);
fDialogOpened = true;
}
/* Worked a bit again... */
if (fDialogOpened)
monitor.worked(1);
/* Remember the worked items */
worked++;
}
/* Completed */
monitor.done();
}
};
/* Execute the Runnable */
try {
dialog.run(false, false, runnable);
} catch (InvocationTargetException e) {
Activator.getDefault().logError(e.getMessage(), e);
} catch (InterruptedException e) {
Activator.getDefault().logError(e.getMessage(), e);
}