Changeset 16461 in josm for trunk/src/org


Ignore:
Timestamp:
2020-05-19T06:32:38+02:00 (5 years ago)
Author:
GerdP
Message:

see #19257: remove duplicated code in different implementations of ShowHistoryAction

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

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

    r16436 r16461  
    4242import org.openstreetmap.josm.data.osm.OsmPrimitive;
    4343import org.openstreetmap.josm.data.osm.PrimitiveId;
    44 import org.openstreetmap.josm.data.osm.history.History;
    45 import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
    4644import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
    4745import org.openstreetmap.josm.gui.HelpAwareOptionPane;
     
    4947import org.openstreetmap.josm.gui.help.HelpUtil;
    5048import org.openstreetmap.josm.gui.history.HistoryBrowserDialogManager;
    51 import org.openstreetmap.josm.gui.history.HistoryLoadTask;
    5249import org.openstreetmap.josm.gui.io.DownloadPrimitivesWithReferrersTask;
    5350import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
    5451import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    55 import org.openstreetmap.josm.gui.util.GuiHelper;
    5652import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
    5753import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    5854import org.openstreetmap.josm.tools.ImageProvider;
    59 import org.openstreetmap.josm.tools.JosmRuntimeException;
    6055import org.openstreetmap.josm.tools.Utils;
    61 import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;
    6256
    6357/**
     
    231225    class ShowHistoryAction extends AbstractAction implements ListSelectionListener {
    232226
    233         private final class ShowHistoryTask implements Runnable {
    234             private final Collection<HistoryOsmPrimitive> primitives;
    235 
    236             private ShowHistoryTask(Collection<HistoryOsmPrimitive> primitives) {
    237                 this.primitives = primitives;
    238             }
    239 
    240             @Override
    241             public void run() {
    242                 try {
    243                     for (HistoryOsmPrimitive p : primitives) {
    244                         final History h = HistoryDataSet.getInstance().getHistory(p.getPrimitiveId());
    245                         if (h == null) {
    246                             continue;
    247                         }
    248                         GuiHelper.runInEDT(() -> HistoryBrowserDialogManager.getInstance().show(h));
    249                     }
    250                 } catch (final JosmRuntimeException | IllegalArgumentException | IllegalStateException e) {
    251                     GuiHelper.runInEDT(() -> BugReportExceptionHandler.handleException(e));
    252                 }
    253             }
    254         }
    255 
    256227        ShowHistoryAction() {
    257228            putValue(NAME, tr("Show history"));
     
    261232        }
    262233
    263         protected List<HistoryOsmPrimitive> filterPrimitivesWithUnloadedHistory(Collection<HistoryOsmPrimitive> primitives) {
    264             return primitives.stream()
    265                     .filter(p -> HistoryDataSet.getInstance().getHistory(p.getPrimitiveId()) == null)
    266                     .collect(Collectors.toList());
    267         }
    268 
    269         public void showHistory(final Collection<HistoryOsmPrimitive> primitives) {
    270 
    271             List<HistoryOsmPrimitive> toLoad = filterPrimitivesWithUnloadedHistory(primitives);
    272             if (!toLoad.isEmpty()) {
    273                 HistoryLoadTask task = new HistoryLoadTask(ChangesetContentPanel.this);
    274                 for (HistoryOsmPrimitive p: toLoad) {
    275                     task.add(p);
    276                 }
    277                 MainApplication.worker.submit(task);
    278             }
    279 
    280             MainApplication.worker.submit(new ShowHistoryTask(primitives));
    281         }
    282234
    283235        protected final void updateEnabledState() {
     
    289241            Set<HistoryOsmPrimitive> selected = getSelectedPrimitives();
    290242            if (selected.isEmpty()) return;
    291             showHistory(selected);
     243            HistoryBrowserDialogManager.getInstance().showHistory(selected);
    292244        }
    293245
  • trunk/src/org/openstreetmap/josm/gui/history/ShowHistoryAction.java

    r16460 r16461  
    5252    static class DoubleClickAdapter extends MouseAdapter {
    5353        private final Function<MouseEvent, PrimitiveId> primitiveIdFunction;
    54         private final ShowHistoryAction showHistoryAction = new ShowHistoryAction();
    5554
    5655        DoubleClickAdapter(Function<MouseEvent, PrimitiveId> primitiveIdFunction) {
     
    6564            if (pid == null || pid.isNew())
    6665                return;
    67             showHistoryAction.setPrimitiveId(pid);
    68             showHistoryAction.run();
     66            HistoryBrowserDialogManager.getInstance().showHistory(Collections.singleton(pid));
    6967        }
    7068    }
Note: See TracChangeset for help on using the changeset viewer.