Package org.geoforge.guillcogc.treenode

Source Code of org.geoforge.guillcogc.treenode.GfrNodCtrMovFolderTogPrjTloCbxSelOgcWmsWwdEarth

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

import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Logger;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import org.geoforge.guillc.handler.IGfrHandlerContainerObjects;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.guillc.tree.GfrTreAbs;
import org.geoforge.guillc.treenode.GfrNodAbs;
import org.geoforge.guillc.treenode.GfrSorterNodChildren;
import org.geoforge.guillcogc.popupmenu.GfrPmuCtlCtrFolderTloOgcWmsWwdEarthSel;
import org.geoforge.awt.image.GfrFactoryIconAbs;
import org.geoforge.guillcogc.enumeration.GfrEnuValuesKindObjectTloSpcPrjOgc;
import org.geoforge.ioogc.awt.image.GfrFactoryIconAppOgc;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.mdl.event.GfrEvtMdlIdAbs;
import org.geoforge.mdldatogc.GfrMdlDatIdObjTloOgcWms;
import org.geoforge.mdldatogc.event.GfrEvtMdlIdDatAddedLloVarWmsLyrLeaf;
import org.geoforge.mdldatogc.event.GfrEvtMdlIdDoneTreeArborWms;
import org.geoforge.wrpbasprsdsp.state.multiple.run.GfrWrpBasPrsDspPrjObjSecMltTogCbx;
import org.geoforge.wrpbasprsdsp.state.multiple.run.GfrWrpBasPrsDspPrjObjSecMltTogRbn;
import org.geoforge.wrpbasprsdsp.viewer.GfrWrpDspSynViewer;
import org.geoforge.wrpbasprssynogc.GfrWrpBasSynObjNameTloWms;

