Package org.geoforge.gfrplgimportshapesgeojson4gfr.swing.dialog

Source Code of org.geoforge.gfrplgimportshapesgeojson4gfr.swing.dialog.GfrDlgPgsImpShpsGeojson

/*
*  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 2
*  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, write to the Free Software
*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package org.geoforge.gfrplgimportshapesgeojson4gfr.swing.dialog;

import java.util.EventObject;
import java.util.logging.Logger;
import javax.swing.JFrame;
import org.geoforge.gfrplgimportshapesgeojson4gfr.lang.thread.GfrPgsThrImpShpsGeojson;
import org.geoforge.guillc.dialog.GfrDlgPgsBldObjsAbs;
import org.geoforge.guillc.thread.GfrPgsThrIdsBldAbs;
import org.geoforge.lang.handler.IGfrHandlerEventListenerThreadJobProgress;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.mdldatecl.*;

/**
*
* @author bantchao@gmail.com
*/
public class GfrDlgPgsImpShpsGeojson extends GfrDlgPgsBldObjsAbs
{
   // ----
   // begin: instantiate logger for this class

   final private static Logger _LOGGER_ = Logger.getLogger(GfrDlgPgsImpShpsGeojson.class.getName());

   static
   {
      GfrDlgPgsImpShpsGeojson._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
   }
   // end: instantiate logger for this class
   // ----
  
   private String _strSourceGeojson_ = null;
  
   public GfrDlgPgsImpShpsGeojson(
           JFrame frmOwner,
           String strSourceGeojson)
   {
      super(frmOwner,
            "Import earth shapes from GeoJSON", // strTitleWhat
            strSourceGeojson);
     
      this._strSourceGeojson_ = strSourceGeojson;
   }
  
   @Override
   public boolean init()
   {
      if (! super.init())
         return false;

   
      try
      {
         if (! super._blnCancelled)  
         {
             super.pack();
             super.setVisible(true);
            
            super._thr = new GfrPgsThrImpShpsGeojson(
               (IGfrHandlerEventListenerThreadJobProgress) this,
               super._pbr,
               super._lbl,
               this._strSourceGeojson_
                    );
      
         }
        
         else
         {
            if (super._frmOwner != null)
            {
               super._frmOwner.setEnabled(true);
               this._frmOwner.toFront();
            }
         }

      }
     
      catch (Exception exc)
      {
         if (super._frmOwner != null)
         {
            super._frmOwner.setEnabled(true);
            this._frmOwner.toFront();
         }
        
         if (super._blnCancelled)
         {
            GfrDlgPgsImpShpsGeojson._LOGGER_.info("super._blnCancelled");
            return true;
         }
        
         exc.printStackTrace();
         String str = exc.getMessage();
         GfrDlgPgsImpShpsGeojson._LOGGER_.severe(str);
         return false;
      }

      return true;
   }
  
   @Override
   public void handleEventThreadJobDone(EventObject e)
   {
      super.setVisible(false);
   
      GfrDlgPgsImpShpsGeojson._LOGGER_.info("IN PROGRESS");
       
      super.handleEventThreadJobDone(e);
   }
  
   @Override
   protected void _invokeLaterCleanUp()
   {
      _invokeLaterCleanUp_();
   }
  
   private void _invokeLaterCleanUp_()
   {
      try
      {
         while (super._thr!=null &&
              !((GfrPgsThrIdsBldAbs) super._thr).isDoneJob()
              )
         {
            try
            {
               Thread.sleep(100);
              
               if (super._blnCancelled)
                  break;
            }
            catch (Exception exc)
            {
               // TODO: workaround? user should manually remove elements!
               /*System.err.println(exc.getMessage());
               super._invokeLaterCleanUp();
               return;*/
               break;
              
            }
         }
      }
     
      catch(Exception exc)
      {
         /*exc.printStackTrace();
         System.err.println(exc.getMessage());
         super._invokeLaterCleanUp();
         return;*/
        
      }
     
      // ---
     
     
     
     
      if (super._thr != null)
      {
         java.util.Set<String> setIds = null;
        
         // ---
         setIds = ((GfrPgsThrImpShpsGeojson) super._thr).getCreatedIdsSector();
        
         if (setIds!=null && !setIds.isEmpty())
         {
            try
            {
               for (String strCur: setIds)
                  GfrMdlDatSetTlosEclSct.getInstance().deleteObjectWithId(strCur);

            }
            catch (Exception exc)
            {
               // don't care
            }
         }
        
         // ---
         setIds = ((GfrPgsThrImpShpsGeojson) super._thr).getCreatedIdsPoint();
        
         if (setIds!=null && !setIds.isEmpty())
         {
            try
            {
               for (String strCur: setIds)
                  GfrMdlDatSetTlosEclPnt.getInstance().deleteObjectWithId(strCur);

            }
            catch (Exception exc)
            {
               // don't care
            }
         }
        
         // ---
         setIds = ((GfrPgsThrImpShpsGeojson) super._thr).getCreatedIdsPath();
        
         if (setIds!=null && !setIds.isEmpty())
         {
            try
            {
               for (String strCur: setIds)
                  GfrMdlDatSetTlosEclPth.getInstance().deleteObjectWithId(strCur);

            }
            catch (Exception exc)
            {
               // don't care
            }
         }
        
         // ---
         setIds = ((GfrPgsThrImpShpsGeojson) super._thr).getCreatedIdsArea();
        
         if (setIds!=null && !setIds.isEmpty())
         {
            try
            {
               for (String strCur: setIds)
                  GfrMdlDatSetTlosEclAre.getInstance().deleteObjectWithId(strCur);

            }
            catch (Exception exc)
            {
               // don't care
            }
         }
        
         // ---
         setIds = ((GfrPgsThrImpShpsGeojson) super._thr).getCreatedIdsPointset();
        
         if (setIds!=null && !setIds.isEmpty())
         {
            try
            {
               for (String strCur: setIds)
                  GfrMdlDatSetTlosEclSpn.getInstance().deleteObjectWithId(strCur);

            }
            catch (Exception exc)
            {
               // don't care
            }
         }
      }
     
      super._invokeLaterCleanUp();
   }
}
TOP

Related Classes of org.geoforge.gfrplgimportshapesgeojson4gfr.swing.dialog.GfrDlgPgsImpShpsGeojson

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.