/*
* 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.util.HashSet;
import javax.swing.JButton;
import org.geoforge.guillc.menuitem.GfrMimActPlg;
import org.geoforge.mgrplg.handler.IGfrHandlerPlugin;
/**
*
* @author robert
*/
abstract public class GfrPmuBtnPlgsActAbs extends GfrPmuBtnPlgsAbs
{
protected GfrPmuBtnPlgsActAbs(JButton btnOwner)
{
super(btnOwner);
}
@Override
protected void _remove(IGfrHandlerPlugin plg)
{
HashSet<GfrMimActPlg> hstMimToRemove = new HashSet<GfrMimActPlg>();
for (int i=0; i<super.getComponentCount(); i++)
{
GfrMimActPlg mimCur = (GfrMimActPlg) super.getComponent(i);
if (plg != mimCur.getPlugin())
continue;
hstMimToRemove.add(mimCur);
}
if (hstMimToRemove.isEmpty())
{
hstMimToRemove = null; // gc
return;
}
for (GfrMimActPlg mimCur: hstMimToRemove)
{
super.remove(mimCur);
mimCur.destroy();
}
if (super.getComponentCount() < 1)
super._btnOwner.setEnabled(false);
hstMimToRemove.clear();
hstMimToRemove = null; // gc
}
}