Package org.geoforge.guillcogc.treenode

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

/*
*  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.panel.GfrPnlStatusBarAbs;
import org.geoforge.guillc.tree.GfrTreAbs;
import org.geoforge.guillc.treenode.GfrNodAbs;
import org.geoforge.guillc.treenode.GfrNodCtrMovFolderTogSecCbxAbs;
import org.geoforge.guillc.treenode.GfrSorterNodChildren;
import org.geoforge.guillcogc.enumeration.GfrEnuValuesKindObjectTloSpcPrjOgc;
import org.geoforge.guillcogc.popupmenu.GfrPmuCtlCtrFolderTloOgcWmsWwdEarthSec;
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.wrpbasprssynogc.GfrWrpBasSynObjNameTloWms;


/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*/
public class GfrNodCtrMovFolderTogSecCbxTloWmsWwdEarth extends GfrNodCtrMovFolderTogSecCbxAbs implements
        IGfrHandlerContainerObjects
{
    // ----
    // begin: instantiate logger for this class
    final private static Logger _LOGGER_ = Logger.getLogger(GfrNodCtrMovFolderTogSecCbxTloWmsWwdEarth.class.getName());

    static
    {
        GfrNodCtrMovFolderTogSecCbxTloWmsWwdEarth._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
    }

    // end: instantiate logger for this class
    // ----
   
    private ActionListener _alrParentPanelMvc_ = null;
   
    public GfrNodCtrMovFolderTogSecCbxTloWmsWwdEarth(
            ActionListener alrControllerSpcPrj,
            ActionListener alrControllerPrs,
            String strIdViewer,
            String strIdUnique,
            GfrTreAbs tre,
            ActionListener alrParentPanelMvc,
            GfrPnlStatusBarAbs pnlStatusBar
            ) throws Exception
    {
        super(
                alrControllerSpcPrj,
                alrControllerPrs,
                strIdUnique,
              GfrWrpBasSynObjNameTloWms.getInstance().getTitleService(strIdUnique),
              tre,
              pnlStatusBar,
              strIdViewer,
              GfrEnuValuesKindObjectTloSpcPrjOgc.VALUE_TLO_WMS);
       
        this._alrParentPanelMvc_ = alrParentPanelMvc;
       
       
        super._pop = new GfrPmuCtlCtrFolderTloOgcWmsWwdEarthSec(
              alrControllerSpcPrj,
              strIdUnique,
              tre,
              strIdViewer);
       
       
      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
            GfrNodCtrMovFolderTogSecCbxTloWmsWwdEarth._LOGGER_.info("exc caught, don't care, allow deletion in another thread");
            return;
         }

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

      super.update(obs, objEvt);
   }
   
    @Override
    public void setSelected(boolean isSelected)
    {
       super.setSelected(isSelected);
    }
   
     @Override
   public boolean init()
   {
      if (!super.init())
         return false;

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

      return true;
   }
    
     @Override
   public void destroy()
   {
       GfrMdlDatIdObjTloOgcWms.getInstance().deleteObserver((Observer) this);
      
      super.destroy();
   }

   @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 GfrNodCtrMovFolderLblLyrPrjWmsLyrWwdEarthSec(
                 super._alrControllerSpace,
                 super._alrControllerPerspective,
                 strsId[i],
                 super._tree,
                 this._alrParentPanelMvc_,
                 super._strId,
                 this._strIdViewer_);
               
         _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 GfrNodCtrMovLeafPrjLblLloLeafWmsWwdEarthSec(
               super._alrControllerSpace,
               super._alrControllerPerspective,
               strsId[i],
               super._strId,
               this._strIdViewer_,
               super._tree,
               this._alrParentPanelMvc_
                 );
        
        
         _addObjectVariableNode_(nodCur);
      }
   }
  
   private void _addObjectVariableNode_(GfrNodAbs nod) throws Exception
    {
       if (! nod.init())
       {
          GfrNodCtrMovFolderTogSecCbxTloWmsWwdEarth._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.GfrNodCtrMovFolderTogSecCbxTloWmsWwdEarth

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.