ProductCategoryModel.java :  » J2EE » Sofia » com » salmonllc » examples » example5 » Java Open Source

Java Open Source » J2EE » Sofia 
Sofia » com » salmonllc » examples » example5 » ProductCategoryModel.java
package com.salmonllc.examples.example5;

import java.sql.SQLException;

import com.salmonllc.sql.*;

//$CUSTOMIMPORTS$
import com.salmonllc.examples.SiteMapConstants;
import com.salmonllc.html.HtmlTreeControl;
import com.salmonllc.html.treeControl.TreeBuffer;
//$ENDCUSTOMIMPORTS$

/**
 * ProductCategoryModel: A SOFIA generated model
 */
public class ProductCategoryModel extends DataStore {

     //constants for columns
     public static final String PRODUCT_CATEGORY_PRODUCT_CAT_ID="product_category.product_cat_id";
     public static final String PRODUCT_CATEGORY_PARENT_ID="product_category.parent_id";
     public static final String PRODUCT_CATEGORY_DESCRIPTION="product_category.description";
     public static final String PRODUCT_CATEGORY_QUANTITY="product_category.quantity";
     public static final String PRODUCT_CATEGORY_PRICE="product_category.price";

     //constants for buckets
     public static final String SELECTED="selected";

     //$CUSTOMVARS$

//$ENDCUSTOMVARS$
     
     /**
      * Create a new ProductCategoryModel object.
      * @param appName The SOFIA application name
      */
     public ProductCategoryModel (String appName) { 
          this(appName, null);
     }

     /**
      * Create a new ProductCategoryModel object.
      * @param appName The SOFIA application name
      * @param profile The database profile to use
      */
     public ProductCategoryModel (String appName, String profile) { 
          super(appName, profile);

          //add columns
          addColumn(computeTableName("product_category"),"product_cat_id",DataStore.DATATYPE_INT,true,true,PRODUCT_CATEGORY_PRODUCT_CAT_ID);
          addColumn(computeTableName("product_category"),"parent_id",DataStore.DATATYPE_INT,false,true,PRODUCT_CATEGORY_PARENT_ID);
          addColumn(computeTableName("product_category"),"description",DataStore.DATATYPE_STRING,false,true,PRODUCT_CATEGORY_DESCRIPTION);
          addColumn(computeTableName("product_category"),"quantity",DataStore.DATATYPE_INT,false,true,PRODUCT_CATEGORY_QUANTITY);
          addColumn(computeTableName("product_category"),"price",DataStore.DATATYPE_DOUBLE,false,true,PRODUCT_CATEGORY_PRICE);

          //add buckets
          addBucket(SELECTED,DataStore.DATATYPE_INT);

          //set order by
          setOrderBy(computeTableAndFieldName("product_category.product_cat_id") + " ASC");

          //$CUSTOMCONSTRUCTOR$

//$ENDCUSTOMCONSTRUCTOR$

     }

     /**
      * Retrieve the value of the product_category.product_cat_id column for the current row.
      * @return int
      * @throws DataStoreException
      */ 
     public int getProductCategoryProductCatId() throws DataStoreException {
          return  getInt(PRODUCT_CATEGORY_PRODUCT_CAT_ID);
     }

     /**
      * Retrieve the value of the product_category.product_cat_id column for the specified row.
      * @param row which row in the table
      * @return int
      * @throws DataStoreException
      */ 
     public int getProductCategoryProductCatId(int row) throws DataStoreException {
          return  getInt(row,PRODUCT_CATEGORY_PRODUCT_CAT_ID);
     }

     /**
      * Set the value of the product_category.product_cat_id column for the current row.
      * @param newValue the new item value
      * @throws DataStoreException
      */ 
     public void setProductCategoryProductCatId(int newValue) throws DataStoreException {
          setInt(PRODUCT_CATEGORY_PRODUCT_CAT_ID, newValue);
     }

     /**
      * Set the value of the product_category.product_cat_id column for the specified row.
      * @param row which row in the table
      * @param newValue the new item value
      * @throws DataStoreException
      */ 
     public void setProductCategoryProductCatId(int row,int newValue) throws DataStoreException {
          setInt(row,PRODUCT_CATEGORY_PRODUCT_CAT_ID, newValue);
     }

