Package org.geoforge.guillcogc.dialog

Source Code of org.geoforge.guillcogc.dialog.GfrDlgPgsCreateOgcWms

/*
*  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.guillcogc.dialog;

import java.awt.BorderLayout;
import java.util.EventObject;
import java.util.logging.Logger;
import javax.swing.*;
import org.geoforge.guillc.dialog.GfrDlgPgsAbs;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.guillcogc.util.GfrResBundleGuiLlcOgc;
import org.geoforge.guillcogc.thread.GfrPgsThrOgcWmsCreate;
import org.geoforge.lang.util.eventobject.GfrEventObjectAbs;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.mdldatogc.GfrMdlDatSetTlosOgcWms;
import org.geoforge.lang.handler.IGfrHandlerEventListenerThreadJobProgress;
import org.geoforge.lang.util.GfrResBundleLang;

/**
*
* @author bantchao
*/
public class GfrDlgPgsCreateOgcWms extends GfrDlgPgsAbs implements
        IGfrHandlerEventListenerThreadJobProgress
{
   // ----
   // begin: instantiate logger for this class

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

   static
   {
      GfrDlgPgsCreateOgcWms._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
   }
   // end: instantiate logger for this class
   // ----
  
   private String _strId_ = null;

   public GfrDlgPgsCreateOgcWms(
           JFrame frmOwner,
           String strMessage,
           String strId)
   {
      super(frmOwner,
              strMessage,
              GfrResBundleGuiLlcOgc.s_getInstance().getValue("sentence.newWmsServiceByEditing"),
              GfrResBundleGuiLlcOgc.s_getInstance().getValue("sentence.retrievingInformationsFromWmsService"),
              BorderLayout.CENTER);

      this._strId_ = strId;
   }

   @Override
   public boolean init()
   {
      if (! super.init())
         return false;
     
     
      try
      {
         if (! super._blnCancelled)  
         {
             super.pack();
             super.setVisible(true);
            
            super._thr = new GfrPgsThrOgcWmsCreate(this._strId_,
                 (IGfrHandlerEventListenerThreadJobProgress) this, super._pbr, super._lbl);
           
          
         }

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

   @Override
   public void handleEventThreadJobDone(EventObject e)
   {
      GfrEventObjectAbs evt = (GfrEventObjectAbs) e;
     
      String strError = evt.getError();
     
      if (strError == null)
      {
         destroy();
         return;
      }
     
      if (super._blnCancelled) // !!!
      {
         destroy();
         return;
      }
     

      String strWarning = "Failed to load WMS maps from server";

      strWarning += "\n\n";
      strWarning += GfrResBundleLang.s_getInstance().getValue("word.details") + "\n";

      int intLastIndexComma = strError.lastIndexOf("http");

      if (intLastIndexComma != -1)
      {
         strWarning += "   " + strError.substring(0, intLastIndexComma-1);

         int intVal = intLastIndexComma + "http".length() -1;

         if (intVal != strError.length()-1)
         {
            strWarning += "\n";
            strWarning += "   " + strError.substring(intLastIndexComma);
         }

         else
            strWarning += "http"; // done in a hurry!!!!
      }

      else
         strWarning += "   " + strError;       

      GfrOptionPaneAbs.s_showDialogWarning(super._frmOwner, strWarning);

      javax.swing.SwingUtilities.invokeLater(new Runnable()
      {
            @Override
            public void run()
            {
               _invokeLaterCleanUp();
               destroy();
            }
      });
   
     
     
   }

   @Override
   protected void _invokeLaterCleanUp()
   {
      try
      {
         GfrMdlDatSetTlosOgcWms.getInstance().deleteObjectWithId(this._strId_);
      }
     
      catch(Exception exc)
      {
         exc.printStackTrace();
         GfrDlgPgsCreateOgcWms._LOGGER_.severe(exc.getMessage());
      }
     
      destroy();
   }
}
TOP

Related Classes of org.geoforge.guillcogc.dialog.GfrDlgPgsCreateOgcWms

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.