Ticket #13745: 13745.patch
File 13745.patch, 6.2 KB (added by , 8 years ago) |
---|
-
src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java
diff --git a/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java b/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java index cad3bae..d3950b8 100644
a b 18 18 import java.util.Collection; 19 19 import java.util.HashSet; 20 20 import java.util.List; 21 import java.util.Objects; 21 22 import java.util.Set; 23 import java.util.stream.Collectors; 22 24 23 25 import javax.swing.AbstractAction; 24 26 import javax.swing.DefaultListSelectionModel; … … 46 48 import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler; 47 49 import org.openstreetmap.josm.data.osm.Changeset; 48 50 import org.openstreetmap.josm.data.osm.ChangesetCache; 51 import org.openstreetmap.josm.data.osm.ChangesetDataSet; 52 import org.openstreetmap.josm.data.osm.PrimitiveId; 53 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive; 49 54 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 50 55 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 51 56 import org.openstreetmap.josm.gui.dialogs.changeset.query.ChangesetQueryDialog; 52 57 import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction; 53 58 import org.openstreetmap.josm.gui.help.HelpUtil; 54 59 import org.openstreetmap.josm.gui.io.CloseChangesetTask; 60 import org.openstreetmap.josm.gui.io.DownloadPrimitivesWithReferrersTask; 55 61 import org.openstreetmap.josm.gui.util.GuiHelper; 56 62 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 57 63 import org.openstreetmap.josm.io.ChangesetQuery; 58 64 import org.openstreetmap.josm.io.OnlineResource; 59 65 import org.openstreetmap.josm.tools.ImageProvider; 60 66 import org.openstreetmap.josm.tools.InputMapUtils; 67 import org.openstreetmap.josm.tools.StreamUtils; 61 68 import org.openstreetmap.josm.tools.WindowGeometry; 62 69 63 70 /** … … public static void destroyInstance() { 106 113 private CloseSelectedChangesetsAction actCloseSelectedChangesetsAction; 107 114 private DownloadSelectedChangesetsAction actDownloadSelectedChangesets; 108 115 private DownloadSelectedChangesetContentAction actDownloadSelectedContent; 116 private DownloadSelectedChangesetObjectsAction actDownloadSelectedChangesetObjects; 109 117 private JTable tblChangesets; 110 118 111 119 /** … … protected JPanel buildChangesetTableActionPanel() { 240 248 model.getSelectionModel().addListSelectionListener(actDownloadSelectedContent); 241 249 tb.add(actDownloadSelectedContent); 242 250 251 // -- download the objects contained in the selected changesets from the OSM server 252 model.getSelectionModel().addListSelectionListener(actDownloadSelectedChangesetObjects); 253 tb.add(actDownloadSelectedChangesetObjects); 254 243 255 pnl.add(tb, BorderLayout.CENTER); 244 256 return pnl; 245 257 } … … protected void build() { 281 293 actCloseSelectedChangesetsAction = new CloseSelectedChangesetsAction(model); 282 294 actDownloadSelectedChangesets = new DownloadSelectedChangesetsAction(model); 283 295 actDownloadSelectedContent = new DownloadSelectedChangesetContentAction(model); 296 actDownloadSelectedChangesetObjects = new DownloadSelectedChangesetObjectsAction(model); 284 297 285 298 cp.add(buildToolbarPanel(), BorderLayout.NORTH); 286 299 cp.add(buildContentPanel(), BorderLayout.CENTER); … … public void valueChanged(ListSelectionEvent e) { 537 550 } 538 551 } 539 552 553 /** 554 * Downloads the objects contained in the selected changesets from the OSM server 555 */ 556 static class DownloadSelectedChangesetObjectsAction extends AbstractAction implements ListSelectionListener { 557 private final ChangesetCacheManagerModel model; 558 559 DownloadSelectedChangesetObjectsAction(ChangesetCacheManagerModel model) { 560 putValue(NAME, tr("Download changed objects")); 561 new ImageProvider("downloadprimitive").getResource().attachImageIcon(this); 562 putValue(SHORT_DESCRIPTION, tr("Download the current version of the changed objects in the selected changesets")); 563 this.model = model; 564 updateEnabledState(); 565 } 566 567 @Override 568 public void actionPerformed(ActionEvent e) { 569 if (!GraphicsEnvironment.isHeadless()) { 570 final List<Integer> changesetsWithoutContent = model.getSelectedChangesets().stream() 571 .filter(cs -> !cs.hasContent()) 572 .map(Changeset::getId) 573 .collect(Collectors.toList()); 574 final ChangesetContentDownloadTask contentDownloadTask = 575 new ChangesetContentDownloadTask(GuiHelper.getWindowAncestorFor(e), changesetsWithoutContent); 576 Main.worker.submit( 577 new PostDownloadHandler(contentDownloadTask, contentDownloadTask.download())); 578 579 final List<PrimitiveId> primitiveIds = model.getSelectedChangesets().stream() 580 .map(Changeset::getContent) 581 .filter(Objects::nonNull) 582 .flatMap(content -> StreamUtils.toStream(content::iterator)) 583 .map(ChangesetDataSet.ChangesetDataSetEntry::getPrimitive) 584 .map(HistoryOsmPrimitive::getPrimitiveId) 585 .distinct() 586 .collect(Collectors.toList()); 587 Main.worker.submit( 588 new DownloadPrimitivesWithReferrersTask(false, primitiveIds, true, true, null, null)); 589 } 590 } 591 592 protected void updateEnabledState() { 593 setEnabled(model.hasSelectedChangesets() && !Main.isOffline(OnlineResource.OSM_API)); 594 } 595 596 @Override 597 public void valueChanged(ListSelectionEvent e) { 598 updateEnabledState(); 599 } 600 } 601 540 602 static class ShowDetailAction extends AbstractAction { 541 603 private final ChangesetCacheManagerModel model; 542 604 … … public void mouseClicked(MouseEvent evt) { 618 680 add(actCloseSelectedChangesetsAction); 619 681 add(actDownloadSelectedChangesets); 620 682 add(actDownloadSelectedContent); 683 add(actDownloadSelectedChangesetObjects); 621 684 } 622 685 } 623 686