/*
* 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.appogceclgsi.actioncontroller;
import java.io.File;
import java.util.Collection;
import java.util.logging.Logger;
import org.geoforge.appogcecl.actioncontroller.GfrAcrSpcAppMainOgcAbs;
import org.geoforge.appogceclgsi.actionmanager.GfrAmrAppMainGsi;
import org.geoforge.guillc.GfrAppSpcAbs;
import org.geoforge.guillc.action.ActionAboutPlugin;
import org.geoforge.guillc.action.ActionPluginDelete;
import org.geoforge.guillc.dialog.GfrDlgAbs;
import org.geoforge.guillc.dialog.GfrDlgCmdCancelAboutPlgLicNo;
import org.geoforge.guillc.dialog.GfrDlgCmdCancelAboutPlgLicYes;
import org.geoforge.guillc.filechooser.GfrUtilFileChooserVol;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.guillcogceclgsi.dialog.GfrDlgCmdCancelAboutAppGfrGsi;
import org.geoforge.guillcogceclgsi.dialog.GfrDlgManagePlgsGsi;
import org.geoforge.java.io.file.GfrJavIoFileExtension;
import org.geoforge.lang.util.GfrResBundleLang;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.mdldspgsi.plugin.GfrMdlDspPlgGsi;
import org.geoforge.mgrplg.handler.IGfrHandlerLicensingPlugin;
import org.geoforge.mgrplg.handler.IGfrHandlerPlugin;
import org.geoforge.mgrplg.impl.GfrPlgImplAbs;
import org.geoforge.mgrplggsi.GfrPluginManagerUtilGsi;
/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*/
public class GfrAcrSpcAppMainOgcEclGsi extends GfrAcrSpcAppMainOgcAbs
{
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrAcrSpcAppMainOgcEclGsi.class.getName());
static
{
GfrAcrSpcAppMainOgcEclGsi._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
public GfrAcrSpcAppMainOgcEclGsi(GfrAppSpcAbs app) throws Exception
{
super(app, new GfrAmrAppMainGsi());
super._acrActive = new GfrAcrSpcAppPrtRootOgcEclGsi(super._app);
}
@Override
public void aboutPluginHandler()
{
try
{
GfrPlgImplAbs plg = (GfrPlgImplAbs) ActionAboutPlugin.s_getInstance().getPlugin();
if (plg == null)
{
String strError = "plg == null";
throw new Exception(strError);
}
String strPathAbsBlackBox = GfrPluginManagerUtilGsi.s_getInstance().getPathAbsoluteCache(plg);
GfrDlgAbs dlg;
if (plg instanceof IGfrHandlerLicensingPlugin)
dlg = new GfrDlgCmdCancelAboutPlgLicYes(plg, strPathAbsBlackBox);
else
dlg = new GfrDlgCmdCancelAboutPlgLicNo(plg, strPathAbsBlackBox);
if (! dlg.init())
{
String strError = "! dlg.init()";
throw new Exception(strError);
}
dlg.setVisible(true);
}
catch(Exception exc)
{
exc.printStackTrace();
String strSevere = exc.getMessage();
GfrAcrSpcAppMainOgcEclGsi._LOGGER_.severe(strSevere);
GfrOptionPaneAbs.s_showDialogError(null, strSevere);
return;
}
}
/*
* MEMO: no dialog messages at launching time!
*/
@Override
protected void _activateLicensedPluginsAtLaunchTime()
{
Collection<IGfrHandlerPlugin> colPlgs = GfrPluginManagerUtilGsi.s_getInstance().getPlugins(IGfrHandlerPlugin.class);
super._activateLicensedPluginsAtLaunchTime(colPlgs);
}
/*
* choose JAR file
* check for valid plugin
* check whether not already installed
* copy file to ~/.../plugins/
*/
@Override
public void addPluginHandler()
{
try
{
File fleSource = GfrUtilFileChooserVol.s_getOpenFile(
null, //java.awt.Component,
GfrJavIoFileExtension.STRS_EXTENSION_PLUGIN,
GfrJavIoFileExtension.STR_DESCRIPTION_PLUGIN);
if (fleSource == null)
return; // cancelled by user
IGfrHandlerPlugin plg = GfrMdlDspPlgGsi.getInstance().add(fleSource);
super._addPluginHandler(plg);
}
catch(Exception exc)
{
exc.printStackTrace();
String strError = exc.getMessage();
GfrAcrSpcAppMainOgcEclGsi._LOGGER_.severe(strError);
GfrOptionPaneAbs.s_showDialogError(null, strError);
}
}
@Override
public void deletePluginHandler()
{
IGfrHandlerPlugin plg = ActionPluginDelete.s_getInstance().getPlugin();
if (plg == null)
{
String strError = "plg == null";
GfrAcrSpcAppMainOgcEclGsi._LOGGER_.severe(strError);
GfrOptionPaneAbs.s_showDialogInfo(null, strError);
return;
}
String strName = plg.getNamePlugin();
String strBody = "Are you sure you want to remove this plugin?";
strBody += "\n " + strName;
if (! GfrOptionPaneAbs.s_showDialogConfirm(null,
GfrResBundleLang.s_getInstance().getValue("verb.confirm"),
strBody))
return; // action cancellled by user
try
{
/*
* TODO: delete related internal frames if any
*/
boolean blnOk = GfrMdlDspPlgGsi.getInstance().remove(plg);
if (blnOk)
{
//plg.releasePlugin();
String strOk = "Successfully removed plugin named\n " + "\"" + strName + "\"";
GfrAcrSpcAppMainOgcEclGsi._LOGGER_.info(strOk);
}
else
{
// !!!
String strWrong = "Failed to delete properly plugin named\n " + "\"" + strName + "\"";
GfrAcrSpcAppMainOgcEclGsi._LOGGER_.severe(strWrong);
throw new Exception(strWrong);
}
}
catch(Exception exc)
{
exc.printStackTrace();
GfrAcrSpcAppMainOgcEclGsi._LOGGER_.severe(exc.getMessage());
GfrOptionPaneAbs.s_showDialogError(null, exc.getMessage());
}
}
@Override
public void deletePluginsHandler()
{
if (! GfrOptionPaneAbs.s_showDialogConfirm(null,
GfrResBundleLang.s_getInstance().getValue("verb.confirm"),
"Are you sure you want to remove all plugins?"))
return; // action cancellled by user
try
{
//GfrAcrAppMainOgcEclGsi._LOGGER_.info("TODO: delete related internal frames if any");
GfrMdlDspPlgGsi.getInstance().removeAll();
}
catch(Exception exc)
{
exc.printStackTrace();
String strError = exc.getMessage();
GfrAcrSpcAppMainOgcEclGsi._LOGGER_.severe(strError);
GfrOptionPaneAbs.s_showDialogError(null, strError);
}
}
/*
* should be "managePluginsHandler" BUT cannot for now refactor coz depend on Action's ID "plugins"
* MEMO: appending "Handler" in low-level class
*/
@Override
public void managePluginsHandler()
{
// ATTN: no call to destroy !!!
GfrDlgManagePlgsGsi.s_getInstance().setVisible(true);
}
@Override
public void aboutApplicationHandler()
{
GfrDlgAbs dlg = new GfrDlgCmdCancelAboutAppGfrGsi();
if (! dlg.init())
{
String strSevere = "! dlg.init()";
GfrAcrSpcAppMainOgcEclGsi._LOGGER_.severe(strSevere);
GfrOptionPaneAbs.s_showDialogError(null, strSevere);
return;
}
dlg.setVisible(true);
}
}