/*
* 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.panel;
import gov.nasa.worldwind.formats.shapefile.DBaseRecord;
import gov.nasa.worldwind.formats.shapefile.ShapefileRecord;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import javax.swing.event.DocumentListener;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.worldwind.formats.shapefile.OurShapefileLoaderLineClosed;
/**
*
* @author bill
*/
abstract public class GfrPnlContentsOkImportShapeTloLineClosedAbs extends GfrPnlContentsOkImportShapeTloAbs
{
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrPnlContentsOkImportShapeTloLineClosedAbs.class.getName());
static
{
GfrPnlContentsOkImportShapeTloLineClosedAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
@Override
abstract public void doJob() throws Exception;
protected GfrPnlContentsOkImportShapeTloLineClosedAbs(
DocumentListener dlrParentDialog,
String[] strsExistingLabels)
{
super(dlrParentDialog, strsExistingLabels);
super._pnlSettings = new GfrPnlSettingsImportFileShapeTlo(
dlrParentDialog,
(ActionListener) this);
}
@Override
protected boolean _check(File fle) throws Exception
{
super._check(fle);
Object objSource = (Object) fle;
super._altRec = OurShapefileLoaderLineClosed.s_getRecordsPolygon(objSource);
if (super._altRec==null || super._altRec.size()<1)
{
String strLog = "super._altRec==null || super._altRec.size()<1, fle.getAbsolutePath()=" + fle.getAbsolutePath();
GfrPnlContentsOkImportShapeTloLineClosedAbs._LOGGER_.warning(strLog);
String strWarning = "No valid records found in file";
strWarning += "\n" + fle.getAbsolutePath();
throw new Exception(strWarning);
}
ShapefileRecord sfr1 = super._altRec.get(0);
DBaseRecord brd = sfr1.getAttributes();
Set<Map.Entry<String, Object>> setAttributes = brd.getEntries();
if (brd == null)
{
String str = "brd == null, fle.getAbsolutePath()=" + fle.getAbsolutePath();
GfrPnlContentsOkImportShapeTloLineClosedAbs._LOGGER_.warning(str);
throw new Exception(str);
}
if (setAttributes==null || setAttributes.isEmpty()) // TODO: let user enter an unused predix for labels
{
String strWarning = "No valid attributes associated with records of file";
strWarning += "\n" + fle.getAbsolutePath();
GfrPnlContentsOkImportShapeTloLineClosedAbs._LOGGER_.warning(strWarning);
GfrOptionPaneAbs.s_showDialogError(null, strWarning);
return false;
}
super._strsAtrributeKey = new String[setAttributes.size()];
int intCount = 0;
Iterator itr = setAttributes.iterator();
while (itr.hasNext())
{
Map.Entry<String, Object> map = (Map.Entry<String, Object>) itr.next();
String strKey = map.getKey();
super._strsAtrributeKey[intCount] = strKey;
intCount++;
}
return true;
}
}