Package org.geoforge.guillc.table

Source Code of org.geoforge.guillc.table.GfrTblPopHeightRowFixManPlgsAbs

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

import java.awt.Component;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Logger;
import javax.swing.JComponent;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.*;
import org.geoforge.guillc.table.tablecellrenderer.GfrImplTableCellRendererLblTxt;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.guillc.popupmenu.GfrPmuTblDelManPlgs;
import org.geoforge.guillc.table.tablecellrenderer.GfrImplTableCellRendererLblBlnTxt;
import org.geoforge.guillc.tablemodel.GfrAtmManagePlgs;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.mdldsp.event.plugin.EvtMdlDspPlgAbs;
import org.geoforge.mdldsp.event.plugin.EvtMdlDspPlgAdded;
import org.geoforge.mdldsp.event.plugin.EvtMdlDspPlgRemoved;
import org.geoforge.mdldsp.event.plugin.EvtMdlDspPlgsRemoved;
import org.geoforge.mgrplg.handler.IGfrHandlerLicensingPlugin;
import org.geoforge.mgrplg.handler.IGfrHandlerPlugin;
import org.geoforge.mgrplg.model.GfrMdlPlg;
import org.geoforge.mgrplg.model.event.GfrEvtMdlPlgActive;




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


abstract public class GfrTblPopHeightRowFixManPlgsAbs extends GfrTblPopHeightRowVarAbs implements
        Observer
{
   // ----
   // begin: instantiate logger for this class

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

   static
   {
      GfrTblPopHeightRowFixManPlgsAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
   }
   // end: instantiate logger for this class
   // ----
   static private String _s_getHtmlFormattedString_(JTable tbl, int intRow)
   {
       String strName = (String) tbl.getValueAt(intRow, GfrAtmManagePlgs.s_getColumnValueName());
       String strVersion = (String) tbl.getValueAt(intRow, GfrAtmManagePlgs.s_getColumnValueVersion());
       String strAuthor = (String) tbl.getValueAt(intRow, GfrAtmManagePlgs.s_getColumnValueAuthor());
       // ---
       boolean blnIsActive = (Boolean) tbl.getValueAt(intRow, GfrAtmManagePlgs.s_getColumnValueActive());
       String strIsActive = "No";
       if (blnIsActive) strIsActive = "Yes";
       // ---
      
       // ---
       String strDescription = (String) tbl.getValueAt(intRow, GfrAtmManagePlgs.s_getColumnValueDescription());
      
       if (strDescription==null || strDescription.length()<1)
           strDescription = "<i>No description</i>";
       else
       {
           strDescription = strDescription.replaceAll("\n", "<br />");
       }
      
       // ---
       // ---
       // ---
       boolean blnIsRequiredLicense = (Boolean) tbl.getValueAt(intRow, GfrAtmManagePlgs.s_getColumnValueRequiredLicense());
       String strIsRequiredLicense = "No";
       if (blnIsRequiredLicense) strIsRequiredLicense = "Yes";
       // ---
      
       String strNameFile = (String) tbl.getValueAt(intRow, GfrAtmManagePlgs.s_getColumnValueNameFile());
      
       // ---
       String str = "<html><head></head><body>";
       str += "<center>";
     
       str += "<h3>";
       str += strName;
       str += "</h3>";
     
      // beg table
      str += "<table align=center border=\"1\" width=\"80%\">";
     
      // ---
      str += "<tr>";
      str += "<td bgcolor=\"rgb(123,118,88)\" align=\"center\"><font color=\"#ffffff\">VERSION</font></td>";
      str += "<td align=\"center\" valign=\"center\"><font size=\"2\">";  
      str += strVersion;
      str += "</font></td>";
      str += "</tr>";
     
     
      // ---
      str += "<tr>";
      str += "<td bgcolor=\"rgb(123,118,88)\" align=\"center\"><font color=\"#ffffff\">AUTHOR</font></td>";
      str += "<td align=\"center\" valign=\"center\"><font size=\"2\">";  
      str += strAuthor;
      str += "</font></td>";
      str += "</tr>";
     
      // ---
      str += "<tr>";
      str += "<td bgcolor=\"rgb(123,118,88)\" align=\"center\"><font color=\"#ffffff\">ACTIVE?</font></td>";
      if (blnIsActive)
         str += "<td bgcolor=\"rgb(0,120,0)\" align=\"center\" valign=\"center\"><font color=\"#ffffff\" size=\"3\">";
      else
          str += "<td bgcolor=\"rgb(120,0,0)\" align=\"center\" valign=\"center\"><font color=\"#ffffff\" size=\"3\">"
      str += strIsActive;
      str += "</font></td>";
      str += "</tr>";
     
      // ---
      str += "<tr>";
      str += "<td bgcolor=\"rgb(123,118,88)\" align=\"center\"><font color=\"#ffffff\">LICENSE REQUIRED?</font></td>";
      str += "<td align=\"center\" valign=\"center\"><font size=\"2\">";  
      str += strIsRequiredLicense;
      str += "</font></td>";
      str += "</tr>";
     
     
     
      // ---
      str += "<tr>";
      str += "<td bgcolor=\"rgb(123,118,88)\" align=\"center\"><font color=\"#ffffff\">FILE NAME</font></td>";
      str += "<td align=\"center\" valign=\"center\"><font size=\"2\">";  
      str += strNameFile;
      str += "</font></td>";
      str += "</tr>";
     
     
      // ---
      str += "<tr>";
      str += "<td bgcolor=\"rgb(123,118,88)\" align=\"center\"><font color=\"#ffffff\">DESCRIPTION</font></td>";
      str += "<td align=\"left\" valign=\"center\"><font size=\"2\">";  
      str += strDescription;
      str += "</font></td>";
      str += "</tr>";
      
      
       // ---
       str += "</table>";
       str += "</center>";
       str += "</body></html>";
       return str;
   }
  
  
  
   // ---
  
   abstract protected Object[][] _getDataFromPluginsManager();
  
   private GfrAtmManagePlgs _atm_ = null;
  
    protected GfrTblPopHeightRowFixManPlgsAbs()
    {
        super();
       
        this._atm_ = new GfrAtmManagePlgs();
        super.setModel(this._atm_);

        super._pop = new GfrPmuTblDelManPlgs((GfrTblAbs) this);
       
        // ---
  
        int intWidthCell;
        TableColumn tcn;
       
        // --- name
        tcn = super.getColumnModel().getColumn(GfrAtmManagePlgs.s_getColumnValueName());
        intWidthCell = 200;
        tcn.setPreferredWidth(intWidthCell);
        tcn.setMaxWidth(intWidthCell);
       
        // --- version
        tcn = super.getColumnModel().getColumn(GfrAtmManagePlgs.s_getColumnValueVersion());
        intWidthCell = 60;
        tcn.setPreferredWidth(intWidthCell);
        tcn.setMaxWidth(intWidthCell);
       
        // --- active
        tcn = super.getColumnModel().getColumn(GfrAtmManagePlgs.s_getColumnValueActive());
        intWidthCell = 60;
        tcn.setPreferredWidth(intWidthCell);
        tcn.setMaxWidth(intWidthCell);
       
       
        // --- description
        //Hiding column coz of troubleshootings with JTextPane:
        /*
         * multi-line: cut (v/s working with mySsmLyrsLithoWorkspaces
         * moreover: foreground not updated (v/s working with mySsmLyrsLithoWorkspaces)
         */
        super.getColumn(GfrAtmManagePlgs.F_STRS_TITLE[GfrAtmManagePlgs.s_getColumnValueDescription()]).setWidth(0);
        super.getColumn(GfrAtmManagePlgs.F_STRS_TITLE[GfrAtmManagePlgs.s_getColumnValueDescription()]).setMinWidth(0);
        super.getColumn(GfrAtmManagePlgs.F_STRS_TITLE[GfrAtmManagePlgs.s_getColumnValueDescription()]).setMaxWidth(0);

        // beg - hiding the 2 last columns
        // 1/3 is license required
        super.getColumn(GfrAtmManagePlgs.F_STRS_TITLE[GfrAtmManagePlgs.s_getColumnValueRequiredLicense()]).setWidth(0);
        super.getColumn(GfrAtmManagePlgs.F_STRS_TITLE[GfrAtmManagePlgs.s_getColumnValueRequiredLicense()]).setMinWidth(0);
        super.getColumn(GfrAtmManagePlgs.F_STRS_TITLE[GfrAtmManagePlgs.s_getColumnValueRequiredLicense()]).setMaxWidth(0);
        // 2/3 file name
        super.getColumn(GfrAtmManagePlgs.F_STRS_TITLE[GfrAtmManagePlgs.s_getColumnValueNameFile()]).setWidth(0);
        super.getColumn(GfrAtmManagePlgs.F_STRS_TITLE[GfrAtmManagePlgs.s_getColumnValueNameFile()]).setMinWidth(0);
        super.getColumn(GfrAtmManagePlgs.F_STRS_TITLE[GfrAtmManagePlgs.s_getColumnValueNameFile()]).setMaxWidth(0);
        // 3/3 description
       
        // end - hiding the 3 last columns
       
        // ---
        GfrMdlPlg.getInstance().addObserver((Observer) this);
    }
   
   
    @Override
    protected JTableHeader createDefaultTableHeader()
   {
      return new JTableHeader(super.columnModel)
      {
        @Override
        public String getToolTipText(MouseEvent evtMouse)
        {
            java.awt.Point pnt = evtMouse.getPoint();
            int intIndexAtX = super.columnModel.getColumnIndexAtX(pnt.x);
            int intIndexReal = super.columnModel.getColumn(intIndexAtX).getModelIndex();
            return GfrAtmManagePlgs.STRS_TIP_COLUMN[intIndexReal];
         }
       };
    }
   
    @Override
    public void destroy()
    {
        GfrMdlPlg.getInstance().deleteObserver((Observer) this);
       
        super.destroy();
    }
   
  

   @Override
   public void update(Observable obs, Object objEvt)
   {
      if (objEvt instanceof GfrEvtMdlPlgActive)
      {
         GfrEvtMdlPlgActive evt = (GfrEvtMdlPlgActive) objEvt;
         IGfrHandlerPlugin plgSource = evt.getSource();
         boolean blnValue = evt.getValue();

          if (! this._updateSetActive_(plgSource, blnValue))
          {
             String strSevere = "! this._updateSetActive_(plgSource, blnValue)";
             GfrTblPopHeightRowFixManPlgsAbs._LOGGER_.severe(strSevere);
             GfrOptionPaneAbs.s_showDialogError(null, strSevere);
          }
           
         return;
      }
      
      if (objEvt instanceof EvtMdlDspPlgAdded)
      {
         Object[] objsRowDataNew = new Object[this._atm_.getColumnCount()];
         int intCountId = 0;
        
         IGfrHandlerPlugin plg = ((EvtMdlDspPlgAbs) objEvt).getValue();
        
         objsRowDataNew[intCountId++] = plg;
         objsRowDataNew[intCountId++] = plg.getVersionThisPlugin();
         objsRowDataNew[intCountId++] = plg.getAuthorPlugin();
         objsRowDataNew[intCountId++] = plg.isActivePlugin(); // !!! new Boolean ???
         objsRowDataNew[intCountId++] = plg.getDescriptionPlugin();
         objsRowDataNew[intCountId++] = (plg instanceof IGfrHandlerLicensingPlugin); // !!! new Boolean ???
         objsRowDataNew[intCountId++] = plg.getNameFilePlugin();
        
        
         this._atm_.addRow(objsRowDataNew);
        
         return;
      }
     
      if (objEvt instanceof EvtMdlDspPlgRemoved)
      {
         IGfrHandlerPlugin plg = ((EvtMdlDspPlgAbs) objEvt).getValue();
        
         this._atm_.removeRow(plg);
         return;
      }
     
      if (objEvt instanceof EvtMdlDspPlgsRemoved)
      {
         this._atm_.removeAllRows();
        
         return;
      }
     
      String strSevere = "Uncaught instanceof objEvt: " + objEvt.getClass().toString();
      GfrTblPopHeightRowFixManPlgsAbs._LOGGER_.severe(strSevere);
      GfrOptionPaneAbs.s_showDialogError(null, strSevere);
   }
  
   @Override
   public boolean init()
   {
      if (!super.init())
         return false;
     
      if (! this._atm_.init())
            return false;
      // ---
     
      TableColumnModel tcm = super.getColumnModel();
     
     
      TableCellRenderer hndTcrTxtCentered = new GfrImplTableCellRendererLblTxt(SwingConstants.CENTER)
      {
          @Override
            public Component getTableCellRendererComponent(
                JTable tbl,
                Object objValue,
                boolean blnIsSelected,
                boolean blnHasFocus,
                int intRow,
                int intCol)
            {
                Component cmp = super.getTableCellRendererComponent(tbl, objValue, blnIsSelected,
                                                blnHasFocus, intRow, intCol);
               
                String strToolTip = GfrTblPopHeightRowFixManPlgsAbs._s_getHtmlFormattedString_(tbl, intRow);
                ((JComponent) cmp).setToolTipText(strToolTip);
                return cmp;
            }
      };
     
      TableCellRenderer hndTcrTxtRight = new GfrImplTableCellRendererLblTxt(SwingConstants.CENTER)
      {
          @Override
            public Component getTableCellRendererComponent(
                JTable tbl,
                Object objValue,
                boolean blnIsSelected,
                boolean blnHasFocus,
                int intRow,
                int intCol)
            {
                Component cmp = super.getTableCellRendererComponent(tbl, objValue, blnIsSelected,
                                                blnHasFocus, intRow, intCol);
               
                String strToolTip = GfrTblPopHeightRowFixManPlgsAbs._s_getHtmlFormattedString_(tbl, intRow);
                ((JComponent) cmp).setToolTipText(strToolTip);
                return cmp;
            }
      };
             
      TableCellRenderer hndTcrCbx = new GfrImplTableCellRendererLblBlnTxt()
      {
          @Override
            public Component getTableCellRendererComponent(
                JTable tbl,
                Object objValue,
                boolean blnIsSelected,
                boolean blnHasFocus,
                int intRow,
                int intCol)
            {
                Component cmp = super.getTableCellRendererComponent(tbl, objValue, blnIsSelected,
                                                blnHasFocus, intRow, intCol);
               
                String strToolTip = GfrTblPopHeightRowFixManPlgsAbs._s_getHtmlFormattedString_(tbl, intRow);
                ((JComponent) cmp).setToolTipText(strToolTip);
                return cmp;
            }
      };
     
      // ---
      // beg row #3
      //final int intMinHeightCell = GfrAtmTopSpcWrkLthLyrAbs.INT_WIDTH_CELL_DISPLAY; // / 2;
      /*hidden coz tbrls
       * TableCellRenderer rndDescription = new GfrImplTableCellRendererVpt()
      {
         @Override
            public Component getTableCellRendererComponent(
                JTable tbl,
                Object objValue,
                boolean blnIsSelected,
                boolean blnHasFocus,
                int intRow,
                int intCol)
            {
                Component cmp = super.getTableCellRendererComponent(tbl, objValue, blnIsSelected,
                                                blnHasFocus, intRow, intCol);
               
                String strToolTip = GfrTblPopHeightRowFixManPlgsAbs._s_getHtmlFormattedString_(tbl, intRow);
                ((JComponent) cmp).setToolTipText(strToolTip);
                return cmp;
            } 
      };*/
     
      //rnd.setMinHeightCell(intMinHeightCell);
    
     
      // ---
    
      tcm.getColumn(GfrAtmManagePlgs.s_getColumnValueName()).setCellRenderer(hndTcrTxtCentered);
      tcm.getColumn(GfrAtmManagePlgs.s_getColumnValueVersion()).setCellRenderer(hndTcrTxtRight);
      tcm.getColumn(GfrAtmManagePlgs.s_getColumnValueAuthor()).setCellRenderer(hndTcrTxtCentered);
      tcm.getColumn(GfrAtmManagePlgs.s_getColumnValueActive()).setCellRenderer(hndTcrCbx);
      //tcm.getColumn(GfrAtmManagePlgs.s_getColumnValueDescription()).setCellRenderer(rndDescription);

     
     
      if (! _fill_())
         return false;
     
   
      return true;
   }
  
   private boolean _updateSetActive_(IGfrHandlerPlugin plgSource, boolean blnValue)
   {
       try
      {
          for (int i=0; i<this._atm_.getRowCount(); i++)
          {
              String strNameCur = (String) this._atm_.getValueAt(i, GfrAtmManagePlgs.s_getColumnValueName());
              String strVersionCur = (String) this._atm_.getValueAt(i, GfrAtmManagePlgs.s_getColumnValueVersion());
             
              // MEMO: assuming the same is sharing name and version
              // ATTN could change in the future
              if (plgSource.getNamePlugin().compareTo(strNameCur) != 0)
                  continue;
             
              if (plgSource.getVersionThisPlugin().compareTo(strVersionCur) != 0)
                  continue;

              this._atm_.setValueAt(Boolean.valueOf(blnValue), i, GfrAtmManagePlgs.s_getColumnValueActive());
              return true;
          }
        
          return true;
      }
     
      catch(Exception exc)
      {
         exc.printStackTrace();
         GfrTblPopHeightRowFixManPlgsAbs._LOGGER_.severe(exc.getMessage());
         return false;
      }
   }
   private boolean _fill_()
   {
      try
      {
         Object[][] objssData = _getDataFromPluginsManager();
         this._atm_.fill(objssData);
      }
     
      catch(Exception exc)
      {
         exc.printStackTrace();
         GfrTblPopHeightRowFixManPlgsAbs._LOGGER_.severe(exc.getMessage());
         return false;
      }
     
      return true;
   }
  
  
   protected Object[][] _getDataFromPluginsManager(ArrayList<IGfrHandlerPlugin> alt)
   {
       if (alt==null || alt.isEmpty())
         return new Object[0][GfrAtmManagePlgs.F_STRS_TITLE.length];
   
      Object[][] objssData = new Object[alt.size()][GfrAtmManagePlgs.F_STRS_TITLE.length];
      int intRowCur = 0;
     
      for (IGfrHandlerPlugin plgCur: alt)
      {
         int intColCur = 0;
         objssData[intRowCur][intColCur++] = plgCur;
         objssData[intRowCur][intColCur++] = plgCur.getVersionThisPlugin();
         objssData[intRowCur][intColCur++] = plgCur.getAuthorPlugin();
         objssData[intRowCur][intColCur++] = plgCur.isActivePlugin();
         objssData[intRowCur][intColCur++] = plgCur.getDescriptionPlugin();
         objssData[intRowCur][intColCur++] = (plgCur instanceof IGfrHandlerLicensingPlugin);
         objssData[intRowCur][intColCur++] = plgCur.getNameFilePlugin();
        
        
         intRowCur++;
      }
     
      return objssData;
   }
  
}
TOP

Related Classes of org.geoforge.guillc.table.GfrTblPopHeightRowFixManPlgsAbs

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.