JOSM #22322 - Add tag list popup menu actions to create filters for selected tags#102
JOSM #22322 - Add tag list popup menu actions to create filters for selected tags#102Woazboat wants to merge 1 commit intoJOSM:masterfrom
Conversation
Add two menu items to the tag list dialog popup menu that create filtersto either hide or exclusively show objects with selected tags. If an equivalent filter is already present in the filter list, re-uses and enables that one instead.
| String val = p.get(key); | ||
| if (val == null || (!sameType && consideredTokens.contains(val))) { | ||
| continue; | ||
| class FilterAction extends AbstractAction implements PopupMenuListener { |
There was a problem hiding this comment.
Stupid question: is there any particular reason why you aren't using JosmAction?
There was a problem hiding this comment.
Mostly for similarity with all the other actions in the context menu which are also simply using AbstractAction. We don't really need any features that JosmAction provides (no shortcuts, listeners, etc...) so we wouldn't gain a lot from using it. Setting the icon etc... would be a tiny bit simplified.
| assertEquals(false, n2.isDisabled()); | ||
| assertEquals(true, n3.isDisabled()); | ||
| } catch (Exception e) { | ||
| fail("Should not throw", e); |
There was a problem hiding this comment.
I don't know if you are aware of assertDoesNotThrow or not, but you can use that instead of catching the exception.
| assertEquals(false, n.isDisabled()); | ||
| assertEquals(false, n2.isDisabled()); | ||
| assertEquals(true, n3.isDisabled()); |
There was a problem hiding this comment.
| assertEquals(false, n.isDisabled()); | |
| assertEquals(false, n2.isDisabled()); | |
| assertEquals(true, n3.isDisabled()); | |
| assertFalse(n.isDisabled()); | |
| assertFalse(n2.isDisabled()); | |
| assertTrue(n3.isDisabled()); |
|
|
||
| assertEquals(expectedFilter, createdFilter); | ||
| assertEquals(0, createdFilter.compareTo(expectedFilter)); | ||
| assertEquals(true, createdFilter.enable); |
There was a problem hiding this comment.
| assertEquals(true, createdFilter.enable); | |
| assertTrue(createdFilter.enable); |
|
|
||
| tagTable.selectAll(); | ||
|
|
||
| assertEquals(0, filterModel.getFilters().size()); |
There was a problem hiding this comment.
| assertEquals(0, filterModel.getFilters().size()); | |
| assertTrue(filterModel.getFilters().isEmpty()); |
| assertEquals(true, createdFilter.enable); | ||
|
|
||
| assertEquals(true, n.isDisabled()); | ||
| assertEquals(true, n2.isDisabled()); | ||
| assertEquals(false, n3.isDisabled()); |
There was a problem hiding this comment.
| assertEquals(true, createdFilter.enable); | |
| assertEquals(true, n.isDisabled()); | |
| assertEquals(true, n2.isDisabled()); | |
| assertEquals(false, n3.isDisabled()); | |
| assertTrue(createdFilter.enable); | |
| assertTrue(n.isDisabled()); | |
| assertTrue(n2.isDisabled()); | |
| assertFalse(n3.isDisabled()); |
| assertEquals(true, n2.isDisabled()); | ||
| assertEquals(false, n3.isDisabled()); | ||
| } catch (Exception e) { | ||
| fail("Should not throw", e); |
There was a problem hiding this comment.
I commented on a similar situation down below. That is what I get for skimming top->bottom and then reviewing from bottom -> top.
|
|
||
| tagTable.selectAll(); | ||
|
|
||
| assertEquals(0, filterModel.getFilters().size()); |
There was a problem hiding this comment.
| assertEquals(0, filterModel.getFilters().size()); | |
| assertTrue(filterModel.getFilters().isEmpty()); |
| Field filterActionHideField = PropertiesDialog.class.getDeclaredField("filterActionHide"); | ||
| filterActionHideField.setAccessible(true); | ||
| FilterAction filterActionHide = (PropertiesDialog.FilterAction) filterActionHideField.get(propertiesDialog); | ||
|
|
||
| Field tagTableField = PropertiesDialog.class.getDeclaredField("tagTable"); | ||
| tagTableField.setAccessible(true); | ||
| JTable tagTable = (JTable) tagTableField.get(propertiesDialog); | ||
|
|
||
| Field tagDataField = PropertiesDialog.class.getDeclaredField("tagData"); | ||
| tagDataField.setAccessible(true); | ||
| ReadOnlyTableModel tagData = (ReadOnlyTableModel) tagDataField.get(propertiesDialog); |
There was a problem hiding this comment.
Maybe this should be extracted? The only difference between this block and the block in filterActionShowOnlyTest is the filterActionHide field.
| return Arrays.stream(viewRows).boxed() | ||
| .map(r -> tagData.getValueAt(tagTable.convertRowIndexToModel(r), 0).toString()) | ||
| .collect(Collectors.toList()); |
There was a problem hiding this comment.
I don't think you need to do boxing here.
| return Arrays.stream(viewRows).boxed() | |
| .map(r -> tagData.getValueAt(tagTable.convertRowIndexToModel(r), 0).toString()) | |
| .collect(Collectors.toList()); | |
| return Arrays.stream(viewRows).map(tagTable::convertRowIndexToModel) | |
| .mapToObj(r -> tagData.getValueAt(r, 0).toString()).collect(Collectors.toList()); |
https://josm.openstreetmap.de/ticket/22322
Add two menu items to the tag list dialog popup menu that create
filters to either hide or exclusively show objects with selected tags.
If an equivalent filter is already present in the filter list, re-uses

and enables that one instead.