Package org.geoforge.guillc.tablemodel

Source Code of org.geoforge.guillc.tablemodel.GfrAtmManagePlgs

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

import java.util.logging.Logger;
import org.geoforge.guillc.table.tablecellrenderer.GfrImplTableCellRendererLblBlnIcn;
import org.geoforge.guillc.table.tablecellrenderer.GfrImplTableCellRendererVpt;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.lang.util.GfrResBundleLang;
import org.geoforge.mgrplg.handler.IGfrHandlerPlugin;

/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*/

public class GfrAtmManagePlgs extends GfrAtmAbs
{
   static public int s_getColumnValueName() { return 0; }
   static public int s_getColumnValueVersion() { return s_getColumnValueName() + 1; }
   static public int s_getColumnValueAuthor() { return s_getColumnValueVersion() + 1; }
   static public int s_getColumnValueActive() { return s_getColumnValueAuthor() + 1; }
   // hidden
   static public int s_getColumnValueDescription() { return s_getColumnValueActive() + 1; }
   static public int s_getColumnValueRequiredLicense() { return s_getColumnValueDescription() + 1; }
   static public int s_getColumnValueNameFile() { return s_getColumnValueRequiredLicense() + 1; }
  
  
  
    // ----
    // begin: instantiate logger for this class
    final static private Logger _LOGGER_ = Logger.getLogger(GfrAtmManagePlgs.class.getName());

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


    // end: instantiate logger for this class
    // ----
   
    final public static String[] F_STRS_TITLE =
    {
        GfrResBundleLang.s_getInstance().getValue("word.name").toUpperCase(),
        "VERSION",
        GfrResBundleLang.s_getInstance().getValue("word.author").toUpperCase(),
        "ACTIVE?",
        "DESCRIPTION", // hidden
        "LICENSE REQUIRED?", // hidden
        "FILE" // hidden
       
    };
   
   
    // hurry!
    final public static String[] STRS_TIP_COLUMN = F_STRS_TITLE;
   
   
    // ---

    public GfrAtmManagePlgs()
    {
        super();
    }
   
    @Override
   public Class getColumnClass(int intCol)
   {
       //if (intCol == s_getColumnValueActive())
         //  return GfrImplTableCellRendererLblBlnIcn.class;

       // not yet in use, hidden coz tbrls
      //if (intCol == s_getColumnValueDescription())
        // return GfrImplTableCellRendererVpt.class;
     
      return super.getColumnClass(intCol);
   }
   
    @Override
    public String getColumnName(int intVal)
    {
        return GfrAtmManagePlgs.F_STRS_TITLE[intVal];
    }
   
    public IGfrHandlerPlugin getPluginAt(int intRow)
    {
       if (this._objssData == null)
            return null;
     
        if (this._objssData[intRow] == null)
            return null;
       
        if (intRow < 0)
            return null; // bug
       
        if (intRow > getRowCount() - 1)
            return null; // bug
       
        Object obj = this._objssData[intRow][s_getColumnValueName()];
        IGfrHandlerPlugin plg = (IGfrHandlerPlugin) obj;
        return plg;
    }
   
    /*
     * !!!
     */
    @Override
   public Object getValueAt(int intRow, int intCol)
   {
      if (this._objssData == null)
            return null;
     
        if (this._objssData[intRow] == null)
            return null;
       
        if (intRow < 0)
            return null; // bug
       
        if (intRow > getRowCount() - 1)
            return null; // bug
       
        if (intCol < 0)
            return null; // bug
       
        //if (intCol > getColumnCount() - 1)
          //  return null; // bug
     
     
      if (intCol == 0)
      {
         Object obj = this._objssData[intRow][0];
         IGfrHandlerPlugin plg = (IGfrHandlerPlugin) obj;
         return plg.getNamePlugin();
      }
     
     
      return super.getValueAt(intRow, intCol);
   }
   
    public void fill(Object[][] objssNew) throws Exception
    {
        super._objssData = objssNew;

        // ---
        fireTableRowsInserted(0, super._objssData.length - 1);
    }
   
    // to encapsulate, should redirect to superclass
   public void removeRow(IGfrHandlerPlugin plgToRemove)
   {     
      for (int i=0; i<super._objssData.length; i++)
      {
         IGfrHandlerPlugin plgCur = (IGfrHandlerPlugin) super._objssData[i][s_getColumnValueName()];
        
         if (plgCur != plgToRemove)
            continue;

         super.removeRow(i);
         return;
      }
   }
  
   // insert at right ascending depth
   @Override
   public void addRow(Object[] objsRowDataToInsert)
   {
        int intIdToInsert = -1;
        IGfrHandlerPlugin plgNew = (IGfrHandlerPlugin) objsRowDataToInsert[s_getColumnValueName()];
        String strNameToInsert = plgNew.getNamePlugin();
       
        for (int i=0; i<super._objssData.length; i++)
        {
           IGfrHandlerPlugin plgCur = (IGfrHandlerPlugin) super._objssData[i][s_getColumnValueName()];
           String strNameCur = plgCur.getNamePlugin();
          
           // !!!!!!!!!!!!!!!! sort alphabetically
           if (strNameToInsert.compareTo(strNameCur) < 0)
           {
              intIdToInsert = i;
              break;
           }
        }
       
        if (intIdToInsert == -1) // append at the end of list
        {
           super.addRow(objsRowDataToInsert);
           return;
        }
       
        // ---
        final int f_intNbRowNew = getRowCount() + 1;
        Object[][] objssNew = new Object[f_intNbRowNew][];
        int jOld = 0;
  
        for (int iNew=0; iNew<objssNew.length; iNew++)
        {
           if (iNew== intIdToInsert)
           {
              objssNew[iNew] = objsRowDataToInsert;
              continue;
           }
          
           objssNew[iNew] = super._objssData[jOld];
           jOld++;
        }
       
        // ---
        super._objssData = objssNew;
        fireTableRowsInserted(f_intNbRowNew - 1, f_intNbRowNew - 1);
    }
  

   @Override
   public int getColumnCount()
   {
      return F_STRS_TITLE.length;
   }
}
TOP

Related Classes of org.geoforge.guillc.tablemodel.GfrAtmManagePlgs

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.