/*
* Copyright (C) 2011-2014 GeoForge Project
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.geoforge.guillc.treenode;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeModel;
/**
*
* @author robert
*/
public class GfrRenamerNodChild
{
// renaming child, then sorting children
static public synchronized void s_doJob(
GfrNodAbs nodChild,
String strNameNew,
JTree tre)
{
nodChild.setUserObject(strNameNew);
DefaultTreeModel dtm = (DefaultTreeModel) tre.getModel();
GfrNodAbs nodParent = (GfrNodAbs) nodChild.getParent();
int intChildCount = nodParent.getChildCount();
if (intChildCount > 1)
{
ArrayList<GfrNodAbs> altChild = new ArrayList<GfrNodAbs>();
for (int i=0; i<intChildCount; i++)
{
GfrNodCtrAbs nodCur = (GfrNodCtrAbs) nodParent.getChildAt(i);
altChild.add(nodCur);
}
Object[] objs = (Object[]) altChild.toArray();
dtm.removeNodeFromParent(nodChild);
Arrays.sort(objs, new GfrComparatorNodes()); // ATTN possible memory leaks
for (int i=0; i<objs.length; i++)
{
GfrNodAbs nodCur = (GfrNodAbs) objs[i];
if (nodCur != nodChild)
continue;
dtm.insertNodeInto(nodCur, nodParent, i);
break;
}
}
dtm.nodeChanged(nodChild);
if (tre.isVisible())
tre.repaint();
}
private GfrRenamerNodChild() {}
}