ProdChooserFactory.java :  » ERP-CRM-Financial » Evaristo-4.0 » com » m16e » mpbiz » xgm » Java Open Source

Java Open Source » ERP CRM Financial » Evaristo 4.0 
Evaristo 4.0 » com » m16e » mpbiz » xgm » ProdChooserFactory.java
/**
 *
 * ProdChooserFactory.java
 *
 * @author carlos@m16e.com
 */

package com.m16e.mpbiz.xgm;

import com.m16e.mpbiz.tables.DbProd;
import com.m16e.tools.Tuple;
import com.m16e.tools.datamodels.QueryData;
import com.m16e.tools.db.DbTableInterface;
import com.m16e.tools.gui.GuiFactory;
import com.m16e.tools.xgm.ObjectManipulator;
import com.m16e.tools.xgm.XgmComponent;
import com.m16e.tools.xgm.XgmException;
import com.m16e.tools.xgm.XgmRootContainer;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;

////////////////////////////////////////////////////////////
public class ProdChooserFactory
{
  private static Logger logger = Logger.getLogger( ProdChooserFactory.class );

  java.util.List<DbProd> prods = null;

  ////////////////////////////////////////////////////////////
  public DbProd getProd( XgmComponent owner, QueryData where, String order )
  {
    try
    {
      prods = new ArrayList<DbProd>();

      XgmRootContainer xrc = null;
      if( owner != null )
        xrc = owner.getXgmContainer().getRootContainer();
      ObjectManipulator om =
        new ObjectManipulator()
        {
          @Override
          public void addObject( XgmComponent xgmComponent, XgmComponent callerComp, Object obj )
          throws XgmException {
            throw new UnsupportedOperationException( "Not supported yet." ); }

          @Override
          public void addObjects( XgmComponent xgmComponent, XgmComponent callerComp, List objs )
          throws XgmException
          {
            if( objs.size() == 1 )
            {
              DbProd prod = (DbProd) objs.get( 0 );
              try
              {
                if( prod.getById() )
                  prods.add( prod );
              }
              catch( Exception e )
              {
                logger.error( e.getMessage(), e );
                GuiFactory.showErrorMsg( xgmComponent, e );
              }
            }
          }

          @Override
          public void addObjectTuples( XgmComponent xgmComponent, String target, java.util.List<String> fieldNames, java.util.List<Tuple> tuple ) throws XgmException {
            throw new UnsupportedOperationException( "Not supported yet." ); }

        };
      XProdListChooser xpc =
        new XProdListChooser(
          xrc, om,
          XProdListChooser.DIALOG_PROD_LIST_CHOOSER, true, true, null,
          where, order );
    }
    catch( Exception e )
    {
      logger.error( e.getMessage(), e );
      GuiFactory.showErrorMsg( owner, e );
    }
    if( prods.size() != 1 )
      return null;
    return prods.get( 0 );
  }

  ////////////////////////////////////////////////////////////
  public java.util.List<DbProd> getProds( 
    XgmComponent owner, QueryData where, String order )
  {
    try
    {
      prods = new ArrayList<DbProd>();

      XgmRootContainer xrc = null;
      if( owner != null )
        xrc = owner.getXgmContainer().getRootContainer();
      ObjectManipulator om =
        new ObjectManipulator()
        {
          @Override
          public void addObject( XgmComponent xgmComponent, XgmComponent callerComp, Object obj )
          throws XgmException {
            throw new UnsupportedOperationException( "Not supported yet." ); }

          @Override
          public void addObjects( XgmComponent xgmComponent, XgmComponent callerComp, List objs )
          throws XgmException
          {
            try
            {
              for( Object o : objs )
              {
                DbProd prod = (DbProd) o;
                if( prod.getById() )
                  prods.add( prod );
              }
            }
            catch( Exception e )
            {
              logger.error( e.getMessage(), e );
              GuiFactory.showErrorMsg( xgmComponent, e );
            }
          }

          @Override
          public void addObjectTuples( XgmComponent xgmComponent, String target, java.util.List<String> fieldNames, java.util.List<Tuple> tuple ) throws XgmException {
            throw new UnsupportedOperationException( "Not supported yet." ); }

        };
      XProdListChooser xpc =
        new XProdListChooser(
          xrc, om,
          XProdListChooser.DIALOG_PROD_LIST_CHOOSER, true, false, null,
          where, order );
    }
    catch( Exception e )
    {
      logger.error( e.getMessage(), e );
      GuiFactory.showErrorMsg( owner, e );
    }
    return prods;
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.