/*
* 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.popupmenu;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.logging.Logger;
import javax.swing.JMenuItem;
import org.geoforge.guillc.handler.IGfrHandlerDisplayableObjectsSet;
import org.geoforge.guillc.handler.IGfrHandlerToggableNode;
import org.geoforge.guillc.menuitem.GfrMimTrsAlrCheckAllAbs;
import org.geoforge.guillc.menuitem.GfrMimTrsAlrCheckAllNo;
import org.geoforge.guillc.menuitem.GfrMimTrsAlrCheckAllYes;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.guillc.tree.GfrTreAbs;
import org.geoforge.java.awt.container.GfrUtilContainer;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.wrpbasprsdat.handler.IGfrHandlerWrapperSetDataTop;
/**
*
* @author robert
*
* toggle buttons of type checkbox v/s of type radiobutton
*/
public class GfrPmuCtlCtrFolderTopPrjTogCbxAbs extends GfrPmuCtlCtrFolderTopAbs
{
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrPmuCtlCtrFolderTopPrjTogCbxAbs.class.getName());
static
{
GfrPmuCtlCtrFolderTopPrjTogCbxAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
transient protected GfrMimTrsAlrCheckAllAbs _mimAllCheckTlo = null;
transient protected GfrMimTrsAlrCheckAllAbs _mimAllUncheckTlo = null;
protected GfrPmuCtlCtrFolderTopPrjTogCbxAbs(
GfrTreAbs tree,
ActionListener alrController,
ActionListener alrParentPanelMvc,
String strValueKindTargetWindow,
IGfrHandlerDisplayableObjectsSet enuValueKindObject,
Observable observableTop,
IGfrHandlerWrapperSetDataTop wrpSetDataTop) throws Exception
{
super(
tree,
alrController,
strValueKindTargetWindow,
enuValueKindObject,
observableTop,
wrpSetDataTop);
ActionListener[] alrs =
{
(ActionListener) this,
alrParentPanelMvc
};
this._mimAllCheckTlo = new GfrMimTrsAlrCheckAllYes(
alrs,
enuValueKindObject.getNameThisDisplayableObjectsSet());
this._mimAllUncheckTlo = new GfrMimTrsAlrCheckAllNo(
alrs,
enuValueKindObject.getNameThisDisplayableObjectsSet());
}
@Override
public boolean init()
{
if (!super.init())
return false;
if (!this._mimAllCheckTlo.init())
return false;
if (!this._mimAllUncheckTlo.init())
return false;
int intPos = 0;
if (super._menPlugins != null)
{
intPos = GfrUtilContainer.s_getPosition(this, super._menPlugins);
intPos += 2;
}
else
{
intPos = GfrUtilContainer.s_getPosition(this, super._mimFolderAllCollapse);
intPos += 2;
}
super.add(this._mimAllCheckTlo, intPos++);
super.add(this._mimAllUncheckTlo, intPos++);
//super.insert(new JPopupMenu.Separator(), intPos++);
return true;
}
@Override
public void destroy()
{
super.destroy();
if (this._mimAllCheckTlo != null)
{
this._mimAllCheckTlo.destroy();
this._mimAllCheckTlo = null;
}
if (this._mimAllUncheckTlo != null)
{
this._mimAllUncheckTlo.destroy();
this._mimAllUncheckTlo = null;
}
}
@Override
public void loadTransient() throws Exception
{
super.loadTransient();
this._mimAllCheckTlo.loadTransient();
this._mimAllUncheckTlo.loadTransient();
this._mimAllCheckTlo.setEnabled(false);
this._mimAllUncheckTlo.setEnabled(false);
}
@Override
public void releaseTransient() throws Exception
{
super.releaseTransient();
// ----
this._mimAllCheckTlo.releaseTransient();
this._mimAllUncheckTlo.releaseTransient();
// ----
this._mimAllCheckTlo.setEnabled(false);
this._mimAllUncheckTlo.setEnabled(false);
}
@Override
public void actionPerformed(ActionEvent e)
{
if (!(e.getSource() instanceof JMenuItem))
{
String str = "! (e.getSource() instanceof JMenuItem), :" + e.getSource().getClass().toString();
GfrPmuCtlCtrFolderTopPrjTogCbxAbs._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
return;
}
JMenuItem mimSource = (JMenuItem) e.getSource();
if (mimSource == this._mimAllCheckTlo)
{
this._childrenAllCheck_();
return;
}
if (mimSource == this._mimAllUncheckTlo)
{
this._childrenAllUncheck_();
return;
}
super.actionPerformed(e);
}
@Override
public void show(Component invoker, int x, int y)
{
try
{
String[] strs = _getUniqueIds_();
boolean blnEnableAllUncheck = _isAllowedChildrenAllUncheck_();
this._mimAllUncheckTlo.setEnabled(blnEnableAllUncheck);
if (blnEnableAllUncheck)
this._mimAllUncheckTlo.setUniqueIdTargets(strs);
boolean blnEnableAllCheck = _isAllowedChildrenAllCheck_();
this._mimAllCheckTlo.setEnabled(blnEnableAllCheck);
if (blnEnableAllCheck)
this._mimAllCheckTlo.setUniqueIdTargets(strs);
super.show(invoker, x, y);
}
catch (Exception exc)
{
GfrPmuCtlCtrFolderTopPrjTogCbxAbs._LOGGER_.info("exc caught, don't care");
}
}
// ----
// private
private void _childrenAllCheck_()
{
if (super._nod == null)
{
String str = "super._nod == null";
GfrPmuCtlCtrFolderTopPrjTogCbxAbs._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
return;
}
for (int i = 0; i < this._nod.getChildCount(); i++)
{
IGfrHandlerToggableNode nodCur = (IGfrHandlerToggableNode) super._nod.getChildAt(i);
if (nodCur.isSelectedToggableNode())
continue;
nodCur.setSelected(true);
}
if (super._tre.isVisible())
super._tre.repaint();
}
private void _childrenAllUncheck_()
{
if (super._nod == null)
{
String str = "super._nod == null";
GfrPmuCtlCtrFolderTopPrjTogCbxAbs._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
return;
}
for (int i = 0; i < this._nod.getChildCount(); i++)
{
IGfrHandlerToggableNode nodCur = (IGfrHandlerToggableNode) super._nod.getChildAt(i);
if (!nodCur.isSelectedToggableNode())
continue;
nodCur.setSelected(false);
}
if (super._tre.isVisible())
super._tre.repaint();
}
private boolean _isAllowedChildrenAllUncheck_() throws Exception
{
for (int i = 0; i < this._nod.getChildCount(); i++)
{
// !!!!!!!
IGfrHandlerToggableNode nodCur = (IGfrHandlerToggableNode) this._nod.getChildAt(i);
if (nodCur.isSelectedToggableNode())
return true;
}
return false;
}
private boolean _isAllowedChildrenAllCheck_() throws Exception
{
for (int i = 0; i < this._nod.getChildCount(); i++)
{
// !!!!!!!!
IGfrHandlerToggableNode nodCur = (IGfrHandlerToggableNode) this._nod.getChildAt(i);
if (!nodCur.isSelectedToggableNode())
return true;
}
return false;
}
private String[] _getUniqueIds_()
{
String[] strs = new String[this._nod.getChildCount()];
for (int i = 0; i < this._nod.getChildCount(); i++)
{
// !!!!!!!!!!!!!!
IGfrHandlerToggableNode nodCur = (IGfrHandlerToggableNode) this._nod.getChildAt(i);
strs[i] = nodCur.getUniqueIdToggableNode();
}
return strs;
}
}