Ticket #20729: josm-validation-with-filters.patch
File josm-validation-with-filters.patch, 11.7 KB (added by , 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; 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.GridBagLayout; 6 7 import java.awt.event.ActionEvent; 7 8 import java.awt.event.KeyEvent; 8 9 import java.util.Collection; 9 10 import java.util.Optional; 10 11 12 import javax.swing.ButtonGroup; 13 import javax.swing.JLabel; 14 import javax.swing.JOptionPane; 15 import javax.swing.JPanel; 16 import javax.swing.JRadioButton; 17 11 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper; 12 20 import org.openstreetmap.josm.data.validation.OsmValidator; 13 21 import org.openstreetmap.josm.data.validation.Test; 14 22 import org.openstreetmap.josm.data.validation.ValidationTask; 15 23 import org.openstreetmap.josm.data.validation.util.AggregatePrimitivesVisitor; 24 import org.openstreetmap.josm.gui.ExtendedDialog; 16 25 import org.openstreetmap.josm.gui.MainApplication; 17 26 import org.openstreetmap.josm.gui.MapFrame; 27 import org.openstreetmap.josm.gui.autofilter.AutoFilterManager; 28 import org.openstreetmap.josm.gui.util.GuiHelper; 29 import org.openstreetmap.josm.tools.GBC; 30 import org.openstreetmap.josm.tools.Logging; 18 31 import org.openstreetmap.josm.tools.Shortcut; 19 32 20 33 /** … … public class ValidateAction extends JosmAction { 41 54 42 55 @Override 43 56 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 44 142 doValidate(true); 45 143 } 46 144 -
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; 9 9 import java.util.Map; 10 10 11 11 import org.openstreetmap.josm.data.preferences.BooleanProperty; 12 import org.openstreetmap.josm.data.preferences.StringProperty; 12 13 import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker; 13 14 import org.openstreetmap.josm.tools.ImageProvider; 14 15 … … public class ValidatorPrefHelper extends SourcePrefHelper { 56 57 */ 57 58 public static final String PREF_FILTER_BY_SELECTION = PREFIX + ".selectionFilter"; 58 59 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 59 67 /** 60 68 * Constructs a new {@code PresetPrefHelper}. 61 69 */ -
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 311 311 return model.getFilters(); 312 312 } 313 313 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 314 323 @Override 315 324 public void sort() { 316 325 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; 11 11 import java.util.List; 12 12 13 13 import javax.swing.BorderFactory; 14 import javax.swing.ButtonGroup; 14 15 import javax.swing.JCheckBox; 15 16 import javax.swing.JLabel; 16 17 import javax.swing.JPanel; 18 import javax.swing.JRadioButton; 17 19 18 20 import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper; 19 21 import org.openstreetmap.josm.data.validation.OsmValidator; … … public class ValidatorTestsPreference implements SubPreferenceSetting { 49 51 private JCheckBox prefUseLayer; 50 52 private JCheckBox prefOtherUpload; 51 53 private JCheckBox prefOther; 54 private ButtonGroup validateWithFiltersGroup; 52 55 53 56 /** The list of all tests */ 54 57 private Collection<Test> allTests; … … public class ValidatorTestsPreference implements SubPreferenceSetting { 92 95 gui.getValidatorPreference().addSubTab(this, tr("Tests"), 93 96 GuiHelper.embedInVerticalScrollPane(testPanel), 94 97 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)); 95 128 } 96 129 97 130 @Override … … public class ValidatorTestsPreference implements SubPreferenceSetting { 121 154 ValidatorPrefHelper.PREF_OTHER.put(prefOther.isSelected()); 122 155 ValidatorPrefHelper.PREF_OTHER_UPLOAD.put(prefOtherUpload.isSelected()); 123 156 ValidatorPrefHelper.PREF_LAYER.put(prefUseLayer.isSelected()); 157 ValidatorPrefHelper.PREF_VALIDATE_WITH_FILTERS_ENABLED_ACTION.put(validateWithFiltersGroup.getSelection().getActionCommand()); 124 158 return false; 125 159 } 126 160