KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > campware > cream > modules > screens > ProductForm


1 package org.campware.cream.modules.screens;
2
3 /* ====================================================================
4  * Copyright (C) 2003 Media Development Loan Fund
5  *
6  * Contact: contact@campware.org - http://www.campware.org
7  * Campware encourages further development. Please let us know.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
27  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  * ====================================================================
36  *
37  * This software consists of voluntary contributions made by many
38  * individuals on behalf of the Apache Software Foundation. For more
39  * information on the Apache Software Foundation, please see
40  * <http://www.apache.org/>.
41  */

42
43 import org.apache.torque.util.Criteria;
44
45 import org.apache.velocity.context.Context;
46
47 import org.campware.cream.om.Product;
48 import org.campware.cream.om.ProductPeer;
49 import org.campware.cream.om.VendorPeer;
50 import org.campware.cream.om.ProductCategoryPeer;
51 import org.campware.cream.om.UomPeer;
52
53 /**
54  * To read comments for this class, please see
55  * the ancestor class
56  */

57 public class ProductForm extends CreamForm
58 {
59     protected void initScreen()
60     {
61         setModuleType(ENTITY);
62         setModuleName("PRODUCT");
63         setIdName(ProductPeer.PRODUCT_ID);
64         setFormIdName("productid");
65     }
66
67     protected boolean getEntry(Criteria criteria, Context context)
68     {
69         try
70         {
71             Product entry = (Product) ProductPeer.doSelect(criteria).get(0);
72             context.put("entry", entry);
73
74             return true;
75         }
76         catch (Exception JavaDoc e)
77         {
78             return false;
79         }
80     }
81     
82     protected boolean getNew(Context context)
83     {
84         try
85         {
86             Product entry = new Product();
87             context.put("entry", entry);
88             return true;
89         }
90         catch (Exception JavaDoc e)
91         {
92             return false;
93         }
94     }
95
96     protected boolean getLookups(Context context)
97     {
98         try
99         {
100             Criteria vendorcrit = new Criteria();
101             vendorcrit.add(VendorPeer.VENDOR_ID, 999, Criteria.GREATER_THAN);
102             vendorcrit.addAscendingOrderByColumn(VendorPeer.VENDOR_NAME);
103             context.put("vendors", VendorPeer.doSelect(vendorcrit));
104
105             Criteria prodcatcrit = new Criteria();
106             prodcatcrit.add(ProductCategoryPeer.PRODUCT_CAT_ID, 999, Criteria.GREATER_THAN);
107             prodcatcrit.addAscendingOrderByColumn(ProductCategoryPeer.PRODUCT_CAT_NAME);
108             context.put("productcats", ProductCategoryPeer.doSelect(prodcatcrit));
109
110             Criteria uomcrit = new Criteria();
111             uomcrit.add(UomPeer.UOM_ID, 900, Criteria.LESS_THAN);
112             Criteria.Criterion criterion = uomcrit.getCriterion(UomPeer.UOM_ID);
113             criterion.or(
114                            uomcrit.getNewCriterion(
115                                          criterion.getTable(),
116                                          criterion.getColumn(),
117                                          new Integer JavaDoc(999),
118                                          Criteria.GREATER_THAN )
119                            );
120
121             uomcrit.addAscendingOrderByColumn(UomPeer.UOM_NAME);
122             context.put("uoms", UomPeer.doSelect(uomcrit));
123
124             return true;
125         }
126         catch (Exception JavaDoc e)
127         {
128             return false;
129         }
130     }
131     
132 }
133
Popular Tags