/*
* 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.tree;
import java.awt.Component;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import javax.swing.event.TreeExpansionListener;
import javax.swing.event.TreeModelListener;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreeModel;
import org.geoforge.guillc.panel.GfrPnlStatusBarSec;
import org.geoforge.guillc.treenode.GfrNodCtrFixFolderRootAbs;
import org.geoforge.io.handler.IGfrHandlerUnserializedObject;
/**
*
* @author bantchao
*/
abstract public class GfrTreCtrTopSpcTogChkPrjSecAbs extends GfrTreCtrTopSpcTogChkPrjAbs implements
IGfrHandlerUnserializedObject
{
protected GfrPnlStatusBarSec _pnlStatusBar = null;
protected String _strIdViewer = null;
@Override
abstract public void childrenAllCheck();
@Override
abstract public void childrenAllUncheck();
protected GfrTreCtrTopSpcTogChkPrjSecAbs(
MouseListener mlrParentMvc,
ActionListener alrParentMvc,
TreeSelectionListener lstTreeSelectionToolbar,
TreeExpansionListener lstTreeExpansionToolbar,
TreeModelListener lstTreeModelToolbar,
GfrNodCtrFixFolderRootAbs nodRoot,
GfrPnlStatusBarSec pnlStatusBar,
String strIdViewer)
{
super(
mlrParentMvc,
nodRoot,
alrParentMvc,
lstTreeSelectionToolbar,
lstTreeExpansionToolbar,
lstTreeModelToolbar);
this._pnlStatusBar = pnlStatusBar;
this._strIdViewer = strIdViewer;
}
@Override
public boolean init()
{
if (! super.init())
return false;
// beg quick fix
TreeModel tml = super.getModel();
GfrNodCtrFixFolderRootAbs nodRoot = (GfrNodCtrFixFolderRootAbs) tml.getRoot();
nodRoot.setTree(this);
// end quick fix
return true;
}
@Override
public void releaseUnserializedObject() throws Exception
{
_releaseUnserializedNodes();
releaseTransient();
for (int i = 0; i < super.getComponentCount(); i++) // not yet in use!
{
Component cmpCur = super.getComponent(i);
if (cmpCur instanceof IGfrHandlerUnserializedObject)
{
IGfrHandlerUnserializedObject serCur = (IGfrHandlerUnserializedObject) cmpCur;
serCur.releaseUnserializedObject();
}
}
}
@Override
public void loadUnserializedObject() throws Exception
{
super.loadTransient();
}
private void _releaseUnserializedNodes() throws Exception
{
TreeModel model = super.getModel();
if (model != null)
{
Object root = model.getRoot();
_releaseUnserializedNode(model, root);
}
}
private void _releaseUnserializedNode(TreeModel model, Object o) throws Exception
{
int cc;
cc = model.getChildCount(o);
for (int i = 0; i < cc; i++)
{
Object objChildCur = model.getChild(o, i);
if (objChildCur instanceof IGfrHandlerUnserializedObject)
{
IGfrHandlerUnserializedObject serCur = (IGfrHandlerUnserializedObject) objChildCur;
serCur.releaseUnserializedObject();
}
if (model.isLeaf(objChildCur))
{
//System.out.println(objChildCur.toString());
}
else
{
//System.out.print(objChildCur.toString() + "--");
_releaseUnserializedNode(model, objChildCur);
}
}
}
}