Ticket #13745: 13745.patch

File 13745.patch, 6.2 KB (added by simon04, 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  
    1818import java.util.Collection;
    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;
    2426import javax.swing.DefaultListSelectionModel;
     
    4648import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
    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;
    5156import org.openstreetmap.josm.gui.dialogs.changeset.query.ChangesetQueryDialog;
    5257import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction;
    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;
    5763import org.openstreetmap.josm.io.ChangesetQuery;
    5864import org.openstreetmap.josm.io.OnlineResource;
    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
    6370/**
    public static void destroyInstance() {  
    106113    private CloseSelectedChangesetsAction actCloseSelectedChangesetsAction;
    107114    private DownloadSelectedChangesetsAction actDownloadSelectedChangesets;
    108115    private DownloadSelectedChangesetContentAction actDownloadSelectedContent;
     116    private DownloadSelectedChangesetObjectsAction actDownloadSelectedChangesetObjects;
    109117    private JTable tblChangesets;
    110118
    111119    /**
    protected JPanel buildChangesetTableActionPanel() {  
    240248        model.getSelectionModel().addListSelectionListener(actDownloadSelectedContent);
    241249        tb.add(actDownloadSelectedContent);
    242250
     251        // -- download the objects contained in the selected changesets from the OSM server
     252        model.getSelectionModel().addListSelectionListener(actDownloadSelectedChangesetObjects);
     253        tb.add(actDownloadSelectedChangesetObjects);
     254
    243255        pnl.add(tb, BorderLayout.CENTER);
    244256        return pnl;
    245257    }
    protected void build() {  
    281293        actCloseSelectedChangesetsAction = new CloseSelectedChangesetsAction(model);
    282294        actDownloadSelectedChangesets = new DownloadSelectedChangesetsAction(model);
    283295        actDownloadSelectedContent = new DownloadSelectedChangesetContentAction(model);
     296        actDownloadSelectedChangesetObjects = new DownloadSelectedChangesetObjectsAction(model);
    284297
    285298        cp.add(buildToolbarPanel(), BorderLayout.NORTH);
    286299        cp.add(buildContentPanel(), BorderLayout.CENTER);
    public void valueChanged(ListSelectionEvent e) {  
    537550        }
    538551    }
    539552
     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
    540602    static class ShowDetailAction extends AbstractAction {
    541603        private final ChangesetCacheManagerModel model;
    542604
    public void mouseClicked(MouseEvent evt) {  
    618680            add(actCloseSelectedChangesetsAction);
    619681            add(actDownloadSelectedChangesets);
    620682            add(actDownloadSelectedContent);
     683            add(actDownloadSelectedChangesetObjects);
    621684        }
    622685    }
    623686