     /**
      * Retrieve the value of the product_category.parent_id column for the current row.
      * @return int
      * @throws DataStoreException
      */ 
     public int getProductCategoryParentId() throws DataStoreException {
          return  getInt(PRODUCT_CATEGORY_PARENT_ID);
     }

     /**
      * Retrieve the value of the product_category.parent_id column for the specified row.
      * @param row which row in the table
      * @return int
      * @throws DataStoreException
      */ 
     public int getProductCategoryParentId(int row) throws DataStoreException {
          return  getInt(row,PRODUCT_CATEGORY_PARENT_ID);
     }

     /**
      * Set the value of the product_category.parent_id column for the current row.
      * @param newValue the new item value
      * @throws DataStoreException
      */ 
     public void setProductCategoryParentId(int newValue) throws DataStoreException {
          setInt(PRODUCT_CATEGORY_PARENT_ID, newValue);
     }

     /**
      * Set the value of the product_category.parent_id column for the specified row.
      * @param row which row in the table
      * @param newValue the new item value
      * @throws DataStoreException
      */ 
     public void setProductCategoryParentId(int row,int newValue) throws DataStoreException {
          setInt(row,PRODUCT_CATEGORY_PARENT_ID, newValue);
     }

     /**
      * Retrieve the value of the product_category.description column for the current row.
      * @return String
      * @throws DataStoreException
      */ 
     public String getProductCategoryDescription() throws DataStoreException {
          return  getString(PRODUCT_CATEGORY_DESCRIPTION);
     }

     /**
      * Retrieve the value of the product_category.description column for the specified row.
      * @param row which row in the table
      * @return String
      * @throws DataStoreException
      */ 
     public String getProductCategoryDescription(int row) throws DataStoreException {
          return  getString(row,PRODUCT_CATEGORY_DESCRIPTION);
     }

     /**
      * Set the value of the product_category.description column for the current row.
      * @param newValue the new item value
      * @throws DataStoreException
      */ 
     public void setProductCategoryDescription(String newValue) throws DataStoreException {
          setString(PRODUCT_CATEGORY_DESCRIPTION, newValue);
     }

     /**
      * Set the value of the product_category.description column for the specified row.
      * @param row which row in the table
      * @param newValue the new item value
      * @throws DataStoreException
      */ 
     public void setProductCategoryDescription(int row,String newValue) throws DataStoreException {
          setString(row,PRODUCT_CATEGORY_DESCRIPTION, newValue);
     }

     /**
      * Retrieve the value of the product_category.quantity column for the current row.
      * @return int
      * @throws DataStoreException
      */ 
     public int getProductCategoryQuantity() throws DataStoreException {
          return  getInt(PRODUCT_CATEGORY_QUANTITY);
     }

     /**
      * Retrieve the value of the product_category.quantity column for the specified row.
      * @param row which row in the table
      * @return int
      * @throws DataStoreException
      */ 
     public int getProductCategoryQuantity(int row) throws DataStoreException {
          return  getInt(row,PRODUCT_CATEGORY_QUANTITY);
     }

     /**
      * Set the value of the product_category.quantity column for the current row.
      * @param newValue the new item value
      * @throws DataStoreException
      */ 
     public void setProductCategoryQuantity(int newValue) throws DataStoreException {
          setInt(PRODUCT_CATEGORY_QUANTITY, newValue);
     }

     /**
      * Set the value of the product_category.quantity column for the specified row.
      * @param row which row in the table
      * @param newValue the new item value
      * @throws DataStoreException
      */ 
     public void setProductCategoryQuantity(int row,int newValue) throws DataStoreException {
          setInt(row,PRODUCT_CATEGORY_QUANTITY, newValue);
     }

     /**
      * Retrieve the value of the product_category.price column for the current row.
      * @return double
      * @throws DataStoreException
      */ 
     public double getProductCategoryPrice() throws DataStoreException {
          return  getDouble(PRODUCT_CATEGORY_PRICE);
     }

     /**
      * Retrieve the value of the product_category.price column for the specified row.
      * @param row which row in the table
      * @return double
      * @throws DataStoreException
      */ 
     public double getProductCategoryPrice(int row) throws DataStoreException {
          return  getDouble(row,PRODUCT_CATEGORY_PRICE);
     }

