MySwingWorker sw = new MySwingWorker(ID) {
@Override
protected void myconstruct() throws Exception {
StatusBar bar = getApplicationWindow().getStatusBar();
ProgressMonitor pm = bar.getProgressMonitor();
int resultDownload = JOptionPane.showConfirmDialog(null, tr.get(ID + ".downloadQuestion"),
tr.get(ID + ".downloadQuestion"), JOptionPane.YES_NO_OPTION);
if (resultDownload == JOptionPane.YES_OPTION) {
String str = "http://peat_hal.users.sourceforge.net/sessions_catalog.j1";
bar.setMessage(tr.get("downloadFrom", str));
istream = new UrlResource(str).getInputStream();
pm.worked(5);
bar.setMessage("");
}
pm.taskStarted(tr.get(ID + ".startTask"), -1);
pm.worked(10);
ImportJavaOne importer = new ImportJavaOne();
ImportJavaOne.overwriteSettings(settings);
FastMap<String, Person> persons = new FastMap<String, Person>();
// TODO update progres:
Collection<JavaOneInterval> coll = importer.parse(istream);
double tmp = 80.0 / (coll.size() + 1);
int counter = 0;
Dao<Event> eDao = dataPool.getDao(Event.class);
for (JavaOneInterval ev : coll) {
pm.worked(10 + (int) (counter * tmp));
counter++;
Event event = eDao.create();
if (ev.getStart() >= 0 && ev.getDuration() > 0) {
IntervalInt si = settings.toInterval(ev.getStartDateTime(), ev.getEndDateTime());
if (si != null)
event.setInterval(si.getStart(), si.getDuration());
}
event.setName(ev.getId());
event.setDescription(ev.getDescription());
if (ev.getSpeakers() != null) {
for (String str : ev.getSpeakers().split(";")) {
str = str.trim();
Person p = persons.get(str);
if (p == null) {
p = new Person();
p.setName(str);
persons.put(str, p);
}
p.addEvent(event, Role.TEACHER, true);
}
}
eDao.attach(event);
}
pm.worked(90);
dataPool.getDao(Person.class).attachAll(persons.values());
pm.worked(100);
}
@Override
protected void done() {
openAllViews();