From 497ade64e82ea4560a47f33f55346bfe58af0984 Mon Sep 17 00:00:00 2001 From: Dave Hoover Date: Tue, 12 May 2009 23:52:37 +0000 Subject: [PATCH] Last rejiggering, I promise! (I hope) Let entries be in multiple groups. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5782 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../admin/client/TabbedDSetEditor.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/java/com/threerings/admin/client/TabbedDSetEditor.java b/src/java/com/threerings/admin/client/TabbedDSetEditor.java index b2c16d505..2187569d5 100644 --- a/src/java/com/threerings/admin/client/TabbedDSetEditor.java +++ b/src/java/com/threerings/admin/client/TabbedDSetEditor.java @@ -53,24 +53,23 @@ public class TabbedDSetEditor extends JPanel public static abstract class EntryGrouper { /** - * Record & return the group for a given entry. + * Subclasses implement the actual logic to figure out a group names from an entry here. */ - public String getGroup (E entry) - { - String group = computeGroup(entry); - _allGroups.add(group); - return group; - } + protected abstract String[] computeGroups (E entry); /** - * Subclasses implement the actual logic to figure out a group name from an entry here. + * Returns a predicate that returns true if the given entry is in the given group. */ - protected abstract String computeGroup (E entry); - protected Predicate getPredicate (final String group) { return new Predicate() { public boolean apply (E entry) { - return group.equals(getGroup(entry)); + String[] groups = computeGroups(entry); + for (String g: groups) { + if (g.equals(group)) { + return true; + } + } + return false; } }; } @@ -81,7 +80,10 @@ public class TabbedDSetEditor extends JPanel */ public void computeGroups (Iterable entries) { for (E entry : entries) { - getGroup(entry); + String[] groups = computeGroups(entry); + for (String group : groups) { + _allGroups.add(group); + } } } @@ -116,19 +118,18 @@ public class TabbedDSetEditor extends JPanel } @Override - protected String computeGroup (E entry) { + protected String[] computeGroups (E entry) { try { - return StringUtil.toString(_field.get(entry)); + return new String[] { StringUtil.toString(_field.get(entry)) }; } catch (IllegalAccessException iae) { // This ain't good, but let's soldier on. - return ""; + return new String[] { "" }; } } protected final Field _field; } - /** * Convenience function to make an edittor that groups based on the values of a given field. */