#9634 closed defect (fixed)
Downloading Referrers Grabs Focus
Reported by: | ingalls | Owned by: | team |
---|---|---|---|
Priority: | normal | Milestone: | 14.04 |
Component: | Core remotecontrol | Version: | tested |
Keywords: | Cc: |
Description
When Downloading nodes through the remote, JOSM grabs focus each time a 'downloading referrs' dialogue appears. Since there is a new dialogue for each and every node being downloaded, large remote downloads make the host computer unusable as JOSM is constantly grabbing focus.
Attachments (4)
Change History (18)
comment:1 by , 11 years ago
Milestone: | → 14.02 |
---|---|
Priority: | major → normal |
comment:2 by , 11 years ago
Milestone: | 14.02 → 14.03 |
---|
comment:3 by , 11 years ago
Milestone: | 14.03 → 14.04 |
---|
follow-up: 5 comment:4 by , 11 years ago
I am trying to do something. But I am not friendly with thread, and I don't understand every thing.
One of the problem is how to do Cancel.
It's rather easy to do a Stop
button (stop downloading next referrers), but a real Cancel
button need to remove all downloading object !
I put code here since in diff file it's not easy to see (it's mainly the older code, but reoder)
I have put some FIXME comment where I have problems.
/** * @param newLayer if the data should be downloaded into a new layer * @param ids * @param downloadReferrers if the referrers of the object should be downloaded as well, i.e., parent relations, and for nodes, additionally, parent ways * @param full if the members of a relation should be downloaded as well */ public static void processItems(boolean newLayer, final List<PrimitiveId> ids, boolean downloadReferrers, boolean full) { class DownloadPrimitivesWithReferrersTask extends PleaseWaitRunnable { final OsmDataLayer layer; List<PrimitiveId> ids; boolean full; DownloadPrimitivesTask task; DownloadPrimitivesWithReferrersTask(final OsmDataLayer layer, List<PrimitiveId> ids, boolean full) { //, ProgressMonitor monitor) { super(tr("Download objects"), false); this.layer = layer; this.ids = ids; this.full = full; } @Override protected void cancel() { // FIXME: how to do ? } @Override protected void realRun() throws SAXException, IOException, OsmTransferException { task = new DownloadPrimitivesTask(layer, ids, full, getProgressMonitor().createSubTaskMonitor(1, false)); // FIXME: Need to run task in an other thread (like Main.worker.submit(task) ? task.run(); getProgressMonitor().setTicksCount(ids.size()); for(PrimitiveId id : ids) { System.out.printf("referrers task %s\n", id.toString()); // FIXME: In an other thread ? new DownloadReferrersTask(layer, id, getProgressMonitor().createSubTaskMonitor(1, false)).run(); } } @Override protected void finish() { // FIXME: Does all task are really finish ? System.out.printf("call to finish\n"); Runnable showErrorsAndWarnings = new Runnable() { @Override public void run() { final Set<PrimitiveId> errs = task.getMissingPrimitives(); if (errs != null && !errs.isEmpty()) { try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { reportProblemDialog(errs, trn("Object could not be downloaded", "Some objects could not be downloaded", errs.size()), trn("One object could not be downloaded.<br>", "{0} objects could not be downloaded.<br>", errs.size(), errs.size()) + tr("The server replied with response code 404.<br>" + "This usually means, the server does not know an object with the requested id."), tr("missing objects:"), JOptionPane.ERROR_MESSAGE ).showDialog(); } }); } catch (InterruptedException ex) { Main.warn("InterruptedException while displaying error dialog"); } catch (InvocationTargetException ex) { Main.warn(ex); } } final Set<PrimitiveId> del = new TreeSet<PrimitiveId>(); DataSet ds = getCurrentDataSet(); for (PrimitiveId id : ids) { OsmPrimitive osm = ds.getPrimitiveById(id); if (osm != null && osm.isDeleted()) { del.add(id); } } if (!del.isEmpty()) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { reportProblemDialog(del, trn("Object deleted", "Objects deleted", del.size()), trn( "One downloaded object is deleted.", "{0} downloaded objects are deleted.", del.size(), del.size()), null, JOptionPane.WARNING_MESSAGE ).showDialog(); } }); } } }; Main.worker.submit(showErrorsAndWarnings); } } System.out.printf("DEBUG: DownloadPrimitiveAction.processItems\n"); OsmDataLayer layer = getEditLayer(); if ((layer == null) || newLayer) { layer = new OsmDataLayer(new DataSet(), OsmDataLayer.createNewName(), null); Main.main.addLayer(layer); } final DownloadPrimitivesWithReferrersTask task = new DownloadPrimitivesWithReferrersTask(layer, ids, full); //, monitor); Main.worker.submit(task); System.out.printf("task done\n"); }
by , 11 years ago
Attachment: | ticket9634_2014-04-06_08:56:16_+0200.patch added |
---|
Draft of current work
comment:5 by , 11 years ago
Replying to Balaitous:
I am trying to do something. But I am not friendly with thread, and I don't understand every thing.
One of the problem is how to do Cancel.
It's rather easy to do aStop
button (stop downloading next referrers), but a realCancel
button need to remove all downloading object !
I put code here since in diff file it's not easy to see (it's mainly the older code, but reoder)
I have put some FIXME comment where I have problems.
Hi Balaitous,
Looks good so far! For cancel, you could save the DownloadPrimitivesTask
and the DownloadReferrersTask
s in fields, so they can be accessed from the cancel method. Then do something like
@Override protected void cancel() { if (task != null) { task.cancel(); } // ... }
I think it is correct to run the tasks directly as you do, without any additional parallel processing. This ensures that they are indeed finished, when finish()
is invoked.
Make sure you don't forget the check for the downloadReferrers
flag. Also you may want to check if the handling of the ProgressMonitor
can be improved. You may have to play a little bit with the options and look at examples, the code for progress update is not too well documented.
by , 11 years ago
Attachment: | ticket9634_2014-04-10_00:46:09_+0200.patch added |
---|
Draft of current work
follow-up: 7 comment:6 by , 11 years ago
I have try to make download into a temporary layer, but a lot of problems remains.
Maybe it should be better to adapt DownloadPrimitivesTask
class be setting a downloadReferrers
flag, and work with dataset instead of layer.
comment:7 by , 11 years ago
Replying to Balaitous:
I have try to make download into a temporary layer, but a lot of problems remains.
What kind of problems?
comment:8 by , 11 years ago
In order to be able to do a full cancel, all primitives and referrers have to be downloaded into a tmpLayer
that is not attach to any mapFrame
.
This involved that it is possible to call DownloadPrimitivesTask
and DownloadReferrersTask
before Main.map
init.
So I have had test if(Main.map != null)
.
Another problem is that when action is cancelled, primitives from the tmpLayer
remains selected.
by , 11 years ago
Attachment: | ticket9634_2014-04-11_00:53:42_+0200.patch added |
---|
Draft of current work, I have found where downloaded primitives are selected. In a good way.
by , 11 years ago
Attachment: | ticket9634_2014-04-12_00:53:36_+0200.patch added |
---|
I think this time it is OK
comment:11 by , 11 years ago
I don't understand every thing with thread. I have a little experience with MPI and openMP, but nothing with java!
comment:12 by , 11 years ago
Then you probably know more about threads than me. Just take care that GUI stuff (like changing the selection) is done in event dispatch thread (EDT). (And everything that takes a long time, like download, must not be done in EDT, otherwise the program will freeze.) I only noticed because there were some warnings on the command line.
comment:13 by , 11 years ago
EDT violations are easy to spot. Just look at warnings printed on Console when you run the program from a local build (i.e Eclipse) :)
Request example: