1 14 package org.compiere.www; 15 16 import javax.servlet.*; 17 import javax.servlet.http.*; 18 import java.io.*; 19 import java.util.*; 20 import org.apache.ecs.*; 21 22 import org.apache.ecs.*; 23 import org.apache.ecs.xhtml.*; 24 25 import org.compiere.util.*; 26 import org.compiere.model.*; 27 28 45 public class WLookup extends HttpServlet 46 { 47 53 public void init(ServletConfig config) throws ServletException 54 { 55 super.init(config); 56 if (!WEnv.initWeb(config)) 57 throw new ServletException("WLookup.init"); 58 } 60 69 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 70 { 71 Log.trace(Log.l3_Util, "WLookup.doGet"); 72 HttpSession sess = request.getSession(false); 73 WWindowStatus ws = null; 74 if (sess != null) 75 ws = (WWindowStatus)sess.getAttribute(WEnv.SA_WINDOW); 76 if (ws == null) 77 { 78 WUtil.createTimeoutPage(request, response, this, null, null); 79 return; 80 } 81 String formName = request.getParameter("FormName"); 83 String columnName = request.getParameter("ColumnName"); 84 MField mField = ws.curTab.getField(columnName); 86 Log.trace(Log.l4_Data, "FormName=" + formName, "ColumnName=" + columnName + ", MField=" + mField.toString()); 87 if (mField == null || formName == null || columnName == null || formName.equals("") || columnName.equals("")) 88 { 89 WUtil.createTimeoutPage(request, response, this, ws.ctx, Msg.getMsg(ws.ctx, "ParameterMissing")); 90 return; 91 } 92 String target = "opener.document." + formName + "." + columnName; 94 95 WDoc doc = WDoc.create (mField.getHeader()); 97 body body = doc.getBody(); 98 body.setOnBlur("self.focus();"); 99 body.addElement(fillTable(ws, mField, target)); 100 101 button reset = new button(); 103 reset.addElement("Reset"); reset.setOnClick(target + ".value='';" + target + "_D.value='';window.close();"); 105 button cancel = new button(); 106 cancel.addElement("Cancel"); cancel.setOnClick("window.close();"); 108 body.addElement(new p(AlignType.right) 109 .addElement(reset) 110 .addElement(" ") 111 .addElement(cancel)); 112 WUtil.createResponse (request, response, this, null, doc, false); 115 } 117 118 125 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 126 { 127 Log.trace(Log.l3_Util, "WLookup.doPost"); 128 doGet(request, response); 129 } 131 132 133 134 142 private table fillTable (WWindowStatus ws, MField mField, String target) 143 { 144 if (mField.getColumnName().equals("C_BPartner_ID")) 145 return fillTable_BPartner (ws, mField, target); 146 else if (mField.getColumnName().equals("M_Product_ID")) 147 return fillTable_Product (ws, mField, target); 148 table table = new table("1"); 150 tr line = new tr(); 151 line.addElement(new th(" ")).addElement(new th(Msg.translate(ws.ctx, "Name"))); 152 table.addElement(line); 153 154 Lookup lookup = mField.getLookup(); 156 lookup.fillComboBox(mField.isMandatory(false), true, true, true); int size = lookup.getSize(); 158 for (int i = 0; i < size; i++) 159 { 160 Object lValue = lookup.getElementAt(i); 161 if (!(lValue != null && lValue instanceof KeyNamePair)) 162 continue; 163 KeyNamePair np = (KeyNamePair)lValue; 166 button button = new button(); 167 button.addElement(">"); 168 StringBuffer script = new StringBuffer (target); 169 script.append(".value='").append(np.getKey()).append("';") 170 .append(target).append("_D.value='").append(np.getName()).append("';window.close();"); 171 button.setOnClick(script.toString()); 172 line = new tr(); 174 line.addElement(new td(button)); 175 String name = np.getName(); 176 if (name == null || name.length() == 0) 177 name = " "; 178 line.addElement(new td(name)); 179 table.addElement(line); 180 } 181 lookup.fillComboBox(true); 183 return table; 184 } 186 194 private table fillTable_BPartner (WWindowStatus ws, MField mField, String target) 195 { 196 table table = new table("1"); 197 tr line = new tr(); 198 line.addElement(new th(" ")).addElement(new th(Msg.translate(ws.ctx, "Name"))); 199 table.addElement(line); 200 201 Lookup lookup = mField.getLookup(); 203 lookup.fillComboBox(mField.isMandatory(false), true, true, true); int size = lookup.getSize(); 205 for (int i = 0; i < size; i++) 206 { 207 Object lValue = lookup.getElementAt(i); 208 if (!(lValue != null && lValue instanceof KeyNamePair)) 209 continue; 210 KeyNamePair np = (KeyNamePair)lValue; 213 button button = new button(); 214 button.addElement(">"); 215 StringBuffer script = new StringBuffer (target); 216 script.append(".value='").append(np.getKey()).append("';") 217 .append(target).append("_D.value='").append(np.getName()).append("';window.close();"); 218 button.setOnClick(script.toString()); 219 line = new tr(); 221 line.addElement(new td(button)); 222 String name = np.getName(); 223 if (name == null || name.length() == 0) 224 name = " "; 225 line.addElement(new td(name)); 226 table.addElement(line); 227 } 228 lookup.fillComboBox(true); 230 return table; 231 } 233 241 private table fillTable_Product (WWindowStatus ws, MField mField, String target) 242 { 243 table table = new table("1"); 244 tr line = new tr(); 245 line.addElement(new th(" ")).addElement(new th(Msg.translate(ws.ctx, "Name"))); 246 table.addElement(line); 247 248 Lookup lookup = mField.getLookup(); 250 lookup.fillComboBox(mField.isMandatory(false), true, true, true); int size = lookup.getSize(); 252 for (int i = 0; i < size; i++) 253 { 254 Object lValue = lookup.getElementAt(i); 255 if (!(lValue != null && lValue instanceof KeyNamePair)) 256 continue; 257 KeyNamePair np = (KeyNamePair)lValue; 260 button button = new button(); 261 button.addElement(">"); 262 StringBuffer script = new StringBuffer (target); 263 script.append(".value='").append(np.getKey()).append("';") 264 .append(target).append("_D.value='").append(np.getName()).append("';window.close();"); 265 button.setOnClick(script.toString()); 266 line = new tr(); 268 line.addElement(new td(button)); 269 String name = np.getName(); 270 if (name == null || name.length() == 0) 271 name = " "; 272 line.addElement(new td(name)); 273 table.addElement(line); 274 } 275 lookup.fillComboBox(true); 277 return table; 278 } 280 } | Popular Tags |