/*
* 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.guillcogc.treenode;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;
import javax.swing.ImageIcon;
import javax.swing.tree.DefaultTreeModel;
import org.geoforge.guillc.tree.GfrTreAbs;
import org.geoforge.guillc.treenode.GfrNodAbs;
import org.geoforge.guillcogc.popupmenu.GfrPmuCtlCtrFolderSetLyrWmsImgLgdSec;
import org.geoforge.awt.image.GfrFactoryIconAbs;
import org.geoforge.ioogc.awt.image.GfrFactoryIconAppOgc;
import org.geoforge.mdldsp.event.state.multiple.GfrEvtMdlTogMltSecCbx;
import org.geoforge.mdldsp.state.multiple.GfrMdlTogMltSecCbx;
import org.geoforge.wrpbasprsdatogc.GfrWrpBasDatObjNameTloWms;
import org.geoforge.wrpbasprsdsp.state.multiple.run.GfrWrpBasPrsDspPrjObjSecMltTogCbx;
import org.geoforge.wrpbasprssynogc.GfrWrpBasSynObjNameTloWms;
/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
* ATTN: SHOULD NOT ALLOW RENAMING FOR NOW rename!!!
*/
public class GfrNodCtrMovFolderLblLyrPrjWmsLgdSec extends GfrNodCtrMovFolderLblLyrPrjWmsAbs
{
private String _strIdViewer_ = null;
private boolean _blnHasLegend_ = false;
private ImageIcon _iinDisplayedYes_ = null;
private ImageIcon _iinDisplayedNo_ = null;
public GfrNodCtrMovFolderLblLyrPrjWmsLgdSec(
ActionListener alrControllerSpcPrj,
ActionListener alrControllerPrs,
String strIdLyrOwner,
GfrTreAbs tre,
ActionListener alrParentPanelMvc,
String strIdOwner,
String strIdViever)
throws Exception
{
super(
alrControllerSpcPrj,
alrControllerPrs,
GfrWrpBasDatObjNameTloWms.s_getIdChildLegendFromIdOwnerLayer(strIdLyrOwner),
tre,
alrParentPanelMvc,
strIdOwner,
GfrWrpBasSynObjNameTloWms.getInstance().getValueTitleLayerFolder(strIdLyrOwner),
GfrFactoryIconAppOgc.s_getLegendLayerWmsNoFolder(GfrFactoryIconAbs.INT_SIZE_XXSMALL));
this._strIdViewer_ = strIdViever;
this._iinDisplayedNo_ = GfrFactoryIconAppOgc.s_getLegendLayerWmsHiddenFolder(GfrFactoryIconAbs.INT_SIZE_XXSMALL);
this._iinDisplayedYes_ = GfrFactoryIconAppOgc.s_getLegendLayerWmsVisibleFolder(GfrFactoryIconAbs.INT_SIZE_XXSMALL);
String str = GfrWrpBasSynObjNameTloWms.getInstance().getValueLegendUrlLayerFolder(strIdLyrOwner);
if (str==null || str.length()<1)
this._blnHasLegend_ = false; // not really need
else
this._blnHasLegend_ = true;
super._pop = new GfrPmuCtlCtrFolderSetLyrWmsImgLgdSec(
alrControllerSpcPrj,
strIdLyrOwner,
strIdOwner,
strIdViever,
tre,
this._blnHasLegend_);
}
@Override
public void loadTransient() throws Exception
{
super.loadTransient();
if (this._blnHasLegend_ == false)
return;
GfrMdlTogMltSecCbx.getInstance().addObserver((Observer) this);
boolean blnIsCheckedThis = GfrWrpBasPrsDspPrjObjSecMltTogCbx.getInstance().isEnabled(this._strIdViewer_, super._strId);
if (blnIsCheckedThis)
this._displayYes();
else
this._displayNo();
}
@Override
public void releaseTransient() throws Exception
{
super.releaseTransient();
if (this._blnHasLegend_)
GfrMdlTogMltSecCbx.getInstance().deleteObserver((Observer) this);
}
@Override
protected void _loadChildrenFolder(String[] strsId) throws Exception
{
if (strsId==null || strsId.length<1)
return;
for (int i=0; i<strsId.length; i++)
{
GfrNodCtrMovFolderLblLyrPrjWmsAbs nodCur = new GfrNodCtrMovFolderLblLyrPrjWmsLgdSec(
super._alrControllerSpace,
super._alrControllerPerspective,
strsId[i],
super._tree,
super._alrParentPanelMvc,
super._strIdOwner,
this._strIdViewer_
);
super._addObjectVariableNode(nodCur);
}
}
@Override
protected void _loadChildrenLeaf(String[] strsId) throws Exception
{
if (strsId==null || strsId.length<1)
return;
for (int i=0; i<strsId.length; i++)
{
GfrNodAbs nodCur = new GfrNodCtrMovLeafPrjLblLloLeafWmsImgLgdSec(
super._alrControllerSpace,
super._alrControllerPerspective,
strsId[i],
super._strIdOwner,
this._strIdViewer_,
super._tree
);
super._addObjectVariableNode(nodCur);
}
}
@Override
protected void _loadChildren() throws Exception
{
String strIdLyrOwner = GfrWrpBasDatObjNameTloWms.s_getIdOwnerLayerFromIdChildLegend(super._strId);
String[] strsIdFolderChild = GfrWrpBasSynObjNameTloWms.getInstance().getIdsFolderChildrenFromFolderParent(strIdLyrOwner);
_loadChildrenFolder(strsIdFolderChild);
String[] strsIdLeafChild = GfrWrpBasSynObjNameTloWms.getInstance().getIdsLeafChildrenFromFolderParent(strIdLyrOwner);
_loadChildrenLeaf(strsIdLeafChild);
boolean blnShouldUpdate = false;
if (strsIdFolderChild!=null && strsIdFolderChild.length>0)
blnShouldUpdate = true;
else if (strsIdLeafChild!=null && strsIdLeafChild.length>0)
blnShouldUpdate = true;
if (blnShouldUpdate)
{
DefaultTreeModel dtm = (DefaultTreeModel) super._tree.getModel();
dtm.nodeStructureChanged(this);
}
}
private void _displayYes()
{
super.setImageIcon(this._iinDisplayedYes_);
if (super._tree.isVisible())
super._tree.repaint();
}
private void _displayNo()
{
super.setImageIcon(this._iinDisplayedNo_);
if (super._tree.isVisible())
super._tree.repaint();
}
@Override
public void update(Observable obs, Object objEvt)
{
if (! this._blnHasLegend_) //should never appear
return;
if (objEvt instanceof GfrEvtMdlTogMltSecCbx)
{
GfrEvtMdlTogMltSecCbx evt = (GfrEvtMdlTogMltSecCbx) objEvt;
String strIdViewer = evt.getKeyViewer();
if (strIdViewer.compareTo(this._strIdViewer_) != 0)
return;
String strId = evt.getKeyObject();
if (strId.compareTo(super.getId()) != 0)
return;
boolean bln = evt.getValueObject();
if (bln)
this._displayYes();
else
this._displayNo();
return;
}
super.update(obs, objEvt);
}
}