Changeset 4408 in josm for trunk/src/org/openstreetmap/josm/gui/history
- Timestamp:
- 2011-09-08T00:08:02+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java
r3083 r4408 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.history; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.awt.Dimension; 5 7 import java.awt.Point; 6 8 import java.util.ArrayList; 9 import java.util.Collection; 7 10 import java.util.HashMap; 8 11 import java.util.Map; 12 import javax.swing.JOptionPane; 13 import javax.swing.SwingUtilities; 9 14 10 15 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 17 import org.openstreetmap.josm.data.osm.history.History; 18 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; 12 19 import org.openstreetmap.josm.gui.MapView; 13 20 import org.openstreetmap.josm.gui.layer.Layer; 21 import org.openstreetmap.josm.tools.BugReportExceptionHandler; 22 import org.openstreetmap.josm.tools.Predicate; 23 import org.openstreetmap.josm.tools.Utils; 14 24 import org.openstreetmap.josm.tools.WindowGeometry; 15 25 … … 123 133 } 124 134 } 135 136 public void showHistory(final Collection<OsmPrimitive> primitives) { 137 final Collection<OsmPrimitive> notNewPrimitives = Utils.filter(primitives, notNewPredicate); 138 if (notNewPrimitives.isEmpty()) { 139 JOptionPane.showMessageDialog( 140 Main.parent, 141 tr("Please select at least one already uploaded node, way, or relation."), 142 tr("Warning"), 143 JOptionPane.WARNING_MESSAGE); 144 return; 145 } 146 Collection<OsmPrimitive> toLoad = Utils.filter(primitives, unloadedHistoryPredicate); 147 if (!toLoad.isEmpty()) { 148 HistoryLoadTask task = new HistoryLoadTask(); 149 task.add(notNewPrimitives); 150 Main.worker.submit(task); 151 } 152 153 Runnable r = new Runnable() { 154 155 @Override 156 public void run() { 157 try { 158 for (OsmPrimitive p : notNewPrimitives) { 159 History h = HistoryDataSet.getInstance().getHistory(p.getPrimitiveId()); 160 if (h == null) { 161 continue; 162 } 163 show(h); 164 } 165 } catch (final Exception e) { 166 SwingUtilities.invokeLater(new Runnable() { 167 168 @Override 169 public void run() { 170 BugReportExceptionHandler.handleException(e); 171 } 172 }); 173 } 174 175 } 176 }; 177 Main.worker.submit(r); 178 } 179 180 private final Predicate<OsmPrimitive> unloadedHistoryPredicate = new Predicate<OsmPrimitive>() { 181 182 HistoryDataSet hds = HistoryDataSet.getInstance(); 183 184 @Override 185 public boolean evaluate(OsmPrimitive p) { 186 if (hds.getHistory(p.getPrimitiveId()) == null) { 187 // reload if the history is not in the cache yet 188 return true; 189 } else if (!p.isNew() && hds.getHistory(p.getPrimitiveId()).getByVersion(p.getUniqueId()) == null) { 190 // reload if the history object of the selected object is not in the cache yet 191 return true; 192 } else { 193 return false; 194 } 195 } 196 }; 197 198 private final Predicate<OsmPrimitive> notNewPredicate = new Predicate<OsmPrimitive>() { 199 200 @Override 201 public boolean evaluate(OsmPrimitive p) { 202 return !p.isNew(); 203 } 204 }; 205 125 206 }
Note:
See TracChangeset
for help on using the changeset viewer.