Package org.geoforge.appogceclgsi.actioncontroller

Source Code of org.geoforge.appogceclgsi.actioncontroller.GfrAcrSpcAppPrtWrkOgcEclGsi

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

import java.awt.event.ActionEvent;
import java.util.logging.Logger;
import org.geoforge.appogcecl.actioncontroller.GfrAcrSpcAppPrtWrkOgcEclAbs;
import org.geoforge.appogceclgsi.actionmanager.GfrAmrAppSpcPrtWorkGsi;
import org.geoforge.appogceclgsi.io.file.GfrUtilFileSpcProjectGsi;
import org.geoforge.appogceclgsi.actionperformer.ActPrfWrkConstructGsi;
import org.geoforge.appogceclgsi.actionperformer.ActPrfWrkDeleteGsi;
import org.geoforge.appogceclgsi.actionperformer.ActPrfWrkRenameGsi;
import org.geoforge.appogceclgsi.actionperformer.ActPrfWrkSettingsGsi;
import org.geoforge.basprjdatgsi.io.GfrIoBasNameDatPrjGsi;
import org.geoforge.basprjdspgsi.io.GfrIoBasNameDspDftObjsCatPrjGsi;
import org.geoforge.basusrspcdsp.table.GfrBasTblUsrSpcPrtHistoryAbs;
import org.geoforge.guillc.GfrAppSpcAbs;
import org.geoforge.guillc.frame.GfrFrmAbs;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.guillc.panel.GfrPnlStatusBarMain;
import org.geoforge.guillc.action.ActionChildCloneProject;
import org.geoforge.guillc.action.ActionChildDeleteProject;
import org.geoforge.guillc.action.ActionChildRenameProject;
import org.geoforge.guillc.actioncontroller.GfrAcrSpcAppAbs;
import org.geoforge.guillc.dialog.*;
import org.geoforge.java.enumeration.GfrEnuSystemPropertiesKeys;
import org.geoforge.lang.util.GfrResBundleLang;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.mdldat.GfrMdlDatSpcPrtWork;
import org.geoforge.wrpbasusr.GfrWrpUsrSpcDspPrtAppRoot;
import org.geoforge.wrpbasusr.GfrWrpUsrSpcDspPrtAppWork;
import org.geoforge.wrpbasspcsyngsi.work.GfrWrpBasSpcWrkDatSynGsi;

/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*
*/
public class GfrAcrSpcAppPrtWrkOgcEclGsi extends GfrAcrSpcAppPrtWrkOgcEclAbs
{
   // ----
   // begin: instantiate logger for this class

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

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

   // end: instantiate logger for this class
   // ----
  
   public GfrAcrSpcAppPrtWrkOgcEclGsi(GfrAppSpcAbs app, GfrAcrSpcAppAbs acrParent) throws Exception
   {
      super(app,
            new GfrAmrAppSpcPrtWorkGsi(),
            acrParent);
   }
  
   @Override
   public void actionPerformed(ActionEvent evt)
   {
      try
      {
         if (ActPrfWrkSettingsGsi.getInstance().doneJob(evt))
            return;
        
         if (ActPrfWrkRenameGsi.getInstance().doneJob(evt))
            return;
        
         if (ActPrfWrkDeleteGsi.getInstance().doneJob(evt))
            return;
        
         if (ActPrfWrkConstructGsi.getInstance().doneJob(evt))
            return;
      }
     
      catch (Exception exc)
      {
         exc.printStackTrace();
         String strError = exc.getMessage();
         GfrAcrSpcAppPrtWrkOgcEclGsi._LOGGER_.severe(strError);
         GfrOptionPaneAbs.s_showDialogError(null, strError);
         return;
      }

      super.actionPerformed(evt);
   }

   // at launching time, or from workspace
   @Override
   public void displayChild(String strName) throws Exception
   {
      if (super._acrChild != null)
      {
         String str = "super._acrChild != null";
         GfrAcrSpcAppPrtWrkOgcEclGsi._LOGGER_.severe(str);
         throw new Exception(str);
      }


      super._acrChild = new GfrAcrSpcAppClsPrjOgcEclGsi(this._app, (GfrAcrSpcAppAbs) this);

      String strId = GfrWrpBasSpcWrkDatSynGsi.getInstance().getIdFromName(strName);
      GfrWrpUsrSpcDspPrtAppWork.getInstance().setLast(GfrBasTblUsrSpcPrtHistoryAbs.STR_WHO_LAST_ONE_OF_MY_CHILDREN,
              strName, strId);

      super.displayChild(strName);
   }

