Package org.geoforge.guillc.treenode

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

/*
*  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.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.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
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*/
abstract public class GfrNodCtrMovFolderLblTloPrjCntVarAbs extends GfrNodCtrMovFolderLblTloPrjAbs implements
        IGfrHandlerContainerObjectsVariableNode
{
   // ----
   // begin: instantiate logger for this class

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

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

   // end: instantiate logger for this class
   // ----
   protected GfrNodCtrMovFolderLblTloPrjCntVarAbs(
           ActionListener alrControllerSpcPrj,
           ActionListener alrControllerPrs,
           ActionListener alrParentPanelMvc,
           String strId,
           String strName,
           IGfrHandlerDisplayableObjectsSet enuValueKindObjectTlo,
           GfrTreAbs tre)
           throws Exception
   {
      super(alrControllerSpcPrj,
              alrControllerPrs,
              alrParentPanelMvc,
              strId,
              strName,
              enuValueKindObjectTlo,
              tre);

      addAllObjects();
   }

   @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 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 true;
      }

      return false;
   }

   @Override
   public void update(Observable obs, Object objEvt)
   {
      try
      {
         if (objEvt instanceof GfrEvtMdlIdDatAddedMlo)
         {
            GfrEvtMdlIdDatAddedMlo evt = (GfrEvtMdlIdDatAddedMlo) objEvt;
            String strIdParent = evt.getIdParent();

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

            String strIdChild = evt.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();
         GfrNodCtrMovFolderLblTloPrjCntVarAbs._LOGGER_.severe(str);
         GfrOptionPaneAbs.s_showDialogError(null, str);
         return;
      }


      super.update(obs, objEvt);
   }

   @Override
   public void _addObjectVariableNode(GfrNodAbs nod) throws Exception
   {
      if (!nod.init())
      {
         GfrNodCtrMovFolderLblTloPrjCntVarAbs._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.GfrNodCtrMovFolderLblTloPrjCntVarAbs

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.