Package org.geoforge.appogcecl.actionperformer

Source Code of org.geoforge.appogcecl.actionperformer.ActPrfPrjConstructOgcAbs

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.geoforge.appogcecl.actionperformer;

import java.awt.event.ActionEvent;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.logging.Logger;
import javax.swing.JFrame;
import org.geoforge.guillc.dialog.GfrDlgPgsAbs;
import org.geoforge.guillc.frame.GfrFrmAbs;
import org.geoforge.guillc.menuitem.GfrMimTrsAlrNewEdt;
import org.geoforge.guillc.menuitem.GfrMimTrsAlrAbs;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.guillcogc.dialog.GfrDlgNewTloOgcWms;
import org.geoforge.guillcogc.dialog.GfrDlgPgsCreateOgcWms;
import org.geoforge.guillcogc.enumeration.GfrEnuValuesKindObjectTloSpcPrjOgc;
import org.geoforge.lang.enumeration.GfrEnuApplicationPropertiesImmutableKeys;
import org.geoforge.lang.util.GfrResBundleLang;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.mdldatogc.GfrMdlDatSetTlosOgcWms;
import org.geoforge.appogcecl.dummylocation.GfrGetterListDefaultWmssAbs;
import org.geoforge.wrpbasprssynogc.GfrWrpBasTopSynOgcWmss;

/**
*
* @author robert
*/
abstract public class ActPrfPrjConstructOgcAbs extends ActPrfAbs
{
   // ----
   // begin: instantiate logger for this class

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

   static
   {
      ActPrfPrjConstructOgcAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
   }
   // end: instantiate logger for this class
   // ----
  
   abstract protected void _newEditTloOgcWms(JFrame frmOwner) throws Exception;

   @Override
   public boolean doneJob(ActionEvent evt) throws Exception
   {

      Object objEvent = evt.getSource();
     
     
      //--- beg new tlo by editing
      if (objEvent instanceof GfrMimTrsAlrNewEdt)
      {
         GfrMimTrsAlrAbs mim = (GfrMimTrsAlrAbs) objEvent;
         JFrame frmOwner = GfrFrmAbs.s_getFrameOwnerTrickForActionController(mim);

         String strValueKindObject = mim.getPropertyImmutable(
                 GfrEnuApplicationPropertiesImmutableKeys.KEY_KIND_OBJECT.name());


         //--
         if (strValueKindObject == null || strValueKindObject.length() <1)
            return false;
     
         //--
        
         if (strValueKindObject.compareTo(GfrEnuValuesKindObjectTloSpcPrjOgc.VALUE_TLO_WMS.name()) == 0)
         {
            _newEditTloOgcWms(frmOwner);
            return true;
         }
      }
      //--- end new tlo by editing
      // ending
      return false;
   }

   // ---
   protected ActPrfPrjConstructOgcAbs()
   {
      super();
   }

   // ---
   protected void _newEditTloOgcWms(
           JFrame frmOwner,
           GfrGetterListDefaultWmssAbs get) throws Exception
   {
      String[] strsChildrenExisting = GfrWrpBasTopSynOgcWmss.getInstance().getSortedNamesTlo();

      String[] strsDefaultServerUrl = get.getDefaultServerUrls();
      String[] strsDefaultServerTitle = get.getDefaultServerTitles();

      String[] strsDefaultWhat = get.getDefaultWhat();
      String[] strsDefaultWho = get.getDefaultWho();
      String[] strsDefaultUrlHomePage = get.getDefaultUrlHomePage();

      // show dialog
      GfrDlgNewTloOgcWms dlg = new GfrDlgNewTloOgcWms(
              frmOwner,
              (String[]) strsChildrenExisting,
              strsDefaultServerTitle,
              strsDefaultServerUrl,
              strsDefaultWho,
              strsDefaultWhat,
              strsDefaultUrlHomePage);

      if (!dlg.init())
      {
         String str = "! dlg.init()";
         ActPrfPrjConstructOgcAbs._LOGGER_.severe(str);
         throw new Exception(str);
      }

      dlg.setVisible(true);

      boolean blnCancelled = dlg.isCancelled();

      String strValue = null;
      String strDescShort = null;
      String strUrl = null;

      if (!blnCancelled)
      {
         strValue = dlg.getValue();
         strDescShort = dlg.getValueDescShort();
         strUrl = dlg.getWmsProviderWebSite();
      }

      dlg.destroy();
      dlg = null;

      if (blnCancelled)
         return;

      // beg handling current bug

      if (strValue == null || strValue.length() < 1)
      {
         String str = "strUrl == null || strUrl.length()<1";
         ActPrfPrjConstructOgcAbs._LOGGER_.severe(str);
         GfrOptionPaneAbs.s_showDialogError(null, "Dev coding error: " + str);

         return;
      }

      // beg code to be located in "new wms" dialog

      try
      {
         URL url = new URL(strValue);
         URLConnection conn = url.openConnection();
         conn.connect();
         // !!! release connection !!!
      }
      catch (MalformedURLException e)
      {
         e.printStackTrace();

         String str = GfrResBundleLang.s_getInstance().getValue("sentence.sorryMalformedUrl")
                 + "\n   " + strValue;

         // the URL is not in a valid form
         ActPrfPrjConstructOgcAbs._LOGGER_.severe(str);
         GfrOptionPaneAbs.s_showDialogError(null, "Dev coding error: " + str);
         return;
      }
      catch (IOException e)
      {
         e.printStackTrace();
         String str = GfrResBundleLang.s_getInstance().getValue("sentence.failedToCOnnectToUrl")
                 + "\n   " + strValue;

         str += "\n\n";
         str += "Message:\n" + e.getMessage();
         ActPrfPrjConstructOgcAbs._LOGGER_.severe(str);
         GfrOptionPaneAbs.s_showDialogWarning(null, str);
         return;
      }

      // end handling current bug


      String strId = GfrMdlDatSetTlosOgcWms.getInstance().newObject(
              strValue,
              strDescShort,
              strUrl,
              frmOwner);

      GfrDlgPgsAbs dlgProgress = new GfrDlgPgsCreateOgcWms(
              frmOwner,
              strValue,
              strId);

      if (!dlgProgress.init())
      {
         String str = "! dlgProgress.init()";
         ActPrfPrjConstructOgcAbs._LOGGER_.severe(str);
         throw new Exception(str);
      }

   }
}
TOP

Related Classes of org.geoforge.appogcecl.actionperformer.ActPrfPrjConstructOgcAbs

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.