Ticket #20729: josm-validation-with-filters.patch

File josm-validation-with-filters.patch, 11.7 KB (added by ljdelight, 4 years ago)
  • TabularUnified src/org/openstreetmap/josm/actions/ValidateAction.java

    diff --git src/org/openstreetmap/josm/actions/ValidateAction.java src/org/openstreetmap/josm/actions/ValidateAction.java
    index 300097a5f..158b166d0 100644
    package org.openstreetmap.josm.actions;  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.GridBagLayout;
    67import java.awt.event.ActionEvent;
    78import java.awt.event.KeyEvent;
    89import java.util.Collection;
    910import java.util.Optional;
    1011
     12import javax.swing.ButtonGroup;
     13import javax.swing.JLabel;
     14import javax.swing.JOptionPane;
     15import javax.swing.JPanel;
     16import javax.swing.JRadioButton;
     17
    1118import org.openstreetmap.josm.data.osm.OsmPrimitive;
     19import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;
    1220import org.openstreetmap.josm.data.validation.OsmValidator;
    1321import org.openstreetmap.josm.data.validation.Test;
    1422import org.openstreetmap.josm.data.validation.ValidationTask;
    1523import org.openstreetmap.josm.data.validation.util.AggregatePrimitivesVisitor;
     24import org.openstreetmap.josm.gui.ExtendedDialog;
    1625import org.openstreetmap.josm.gui.MainApplication;
    1726import org.openstreetmap.josm.gui.MapFrame;
     27import org.openstreetmap.josm.gui.autofilter.AutoFilterManager;
     28import org.openstreetmap.josm.gui.util.GuiHelper;
     29import org.openstreetmap.josm.tools.GBC;
     30import org.openstreetmap.josm.tools.Logging;
    1831import org.openstreetmap.josm.tools.Shortcut;
    1932
    2033/**
    public class ValidateAction extends JosmAction {  
    4154
    4255    @Override
    4356    public void actionPerformed(ActionEvent ev) {
     57        // Warn user if validating while filters are active and see if they wish to
     58        // continue, as OSM primitives are excluded from validation due to the
     59        // filtering (which could possibly lead to a false sense of confidence)
     60        boolean filtersActive = AutoFilterManager.getInstance().getCurrentAutoFilter() != null ||
     61            (MainApplication.getMap() != null &&
     62             MainApplication.getMap().filterDialog != null &&
     63             MainApplication.getMap().filterDialog.getFilterModel().hasDisabledOrHiddenPrimitives());
     64        if (filtersActive && "fail".equals(ValidatorPrefHelper.PREF_VALIDATE_WITH_FILTERS_ENABLED_ACTION.get())) {
     65            // To avoid any confusion, if user has already indicated they do not want to validate
     66            // when filters are active, then let them know that validation was not performed
     67            // due to active filters
     68            GuiHelper.runInEDT(() -> JOptionPane.showMessageDialog(
     69                    MainApplication.getMainFrame(),
     70                    tr("Validation not performed due to filters being active. Please disable filters."),
     71                    tr("Error"),
     72                    JOptionPane.ERROR_MESSAGE
     73            ));
     74            return;
     75        }
     76
     77        if (filtersActive && "ask".equals(ValidatorPrefHelper.PREF_VALIDATE_WITH_FILTERS_ENABLED_ACTION.get())) {
     78            JPanel p = new JPanel(new GridBagLayout());
     79            p.add(new JLabel("<html><body style=\"width: 375px;\">" +
     80                    tr("You are validating while filters are active, this could: ") + "<br/>" +
     81                    "<ul>" +
     82                    "<li>" + tr("Potentially exclude objects from validation.") + "</li>" +
     83                    "<li>" + tr("Make it harder to see validation objects if they are hidden by a filter.") + "</li>" +
     84                    "</ul><br/>" +
     85                    tr("Do you want to continue?") +
     86                    "</body></html>"), GBC.eol());
     87
     88            JRadioButton validateWithFiltersAsk = new JRadioButton(tr("Show this dialog again the next time"));
     89            validateWithFiltersAsk.setActionCommand("ask");
     90            JRadioButton validateWithFiltersContinue = new JRadioButton(tr("Do not show this again (remembers choice)"));
     91            validateWithFiltersContinue.setActionCommand("continue");
     92            JRadioButton validateWithFiltersFail = new JRadioButton(
     93                    tr("Skip validation and show an error message the next time (remembers choice)"));
     94            validateWithFiltersFail.setActionCommand("fail");
     95
     96            switch(ValidatorPrefHelper.PREF_VALIDATE_WITH_FILTERS_ENABLED_ACTION.get()) {
     97                case "ask":
     98                    validateWithFiltersAsk.setSelected(true);
     99                    break;
     100                case "continue":
     101                    validateWithFiltersContinue.setSelected(true);
     102                    break;
     103                case "fail":
     104                    validateWithFiltersFail.setSelected(true);
     105                    break;
     106            }
     107
     108            ButtonGroup validateWithFiltersGroup = new ButtonGroup();
     109            validateWithFiltersGroup.add(validateWithFiltersAsk);
     110            validateWithFiltersGroup.add(validateWithFiltersContinue);
     111            validateWithFiltersGroup.add(validateWithFiltersFail);
     112
     113            p.add(validateWithFiltersAsk, GBC.eol().insets(30, 10, 0, 0));
     114            p.add(validateWithFiltersContinue, GBC.eol().insets(30, 0, 0, 0));
     115            p.add(validateWithFiltersFail, GBC.eol().insets(30, 0, 0, 10));
     116
     117            ExtendedDialog ed = new ExtendedDialog(MainApplication.getMainFrame(),
     118                    tr("Validation with active filters"),
     119                    tr("Continue"),
     120                    tr("Cancel"))
     121                    .setContent(p)
     122                    .configureContextsensitiveHelp("Dialog/Validator", true);
     123
     124            ed.setButtonIcons("ok", "cancel");
     125
     126            int result = ed.showDialog().getValue();
     127
     128            if (result != 1) {
     129                Logging.debug("Dialog result indicates the user does not want to continue with validation");
     130                return;
     131            }
     132
     133            // Update the persistent preference based on the user's selection
     134            ValidatorPrefHelper.PREF_VALIDATE_WITH_FILTERS_ENABLED_ACTION.put(validateWithFiltersGroup.getSelection().getActionCommand());
     135
     136            // Return (skip validation) if the user wants to skip validation and show the error dialog next time
     137            if ("fail".equals(validateWithFiltersGroup.getSelection().getActionCommand())) {
     138                return;
     139            }
     140        }
     141
    44142        doValidate(true);
    45143    }
    46144
  • TabularUnified src/org/openstreetmap/josm/data/preferences/sources/ValidatorPrefHelper.java

    diff --git src/org/openstreetmap/josm/data/preferences/sources/ValidatorPrefHelper.java src/org/openstreetmap/josm/data/preferences/sources/ValidatorPrefHelper.java
    index a5fe3e30e..455c7f452 100644
    import java.util.List;  
    99import java.util.Map;
    1010
    1111import org.openstreetmap.josm.data.preferences.BooleanProperty;
     12import org.openstreetmap.josm.data.preferences.StringProperty;
    1213import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
    1314import org.openstreetmap.josm.tools.ImageProvider;
    1415
    public class ValidatorPrefHelper extends SourcePrefHelper {  
    5657     */
    5758    public static final String PREF_FILTER_BY_SELECTION = PREFIX + ".selectionFilter";
    5859
     60    /**
     61     * The preferences for showing a warning if validation action is performed with filters enabled
     62     * @since xxx
     63     * */
     64    public static final StringProperty PREF_VALIDATE_WITH_FILTERS_ENABLED_ACTION =
     65            new StringProperty(PREFIX + ".validate_with_filters_action", "ask");
     66
    5967    /**
    6068     * Constructs a new {@code PresetPrefHelper}.
    6169     */
  • TabularUnified src/org/openstreetmap/josm/gui/dialogs/FilterTableModel.java

    diff --git src/org/openstreetmap/josm/gui/dialogs/FilterTableModel.java src/org/openstreetmap/josm/gui/dialogs/FilterTableModel.java
    index 07c198f72..a555835e2 100644
    public class FilterTableModel extends AbstractTableModel implements SortableTabl  
    311311        return model.getFilters();
    312312    }
    313313
     314    /**
     315     * Determines if at least one OSM primitive is disabled or hidden due to filtering.
     316     * @return {@code true} if at least one primitive is disabled or hidden
     317     * @since xxx
     318     */
     319    public boolean hasDisabledOrHiddenPrimitives() {
     320        return model.getDisabledAndHiddenCount() > 0 || model.getDisabledCount() > 0;
     321    }
     322
    314323    @Override
    315324    public void sort() {
    316325        model.sort();
  • TabularUnified src/org/openstreetmap/josm/gui/preferences/validator/ValidatorTestsPreference.java

    diff --git src/org/openstreetmap/josm/gui/preferences/validator/ValidatorTestsPreference.java src/org/openstreetmap/josm/gui/preferences/validator/ValidatorTestsPreference.java
    index a280ae8ec..407e99a09 100644
    import java.util.LinkedList;  
    1111import java.util.List;
    1212
    1313import javax.swing.BorderFactory;
     14import javax.swing.ButtonGroup;
    1415import javax.swing.JCheckBox;
    1516import javax.swing.JLabel;
    1617import javax.swing.JPanel;
     18import javax.swing.JRadioButton;
    1719
    1820import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;
    1921import org.openstreetmap.josm.data.validation.OsmValidator;
    public class ValidatorTestsPreference implements SubPreferenceSetting {  
    4951    private JCheckBox prefUseLayer;
    5052    private JCheckBox prefOtherUpload;
    5153    private JCheckBox prefOther;
     54    private ButtonGroup validateWithFiltersGroup;
    5255
    5356    /** The list of all tests */
    5457    private Collection<Test> allTests;
    public class ValidatorTestsPreference implements SubPreferenceSetting {  
    9295        gui.getValidatorPreference().addSubTab(this, tr("Tests"),
    9396                GuiHelper.embedInVerticalScrollPane(testPanel),
    9497                tr("Choose tests to enable"));
     98
     99        JRadioButton validateWithFiltersAsk = new JRadioButton(tr("Ask to continue with validation"));
     100        validateWithFiltersAsk.setActionCommand("ask");
     101        JRadioButton validateWithFiltersContinue = new JRadioButton(tr("Continue with validation"));
     102        validateWithFiltersContinue.setActionCommand("continue");
     103        JRadioButton validateWithFiltersFail = new JRadioButton(tr("Show an error message"));
     104        validateWithFiltersFail.setActionCommand("fail");
     105
     106        switch(ValidatorPrefHelper.PREF_VALIDATE_WITH_FILTERS_ENABLED_ACTION.get()) {
     107            case "ask":
     108                validateWithFiltersAsk.setSelected(true);
     109                break;
     110            case "continue":
     111                validateWithFiltersContinue.setSelected(true);
     112                break;
     113            case "fail":
     114                validateWithFiltersFail.setSelected(true);
     115                break;
     116        }
     117
     118        validateWithFiltersGroup = new ButtonGroup();
     119        validateWithFiltersGroup.add(validateWithFiltersAsk);
     120        validateWithFiltersGroup.add(validateWithFiltersContinue);
     121        validateWithFiltersGroup.add(validateWithFiltersFail);
     122
     123        JLabel validateWithFiltersLabel = new JLabel(tr("When validation is performed with filters enabled:"));
     124        testPanel.add(validateWithFiltersLabel, GBC.eol());
     125        testPanel.add(validateWithFiltersAsk, GBC.eol().insets(40, 0, 0, 0));
     126        testPanel.add(validateWithFiltersContinue, GBC.eol().insets(40, 0, 0, 0));
     127        testPanel.add(validateWithFiltersFail, GBC.eol().insets(40, 0, 0, 0));
    95128    }
    96129
    97130    @Override
    public class ValidatorTestsPreference implements SubPreferenceSetting {  
    121154        ValidatorPrefHelper.PREF_OTHER.put(prefOther.isSelected());
    122155        ValidatorPrefHelper.PREF_OTHER_UPLOAD.put(prefOtherUpload.isSelected());
    123156        ValidatorPrefHelper.PREF_LAYER.put(prefUseLayer.isSelected());
     157        ValidatorPrefHelper.PREF_VALIDATE_WITH_FILTERS_ENABLED_ACTION.put(validateWithFiltersGroup.getSelection().getActionCommand());
    124158        return false;
    125159    }
    126160