/*
* 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.menu;
import java.util.logging.Logger;
import org.geoforge.guillc.menuitem.GfrMimAlrHlpOflAllContentsAbs;
import org.geoforge.guillc.menuitem.GfrMimAlrHlpOflAllContentsAppToPlg;
import org.geoforge.io.awt.image.GfrFactoryIconAppGfr;
import org.geoforge.lang.util.GfrResBundleLang;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.mgrplg.handler.IGfrHandlerPlugin;
import org.geoforge.mgrplg.handler.IGfrHandlerPluginHelp;
/**
*
* @author robert
*/
abstract public class GfrMenPlgsHlpMainAbs extends GfrMenPlgsAbs
{
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrMenPlgsHlpMainAbs.class.getName());
static
{
GfrMenPlgsHlpMainAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// ---
protected GfrMenPlgsHlpMainAbs()
{
super(
GfrResBundleLang.s_getInstance().getValue("sentence.pluginsHelps"),
GfrFactoryIconAppGfr.s_getPluginsHelp(GfrFactoryIconAppGfr.INT_SIZE_XXSMALL));
}
@Override
protected void _add(IGfrHandlerPlugin plg)
{
if (! (plg instanceof IGfrHandlerPluginHelp))
return;
if (! plg.isValidPlugin())
return;
if (_addValid((IGfrHandlerPluginHelp) plg))
{
if (! super.isEnabled())
super.setEnabled(true);
}
}
@Override
protected void _remove(IGfrHandlerPlugin plg)
{
if (! (plg instanceof IGfrHandlerPluginHelp))
return;
for (int i=0; i<super.getMenuComponentCount(); i++)
{
GfrMimAlrHlpOflAllContentsAppToPlg mimCur = (GfrMimAlrHlpOflAllContentsAppToPlg) super.getMenuComponent(i);
if (plg != mimCur.getPlugin())
continue;
super.remove(mimCur);
mimCur.destroy();
break;
}
if (super.getMenuComponentCount() < 1)
super.setEnabled(false);
}
protected boolean _addValid(IGfrHandlerPluginHelp plg)
{
try
{
GfrMimAlrHlpOflAllContentsAbs mim = new GfrMimAlrHlpOflAllContentsAppToPlg(plg);
if (! mim.init())
{
String strWhat = "Failed to init menuItem";
super._showDialogFailedPlugin(plg, strWhat);
return false;
}
super.add(mim);
return true;
}
catch(Exception exc)
{
exc.printStackTrace();
String strWhat = exc.getMessage();
GfrMenPlgsHlpMainAbs._LOGGER_.warning(strWhat);
super._showDialogFailedPlugin(plg, strWhat);
return false;
}
catch(AbstractMethodError errAbstractMethod)
{
errAbstractMethod.printStackTrace();
String strWhat = errAbstractMethod.getMessage();
GfrMenPlgsHlpMainAbs._LOGGER_.warning(strWhat);
super._showDialogFailedPlugin(plg, strWhat);
return false;
}
}
}