- Timestamp:
- 2016-08-23T22:07:06+02:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ValidateAction.java
r10601 r10880 169 169 } 170 170 tests = null; 171 if ( Main.pref.getBoolean(ValidatorPreference.PREF_USE_IGNORE, true)) {171 if (ValidatorPreference.PREF_USE_IGNORE.get()) { 172 172 getProgressMonitor().subTask(tr("Updating ignored errors ...")); 173 173 for (TestError error : errors) { -
trunk/src/org/openstreetmap/josm/actions/upload/ValidateUploadHook.java
r10448 r10880 61 61 test.visit(selection); 62 62 test.endTest(); 63 if (ValidatorPreference.PREF_OTHER.get() && 64 Main.pref.getBoolean(ValidatorPreference.PREF_OTHER_UPLOAD, false)) { 63 if (ValidatorPreference.PREF_OTHER.get() && ValidatorPreference.PREF_OTHER_UPLOAD.get()) { 65 64 errors.addAll(test.getErrors()); 66 65 } else { … … 83 82 return true; 84 83 85 if ( Main.pref.getBoolean(ValidatorPreference.PREF_USE_IGNORE, true)) {84 if (ValidatorPreference.PREF_USE_IGNORE.get()) { 86 85 int nume = 0; 87 86 for (TestError error : errors) { -
trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java
r10765 r10880 183 183 private static void loadIgnoredErrors() { 184 184 ignoredErrors.clear(); 185 if ( Main.pref.getBoolean(ValidatorPreference.PREF_USE_IGNORE, true)) {185 if (ValidatorPreference.PREF_USE_IGNORE.get()) { 186 186 Path path = Paths.get(getValidatorDir()).resolve("ignorederrors"); 187 187 if (Files.exists(path)) { … … 217 217 218 218 public static synchronized void initializeErrorLayer() { 219 if (! Main.pref.getBoolean(ValidatorPreference.PREF_LAYER, true))219 if (!ValidatorPreference.PREF_LAYER.get()) 220 220 return; 221 221 if (errorLayer == null) { -
trunk/src/org/openstreetmap/josm/data/validation/TestError.java
r10778 r10880 269 269 } 270 270 271 /** 272 * Set the tester that raised the error. 273 * @param tester te tester 274 */ 271 275 public void setTester(Test tester) { 272 276 this.tester = tester; -
trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
r10759 r10880 151 151 buttons.add(fixButton); 152 152 153 if ( Main.pref.getBoolean(ValidatorPreference.PREF_USE_IGNORE, true)) {153 if (ValidatorPreference.PREF_USE_IGNORE.get()) { 154 154 ignoreButton = new SideButton(new AbstractAction() { 155 155 { … … 193 193 } 194 194 super.setVisible(v); 195 Main.map.repaint();196 195 } 197 196 -
trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java
r10715 r10880 11 11 import java.util.EnumMap; 12 12 import java.util.Enumeration; 13 import java.util.HashMap;14 13 import java.util.HashSet; 15 14 import java.util.List; … … 18 17 import java.util.Set; 19 18 import java.util.function.Predicate; 19 import java.util.stream.Collectors; 20 20 21 21 import javax.swing.JTree; … … 36 36 import org.openstreetmap.josm.gui.util.GuiHelper; 37 37 import org.openstreetmap.josm.tools.Destroyable; 38 import org.openstreetmap.josm.tools. MultiMap;38 import org.openstreetmap.josm.tools.ListenerList; 39 39 40 40 /** … … 73 73 private transient Set<? extends OsmPrimitive> filter; 74 74 75 /** a counter to check if tree has been rebuild */ 76 private int updateCount; 75 private final ListenerList<Runnable> invalidationListeners = ListenerList.create(); 77 76 78 77 /** … … 135 134 } 136 135 super.setVisible(v); 136 invalidationListeners.fireEvent(Runnable::run); 137 137 } 138 138 … … 141 141 */ 142 142 public void buildTree() { 143 updateCount++;144 143 final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(); 145 144 … … 172 171 } 173 172 174 Map<Severity, MultiMap<String, TestError>> errorTree = new EnumMap<>(Severity.class); 175 Map<Severity, HashMap<String, MultiMap<String, TestError>>> errorTreeDeep = new EnumMap<>(Severity.class); 176 for (Severity s : Severity.values()) { 177 errorTree.put(s, new MultiMap<String, TestError>(20)); 178 errorTreeDeep.put(s, new HashMap<String, MultiMap<String, TestError>>()); 179 } 180 181 final Boolean other = ValidatorPreference.PREF_OTHER.get(); 182 for (TestError e : errors) { 183 if (e.isIgnored()) { 184 continue; 185 } 186 Severity s = e.getSeverity(); 187 if (!other && s == Severity.OTHER) { 188 continue; 189 } 190 String d = e.getDescription(); 191 String m = e.getMessage(); 192 if (filter != null) { 193 boolean found = false; 194 for (OsmPrimitive p : e.getPrimitives()) { 195 if (filter.contains(p)) { 196 found = true; 197 break; 198 } 199 } 200 if (!found) { 201 continue; 202 } 203 } 204 if (d != null) { 205 MultiMap<String, TestError> b = errorTreeDeep.get(s).get(m); 206 if (b == null) { 207 b = new MultiMap<>(20); 208 errorTreeDeep.get(s).put(m, b); 209 } 210 b.put(d, e); 211 } else { 212 errorTree.get(s).put(m, e); 213 } 214 } 173 Predicate<TestError> filterToUse = e -> !e.isIgnored(); 174 if (!ValidatorPreference.PREF_OTHER.get()) { 175 filterToUse = filterToUse.and(e -> e.getSeverity() != Severity.OTHER); 176 } 177 if (filter != null) { 178 filterToUse = filterToUse.and(e -> e.getPrimitives().stream().anyMatch(filter::contains)); 179 } 180 Map<Severity, Map<String, Map<String, List<TestError>>>> errorTreeDeep 181 = errors.stream().filter(filterToUse).collect( 182 Collectors.groupingBy(e -> e.getSeverity(), () -> new EnumMap<>(Severity.class), 183 Collectors.groupingBy(e -> e.getDescription() == null ? "" : e.getDescription(), 184 Collectors.groupingBy(e -> e.getMessage())))); 215 185 216 186 List<TreePath> expandedPaths = new ArrayList<>(); 217 for (Severity s : Severity.values()) { 218 MultiMap<String, TestError> severityErrors = errorTree.get(s); 219 Map<String, MultiMap<String, TestError>> severityErrorsDeep = errorTreeDeep.get(s); 220 if (severityErrors.isEmpty() && severityErrorsDeep.isEmpty()) { 221 continue; 222 } 223 187 errorTreeDeep.forEach((s, severityErrorsDeep) -> { 224 188 // Severity node 225 189 DefaultMutableTreeNode severityNode = new GroupTreeNode(s); … … 230 194 } 231 195 232 for (Entry<String, Set<TestError>> msgErrors : severityErrors.entrySet()) { 233 // Message node 234 Set<TestError> errs = msgErrors.getValue(); 235 String msg = tr("{0} ({1})", msgErrors.getKey(), errs.size()); 236 DefaultMutableTreeNode messageNode = new DefaultMutableTreeNode(msg); 237 severityNode.add(messageNode); 238 239 if (oldSelectedRows.contains(msgErrors.getKey())) { 240 expandedPaths.add(new TreePath(new Object[] {rootNode, severityNode, messageNode})); 241 } 242 243 for (TestError error : errs) { 244 // Error node 245 DefaultMutableTreeNode errorNode = new DefaultMutableTreeNode(error); 246 messageNode.add(errorNode); 247 } 248 } 249 for (Entry<String, MultiMap<String, TestError>> bag : severityErrorsDeep.entrySet()) { 196 Map<String, List<TestError>> severityErrors = severityErrorsDeep.get(""); 197 if (severityErrors != null) { 198 for (Entry<String, List<TestError>> msgErrors : severityErrors.entrySet()) { 199 // Message node 200 List<TestError> errs = msgErrors.getValue(); 201 String msg = tr("{0} ({1})", msgErrors.getKey(), errs.size()); 202 DefaultMutableTreeNode messageNode = new DefaultMutableTreeNode(msg); 203 severityNode.add(messageNode); 204 205 if (oldSelectedRows.contains(msgErrors.getKey())) { 206 expandedPaths.add(new TreePath(new Object[] {rootNode, severityNode, messageNode})); 207 } 208 209 errs.stream().map(DefaultMutableTreeNode::new).forEach(messageNode::add); 210 } 211 } 212 213 severityErrorsDeep.forEach((description, errorlist) -> { 214 if (description.isEmpty()) { 215 return; 216 } 250 217 // Group node 251 MultiMap<String, TestError> errorlist = bag.getValue(); 252 DefaultMutableTreeNode groupNode = null; 218 DefaultMutableTreeNode groupNode; 253 219 if (errorlist.size() > 1) { 254 groupNode = new GroupTreeNode( bag.getKey());220 groupNode = new GroupTreeNode(description); 255 221 severityNode.add(groupNode); 256 if (oldSelectedRows.contains( bag.getKey())) {222 if (oldSelectedRows.contains(description)) { 257 223 expandedPaths.add(new TreePath(new Object[] {rootNode, severityNode, groupNode})); 258 224 } 259 } 260 261 for (Entry<String, Set<TestError>> msgErrors : errorlist.entrySet()) { 225 } else { 226 groupNode = null; 227 } 228 229 errorlist.forEach((message, errs) -> { 262 230 // Message node 263 Set<TestError> errs = msgErrors.getValue();264 231 String msg; 265 232 if (groupNode != null) { 266 msg = tr("{0} ({1})", m sgErrors.getKey(), errs.size());233 msg = tr("{0} ({1})", message, errs.size()); 267 234 } else { 268 msg = tr("{0} - {1} ({2})", m sgErrors.getKey(), bag.getKey(), errs.size());235 msg = tr("{0} - {1} ({2})", message, description, errs.size()); 269 236 } 270 237 DefaultMutableTreeNode messageNode = new DefaultMutableTreeNode(msg); … … 275 242 } 276 243 277 if (oldSelectedRows.contains(m sgErrors.getKey())) {244 if (oldSelectedRows.contains(message)) { 278 245 if (groupNode != null) { 279 246 expandedPaths.add(new TreePath(new Object[] {rootNode, severityNode, groupNode, messageNode})); … … 283 250 } 284 251 285 for (TestError error : errs) { 286 // Error node 287 DefaultMutableTreeNode errorNode = new DefaultMutableTreeNode(error); 288 messageNode.add(errorNode); 289 } 290 } 291 } 292 } 252 errs.stream().map(DefaultMutableTreeNode::new).forEach(messageNode::add); 253 }); 254 }); 255 }); 293 256 294 257 valTreeModel.setRoot(rootNode); … … 296 259 this.expandPath(path); 297 260 } 261 262 invalidationListeners.fireEvent(Runnable::run); 263 } 264 265 /** 266 * Add a new invalidation listener 267 * @param listener The listener 268 */ 269 public void addInvalidationListener(Runnable listener) { 270 invalidationListeners.addListener(listener); 271 } 272 273 /** 274 * Remove an invalidation listener 275 * @param listener The listener 276 * @since 10880 277 */ 278 public void removeInvalidationListener(Runnable listener) { 279 invalidationListeners.removeListener(listener); 298 280 } 299 281 … … 426 408 } 427 409 428 /**429 * Returns a value to check if tree has been rebuild430 * @return the current counter431 */432 public int getUpdateCount() {433 return updateCount;434 }435 436 410 private void clearErrors() { 437 411 if (errors != null) { -
trunk/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java
r10507 r10880 41 41 */ 42 42 public class ValidatorLayer extends Layer implements LayerChangeListener { 43 44 private int updateCount = -1; 43 private final Runnable invalidator = this::invalidate; 45 44 46 45 /** … … 50 49 super(tr("Validation errors")); 51 50 Main.getLayerManager().addLayerChangeListener(this); 51 Main.map.validatorDialog.tree.addInvalidationListener(invalidator); 52 52 } 53 53 … … 68 68 @Override 69 69 public void paint(final Graphics2D g, final MapView mv, Bounds bounds) { 70 updateCount = Main.map.validatorDialog.tree.getUpdateCount();71 70 DefaultMutableTreeNode root = Main.map.validatorDialog.tree.getRoot(); 72 71 if (root == null || root.getChildCount() == 0) … … 124 123 125 124 @Override 126 public boolean isChanged() {127 return updateCount != Main.map.validatorDialog.tree.getUpdateCount();128 }129 130 @Override131 125 public void visitBoundingBox(BoundingXYVisitor v) { 132 126 // Do nothing … … 168 162 e.scheduleRemoval(Collections.singleton(this)); 169 163 } else if (e.getRemovedLayer() == this) { 170 Main.getLayerManager().removeLayerChangeListener(this);171 164 OsmValidator.errorLayer = null; 172 165 } … … 177 170 return LayerPositionStrategy.IN_FRONT; 178 171 } 172 173 @Override 174 public void destroy() { 175 Main.map.validatorDialog.tree.removeInvalidationListener(invalidator); 176 Main.getLayerManager().removeLayerChangeListener(this); 177 super.destroy(); 178 } 179 179 } -
trunk/src/org/openstreetmap/josm/gui/preferences/validator/ValidatorPreference.java
r8378 r10880 40 40 41 41 /** The preferences key for error layer */ 42 public static final String PREF_LAYER = PREFIX + ".layer";42 public static final BooleanProperty PREF_LAYER = new BooleanProperty(PREFIX + ".layer", true); 43 43 44 44 /** The preferences key for enabled tests */ … … 46 46 47 47 /** The preferences key for enabled tests */ 48 public static final String PREF_USE_IGNORE = PREFIX + ".ignore";48 public static final BooleanProperty PREF_USE_IGNORE = new BooleanProperty(PREFIX + ".ignore", true); 49 49 50 50 /** The preferences key for enabled tests before upload*/ … … 52 52 53 53 /** The preferences key for ignored severity other on upload */ 54 public static final String PREF_OTHER_UPLOAD = PREFIX + ".otherUpload";54 public static final BooleanProperty PREF_OTHER_UPLOAD = new BooleanProperty(PREFIX + ".otherUpload", false); 55 55 56 56 /** The preferences for ignored severity other */ -
trunk/src/org/openstreetmap/josm/gui/preferences/validator/ValidatorTestsPreference.java
r10611 r10880 58 58 testPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 59 59 60 prefUseIgnore = new JCheckBox(tr("Use ignore list."), Main.pref.getBoolean(ValidatorPreference.PREF_USE_IGNORE, true));60 prefUseIgnore = new JCheckBox(tr("Use ignore list."), ValidatorPreference.PREF_USE_IGNORE.get()); 61 61 prefUseIgnore.setToolTipText(tr("Use the ignore list to suppress warnings.")); 62 62 testPanel.add(prefUseIgnore, GBC.eol()); 63 63 64 prefUseLayer = new JCheckBox(tr("Use error layer."), Main.pref.getBoolean(ValidatorPreference.PREF_LAYER, true));64 prefUseLayer = new JCheckBox(tr("Use error layer."), ValidatorPreference.PREF_LAYER.get()); 65 65 prefUseLayer.setToolTipText(tr("Use the error layer to display problematic elements.")); 66 66 testPanel.add(prefUseLayer, GBC.eol()); … … 71 71 72 72 prefOtherUpload = new JCheckBox(tr("Show informational level on upload."), 73 Main.pref.getBoolean(ValidatorPreference.PREF_OTHER_UPLOAD, false));73 ValidatorPreference.PREF_OTHER_UPLOAD.get()); 74 74 prefOtherUpload.setToolTipText(tr("Show the informational tests in the upload check windows.")); 75 75 testPanel.add(prefOtherUpload, GBC.eol()); … … 117 117 Main.pref.putCollection(ValidatorPreference.PREF_SKIP_TESTS, tests); 118 118 Main.pref.putCollection(ValidatorPreference.PREF_SKIP_TESTS_BEFORE_UPLOAD, testsBeforeUpload); 119 Main.pref.put(ValidatorPreference.PREF_USE_IGNORE,prefUseIgnore.isSelected());119 ValidatorPreference.PREF_USE_IGNORE.put(prefUseIgnore.isSelected()); 120 120 ValidatorPreference.PREF_OTHER.put(prefOther.isSelected()); 121 Main.pref.put(ValidatorPreference.PREF_OTHER_UPLOAD,prefOtherUpload.isSelected());122 Main.pref.put(ValidatorPreference.PREF_LAYER,prefUseLayer.isSelected());121 ValidatorPreference.PREF_OTHER_UPLOAD.put(prefOtherUpload.isSelected()); 122 ValidatorPreference.PREF_LAYER.put(prefUseLayer.isSelected()); 123 123 return false; 124 124 } -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanelTest.java
r9811 r10880 44 44 new TestError(null, Severity.WARNING, "warn", 0, new Node(2))))); 45 45 assertNotNull(vtp); 46 assertEquals(1, vtp.getUpdateCount());47 46 assertEquals(2, vtp.getErrors().size()); 48 47 vtp.setVisible(true);
Note:
See TracChangeset
for help on using the changeset viewer.