1ef1f31f1f
way we can remove and re-add the same panel (if it's in a tabbed pane, for instance). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5807 542714f4-19e9-0310-aa3c-eee0fc999fb1
150 lines
4.8 KiB
Java
150 lines
4.8 KiB
Java
//
|
|
// $Id$
|
|
//
|
|
// Narya library - tools for developing networked games
|
|
// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved
|
|
// http://www.threerings.net/code/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.util.Comparator;
|
|
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JScrollPane;
|
|
import javax.swing.JTabbedPane;
|
|
|
|
import com.samskivert.util.QuickSort;
|
|
import com.samskivert.swing.VGroupLayout;
|
|
|
|
import com.threerings.presents.util.PresentsContext;
|
|
|
|
import static com.threerings.admin.Log.log;
|
|
|
|
/**
|
|
* Fetches a list of the configuration objects in use by the server and
|
|
* displays their fields in a tree widget to be viewed and edited.
|
|
*/
|
|
public class ConfigEditorPanel extends JPanel
|
|
implements AdminService.ConfigInfoListener
|
|
{
|
|
/**
|
|
* Constructs an editor panel which will use the supplied context to
|
|
* access the distributed object services.
|
|
*/
|
|
public ConfigEditorPanel (PresentsContext ctx)
|
|
{
|
|
this(ctx, null);
|
|
}
|
|
|
|
/**
|
|
* Constructs an editor panel with the specified pane defaulting to
|
|
* selected.
|
|
*/
|
|
public ConfigEditorPanel (PresentsContext ctx, String defaultPane)
|
|
{
|
|
_ctx = ctx;
|
|
_defaultPane = defaultPane;
|
|
|
|
setLayout(new VGroupLayout(VGroupLayout.STRETCH, VGroupLayout.STRETCH,
|
|
VGroupLayout.DEFAULT_GAP, VGroupLayout.CENTER));
|
|
|
|
// create our objects tabbed pane
|
|
add(_oeditors = new JTabbedPane(JTabbedPane.LEFT));
|
|
|
|
// add a handy label at the bottom
|
|
add(new JLabel("Fields outline in red have been modified " +
|
|
"but not yet committed."), VGroupLayout.FIXED);
|
|
add(new JLabel("Press return in a modified field to commit " +
|
|
"the change."), VGroupLayout.FIXED);
|
|
}
|
|
|
|
@Override
|
|
public void addNotify ()
|
|
{
|
|
super.addNotify();
|
|
|
|
// ship off a getConfigInfo request to find out what config
|
|
// objects are available for editing
|
|
AdminService service = _ctx.getClient().requireService(AdminService.class);
|
|
service.getConfigInfo(_ctx.getClient(), this);
|
|
}
|
|
|
|
@Override
|
|
public void removeNotify ()
|
|
{
|
|
super.removeNotify();
|
|
|
|
// when we're hidden, we want to clear out our subscriptions
|
|
int ccount = _oeditors.getComponentCount();
|
|
for (int ii = 0; ii < ccount; ii++) {
|
|
JScrollPane scrolly = (JScrollPane)_oeditors.getComponent(ii);
|
|
ObjectEditorPanel opanel = (ObjectEditorPanel)
|
|
scrolly.getViewport().getView();
|
|
opanel.cleanup();
|
|
}
|
|
_oeditors.removeAll();
|
|
}
|
|
|
|
/**
|
|
* Called in response to our getConfigInfo server-side service request.
|
|
*/
|
|
public void gotConfigInfo (final String[] keys, final int[] oids)
|
|
{
|
|
// make sure we're still added
|
|
if (!isDisplayable()) {
|
|
return;
|
|
}
|
|
|
|
Integer indexes[] = new Integer[keys.length];
|
|
for (int ii = 0; ii < indexes.length; ii++) {
|
|
indexes[ii] = ii;
|
|
}
|
|
|
|
QuickSort.sort(indexes, new Comparator<Integer>() {
|
|
public int compare (Integer i1, Integer i2) {
|
|
return keys[i1].compareTo(keys[i2]);
|
|
}
|
|
});
|
|
|
|
// create object editor panels for each of the categories
|
|
for (Integer ii : indexes) {
|
|
ObjectEditorPanel panel = new ObjectEditorPanel(_ctx, keys[ii], oids[ii]);
|
|
JScrollPane scrolly = new JScrollPane(panel);
|
|
_oeditors.addTab(keys[ii], scrolly);
|
|
if (keys[ii].equals(_defaultPane)) {
|
|
_oeditors.setSelectedComponent(scrolly);
|
|
}
|
|
}
|
|
}
|
|
|
|
// documentation inherited from interface
|
|
public void requestFailed (String reason)
|
|
{
|
|
log.warning("Failed to get config info", "reason", reason);
|
|
}
|
|
|
|
/** Our client context. */
|
|
protected PresentsContext _ctx;
|
|
|
|
/** Holds our object editors. */
|
|
protected JTabbedPane _oeditors;
|
|
|
|
/** Our default tab pane. */
|
|
protected String _defaultPane;
|
|
}
|