Ticket #17344: 17344.patch
| File 17344.patch, 11.1 KB (added by , 7 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
26 26 import javax.swing.event.TreeSelectionEvent; 27 27 import javax.swing.event.TreeSelectionListener; 28 28 import javax.swing.tree.DefaultMutableTreeNode; 29 import javax.swing.tree.TreeNode;30 29 import javax.swing.tree.TreePath; 31 30 32 31 import org.openstreetmap.josm.actions.AbstractSelectAction; … … 40 39 import org.openstreetmap.josm.data.osm.Node; 41 40 import org.openstreetmap.josm.data.osm.OsmPrimitive; 42 41 import org.openstreetmap.josm.data.osm.WaySegment; 42 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 43 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter; 44 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 45 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 43 46 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 44 47 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 45 48 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; … … 75 78 * 76 79 * @author frsantos 77 80 */ 78 public class ValidatorDialog extends ToggleDialog implements DataSelectionListener, ActiveLayerChangeListener { 81 public class ValidatorDialog extends ToggleDialog 82 implements DataSelectionListener, ActiveLayerChangeListener, DataSetListenerAdapter.Listener { 79 83 80 84 /** The display tree */ 81 85 public ValidatorTreePanel tree; … … 83 87 /** The validate action */ 84 88 public static final ValidateAction validateAction = new ValidateAction(); 85 89 86 /** The fix button */87 private final SideButton fixButton;88 /** The ignore button */89 private final SideButton ignoreButton;90 /** The reset ignorelist button */91 private final SideButton ignorelistManagement;92 /** The select button */93 private final SideButton selectButton;94 /** The lookup button */95 private final SideButton lookupButton;90 /** The fix action */ 91 private final transient Action fixAction; 92 /** The ignore action */ 93 private final transient Action ignoreAction; 94 /** The ignore-list management action */ 95 private final transient Action ignorelistManagementAction; 96 /** The select action */ 97 private final transient Action selectAction; 98 /** The lookup action */ 99 private final transient LookupAction lookupAction; 96 100 97 101 private final JPopupMenu popupMenu = new JPopupMenu(); 98 102 private final transient PopupMenuHandler popupMenuHandler = new PopupMenuHandler(popupMenu); 103 private final transient DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this); 99 104 100 105 /** Last selected element */ 101 106 private DefaultMutableTreeNode lastSelectedNode; … … 118 123 119 124 List<SideButton> buttons = new LinkedList<>(); 120 125 121 select Button = new SideButton(new AbstractSelectAction() {126 selectAction = new AbstractSelectAction() { 122 127 @Override 123 128 public void actionPerformed(ActionEvent e) { 124 129 setSelectedItems(); 125 130 } 126 }); 127 InputMapUtils.addEnterAction(tree, selectButton.getAction()); 131 }; 132 selectAction.setEnabled(false); 133 InputMapUtils.addEnterAction(tree, selectAction); 134 buttons.add(new SideButton(selectAction)); 128 135 129 selectButton.setEnabled(false);130 buttons.add( selectButton);136 lookupAction = new LookupAction(); 137 buttons.add(new SideButton(lookupAction)); 131 138 132 lookupButton = new SideButton(new LookupAction());133 buttons.add(lookupButton);134 135 139 buttons.add(new SideButton(validateAction)); 136 140 137 fix Button = new SideButton(new AbstractAction() {141 fixAction = new AbstractAction() { 138 142 { 139 143 putValue(NAME, tr("Fix")); 140 144 putValue(SHORT_DESCRIPTION, tr("Fix the selected issue.")); … … 144 148 public void actionPerformed(ActionEvent e) { 145 149 fixErrors(); 146 150 } 147 } );148 fix Button.setEnabled(false);149 buttons.add( fixButton);151 }; 152 fixAction.setEnabled(false); 153 buttons.add(new SideButton(fixAction)); 150 154 151 155 if (ValidatorPrefHelper.PREF_USE_IGNORE.get()) { 152 ignore Button = new SideButton(new AbstractAction() {156 ignoreAction = new AbstractAction() { 153 157 { 154 158 putValue(NAME, tr("Ignore")); 155 159 putValue(SHORT_DESCRIPTION, tr("Ignore the selected issue next time.")); … … 159 163 public void actionPerformed(ActionEvent e) { 160 164 ignoreErrors(); 161 165 } 162 } );163 ignore Button.setEnabled(false);164 buttons.add( ignoreButton);166 }; 167 ignoreAction.setEnabled(false); 168 buttons.add(new SideButton(ignoreAction)); 165 169 166 ignorelistManagement = new SideButton(new AbstractAction() {170 ignorelistManagementAction = new AbstractAction() { 167 171 { 168 172 putValue(NAME, tr("Manage Ignore")); 169 173 putValue(SHORT_DESCRIPTION, tr("Manage the ignore list")); … … 174 178 public void actionPerformed(ActionEvent e) { 175 179 new ValidatorListManagementDialog("Ignore"); 176 180 } 177 } );178 buttons.add( ignorelistManagement);181 }; 182 buttons.add(new SideButton(ignorelistManagementAction)); 179 183 } else { 180 ignore Button = null;181 ignorelistManagement = null;184 ignoreAction = null; 185 ignorelistManagementAction = null; 182 186 } 183 187 184 188 createLayout(tree, true, buttons); … … 187 191 /** 188 192 * The action to lookup the selection in the error tree. 189 193 */ 190 class LookupAction extends AbstractAction implements DataSelectionListener{194 class LookupAction extends AbstractAction { 191 195 192 196 LookupAction() { 193 197 putValue(NAME, tr("Lookup")); 194 198 putValue(SHORT_DESCRIPTION, tr("Looks up the selected primitives in the error list.")); 195 199 new ImageProvider("dialogs", "search").getResource().attachImageIcon(this, true); 196 SelectionEventManager.getInstance().addSelectionListener(this);197 200 updateEnabledState(); 198 201 } 199 202 … … 206 209 tree.selectRelatedErrors(ds.getSelected()); 207 210 } 208 211 209 p rotectedvoid updateEnabledState() {212 public void updateEnabledState() { 210 213 boolean found = false; 211 214 for (TestError e : tree.getErrors()) { 212 215 for (OsmPrimitive p : e.getPrimitives()) { … … 218 221 } 219 222 setEnabled(found); 220 223 } 221 222 @Override223 public void selectionChanged(SelectionChangeEvent event) {224 updateEnabledState();225 }226 224 } 227 225 228 226 @Override 229 227 public void showNotify() { 228 DatasetEventManager.getInstance().addDatasetListener(dataChangedAdapter, FireMode.IN_EDT_CONSOLIDATED); 230 229 SelectionEventManager.getInstance().addSelectionListener(this); 231 230 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 232 231 if (ds != null) { … … 233 232 updateSelection(ds.getAllSelected()); 234 233 } 235 234 MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(this); 235 236 236 } 237 237 238 238 @Override 239 239 public void hideNotify() { 240 DatasetEventManager.getInstance().removeDatasetListener(dataChangedAdapter); 240 241 MainApplication.getLayerManager().removeActiveLayerChangeListener(this); 241 242 SelectionEventManager.getInstance().removeSelectionListener(this); 242 243 } … … 347 348 Collection<OsmPrimitive> sel = new HashSet<>(40); 348 349 for (TreePath path : selectedPaths) { 349 350 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); 350 Enumeration< TreeNode> children = node.breadthFirstEnumeration();351 Enumeration<?> children = node.breadthFirstEnumeration(); 351 352 while (children.hasMoreElements()) { 352 353 DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement(); 353 354 Object nodeInfo = childNode.getUserObject(); … … 392 393 .forEach(sel::add); 393 394 } 394 395 }); 395 select Button.setEnabled(true);396 if (ignore Button != null) {397 ignore Button.setEnabled(node.getDepth() <= 1);396 selectAction.setEnabled(true); 397 if (ignoreAction != null) { 398 ignoreAction.setEnabled(node.getDepth() <= 1); 398 399 } 399 400 } 400 401 … … 470 471 tree.clearSelection(); 471 472 } 472 473 473 fix Button.setEnabled(false);474 if (ignore Button != null) {475 ignore Button.setEnabled(false);474 fixAction.setEnabled(false); 475 if (ignoreAction != null) { 476 ignoreAction.setEnabled(false); 476 477 } 477 select Button.setEnabled(false);478 selectAction.setEnabled(false); 478 479 479 480 boolean isDblClick = isDoubleClick(e); 480 481 … … 481 482 Collection<OsmPrimitive> sel = isDblClick ? new HashSet<>(40) : null; 482 483 483 484 boolean hasFixes = setSelection(sel, isDblClick); 484 fix Button.setEnabled(hasFixes);485 fixAction.setEnabled(hasFixes); 485 486 486 487 if (isDblClick) { 487 488 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); … … 512 513 public class SelectionWatch implements TreeSelectionListener { 513 514 @Override 514 515 public void valueChanged(TreeSelectionEvent e) { 515 fixButton.setEnabled(false); 516 if (ignoreButton != null) { 517 ignoreButton.setEnabled(false); 516 if (ignoreAction!= null) { 517 ignoreAction.setEnabled(false); 518 518 } 519 select Button.setEnabled(false);519 selectAction.setEnabled(false); 520 520 521 521 Collection<OsmPrimitive> sel = new HashSet<>(); 522 522 boolean hasFixes = setSelection(sel, true); 523 fix Button.setEnabled(hasFixes);523 fixAction.setEnabled(hasFixes); 524 524 popupMenuHandler.setPrimitives(sel); 525 525 invalidateValidatorLayers(); 526 526 } … … 576 576 @Override 577 577 public void selectionChanged(SelectionChangeEvent event) { 578 578 updateSelection(event.getSelection()); 579 lookupAction.updateEnabledState(); 579 580 } 580 581 581 582 /** … … 655 656 } 656 657 657 658 @Override 658 public void destroy() { 659 if (lookupButton != null && lookupButton.getAction() instanceof DataSelectionListener) { 660 Action a = lookupButton.getAction(); 661 SelectionEventManager.getInstance().removeSelectionListener((DataSelectionListener) a); 662 } 663 super.destroy(); 659 public void processDatasetEvent(AbstractDatasetChangedEvent event) { 660 validateAction.updateEnabledState(); 664 661 } 665 662 }
