Changeset 12667 in josm for trunk/src/org


Ignore:
Timestamp:
2017-08-26T21:28:55+02:00 (7 years ago)
Author:
Don-vip
Message:

see #14704 - allow to export validator errors ("Save as" in validator layer contextual menu). Same format than Osmose

Location:
trunk/src/org/openstreetmap/josm
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java

    r12636 r12667  
    105105                org.openstreetmap.josm.io.GeoJSONExporter.class,
    106106                org.openstreetmap.josm.io.WMSLayerExporter.class,
    107                 org.openstreetmap.josm.io.NoteExporter.class
     107                org.openstreetmap.josm.io.NoteExporter.class,
     108                org.openstreetmap.josm.io.ValidatorErrorExporter.class
    108109        );
    109110
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r12649 r12667  
    1717import java.util.Collection;
    1818import java.util.Collections;
     19import java.util.EnumMap;
    1920import java.util.HashMap;
     21import java.util.List;
    2022import java.util.Map;
    2123import java.util.SortedMap;
    2224import java.util.TreeMap;
    2325import java.util.TreeSet;
     26import java.util.function.Predicate;
     27import java.util.stream.Collectors;
    2428
    2529import javax.swing.JOptionPane;
     
    6266import org.openstreetmap.josm.gui.layer.ValidatorLayer;
    6367import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;
     68import org.openstreetmap.josm.tools.AlphanumComparator;
    6469import org.openstreetmap.josm.tools.Logging;
    6570import org.openstreetmap.josm.tools.Utils;
     
    389394    }
    390395
     396    /**
     397     * Groups the given collection of errors by severity, then message, then description.
     398     * @param errors list of errors to group
     399     * @param filterToUse optional filter
     400     * @return collection of errors grouped by severity, then message, then description
     401     * @since 12667
     402     */
     403    public static Map<Severity, Map<String, Map<String, List<TestError>>>> getErrorsBySeverityMessageDescription(
     404            Collection<TestError> errors, Predicate<? super TestError> filterToUse) {
     405        return errors.stream().filter(filterToUse).collect(
     406                Collectors.groupingBy(TestError::getSeverity, () -> new EnumMap<>(Severity.class),
     407                        Collectors.groupingBy(TestError::getMessage, () -> new TreeMap<>(AlphanumComparator.getInstance()),
     408                                Collectors.groupingBy(e -> e.getDescription() == null ? "" : e.getDescription(),
     409                                        () -> new TreeMap<>(AlphanumComparator.getInstance()),
     410                                        Collectors.toList()
     411                                ))));
     412    }
    391413}
  • trunk/src/org/openstreetmap/josm/data/validation/Severity.java

    r12620 r12667  
    1414    // CHECKSTYLE.OFF: SingleSpaceSeparator
    1515    /** Error messages */
    16     ERROR(tr("Errors"), /* ICON(data/) */"error",       new ColorProperty(marktr("validation error"), Color.RED).get()),
     16    ERROR(1, tr("Errors"), /* ICON(data/) */"error",       new ColorProperty(marktr("validation error"), Color.RED).get()),
    1717    /** Warning messages */
    18     WARNING(tr("Warnings"), /* ICON(data/) */"warning", new ColorProperty(marktr("validation warning"), Color.YELLOW).get()),
     18    WARNING(2, tr("Warnings"), /* ICON(data/) */"warning", new ColorProperty(marktr("validation warning"), Color.YELLOW).get()),
    1919    /** Other messages */
    20     OTHER(tr("Other"), /* ICON(data/) */"other",        new ColorProperty(marktr("validation other"), Color.CYAN).get());
     20    OTHER(3, tr("Other"), /* ICON(data/) */"other",        new ColorProperty(marktr("validation other"), Color.CYAN).get());
    2121    // CHECKSTYLE.ON: SingleSpaceSeparator
     22
     23    /** Numeric ordering of the severities, 1 being major, 3 being minor */
     24    private final int level;
    2225
    2326    /** Description of the severity code */
     
    3336     * Constructor
    3437     *
     38     * @param level Numeric ordering, 1 being major, 3 being minor
    3539     * @param message Description
    3640     * @param icon Associated icon
    3741     * @param color The color of this severity
    3842     */
    39     Severity(String message, String icon, Color color) {
     43    Severity(int level, String message, String icon, Color color) {
     44        this.level = level;
    4045        this.message = message;
    4146        this.icon = icon;
     
    7277        return color;
    7378    }
     79
     80    /**
     81     * Gets the severity level, 1 being major, 3 being minor
     82     * @return The severity level
     83     * @since 12667
     84     */
     85    public int getLevel() {
     86        return level;
     87    }
    7488}
  • trunk/src/org/openstreetmap/josm/data/validation/Test.java

    r12656 r12667  
    3939 * @author frsantos
    4040 */
    41 public class Test extends AbstractVisitor {
     41public class Test extends AbstractVisitor implements Comparable<Test> {
    4242
    4343    protected static final Predicate<OsmPrimitive> IN_DOWNLOADED_AREA = new NotOutsideDataSourceArea();
     
    359359               Objects.equals(description, test.description);
    360360    }
     361
     362    @Override
     363    public int compareTo(Test t) {
     364        return name.compareTo(t.name);
     365    }
    361366}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java

    r12649 r12667  
    99import java.util.Collection;
    1010import java.util.Collections;
    11 import java.util.EnumMap;
    1211import java.util.Enumeration;
    1312import java.util.HashSet;
     
    1514import java.util.Map;
    1615import java.util.Set;
    17 import java.util.TreeMap;
    1816import java.util.function.Predicate;
    19 import java.util.stream.Collectors;
    2017
    2118import javax.swing.JTree;
     
    4037import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
    4138import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;
     39import org.openstreetmap.josm.data.validation.OsmValidator;
    4240import org.openstreetmap.josm.data.validation.Severity;
    4341import org.openstreetmap.josm.data.validation.TestError;
     
    4543import org.openstreetmap.josm.gui.MainApplication;
    4644import org.openstreetmap.josm.gui.util.GuiHelper;
    47 import org.openstreetmap.josm.tools.AlphanumComparator;
    4845import org.openstreetmap.josm.tools.Destroyable;
    4946import org.openstreetmap.josm.tools.ListenerList;
     
    191188        }
    192189        Map<Severity, Map<String, Map<String, List<TestError>>>> errorsBySeverityMessageDescription
    193             = errors.stream().filter(filterToUse).collect(
    194                     Collectors.groupingBy(TestError::getSeverity, () -> new EnumMap<>(Severity.class),
    195                             Collectors.groupingBy(TestError::getMessage, () -> new TreeMap<>(AlphanumComparator.getInstance()),
    196                                     Collectors.groupingBy(e -> e.getDescription() == null ? "" : e.getDescription(),
    197                                             () -> new TreeMap<>(AlphanumComparator.getInstance()),
    198                                             Collectors.toList()
    199                                     ))));
     190            = OsmValidator.getErrorsBySeverityMessageDescription(errors, filterToUse);
    200191
    201192        final List<TreePath> expandedPaths = new ArrayList<>();
  • trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java

    r12630 r12667  
    275275    @Override
    276276    public File createAndOpenSaveFileChooser() {
    277         return SaveActionBase.createAndOpenSaveFileChooser(tr("Save GPX file"), NoteExporter.FILE_FILTER);
     277        return SaveActionBase.createAndOpenSaveFileChooser(tr("Save Note file"), NoteExporter.FILE_FILTER);
    278278    }
    279279
  • trunk/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java

    r12636 r12667  
    55
    66import java.awt.Graphics2D;
     7import java.io.File;
    78import java.util.Collections;
    89import java.util.Enumeration;
     
    1516
    1617import org.openstreetmap.josm.actions.RenameLayerAction;
     18import org.openstreetmap.josm.actions.SaveActionBase;
    1719import org.openstreetmap.josm.data.Bounds;
    1820import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     
    2931import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
    3032import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
     33import org.openstreetmap.josm.io.ValidatorErrorExporter;
    3134import org.openstreetmap.josm.tools.ImageProvider;
    3235import org.openstreetmap.josm.tools.MultiMap;
     
    140143                new RenameLayerAction(null, this),
    141144                SeparatorLayerAction.INSTANCE,
    142                 new LayerListPopup.InfoAction(this) };
     145                new LayerListPopup.InfoAction(this),
     146                new LayerSaveAsAction(this)
     147                };
     148    }
     149
     150    @Override
     151    public File createAndOpenSaveFileChooser() {
     152        return SaveActionBase.createAndOpenSaveFileChooser(tr("Save Validation errors file"), ValidatorErrorExporter.FILE_FILTER);
    143153    }
    144154
Note: See TracChangeset for help on using the changeset viewer.