/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*/
public class GfrNodCtrMovFolderTogPrjTloCbxSelOgcWmsWwdEarth extends GfrNodCtrMovFolderTogPrjTloCbxSelOgcAbs implements
        IGfrHandlerContainerObjects
{
   // ----
   // begin: instantiate logger for this class

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

   static
   {
      GfrNodCtrMovFolderTogPrjTloCbxSelOgcWmsWwdEarth._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
   }
   // end: instantiate logger for this class
   // ----
   private ActionListener _alrParentPanelMvc_ = null;

   public GfrNodCtrMovFolderTogPrjTloCbxSelOgcWmsWwdEarth(
           ActionListener alrControllerSpcPrj,
           ActionListener alrControllerPrs,
           String strIdUnique,
           GfrTreAbs tre,
           ActionListener alrParentPanelMvc) throws Exception
   {
      super(
              alrControllerSpcPrj,
              alrControllerPrs,
              strIdUnique,
              GfrWrpBasSynObjNameTloWms.getInstance().getTitleService(strIdUnique),
              GfrEnuValuesKindObjectTloSpcPrjOgc.VALUE_TLO_WMS,
              tre);

      this._alrParentPanelMvc_ = alrParentPanelMvc;

      super._pop = new GfrPmuCtlCtrFolderTloOgcWmsWwdEarthSel(
              alrControllerSpcPrj,
              strIdUnique,
              tre);


      GfrMdlDatIdObjTloOgcWms.getInstance().addObserver((Observer) this);
   }

   @Override
   public void update(Observable obs, Object objEvt)
   {
      try
      {
         if (objEvt instanceof GfrEvtMdlIdDoneTreeArborWms)
         {
            GfrEvtMdlIdAbs evtId = (GfrEvtMdlIdAbs) objEvt;
            String strIdCandidate = evtId.getId();


            if (strIdCandidate.compareTo(super._strId) != 0)
               return;

            _loadChildren_();
         }
      }
      catch (Exception exc)
      {
         if (objEvt instanceof GfrEvtMdlIdDatAddedLloVarWmsLyrLeaf)
         {
            // don't care, allow deletion in another thread
            GfrNodCtrMovFolderTogPrjTloCbxSelOgcWmsWwdEarth._LOGGER_.info("exc caught, don't care, allow deletion in another thread");
            return;
         }

         exc.printStackTrace();
         String str = exc.getMessage();
         GfrNodCtrMovFolderTogPrjTloCbxSelOgcWmsWwdEarth._LOGGER_.severe(str);
         GfrOptionPaneAbs.s_showDialogError(null, str);
         return;
      }

      super.update(obs, objEvt);
   }

   @Override
   public void setSelected(boolean bln)
   {
      // memo: this order!

      try
      {
         _updateDisplayLayers_(super._strId, bln);
      }
      catch (Exception exc)
      {
         exc.printStackTrace();
         String str = exc.getMessage();
         GfrNodCtrMovFolderTogPrjTloCbxSelOgcWmsWwdEarth._LOGGER_.severe(str);
         GfrOptionPaneAbs.s_showDialogError(null, str);
         return;
      }

      super.setSelected(bln);
   }

   @Override
   public boolean init()
   {
      if (!super.init())
         return false;

      try
      {
         addAllObjects();
      }
      catch (Exception exc)
      {
         exc.printStackTrace();
         String str = exc.getMessage();
         GfrNodCtrMovFolderTogPrjTloCbxSelOgcWmsWwdEarth._LOGGER_.severe(str);
         return false;
      }

      return true;
   }

   @Override
   public void destroy()
   {
      GfrMdlDatIdObjTloOgcWms.getInstance().deleteObserver((Observer) this);

      super.destroy();

   }

   private void _updateDisplayLayers_(String strIdParent, boolean bln) throws Exception
   {
      String[] strsChildren = GfrWrpBasSynObjNameTloWms.getInstance().getAllIdsLayerLeafFromTop(strIdParent);

      if (bln)
      {
         for (int i = 0; i < strsChildren.length; i++)
         {
            GfrWrpDspSynViewer.s_getInstance().updateExistingViewersUnchecked(strsChildren[i]);
         }
      }
      else
      {
         for (int i = 0; i < strsChildren.length; i++)
         {
            GfrWrpBasPrsDspPrjObjSecMltTogCbx.getInstance().delete(strsChildren[i]);
            GfrWrpBasPrsDspPrjObjSecMltTogRbn.getInstance().delete(strsChildren[i]);
         }
      }
   }

   @Override
   public void addAllObjects() throws Exception
   {
      _loadChildren_();
   }

   @Override
   public void removeAllObjects() throws Exception
   {
      throw new UnsupportedOperationException("Not supported yet.");
   }

   private void _loadChildren_() throws Exception
   {
      String[] strsIdFolderChild = GfrWrpBasSynObjNameTloWms.getInstance().getIdsFolderTop(super._strId);

      _loadChildrenFolder_(strsIdFolderChild);

      String[] strsIdLeafChild = GfrWrpBasSynObjNameTloWms.getInstance().getIdsLeafTop(super._strId);

      _loadChildrenLeaf_(strsIdLeafChild);

      boolean blnShouldUpdate = false;

      if (strsIdFolderChild != null && strsIdFolderChild.length > 0)
         blnShouldUpdate = true;
      else if (strsIdLeafChild != null && strsIdLeafChild.length > 0)
         blnShouldUpdate = true;

      if (blnShouldUpdate)
      {
         DefaultTreeModel dtm = (DefaultTreeModel) super._tree.getModel();
         dtm.nodeStructureChanged(this);
      }
   }

   private void _loadChildrenFolder_(String[] strsId) throws Exception
   {
      if (strsId == null || strsId.length < 1)
         return;

      for (int i = 0; i < strsId.length; i++)
      {
         GfrNodCtrMovFolderLblLyrPrjWmsLyrAbs nodCur = new GfrNodCtrMovFolderLblLyrPrjWmsLyrWwdEarthSel(
                 super._alrControllerSpace,
                 super._alrControllerPerspective,
                 strsId[i],
                 super._tree,
                 this._alrParentPanelMvc_,
                 super._strId);

         _addObjectVariableNode_(nodCur);
      }
   }

   private void _loadChildrenLeaf_(String[] strsId) throws Exception
   {
      if (strsId == null || strsId.length < 1)
         return;

      for (int i = 0; i < strsId.length; i++)
      {
         GfrNodAbs nodCur = new GfrNodCtrMovLeafPrjLblLloLeafWmsWwdEarthSel(
                 super._alrControllerSpace,
                 super._alrControllerPerspective,
                 strsId[i],
                 super._strId,
                 super._tree);

         _addObjectVariableNode_(nodCur);
      }
   }

   private void _addObjectVariableNode_(GfrNodAbs nod) throws Exception
   {
      if (!nod.init())
      {
         GfrNodCtrMovFolderTogPrjTloCbxSelOgcWmsWwdEarth._LOGGER_.severe("! nod.init()");
         throw new Exception("! nod.init()");
      }

      String strName = (String) nod.getUserObject();
      int intPos = GfrSorterNodChildren.s_getPositionChildToAdd(this, strName);

      DefaultTreeModel dtm = (DefaultTreeModel) super._tree.getModel();
      dtm.insertNodeInto(nod, this, intPos);
      // IN COMMENTS COZ OF DISPLAY TBRL, LABEL BEING TRUNCATED AT THE END !!! I.E., AT IMPORT TIME
      //TreePath tphCur = new TreePath(nod.getPath());
      //if (!super._tree.isVisible(tphCur))
      {
         TreePath tphThis = new TreePath(this.getPath());
         super._tree.expandPath(tphThis);
      }
   }
}
TOP

Related Classes of org.geoforge.guillcogc.treenode.GfrNodCtrMovFolderTogPrjTloCbxSelOgcWmsWwdEarth

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.