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

Add support for alternative tagging of the presets. #126

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion resources/data/tagging-preset.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
<complexType name="preset_link">
<annotation>
<documentation><![CDATA[
Adds a link to an other preset with a label on top. The preset_name attribute is required, text to override the label (default is "Edit also …") and text_context are optional. A sequence of <preset_link /> without text or a identical text value are grouped below one label. Watch out for presets with identical name as it is not predictable to which preset the link will lead to, see #12716.
Adds a link to an other preset with a label on top. The preset_name attribute is required. alternative, text to override the label (default is "Edit also …") and text_context are optional. A sequence of <preset_link /> without text or a identical text value are grouped below one label. Watch out for presets with identical name as it is not predictable to which preset the link will lead to, see #12716.
Copy link

Choose a reason for hiding this comment

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

I'm not quite certain what you are trying to say/change here.

]]></documentation>
</annotation>
<attribute name="preset_name" type="string" use="required">
Expand All @@ -298,6 +298,13 @@
</documentation>
</annotation>
</attribute>
<attribute name="alternative" type="boolean">
<annotation>
<documentation>
Indicates that the preset link points to an alternative tagging of the object.
</documentation>
</annotation>
</attribute>
<attributeGroup ref="tns:attributes.text" />
<attribute name="name" use="prohibited" />
<anyAttribute processContents="skip" />
Expand Down
31 changes: 25 additions & 6 deletions src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
Expand Down Expand Up @@ -419,23 +418,43 @@ public void applyComponentOrientation(ComponentOrientation o) {
}
};
JPanel linkPanel = new JPanel(new GridBagLayout());
TaggingPresetItem previous = null;
List<PresetLink> alternativeTags = new ArrayList<>(); //list to store PresetLinks with alternative="true"
List<PresetLink> editAlsoTags = new ArrayList<>(); //list to store other presetLinks
for (TaggingPresetItem i : data) {
if (i instanceof Link) {
i.addToPanel(linkPanel, itemGuiSupport);
p.hasElements = true;
} else {
if (i instanceof PresetLink) {
PresetLink link = (PresetLink) i;
if (!(previous instanceof PresetLink && Objects.equals(((PresetLink) previous).text, link.text))) {
itemPanel.add(link.createLabel(), GBC.eol().insets(0, 8, 0, 0));
if (link.isAlternative()) {
alternativeTags.add(link);
} else {
editAlsoTags.add(link);
}
}
if (i.addToPanel(itemPanel, itemGuiSupport)) {
if (!(i instanceof PresetLink) && (i.addToPanel(itemPanel, itemGuiSupport))) {
Copy link

Choose a reason for hiding this comment

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

You might want to add a comment for this (e.g. "Not adding preset links to panel here since we want to order alternative tags and tags that users may want to use in addition").

p.hasElements = true;
}
}
previous = i;
}

if (!alternativeTags.isEmpty()) {
PresetLink link = new PresetLink();
itemPanel.add(link.createAlternativeLabel(), GBC.eol().insets(0, 8, 0, 0));
for (PresetLink links : alternativeTags) {
links.addToPanel(itemPanel, itemGuiSupport);
p.hasElements = true;
}
}

if (!editAlsoTags.isEmpty()) {
PresetLink link = new PresetLink();
itemPanel.add(link.createLabel(), GBC.eol().insets(0, 8, 0, 0));
for (PresetLink links : editAlsoTags) {
links.addToPanel(itemPanel, itemGuiSupport);
p.hasElements = true;
}
Comment on lines +442 to +457
Copy link

Choose a reason for hiding this comment

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

If you consolidate the createLabel/createAlternativeLabel, this could be done like so:

Suggested change
if (!alternativeTags.isEmpty()) {
PresetLink link = new PresetLink();
itemPanel.add(link.createAlternativeLabel(), GBC.eol().insets(0, 8, 0, 0));
for (PresetLink links : alternativeTags) {
links.addToPanel(itemPanel, itemGuiSupport);
p.hasElements = true;
}
}
if (!editAlsoTags.isEmpty()) {
PresetLink link = new PresetLink();
itemPanel.add(link.createLabel(), GBC.eol().insets(0, 8, 0, 0));
for (PresetLink links : editAlsoTags) {
links.addToPanel(itemPanel, itemGuiSupport);
p.hasElements = true;
}
for (List<PresetLink> linkList : Arrays.asList(alternativeTags, editAlsoTags)) {
if (!linkList.isEmpty()) {
PresetLink link = new PresetLink();
itemPanel.add(link.createLabel(), GBC.eol().insets(0, 8, 0, 0));
for (PresetLink links : linkList) {
links.addToPanel(itemPanel, itemGuiSupport);
p.hasElements = true;
}
}
}

Copy link
Author

Choose a reason for hiding this comment

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

link.isAlternative() is always false, therefore same label is being created for both preset alternative and editalso tags. We may want to create label based on the links of the linkedList

}
p.add(itemPanel, GBC.eol().fill());
p.add(linkPanel, GBC.eol().fill());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,40 @@ public void mouseClicked(MouseEvent e) {
/** The exact name of the preset to link to. Required. */
public String preset_name = ""; // NOSONAR

/**
* true if the PresetLink points to the alternative tagging of the preset.
*/
private boolean alternative;

/**
* Gets the alternative for the preset
*/
public boolean isAlternative() {
return alternative;
}

/**
* Sets the alternative for the preset.
*/
public void setAlternative(boolean alternative) {
this.alternative = alternative;
}

/**
* Creates a label to be inserted above this link
* @return a label
*/
public JLabel createLabel() {
initializeLocaleText(tr("Edit also …"));
initializeLocaleText(tr("Additional tags to edit"));
return new JLabel(locale_text);
}

/**
* Creates a label to be inserted above the alternative presets
* @return a label
*/
public JLabel createAlternativeLabel() {
initializeLocaleText(tr("Similar but different tags"));
Comment on lines +71 to +80
Copy link

Choose a reason for hiding this comment

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

We only use createLabel in one location. These two methods should probably be consolidated.

Suggested change
initializeLocaleText(tr("Additional tags to edit"));
return new JLabel(locale_text);
}
/**
* Creates a label to be inserted above the alternative presets
* @return a label
*/
public JLabel createAlternativeLabel() {
initializeLocaleText(tr("Similar but different tags"));
if (!alternative) {
initializeLocaleText(tr("Additional tags to edit"));
return new JLabel(locale_text);
}
initializeLocaleText(tr("Similar but different tags"));

return new JLabel(locale_text);
}

Expand Down