KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_actionButton > ActionButtonUtility


1 /*
2  *************************************************************************
3  * The contents of this file are subject to the Openbravo Public License
4  * Version 1.0 (the "License"), being the Mozilla Public License
5  * Version 1.1 with a permitted attribution clause; you may not use this
6  * file except in compliance with the License. You may obtain a copy of
7  * the License at http://www.openbravo.com/legal/license.html
8  * Software distributed under the License is distributed on an "AS IS"
9  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10  * License for the specific language governing rights and limitations
11  * under the License.
12  * The Original Code is Openbravo ERP.
13  * The Initial Developer of the Original Code is Openbravo SL
14  * All portions are Copyright (C) 2001-2006 Openbravo SL
15  * All Rights Reserved.
16  * Contributor(s): ______________________________________.
17  ************************************************************************
18 */

19 package org.openbravo.erpCommon.ad_actionButton;
20
21 import java.util.Vector JavaDoc;
22 import org.openbravo.database.ConnectionProvider;
23 import org.openbravo.base.secureApp.VariablesSecureApp;
24 import org.openbravo.erpCommon.utility.ComboTableData;
25 import org.openbravo.erpCommon.utility.Utility;
26 import org.openbravo.erpCommon.utility.SQLReturnObject;
27 import org.openbravo.data.FieldProvider;
28 import org.apache.log4j.Logger;
29
30 public class ActionButtonUtility {
31   static Logger log4j = Logger.getLogger(ActionButtonUtility.class);
32
33   public static FieldProvider[] docAction(ConnectionProvider conn, VariablesSecureApp vars, String JavaDoc strDocAction, String JavaDoc strReference, String JavaDoc strDocStatus, String JavaDoc strProcessing, String JavaDoc strTable) {
34     FieldProvider[] ld = null;
35     if (log4j.isDebugEnabled()) log4j.debug("DocAction - generating combo elements for table: " + strTable + " - actual status: " + strDocStatus);
36     try {
37       ComboTableData comboTableData = new ComboTableData(vars, conn, "LIST", "DocAction", strReference, "", Utility.getContext(conn, vars, "#User_Org", "ActionButtonUtility"), Utility.getContext(conn, vars, "#User_Client", "ActionButtonUtility"), 0);
38       Utility.fillSQLParameters(conn, vars, null, comboTableData, "ActionButtonUtility", "");
39       ld = comboTableData.select(false);
40       comboTableData = null;
41     } catch (Exception JavaDoc e) {
42       return null;
43     }
44     SQLReturnObject[] data=null;
45     if (ld!=null) {
46       Vector JavaDoc<Object JavaDoc> v = new Vector JavaDoc<Object JavaDoc>();
47       SQLReturnObject data1 = new SQLReturnObject();
48       if (!strProcessing.equals("") && strProcessing.equals("Y")) {
49         data1.setData("ID", "XL");
50         v.addElement(data1);
51       } else if (strDocStatus.equals("NA")) {
52         data1.setData("ID", "AP");
53         v.addElement(data1);
54         data1 = new SQLReturnObject();
55         data1.setData("ID", "RJ");
56         v.addElement(data1);
57         data1 = new SQLReturnObject();
58         data1.setData("ID", "VO");
59         v.addElement(data1);
60       } else if (strDocStatus.equals("DR") || strDocStatus.equals("IP")) {
61         data1.setData("ID", "CO");
62         v.addElement(data1);
63         data1 = new SQLReturnObject();
64         data1.setData("ID", "VO");
65         v.addElement(data1);
66       } else if (strDocStatus.equals("CO")) {
67         data1.setData("ID", "CL");
68         v.addElement(data1);
69       }
70       data1 = new SQLReturnObject();
71       if (strTable.equals("259")) {
72         if (strDocStatus.equals("DR")) {
73           data1.setData("ID", "PR");
74           v.addElement(data1);
75         } else if (strDocStatus.equals("CO")) {
76           data1.setData("ID", "RE");
77           v.addElement(data1);
78         }
79       } else if (strTable.equals("318")) {
80         if (strDocStatus.equals("CO")) {
81           data1.setData("ID", "RC");
82           v.addElement(data1);
83           data1 = new SQLReturnObject();
84           data1.setData("ID", "RE");
85           v.addElement(data1);
86         }
87       } else if (strTable.equals("319")) {
88         if (strDocStatus.equals("CO")) {
89           data1.setData("ID", "RC");
90           v.addElement(data1);
91         }
92       } else if (strTable.equals("224")) {
93         if (strDocStatus.equals("CO")) {
94           data1.setData("ID", "RE");
95           v.addElement(data1);
96         }
97       }
98
99       data = new SQLReturnObject[v.size()];
100       v.copyInto(data);
101       if (log4j.isDebugEnabled()) log4j.debug("DocAction - total combo elements: " + data.length);
102       for (int i=0;i<data.length;i++) {
103         if (log4j.isDebugEnabled()) log4j.debug("DocAction - Element: " + i + " - ID: " + data[i].getField("ID"));
104         for (int j=0;j<ld.length;j++) {
105           if (data[i].getField("ID").equals(ld[j].getField("ID"))) {
106             data[i].setData("NAME", ld[j].getField("NAME"));
107             data[i].setData("DESCRIPTION", ld[j].getField("DESCRIPTION"));
108             break;
109           }
110         }
111       }
112     }
113     return data;
114   }
115
116   public static FieldProvider[] projectAction(ConnectionProvider conn, VariablesSecureApp vars, String JavaDoc strProjectAction, String JavaDoc strReference, String JavaDoc strProjectStatus) {
117     FieldProvider[] ld = null;
118     try {
119       ComboTableData comboTableData = new ComboTableData(vars, conn, "LIST", "ProjectAction", strReference, "", Utility.getContext(conn, vars, "#User_Org", "ActionButtonUtility"), Utility.getContext(conn, vars, "#User_Client", "ActionButtonUtility"), 0);
120       Utility.fillSQLParameters(conn, vars, null, comboTableData, "ActionButtonUtility", "");
121       ld = comboTableData.select(false);
122       comboTableData = null;
123     } catch (Exception JavaDoc e) {
124       return null;
125     }
126     SQLReturnObject[] data=null;
127     if (ld!=null) {
128       Vector JavaDoc<Object JavaDoc> v = new Vector JavaDoc<Object JavaDoc>();
129       SQLReturnObject data1 = new SQLReturnObject();
130       if (strProjectStatus.equals("NF") || strProjectStatus.equals("OP")) {
131         data1.setData("ID", "OR");
132         v.addElement(data1);
133         data1 = new SQLReturnObject();
134         data1.setData("ID", "OC");
135         v.addElement(data1);
136       } else if (strProjectStatus.equals("OR")) {
137         data1.setData("ID", "OC");
138         v.addElement(data1);
139       }
140
141       if (v.size()>0) {
142         data = new SQLReturnObject[v.size()];
143         v.copyInto(data);
144         for (int i=0;i<data.length;i++) {
145           for (int j=0;j<ld.length;j++) {
146             if (data[i].getField("ID").equals(ld[j].getField("ID"))) {
147               data[i].setData("NAME", ld[j].getField("NAME"));
148               data[i].setData("DESCRIPTION", ld[j].getField("DESCRIPTION"));
149               break;
150             }
151           }
152         }
153       }
154     }
155     return data;
156   }
157 }
158
Popular Tags