     /**
      * Set the value of the product_category.price column for the current row.
      * @param newValue the new item value
      * @throws DataStoreException
      */ 
     public void setProductCategoryPrice(double newValue) throws DataStoreException {
          setDouble(PRODUCT_CATEGORY_PRICE, newValue);
     }

     /**
      * Set the value of the product_category.price column for the specified row.
      * @param row which row in the table
      * @param newValue the new item value
      * @throws DataStoreException
      */ 
     public void setProductCategoryPrice(int row,double newValue) throws DataStoreException {
          setDouble(row,PRODUCT_CATEGORY_PRICE, newValue);
     }

     /**
      * Retrieve the value of the selected bucket for the current row.
      * @return int
      * @throws DataStoreException
      */ 
     public int getSelected() throws DataStoreException {
          return  getInt(SELECTED);
     }

     /**
      * Retrieve the value of the selected bucket for the specified row.
      * @param row which row in the table
      * @return int
      * @throws DataStoreException
      */ 
     public int getSelected(int row) throws DataStoreException {
          return  getInt(row,SELECTED);
     }

     /**
      * Set the value of the selected bucket for the current row.
      * @param newValue the new item value
      * @throws DataStoreException
      */ 
     public void setSelected(int newValue) throws DataStoreException {
          setInt(SELECTED, newValue);
     }

     /**
      * Set the value of the selected bucket for the specified row.
      * @param row which row in the table
      * @param newValue the new item value
      * @throws DataStoreException
      */ 
     public void setSelected(int row,int newValue) throws DataStoreException {
          setInt(row,SELECTED, newValue);
     }
     
     //$CUSTOMMETHODS$
  /**
   * This method can be used to populate a GUI tree control with the contents of this model
   */
  public void populateTree(HtmlTreeControl tree) throws SQLException, DataStoreException  {
     //load the data from the database
     retrieve();

     //create a new tree buffer (model)
     TreeBuffer b = new TreeBuffer();
     
     //load the images for the tree
     int rootImage = b.addImage(tree.translateSiteMapURL("%" + SiteMapConstants.TREE_IMAGE_ROOT));
     int leafImage = b.addImage(tree.translateSiteMapURL("%" + SiteMapConstants.TREE_IMAGE_FILE));
     int expandedImage = b.addImage(tree.translateSiteMapURL("%" + SiteMapConstants.TREE_IMAGE_OPENED_FOLDER));
     int contractedImage = b.addImage(tree.translateSiteMapURL("%" + SiteMapConstants.TREE_IMAGE_CLOSED_FOLDER));

     //add the root image
     int handle = b.addChild("Products",null,rootImage,rootImage,null,null);
     populateTreeChildren(1,b,handle,getProductCategoryProductCatId(0),contractedImage,expandedImage,leafImage);

     //add the tree buffer to the tree control
     b.setMode(TreeBuffer.MODE_SUBMIT);
     b.setSelectMode(TreeBuffer.SELECT_NONE);
     tree.setUsePathForClickSort(true);
     tree.setTreeBuffer(b);

  }

  /**
   * This method is called recursively to walk through the data and build a tree. Returns true if node has children.
   */
  private boolean populateTreeChildren(int startRow, TreeBuffer tb, int handle, int parent, int image, int expandedImage, int leafImage) throws DataStoreException{
     boolean retVal = false;
     tb.gotoItem(handle);
     tb.setExpanded(true);
  
     for (int i = startRow; i < getRowCount(); i++) {
         if (getProductCategoryParentId(i) == parent) {
           retVal = true;
           tb.gotoItem(handle);
           int newHandle = tb.addChild(getProductCategoryDescription(i),null,image, expandedImage,null,null);
           tb.gotoItem(newHandle);
           tb.setRow(i);
           if (! populateTreeChildren(i + 1,tb,newHandle,getProductCategoryProductCatId(i),image,expandedImage,leafImage)) {
             tb.gotoItem(newHandle);
             tb.setImages(leafImage,leafImage);
           }
         }
     }
     return retVal;
  }

//$ENDCUSTOMMETHODS$
     
}
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.