Changeset 10502 in osm for applications/editors/josm/plugins/validator/src/org
- Timestamp:
- 2008-09-05T21:35:35+02:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ErrorTreePanel.java
r10490 r10502 1 1 package org.openstreetmap.josm.plugins.validator; 2 2 3 import java.util.*; 3 import java.util.ArrayList; 4 import java.util.Collections; 5 import java.util.Enumeration; 6 import java.util.HashMap; 7 import java.util.HashSet; 8 import java.util.List; 9 import java.util.Set; 10 import java.util.Map; 4 11 import java.util.Map.Entry; 5 12 … … 8 15 import javax.swing.JTree; 9 16 import javax.swing.ToolTipManager; 10 import javax.swing.tree.*; 17 import javax.swing.tree.DefaultMutableTreeNode; 18 import javax.swing.tree.DefaultTreeModel; 19 import javax.swing.tree.TreePath; 20 import javax.swing.tree.TreeSelectionModel; 11 21 12 22 import org.openstreetmap.josm.plugins.validator.util.Bag; … … 125 135 } 126 136 127 Map<Severity, Bag<String, TestError>> errorTree = new HashMap<Severity, Bag<String, TestError>>(); 128 Map<Severity, HashMap<String, Bag<String, TestError>>> errorTreeDeep = new HashMap<Severity, HashMap<String, Bag<String, TestError>>>(); 137 Map<Severity, Bag<String, TestError>> errorTree 138 = new HashMap<Severity, Bag<String, TestError>>(); 139 Map<Severity, HashMap<String, Bag<String, TestError>>> errorTreeDeep 140 = new HashMap<Severity, HashMap<String, Bag<String, TestError>>>(); 129 141 for(Severity s : Severity.values()) 130 142 { … … 135 147 for(TestError e : errors) 136 148 { 149 if(e.getIgnored()) 150 continue; 137 151 Severity s = e.getSeverity(); 138 152 String d = e.getDescription(); … … 176 190 177 191 if( oldSelectedRows.contains(msgErrors.getKey())) 178 expandedPaths.add( new TreePath( new Object[] {rootNode, severityNode, messageNode} ) ); 192 { 193 expandedPaths.add( new TreePath( new Object[] 194 {rootNode, severityNode, messageNode} ) ); 195 } 179 196 180 197 for (TestError error : errors) … … 189 206 // Group node 190 207 Bag <String, TestError> errorlist = bag.getValue(); 191 String nmsg = bag.getKey() + " (" + errorlist.size() + ")"; 192 DefaultMutableTreeNode groupNode = new DefaultMutableTreeNode(nmsg); 193 severityNode.add(groupNode); 194 195 if( oldSelectedRows.contains(bag.getKey())) 196 expandedPaths.add( new TreePath( new Object[] {rootNode, severityNode, groupNode} ) ); 208 DefaultMutableTreeNode groupNode = null; 209 if(errorlist.size() > 1) 210 { 211 String nmsg = bag.getKey() + " (" + errorlist.size() + ")"; 212 groupNode = new DefaultMutableTreeNode(nmsg); 213 severityNode.add(groupNode); 214 if( oldSelectedRows.contains(bag.getKey())) 215 { 216 expandedPaths.add( new TreePath( new Object[] 217 {rootNode, severityNode, groupNode} ) ); 218 } 219 } 197 220 198 221 for(Entry<String, List<TestError>> msgErrors : errorlist.entrySet()) … … 202 225 String msg = msgErrors.getKey() + " (" + errors.size() + ")"; 203 226 DefaultMutableTreeNode messageNode = new DefaultMutableTreeNode(msg); 204 groupNode.add(messageNode); 227 if(groupNode != null) 228 groupNode.add(messageNode); 229 else 230 severityNode.add(messageNode); 205 231 206 232 if( oldSelectedRows.contains(msgErrors.getKey())) 207 expandedPaths.add( new TreePath( new Object[] {rootNode, severityNode, groupNode, messageNode} ) ); 233 { 234 if(groupNode != null) 235 { 236 expandedPaths.add(new TreePath(new Object[] 237 {rootNode, severityNode, groupNode, messageNode})); 238 } 239 else 240 { 241 expandedPaths.add(new TreePath(new Object[] 242 {rootNode, severityNode, messageNode})); 243 } 244 } 208 245 209 246 for (TestError error : errors) -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java
r10122 r10502 4 4 5 5 import java.lang.reflect.InvocationTargetException; 6 import java.util.*; 6 import java.io.BufferedReader; 7 import java.io.FileNotFoundException; 8 import java.io.FileReader; 9 import java.io.FileWriter; 10 import java.io.IOException; 11 import java.io.PrintWriter; 12 import java.util.ArrayList; 13 import java.util.Collection; 14 import java.util.Iterator; 15 import java.util.LinkedList; 16 import java.util.List; 17 import java.util.HashMap; 18 import java.util.Map; 19 import java.util.TreeSet; 7 20 import java.util.regex.Matcher; 8 21 import java.util.regex.Pattern; … … 38 51 /** The list of errors per layer*/ 39 52 Map<Layer, List<TestError>> layerErrors = new HashMap<Layer, List<TestError>>(); 53 54 public Collection<String> ignoredErrors = new TreeSet<String>(); 40 55 41 56 /** … … 66 81 { 67 82 initializeTests( getTests() ); 83 loadIgnoredErrors(); 84 } 85 86 private void loadIgnoredErrors() { 87 ignoredErrors.clear(); 88 if(Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true)) 89 { 90 try { 91 final BufferedReader in = new BufferedReader(new FileReader(Util.getPluginDir() + "ignorederrors")); 92 for (String line = in.readLine(); line != null; line = in.readLine()) { 93 ignoredErrors.add(line); 94 } 95 } 96 catch (final FileNotFoundException e) {} 97 catch (final IOException e) { 98 e.printStackTrace(); 99 } 100 } 101 } 102 103 public void saveIgnoredErrors() { 104 try { 105 final PrintWriter out = new PrintWriter(new FileWriter(Util.getPluginDir() + "ignorederrors"), false); 106 for (String e : ignoredErrors) 107 out.println(e); 108 out.close(); 109 } catch (final IOException e) { 110 e.printStackTrace(); 111 } 68 112 } 69 113 … … 102 146 } 103 147 if( newFrame != null ) 104 hooks.add( 0, new ValidateUploadHook( ) );148 hooks.add( 0, new ValidateUploadHook(this) ); 105 149 } 106 150 … … 183 227 if( test.enabled ) 184 228 { 185 test.getClass().getMethod("initialize", new Class[] { OSMValidatorPlugin.class} ).invoke(null, new Object[] {this}); 229 test.getClass().getMethod("initialize", new Class[] 230 { OSMValidatorPlugin.class} ).invoke(null, new Object[] {this}); 186 231 } 187 232 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateAction.java
r10490 r10502 20 20 * This action iterates through all active tests and give them the data, so that 21 21 * each one can test it. 22 * 22 * 23 23 * @author frsantos 24 24 */ 25 public class ValidateAction extends JosmAction 25 public class ValidateAction extends JosmAction 26 26 { 27 27 private OSMValidatorPlugin plugin; 28 28 29 29 /** Serializable ID */ 30 30 private static final long serialVersionUID = -2304521273582574603L; 31 31 32 32 /** Last selection used to validate */ 33 33 private Collection<OsmPrimitive> lastSelection; 34 35 34 35 /** 36 36 * Constructor 37 37 */ 38 38 public ValidateAction(OSMValidatorPlugin plugin) { 39 super(tr("Validation"), "validator", tr("Performs the data validation"), KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK + KeyEvent.ALT_MASK, true); 39 super(tr("Validation"), "validator", tr("Performs the data validation"), 40 KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK + KeyEvent.ALT_MASK, true); 40 41 this.plugin = plugin; 41 42 } … … 45 46 doValidate(ev, true); 46 47 } 47 48 48 49 /** 49 50 * Does the validation. … … 52 53 * is selected) are validated. If it is false, last selected items are 53 54 * revalidated 54 * 55 * 55 56 * @param ev The event 56 57 * @param getSelectedItems If selected or last selected items must be validated … … 58 59 public void doValidate(@SuppressWarnings("unused") ActionEvent ev, boolean getSelectedItems) 59 60 { 60 61 62 61 if( plugin.validateAction == null || Main.map == null || !Main.map.isVisible() ) 62 return; 63 63 64 Collection<Test> tests = OSMValidatorPlugin.getEnabledTests(false); 64 65 if( tests.isEmpty() ) 65 66 return; 66 67 67 68 Collection<OsmPrimitive> selection; 68 69 if( getSelectedItems ) … … 109 110 for(String state : s) 110 111 { 111 if(state != null && plugin. validationDialog.ignoredErrors.contains(state))112 if(state != null && plugin.ignoredErrors.contains(state)) 112 113 { 113 114 error.setIgnored(true); -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateUploadHook.java
r10490 r10502 4 4 5 5 import java.awt.GridBagLayout; 6 import java.util.*; 6 import java.util.Collection; 7 import java.util.ArrayList; 8 import java.util.List; 7 9 8 import javax.swing.*; 10 import javax.swing.JOptionPane; 11 import javax.swing.JPanel; 12 import javax.swing.JScrollPane; 9 13 10 14 import org.openstreetmap.josm.Main; … … 19 23 * This action iterates through all active tests and give them the data, so that 20 24 * each one can test it. 21 * 25 * 22 26 * @author frsantos 23 27 */ … … 25 29 { 26 30 /** Serializable ID */ 27 31 private static final long serialVersionUID = -2304521273582574603L; 28 32 29 /** 30 * Validate the modified data before uploading 31 */ 32 public boolean checkUpload(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete) 33 { 34 Collection<Test> tests = OSMValidatorPlugin.getEnabledTests(true); 35 if( tests.isEmpty() ) 36 return true; 37 38 AgregatePrimitivesVisitor v = new AgregatePrimitivesVisitor(); 39 v.visit(add); 40 Collection<OsmPrimitive> selection = v.visit(update); 33 private OSMValidatorPlugin plugin; 41 34 42 List<TestError> errors = new ArrayList<TestError>(30); 43 for(Test test : tests) 44 { 45 test.setBeforeUpload(true); 46 test.setPartialSelection(true); 47 test.startTest(); 48 test.visit(selection); 49 test.endTest(); 50 errors.addAll( test.getErrors() ); 51 } 52 tests = null; 53 54 return displayErrorScreen(errors); 55 } 56 57 /** 58 * Displays a screen where the actions that would be taken are displayed and 59 * give the user the possibility to cancel the upload. 60 * @param errors The errors displayed in the screen 61 * @return <code>true</code>, if the upload should continue. <code>false</code> 62 * if the user requested cancel. 63 */ 64 private boolean displayErrorScreen(List<TestError> errors) 65 { 66 if( errors == null || errors.isEmpty() ) 67 { 68 return true; 69 } 35 public ValidateUploadHook(OSMValidatorPlugin plugin) 36 { 37 this.plugin = plugin; 38 } 70 39 71 JPanel p = new JPanel(new GridBagLayout()); 72 ErrorTreePanel errorPanel = new ErrorTreePanel(errors); 73 errorPanel.expandAll(); 74 p.add(new JScrollPane(errorPanel), GBC.eol()); 40 /** 41 * Validate the modified data before uploading 42 */ 43 public boolean checkUpload(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete) 44 { 45 Collection<Test> tests = OSMValidatorPlugin.getEnabledTests(true); 46 if( tests.isEmpty() ) 47 return true; 75 48 76 return JOptionPane.showConfirmDialog(Main.parent, p, tr("Data with errors. Upload anyway?"), 77 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION; 78 } 49 AgregatePrimitivesVisitor v = new AgregatePrimitivesVisitor(); 50 v.visit(add); 51 Collection<OsmPrimitive> selection = v.visit(update); 52 53 List<TestError> errors = new ArrayList<TestError>(30); 54 for(Test test : tests) 55 { 56 test.setBeforeUpload(true); 57 test.setPartialSelection(true); 58 test.startTest(); 59 test.visit(selection); 60 test.endTest(); 61 errors.addAll( test.getErrors() ); 62 } 63 tests = null; 64 if(errors == null || errors.isEmpty()) 65 return true; 66 67 if(Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true)) 68 { 69 int nume = 0; 70 for(TestError error : errors) 71 { 72 List<String> s = new ArrayList<String>(); 73 s.add(error.getIgnoreState()); 74 s.add(error.getIgnoreGroup()); 75 s.add(error.getIgnoreSubGroup()); 76 for(String state : s) 77 { 78 if(state != null && plugin.ignoredErrors.contains(state)) 79 { 80 error.setIgnored(true); 81 } 82 } 83 if(!error.getIgnored()) 84 ++nume; 85 } 86 if(nume == 0) 87 return true; 88 } 89 return displayErrorScreen(errors); 90 } 91 92 /** 93 * Displays a screen where the actions that would be taken are displayed and 94 * give the user the possibility to cancel the upload. 95 * @param errors The errors displayed in the screen 96 * @return <code>true</code>, if the upload should continue. <code>false</code> 97 * if the user requested cancel. 98 */ 99 private boolean displayErrorScreen(List<TestError> errors) 100 { 101 JPanel p = new JPanel(new GridBagLayout()); 102 ErrorTreePanel errorPanel = new ErrorTreePanel(errors); 103 errorPanel.expandAll(); 104 p.add(new JScrollPane(errorPanel), GBC.eol()); 105 106 int res = JOptionPane.showConfirmDialog(Main.parent, p, 107 tr("Data with errors. Upload anyway?"), JOptionPane.YES_NO_OPTION); 108 if(res == JOptionPane.NO_OPTION) 109 { 110 plugin.validationDialog.tree.setErrors(errors); 111 plugin.validationDialog.setVisible(true); 112 Main.ds.fireSelectionChanged(Main.ds.getSelected()); 113 } 114 return res == JOptionPane.YES_OPTION; 115 } 79 116 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidatorDialog.java
r10490 r10502 6 6 import java.awt.BorderLayout; 7 7 import java.awt.GridLayout; 8 import java.awt.event. *;9 import java. io.BufferedReader;10 import java. io.FileNotFoundException;11 import java. io.FileReader;12 import java. io.FileWriter;13 import java. io.IOException;14 import java. io.PrintWriter;15 import java.util. *;8 import java.awt.event.ActionEvent; 9 import java.awt.event.ActionListener; 10 import java.awt.event.KeyEvent; 11 import java.awt.event.MouseEvent; 12 import java.awt.event.MouseAdapter; 13 import java.util.Collection; 14 import java.util.Enumeration; 15 import java.util.HashSet; 16 16 import java.util.Map.Entry; 17 18 import javax.swing.*; 17 import java.util.Set; 18 19 import javax.swing.JPanel; 20 import javax.swing.JOptionPane; 21 import javax.swing.JScrollPane; 19 22 import javax.swing.event.TreeSelectionEvent; 20 23 import javax.swing.event.TreeSelectionListener; 21 import javax.swing.tree.*; 24 import javax.swing.tree.DefaultMutableTreeNode; 25 import javax.swing.tree.TreePath; 22 26 23 27 import org.openstreetmap.josm.Main; … … 49 53 protected ErrorTreePanel tree; 50 54 51 public Collection<String> ignoredErrors = new TreeSet<String>();52 53 55 private SideButton fixButton; /** The fix button */ 54 56 private SideButton ignoreButton; /** The ignore button */ … … 94 96 } 95 97 add(buttonPanel, BorderLayout.SOUTH); 96 loadIgnoredErrors();97 }98 99 private void loadIgnoredErrors() {100 ignoredErrors.clear();101 if(Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true))102 {103 try {104 final BufferedReader in = new BufferedReader(new FileReader(Util.getPluginDir() + "ignorederrors"));105 for (String line = in.readLine(); line != null; line = in.readLine()) {106 ignoredErrors.add(line);107 }108 }109 catch (final FileNotFoundException e) {}110 catch (final IOException e) {111 e.printStackTrace();112 }113 }114 }115 116 private void saveIgnoredErrors() {117 try {118 final PrintWriter out = new PrintWriter(new FileWriter(Util.getPluginDir() + "ignorederrors"), false);119 for (String e : ignoredErrors)120 out.println(e);121 out.close();122 } catch (final IOException e) {123 e.printStackTrace();124 }125 98 } 126 99 … … 235 208 } 236 209 for(String s : state) 237 ignoredErrors.add(s);210 plugin.ignoredErrors.add(s); 238 211 continue; 239 212 } … … 256 229 String state = error.getIgnoreState(); 257 230 if(state != null) 258 ignoredErrors.add(state);231 plugin.ignoredErrors.add(state); 259 232 changed = true; 260 233 error.setIgnored(true); … … 265 238 { 266 239 tree.resetErrors(); 267 saveIgnoredErrors();240 plugin.saveIgnoredErrors(); 268 241 Main.map.repaint(); 269 242 } 270 243 } 271 244 272 273 274 275 276 private void setSelectedItems() 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 245 /** 246 * Sets the selection of the map to the current selected items. 247 */ 248 @SuppressWarnings("unchecked") 249 private void setSelectedItems() 250 { 251 if( tree == null ) 252 return; 253 254 Collection<OsmPrimitive> sel = new HashSet<OsmPrimitive>(40); 255 256 TreePath[] selectedPaths = tree.getSelectionPaths(); 257 if( selectedPaths == null) 258 return; 259 260 for( TreePath path : selectedPaths) 261 { 262 DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); 263 Enumeration<DefaultMutableTreeNode> children = node.breadthFirstEnumeration(); 264 while( children.hasMoreElements() ) 265 { 266 DefaultMutableTreeNode childNode = children.nextElement(); 267 Object nodeInfo = childNode.getUserObject(); 268 if( nodeInfo instanceof TestError) 269 { 270 TestError error = (TestError)nodeInfo; 271 sel.addAll( error.getPrimitives() ); 272 } 273 } 274 } 275 276 Main.ds.setSelected(sel); 277 } 305 278 306 279 public void actionPerformed(ActionEvent e) … … 317 290 } 318 291 319 320 321 322 323 324 325 292 /** 293 * Checks for fixes in selected element and, if needed, adds to the sel parameter all selected elements 294 * @param sel The collection where to add all selected elements 295 * @param addSelected if true, add all selected elements to collection 296 * @return whether the selected elements has any fix 297 */ 298 @SuppressWarnings("unchecked") 326 299 private boolean setSelection(Collection<OsmPrimitive> sel, boolean addSelected) 327 300 { 328 301 boolean hasFixes = false; 329 302 330 331 332 333 334 335 336 337 338 339 340 341 342 343 } 344 303 DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); 304 if( lastSelectedNode != null && !lastSelectedNode.equals(node) ) 305 { 306 Enumeration<DefaultMutableTreeNode> children = lastSelectedNode.breadthFirstEnumeration(); 307 while( children.hasMoreElements() ) 308 { 309 DefaultMutableTreeNode childNode = children.nextElement(); 310 Object nodeInfo = childNode.getUserObject(); 311 if( nodeInfo instanceof TestError) 312 { 313 TestError error = (TestError)nodeInfo; 314 error.setSelected(false); 315 } 316 } 317 } 345 318 346 319 lastSelectedNode = node; … … 368 341 if(ignoreButton != null) 369 342 ignoreButton.setEnabled(true); 370 343 371 344 return hasFixes; 372 345 } … … 375 348 * Watches for clicks. 376 349 */ 377 public class ClickWatch extends MouseAdapter 350 public class ClickWatch extends MouseAdapter 378 351 { 379 352 @Override … … 401 374 * Watches for tree selection. 402 375 */ 403 public class SelectionWatch implements TreeSelectionListener 376 public class SelectionWatch implements TreeSelectionListener 404 377 { 405 378 @SuppressWarnings("unchecked")
Note:
See TracChangeset
for help on using the changeset viewer.