   @Override
   public String actionControllerContainerSpaceNewChild() throws Exception
   {
      // get current children

      String[] strsChildrenExisting = GfrWrpUsrSpcDspPrtAppRoot.getInstance().getSortedNamesLastChildFromHistory();

      // show dialog

      GfrDlgNewSettingsNameSpcAppPrj dlg = new GfrDlgNewSettingsNameSpcAppPrj(
              super._app.getFrame(), strsChildrenExisting);


      if (!dlg.init())
      {
         String str = "! dlg.init()";
         GfrAcrSpcAppPrtWrkOgcEclGsi._LOGGER_.severe(str);
         throw new Exception(str);
      }

      dlg.setVisible(true);

      boolean blnCancelled = dlg.isCancelled();

      String strValue = null;

      if (!blnCancelled)
      {
         strValue = dlg.getValue();
      }

      dlg.setVisible(false);
      dlg.destroy();
      dlg = null;


      if (blnCancelled)
         return null;

      GfrMdlDatSpcPrtWork.getInstance().newChild(strValue, GfrWrpBasSpcWrkDatSynGsi.getInstance());
     
      // update
      updateStateActions();

      // ending
      return strValue;

   }

   @Override
   public void actionControllerContainerUpdateContentsDialogManageChildren() throws Exception
   {
      if (super._dlgManageChildren == null)
         return;

      if (!super._dlgManageChildren.isVisible())
         return;

      String[] strsChildrenExisting = GfrWrpUsrSpcDspPrtAppRoot.getInstance().getSortedNamesLastChildFromHistory();

      Object[][] objssData = null;

      if (strsChildrenExisting == null)
         objssData = new Object[0][0];
      else
      {
         int intNbCols = 2;
         objssData = new Object[strsChildrenExisting.length][intNbCols];

         for (int i = 0; i < strsChildrenExisting.length; i++)
         {
            objssData[i][0] = strsChildrenExisting[i];

            String strKindSource = GfrWrpBasSpcWrkDatSynGsi.getInstance().getKindFromName(strsChildrenExisting[i]);
            objssData[i][1] = strKindSource;
         }
      }

      ((GfrDlgManageChildrenSpcAbs) super._dlgManageChildren).fill(objssData);
   }

   @Override
   public void actionControllerContainerSpaceDeleteChild() throws Exception
   {

      // confirm
      if (!GfrOptionPaneAbs.s_showDialogConfirm(
              GfrFrmAbs.s_getFrameOwner(GfrPnlStatusBarMain.s_getInstance()),
              GfrResBundleLang.s_getInstance().getValue("verb.confirm"),
              GfrResBundleLang.s_getInstance().getValue("sentence.confirmDeleteProject")))
         return; // action cancellled by user



      String strNameSource = ActionChildDeleteProject.s_getInstance().getChild();


      GfrMdlDatSpcPrtWork.getInstance().deleteChild(
              strNameSource,
              GfrWrpBasSpcWrkDatSynGsi.getInstance(),
              GfrUtilFileSpcProjectGsi.getInstance());
    
      // update
      updateStateActions();
   }

   @Override
   public void actionControllerContainerSpaceCloneChild() throws Exception
   {

      String strNameSource = ActionChildCloneProject.s_getInstance().getChild();

      if (strNameSource == null)
      {
         String str = "strPathSource == null";
         GfrAcrSpcAppPrtWrkOgcEclGsi._LOGGER_.severe(str);
         throw new Exception(str);
      }


      String[] strsChildrenExisting = GfrWrpUsrSpcDspPrtAppRoot.getInstance().getSortedNamesLastChildFromHistory();

      GfrDlgOkTextSaveCopy dlg = new GfrDlgOkTextSaveCopy(super._app.getFrame(),
              GfrResBundleLang.s_getInstance().getValue("sentence.cloneProject").toLowerCase(),
              strsChildrenExisting,
              strNameSource);

      if (!dlg.init())
      {
         String str = "! dlg.init()";
         GfrAcrSpcAppPrtWrkOgcEclGsi._LOGGER_.severe(str);
         throw new Exception(str);
      }

      dlg.setVisible(true);

      boolean blnCancelled = dlg.isCancelled();

      String strNameTarget = null;

      if (!blnCancelled)
      {
         strNameTarget = dlg.getValue();
      }

      dlg.setVisible(false);
      dlg.destroy();
      dlg = null;

      if (blnCancelled)
         return;

      // -----
      // beg doJob

      // ----
     

      GfrMdlDatSpcPrtWork.getInstance().cloneChild(strNameSource, strNameTarget,
              GfrWrpBasSpcWrkDatSynGsi.getInstance());
   }

