Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Woazboat
Copy link

@Woazboat Woazboat commented Aug 28, 2022

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.
josm_tag_popup_filter_action

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.
@Woazboat Woazboat changed the title Add tag list popup menu actions to create filters for selected tags JOSM #22322 - Add tag list popup menu actions to create filters for selected tags Aug 28, 2022
String val = p.get(key);
if (val == null || (!sameType && consideredTokens.contains(val))) {
continue;
class FilterAction extends AbstractAction implements PopupMenuListener {
Copy link

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?

Copy link
Author

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.

Copy link

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);
Copy link

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.

Comment on lines +190 to +192
assertEquals(false, n.isDisabled());
assertEquals(false, n2.isDisabled());
assertEquals(true, n3.isDisabled());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertEquals(true, createdFilter.enable);
assertTrue(createdFilter.enable);


tagTable.selectAll();

assertEquals(0, filterModel.getFilters().size());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertEquals(0, filterModel.getFilters().size());
assertTrue(filterModel.getFilters().isEmpty());

Comment on lines +121 to +125
assertEquals(true, createdFilter.enable);

assertEquals(true, n.isDisabled());
assertEquals(true, n2.isDisabled());
assertEquals(false, n3.isDisabled());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link

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());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertEquals(0, filterModel.getFilters().size());
assertTrue(filterModel.getFilters().isEmpty());

Comment on lines +90 to +100
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);
Copy link

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.

Comment on lines +253 to +255
return Arrays.stream(viewRows).boxed()
.map(r -> tagData.getValueAt(tagTable.convertRowIndexToModel(r), 0).toString())
.collect(Collectors.toList());
Copy link

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.

Suggested change
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());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants