
com.threerings.admin.client.TabbedDSetEditor Maven / Gradle / Ivy
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2012 Three Rings Design, Inc., All Rights Reserved
// http://code.google.com/p/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.admin.client;
import java.lang.reflect.Field;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Set;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import com.google.common.base.Functions;
import com.google.common.base.Predicate;
import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
import com.samskivert.util.Logger;
import com.samskivert.util.QuickSort;
import com.samskivert.util.StringUtil;
import com.samskivert.swing.ObjectEditorTable;
import com.threerings.presents.dobj.AttributeChangeListener;
import com.threerings.presents.dobj.AttributeChangedEvent;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DSet;
import com.threerings.presents.dobj.EntryAddedEvent;
import com.threerings.presents.dobj.EntryRemovedEvent;
import com.threerings.presents.dobj.EntryUpdatedEvent;
import com.threerings.presents.dobj.SetListener;
/**
* Allows simple editing of DSets within a distributed object and easily groups entries into tabs
* based on the content of some field.
*/
public class TabbedDSetEditor extends JPanel
implements AttributeChangeListener, SetListener
{
/**
* Defines how DSetEditor data-access plugins should be created.
*/
public interface AccessorFactory
{
public DSetEditor.Accessor createAccessor (DSetEditor editor);
}
/**
* Used to divide various entires into different groups.
*/
public static abstract class EntryGrouper
{
/**
* Subclasses implement the actual logic to figure out a group names from an entry here.
*/
protected abstract String[] computeGroups (E entry);
/**
* Returns a predicate that returns true if the given entry is in the given group.
*/
protected Predicate getPredicate (final String group) {
return new Predicate() {
public boolean apply (E entry) {
String[] groups = computeGroups(entry);
for (String g: groups) {
if (g.equals(group)) {
return true;
}
}
return false;
}
};
}
/**
* Grinds through the
* @param entries
*/
public void computeGroups (Iterable entries) {
for (E entry : entries) {
String[] groups = computeGroups(entry);
for (String group : groups) {
_allGroups.add(group);
}
}
}
/**
* Returns all the groups we know about, ordered as they should be displayed.
*/
public String[] getAllGroups () {
String[] list = _allGroups.toArray(new String[_allGroups.size()]);
QuickSort.sort(list, getComparator());
return list;
}
protected Comparator
© 2015 - 2025 Weber Informatics LLC | Privacy Policy