   @Override
   public void actionControllerContainerSpaceMoveChild() throws Exception
   {
      //Get the name of proj to rename
      String strNameProjectOld = ActionChildRenameProject.s_getInstance().getChild();

      //check validity
      if (strNameProjectOld == null)
      {
         String str = "strNameSource == null";
         GfrAcrSpcAppPrtWrkOgcEclGsi._LOGGER_.severe(str);
         throw new Exception(str);
      }

      //read in db the list of project names for display.
      String[] strsChildrenExisting = GfrWrpUsrSpcDspPrtAppRoot.getInstance().getSortedNamesLastChildFromHistory();

      GfrDlgOkTextSaveRename dlg = new GfrDlgOkTextSaveRename(null,
              strsChildrenExisting,
              strNameProjectOld);

      if (!dlg.init())
      {
         String str = "! dlg.init()";
         GfrAcrSpcAppPrtWrkOgcEclGsi._LOGGER_.severe(str);
         throw new Exception(str);
      }

      dlg.setVisible(true);

      boolean blnCancelled = dlg.isCancelled();

      String strNameProjectNew = null;

      if (!blnCancelled)
      {
         strNameProjectNew = dlg.getValue();
      }

      dlg.setVisible(false);
      dlg.destroy();

      if (blnCancelled)
         return;
     

      GfrMdlDatSpcPrtWork.getInstance().moveChild(strNameProjectOld, strNameProjectNew,
              GfrWrpBasSpcWrkDatSynGsi.getInstance());
   }

   @Override
   public void actionControllerContainerSpaceDeleteChildren() throws Exception
   {

      if (!GfrOptionPaneAbs.s_showDialogConfirm(GfrFrmAbs.s_getFrameOwner(GfrPnlStatusBarMain.s_getInstance()),
              GfrResBundleLang.s_getInstance().getValue("verb.confirm"),
              GfrResBundleLang.s_getInstance().getValue("sentence.confirmDeleteProjects")))
         return;

      // ATTN: if any problem while deleting folders or/and files, DB not up2date!
      // THINGS TODO: make a copy of DB, in case of exceptions, override original DB by copy

    
      GfrMdlDatSpcPrtWork.getInstance().deleteAllChildren(
              GfrWrpBasSpcWrkDatSynGsi.getInstance(),
              GfrUtilFileSpcProjectGsi.getInstance());
     
      // ----
      // 3) update

      updateStateActions();
   }

   @Override
   public void actionControllerContainerManageChildren() throws Exception
   {

      String[] strsChildrenExisting = GfrWrpUsrSpcDspPrtAppRoot.getInstance().getSortedNamesLastChildFromHistory();

      Object[][] objssData = null;

      if (strsChildrenExisting == null)
         objssData = new Object[0][0];
      else
      {
         int intNbCols = 2;
         objssData = new Object[strsChildrenExisting.length][intNbCols];

         for (int i = 0; i < strsChildrenExisting.length; i++)
         {
            objssData[i][0] = strsChildrenExisting[i];

            String strKindSource = GfrWrpBasSpcWrkDatSynGsi.getInstance().getKindFromName(strsChildrenExisting[i]);

            objssData[i][1] = strKindSource;
         }
      }

      if (super._dlgManageChildren == null)
      {
         super._dlgManageChildren = new GfrDlgManageChildrenSpcPrj(
                 super._app.getFrame(),
                 objssData,
                 GfrWrpBasSpcWrkDatSynGsi.getInstance());

         if (!super._dlgManageChildren.init())
            throw new Exception("! super._dlgManageChildren_.init()");

      }

      super._dlgManageChildren.setVisible(true);
   }

   @Override
   protected void _importProjectHandler(String strName) throws Exception
   {
      GfrWrpBasSpcWrkDatSynGsi.getInstance().save(strName,
               System.getProperty(GfrEnuSystemPropertiesKeys.NAME_LONG_APPLI.getLabel()));
   }

   @Override
   protected String _getNameDbDataProjectAppli()
   {
      return GfrIoBasNameDatPrjGsi.STR_FILE;
   }

   @Override
   protected String _getNameDbDisplayDefaultProjectAppli()
   {
      return GfrIoBasNameDspDftObjsCatPrjGsi.STR_FILE;
   }

   @Override
   protected String _getIdProjectFromName(String strName) throws Exception
   {
      return GfrWrpBasSpcWrkDatSynGsi.getInstance().getIdFromName(strName);
   }
}
TOP

Related Classes of org.geoforge.appogceclgsi.actioncontroller.GfrAcrSpcAppPrtWrkOgcEclGsi

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.