Skip to content
Open
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
30 changes: 19 additions & 11 deletions client/src/com/mirth/connect/client/ui/TagTreeCellRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.swing.Icon;
import javax.swing.ImageIcon;
Expand All @@ -43,6 +47,9 @@ public class TagTreeCellRenderer extends JPanel implements TreeCellRenderer {
private boolean renderTags = false;
private boolean tagTextMode = false;

private Set<ChannelTag> tagIndexSnapshot;
private Map<String, List<ChannelTag>> tagsByChannelId = Collections.emptyMap();

Comment on lines +50 to +52
public TagTreeCellRenderer(boolean renderTags, boolean tagTextMode) {
super(new MigLayout("insets 0, novisualpadding, hidemode 3, fill, gap " + GAP));
this.renderTags = renderTags;
Expand Down Expand Up @@ -128,21 +135,22 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean
label.setText(name);
tagPanel.removeAll();
if (renderTags && channel) {
List<ChannelTag> tags = new ArrayList<ChannelTag>();
for (ChannelTag tag : PlatformUI.MIRTH_FRAME.getCachedChannelTags()) {
if (tag.getChannelIds().contains(channelId)) {
tags.add(tag);
Set<ChannelTag> currentTags = PlatformUI.MIRTH_FRAME.getCachedChannelTags();
if (currentTags != tagIndexSnapshot) {
Map<String, List<ChannelTag>> newIndex = new HashMap<>();
for (ChannelTag tag : currentTags) {
for (String cid : tag.getChannelIds()) {
newIndex.computeIfAbsent(cid, k -> new ArrayList<>()).add(tag);
}
}
Comparator<ChannelTag> byName = (t1, t2) -> t1.getName().compareToIgnoreCase(t2.getName());
newIndex.values().forEach(list -> list.sort(byName));
tagsByChannelId = newIndex;
tagIndexSnapshot = currentTags;
}
Comment on lines +138 to 150

List<ChannelTag> tags = tagsByChannelId.getOrDefault(channelId, Collections.emptyList());
if (CollectionUtils.isNotEmpty(tags)) {
tags.sort(new Comparator<ChannelTag>() {
@Override
public int compare(ChannelTag tag1, ChannelTag tag2) {
return tag1.getName().compareToIgnoreCase(tag2.getName());
}
});

String constraints = tagTextMode ? "h 16!, growx" : "";
for (ChannelTag tag : tags) {
tagPanel.add(ChannelTagLabelCache.getInstance().getLabel(tag, tagTextMode), constraints);
Expand Down
Loading