Changeset 11091 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2016-10-07T21:13:12+02:00 (8 years ago)
Author:
simon04
Message:

fix #13745 - Changeset manager: allow to download objects from a changeset

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java

    r10791 r11091  
    1919import java.util.HashSet;
    2020import java.util.List;
     21import java.util.Objects;
    2122import java.util.Set;
     23import java.util.stream.Collectors;
    2224
    2325import javax.swing.AbstractAction;
     
    4749import org.openstreetmap.josm.data.osm.Changeset;
    4850import org.openstreetmap.josm.data.osm.ChangesetCache;
     51import org.openstreetmap.josm.data.osm.ChangesetDataSet;
     52import org.openstreetmap.josm.data.osm.PrimitiveId;
     53import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
    4954import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    5055import org.openstreetmap.josm.gui.JosmUserIdentityManager;
     
    5358import org.openstreetmap.josm.gui.help.HelpUtil;
    5459import org.openstreetmap.josm.gui.io.CloseChangesetTask;
     60import org.openstreetmap.josm.gui.io.DownloadPrimitivesWithReferrersTask;
    5561import org.openstreetmap.josm.gui.util.GuiHelper;
    5662import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     
    5965import org.openstreetmap.josm.tools.ImageProvider;
    6066import org.openstreetmap.josm.tools.InputMapUtils;
     67import org.openstreetmap.josm.tools.StreamUtils;
    6168import org.openstreetmap.josm.tools.WindowGeometry;
    6269
     
    107114    private DownloadSelectedChangesetsAction actDownloadSelectedChangesets;
    108115    private DownloadSelectedChangesetContentAction actDownloadSelectedContent;
     116    private DownloadSelectedChangesetObjectsAction actDownloadSelectedChangesetObjects;
    109117    private JTable tblChangesets;
    110118
     
    240248        model.getSelectionModel().addListSelectionListener(actDownloadSelectedContent);
    241249        tb.add(actDownloadSelectedContent);
     250
     251        // -- download the objects contained in the selected changesets from the OSM server
     252        model.getSelectionModel().addListSelectionListener(actDownloadSelectedChangesetObjects);
     253        tb.add(actDownloadSelectedChangesetObjects);
    242254
    243255        pnl.add(tb, BorderLayout.CENTER);
     
    282294        actDownloadSelectedChangesets = new DownloadSelectedChangesetsAction(model);
    283295        actDownloadSelectedContent = new DownloadSelectedChangesetContentAction(model);
     296        actDownloadSelectedChangesetObjects = new DownloadSelectedChangesetObjectsAction(model);
    284297
    285298        cp.add(buildToolbarPanel(), BorderLayout.NORTH);
     
    538551    }
    539552
     553    /**
     554     * Downloads the objects contained in the selected changesets from the OSM server
     555     */
     556    private class DownloadSelectedChangesetObjectsAction extends AbstractAction implements ListSelectionListener {
     557
     558        DownloadSelectedChangesetObjectsAction(ChangesetCacheManagerModel model) {
     559            putValue(NAME, tr("Download changed objects"));
     560            new ImageProvider("downloadprimitive").getResource().attachImageIcon(this);
     561            putValue(SHORT_DESCRIPTION, tr("Download the current version of the changed objects in the selected changesets"));
     562            updateEnabledState();
     563        }
     564
     565        @Override
     566        public void actionPerformed(ActionEvent e) {
     567            if (!GraphicsEnvironment.isHeadless()) {
     568                actDownloadSelectedContent.actionPerformed(e);
     569                Main.worker.submit(() -> {
     570                    final List<PrimitiveId> primitiveIds = model.getSelectedChangesets().stream()
     571                            .map(Changeset::getContent)
     572                            .filter(Objects::nonNull)
     573                            .flatMap(content -> StreamUtils.toStream(content::iterator))
     574                            .map(ChangesetDataSet.ChangesetDataSetEntry::getPrimitive)
     575                            .map(HistoryOsmPrimitive::getPrimitiveId)
     576                            .distinct()
     577                            .collect(Collectors.toList());
     578                    new DownloadPrimitivesWithReferrersTask(false, primitiveIds, true, true, null, null).run();
     579                });
     580            }
     581        }
     582
     583        protected void updateEnabledState() {
     584            setEnabled(model.hasSelectedChangesets() && !Main.isOffline(OnlineResource.OSM_API));
     585        }
     586
     587        @Override
     588        public void valueChanged(ListSelectionEvent e) {
     589            updateEnabledState();
     590        }
     591    }
     592
    540593    static class ShowDetailAction extends AbstractAction {
    541594        private final ChangesetCacheManagerModel model;
     
    619672            add(actDownloadSelectedChangesets);
    620673            add(actDownloadSelectedContent);
     674            add(actDownloadSelectedChangesetObjects);
    621675        }
    622676    }
Note: See TracChangeset for help on using the changeset viewer.