-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JOSM #22322 - Add tag list popup menu actions to create filters for selected tags #102
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stupid question: is there any particular reason why you aren't using JosmAction
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough.
assertEquals(false, n2.isDisabled()); | ||
assertEquals(true, n3.isDisabled()); | ||
} catch (Exception e) { | ||
fail("Should not throw", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertEquals(true, createdFilter.enable); | |
assertTrue(createdFilter.enable); |
|
||
tagTable.selectAll(); | ||
|
||
assertEquals(0, filterModel.getFilters().size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.