Package org.geoforge.guillc.treenode

Source Code of org.geoforge.guillc.treenode.GfrNodCtrMovFolderTogSecCbxSetVarAbs

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

import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Observable;
import java.util.logging.Logger;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import org.geoforge.guillc.handler.IGfrHandlerContainerObjectsVariableNode;
import org.geoforge.guillc.handler.IGfrHandlerDisplayableObjectsSet;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.guillc.panel.GfrPnlStatusBarAbs;
import org.geoforge.guillc.tree.GfrTreAbs;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.mdl.event.GfrEvtMdlIdAbs;
import org.geoforge.mdldat.event.GfrEvtMdlIdDatAddedMlo;
import org.geoforge.mdldat.event.GfrEvtMdlIdDatRemovedAllMlo;
import org.geoforge.mdldat.event.GfrEvtMdlIdDatRemovedMlo;
import org.geoforge.mdldat.event.GfrEvtMdlIdDatRenamedMlo;

/**
*
* @author bantchao
*
*/
abstract public class GfrNodCtrMovFolderTogSecCbxSetVarAbs extends GfrNodCtrMovFolderTogSecCbxSetAbs implements
        IGfrHandlerContainerObjectsVariableNode
{
   // ----
   // begin: instantiate logger for this class

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

   static
   {
      GfrNodCtrMovFolderTogSecCbxSetVarAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
   }
   // end: instantiate logger for this class
   // ----
  
   protected GfrNodCtrMovFolderTogSecCbxSetVarAbs(
           ActionListener alrControllerSpcPrj,
           ActionListener alrControllerPrs,
            String strIdViewer,
            String strIdUnique,
            String strName,
            GfrTreAbs tre,
            GfrPnlStatusBarAbs pnlStatusBar,
            ActionListener alrParentPanelMvc,
           IGfrHandlerDisplayableObjectsSet enuKindObject)
           throws Exception
   {
      super(alrControllerSpcPrj,
              alrControllerPrs,
              strIdViewer,
              strIdUnique,
              strName,
              tre,
              pnlStatusBar,
              alrParentPanelMvc,
              enuKindObject)
     
      addAllObjects();
   }

   @Override
   public boolean removeObjectVariable(String strId) throws Exception
   {
      for (int i=0; i<super.getChildCount(); i++)
      {
         GfrNodCtrMovAbs nodCur = (GfrNodCtrMovAbs) super.getChildAt(i);
         String strIdCur = nodCur.getId();
        
         if (strIdCur.compareTo(strId) != 0)
            continue;
        
         DefaultTreeModel dtm = (DefaultTreeModel) super._tree.getModel();
         dtm.removeNodeFromParent(nodCur);
         nodCur.releaseTransient();
         nodCur.destroy();
         return false;
      }
        
      return false;
   }
   
    @Override
   public void removeAllObjects() throws Exception
   {
      if (super.getChildCount() < 1)
         return;
     
        ArrayList<GfrNodCtrAbs> nodsChild = new ArrayList<GfrNodCtrAbs>();
       
        for (int i=0; i<super.getChildCount(); i++)
        {
            GfrNodCtrAbs nodCur = (GfrNodCtrAbs) super.getChildAt(i);
            nodsChild.add(nodCur);
        }
       
        for (int i=0; i<nodsChild.size(); i++)
        {
            GfrNodCtrAbs nodCur =  nodsChild.get(i);
            nodCur.removeFromParent();
        }
       
        DefaultTreeModel dtm = (DefaultTreeModel) super._tree.getModel();
        dtm.nodeStructureChanged(this);
       
        // TODO: something wtith nodCur's children
        for (int i=0; i<nodsChild.size(); i++)
        {
            GfrNodCtrAbs nodCur =  nodsChild.get(i);
            nodCur.releaseTransient();
            nodCur.destroy();
            nodCur = null;
        }
       
        nodsChild.clear();
        nodsChild = null;
   }
   
    @Override
    public void update(Observable obs, Object objEvt)
    {
       try
       {
          if (objEvt instanceof GfrEvtMdlIdDatAddedMlo)
          {
             GfrEvtMdlIdDatAddedMlo mdl = (GfrEvtMdlIdDatAddedMlo) objEvt;
             String strIdParent = mdl.getIdParent();

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

             String strIdChild = mdl.getId();
             addObjectVariable(strIdChild);
             return;
          }
         
          if (objEvt instanceof GfrEvtMdlIdDatRemovedMlo)
         {
            GfrEvtMdlIdDatRemovedMlo evt = (GfrEvtMdlIdDatRemovedMlo) objEvt;
            String strIdParent = evt.getIdParent();

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

            String strIdChild = evt.getId();
            removeObjectVariable(strIdChild);
            return;
         }
        
         if (objEvt instanceof GfrEvtMdlIdDatRenamedMlo)
         {
            GfrEvtMdlIdDatRenamedMlo evt = (GfrEvtMdlIdDatRenamedMlo) objEvt;
            String strIdParent = evt.getIdParent();

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

            String strIdChild = evt.getId();
            String strNameNewChild = evt.getValueNew();
            _renameObject_(strIdChild, strNameNewChild);
            return;
         }
        
         if (objEvt instanceof GfrEvtMdlIdDatRemovedAllMlo)
         {
            GfrEvtMdlIdAbs evt = (GfrEvtMdlIdAbs) objEvt;
            String strId = evt.getId();

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

            removeAllObjects();
            return;
         }
       }
      
       catch(Exception exc)
       {
          exc.printStackTrace();
          String str = exc.getMessage();
          GfrNodCtrMovFolderTogSecCbxSetVarAbs._LOGGER_.severe(str);
          GfrOptionPaneAbs.s_showDialogError(null, str);
          System.exit(1);
       }
      
       super.update(obs, objEvt);
    }
   
    @Override
   public void _addObjectVariableNode(GfrNodAbs nod) throws Exception
    {
       if (! nod.init())
       {
          GfrNodCtrMovFolderTogSecCbxSetVarAbs._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);
      }
    }
   
    private void _renameObject_(String strIdChild, String strNameNewChild)
           throws Exception
   {
      for (int i=0; i<super.getChildCount(); i++)
      {
         GfrNodCtrMovAbs nodCur = (GfrNodCtrMovAbs) super.getChildAt(i);
         String strIdCur = nodCur.getId();
        
         if (strIdCur.compareTo(strIdChild) != 0)
            continue;
        
         String strNameCur = (String) nodCur.getUserObject();
        
         if (strNameCur.compareTo(strNameNewChild) == 0)
            return;
        
         nodCur.setUserObject(strNameNewChild);
         DefaultTreeModel dtm = (DefaultTreeModel) super._tree.getModel();
         dtm.nodeChanged(nodCur);
         return;
     
   }
}
TOP

Related Classes of org.geoforge.guillc.treenode.GfrNodCtrMovFolderTogSecCbxSetVarAbs

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.