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 java.sql.*; 21 import java.math.BigDecimal ; 22 import java.text.*; 23 24 import org.apache.ecs.*; 25 import org.apache.ecs.xhtml.*; 26 27 import org.compiere.model.*; 28 import org.compiere.util.*; 29 30 36 public class WWindow extends HttpServlet 37 { 38 43 public void init(ServletConfig config) throws ServletException 44 { 45 super.init (config); 46 if (!WEnv.initWeb(config)) 47 throw new ServletException("WWindow.init"); 48 } 50 54 public String getServletInfo() 55 { 56 return "Compiere Web Window"; 57 } 59 62 public void destroy() 63 { 64 Log.trace(Log.l1_User, "WWindow.destroy"); 65 } 67 68 private static int s_WindowNo = 1; 69 70 private static final String FORM_NAME = "WForm"; 71 72 73 private static final String P_Command = "PCommand"; 74 75 private static final String P_Tab = "PTab"; 76 77 private static final String P_MR_RowNo = "PMRRowNo"; 78 79 private static final String C_MANDATORY = "Cmandatory"; 81 private static final String C_ERROR = "Cerror"; 82 83 84 private static final int MAX_LINES = 12; 85 86 private static final int LAST_LINE = 999999; 87 88 89 private static final String ERROR = " ERROR! "; 90 91 107 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 108 { 109 Log.trace(Log.l1_User, "WWindow.doGet"); 110 HttpSession sess = request.getSession(); 112 Properties ctx = (Properties)sess.getAttribute(WEnv.SA_CONTEXT); 113 String loginInfo = (String )sess.getAttribute(WEnv.SA_LOGININFO); 114 if (ctx == null) 115 { 116 WUtil.createTimeoutPage(request, response, this, null, null); 117 return; 118 } 119 120 int AD_Window_ID = WUtil.getParameterAsInt(request, "AD_Window_ID"); 122 int AD_Menu_ID = WUtil.getParameterAsInt(request, "AD_Menu_ID"); 124 Log.trace(Log.l4_Data, "AD_Window_ID=" + AD_Window_ID 125 + "; AD_Menu_ID=" + AD_Menu_ID); 126 127 WWindowStatus ws = (WWindowStatus)sess.getAttribute(WEnv.SA_WINDOW); 129 if (ws != null) 130 { 131 int WindowNo = ws.mWindow.getWindowNo(); 132 Log.trace(Log.l4_Data, "WWindow.doGet - disposing", 133 "WindowNo=" + WindowNo + ", ID=" + ws.mWindow.getAD_Window_ID()); 134 ws.mWindow.dispose(); 135 Env.clearWinContext(ctx, WindowNo); 136 } 137 138 141 MWindowVO mWindowVO = MWindowVO.create (ctx, s_WindowNo++, AD_Window_ID, AD_Menu_ID); 142 if (mWindowVO == null) 143 { 144 String msg = Msg.translate(ctx, "AD_Window_ID") + " " 145 + Msg.getMsg(ctx, "NotFound") + ", ID=" + AD_Window_ID + "/" + AD_Menu_ID; 146 WUtil.createErrorPage(request, response, this, ws==null ? null : ws.ctx, msg); 147 sess.setAttribute(WEnv.SA_WINDOW, null); 148 return; 149 } 150 ws = new WWindowStatus(mWindowVO); 152 sess.setAttribute(WEnv.SA_WINDOW, ws); 153 154 155 ws.curTab.query(ws.mWindow.isTransaction()); 157 ws.curTab.navigate(0); 158 159 162 WDoc doc = preparePage(ws); 163 164 body b = doc.getBody(); 166 if (ws.curTab.isSingleRow()) 167 b.addElement(getSR_Form(request.getRequestURI(), ws, loginInfo)); 168 else 169 b.addElement(getMR_Form(request.getRequestURI(), ws, loginInfo)); 170 171 Log.trace(Log.l1_User, "WWindow.doGet", "fini"); 173 WUtil.createResponse (request, response, this, null, doc, true); 175 Log.trace(Log.l1_User, "WWindow.doGet - closed"); 176 } 178 179 180 181 189 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 190 { 191 Log.trace(Log.l1_User, "WWindow.doPost"); 192 193 HttpSession sess = request.getSession(); 195 WWindowStatus ws = null; 196 if (sess != null) 197 ws = (WWindowStatus)sess.getAttribute(WEnv.SA_WINDOW); 198 if (ws == null) 199 { 200 Properties ctx = (Properties)sess.getAttribute(WEnv.SA_CONTEXT); 201 if (ctx == null) 202 WUtil.createTimeoutPage(request, response, this, ctx, "No Context"); 203 else 204 doGet(request, response); 205 return; 206 } 207 String loginInfo = (String )sess.getAttribute(WEnv.SA_LOGININFO); 208 209 String p_cmd = request.getParameter(P_Command); 211 212 215 if (p_cmd.equals("Exit")) 216 { 217 WUtil.createLoginPage(request, response, this, ws.ctx, "Exit"); 218 return; 219 } 220 executeCommand(request, p_cmd, ws); 221 222 225 WDoc doc = preparePage(ws); 226 227 body b = doc.getBody(); 229 if (ws.curTab.isSingleRow()) 231 b.addElement(getSR_Form(request.getRequestURI(), ws, loginInfo)); 232 else 233 b.addElement(getMR_Form(request.getRequestURI(), ws, loginInfo)); 234 235 Log.trace(Log.l1_User, "WWindow.doPost - fini"); 237 WUtil.createResponse (request, response, this, null, doc, true); 239 } 241 242 243 250 private WDoc preparePage(WWindowStatus ws) 251 { 252 WDoc doc = WDoc.create (ws.mWindow.getName()); 253 head header = doc.getHead(); 254 header.addElement(new script("", WEnv.getBaseDirectory("window.js"))); 256 header.addElement(new link().setRel("stylesheet").setHref(WEnv.getBaseDirectory("window.css"))); 257 script script = new script("deleteText='" + Msg.getMsg(ws.ctx, "DeleteRecord?") + "';"); 260 doc.getBody().addElement(script); 261 return doc; 263 } 265 272 private void executeCommand (HttpServletRequest request, String p_cmd, WWindowStatus ws) 273 { 274 String p_tab = request.getParameter(P_Tab); 276 String p_row = request.getParameter(P_MR_RowNo); Log.trace(Log.l4_Data, "WWindow.executeCommand", 278 p_cmd + " - Tab=" + p_tab + " - Row=" + p_row); 279 280 283 if (p_row != null && p_row.length() > 0) 284 { 285 try 286 { 287 int newRowNo = Integer.parseInt (p_row); 288 ws.curTab.navigate(newRowNo); 289 ws.curTab.setSingleRow(true); 290 } 291 catch (Exception e) 292 { 293 Log.error("WWindow.executeCommand - Parse RowNo="+ p_row, e); 294 } 295 } 296 297 300 else if (p_tab != null && p_tab.length() > 0) 301 { 302 int newTabNo = 0; 303 try 304 { 305 newTabNo = Integer.parseInt (p_tab); 306 } 307 catch (Exception e) 308 { 309 Log.error("WWindow.executeCommand - Parse TabNo="+ p_tab, e); 310 } 311 if (newTabNo > ws.curTab.getTabNo()) 313 { 314 ws.curTab = ws.mWindow.getTab(newTabNo); 315 ws.curTab.query(false); 316 ws.curTab.navigate(0); 317 } 318 else if (newTabNo < ws.curTab.getTabNo()) 320 { 321 ws.curTab = ws.mWindow.getTab(newTabNo); 322 ws.curTab.dataRefresh(); 323 } 324 } 325 326 329 else if (p_cmd.equals("Multi")) 330 { 331 boolean single = ws.curTab.isSingleRow(); 332 ws.curTab.setSingleRow(!single); 333 if (single) 334 ws.curTab.navigate(0); 335 } 336 337 340 else if (p_cmd.equals("First")) 341 { 342 ws.curTab.navigate(0); 343 } 344 else if (p_cmd.equals("Next")) 345 { 346 ws.curTab.navigateRelative(+1); } 348 else if (p_cmd.equals("Previous")) 349 { 350 int rows = ws.curTab.isSingleRow() ? -1 : -2*MAX_LINES; 351 ws.curTab.navigateRelative(rows); 352 } 353 else if (p_cmd.equals("Last")) 354 { 355 ws.curTab.navigateRelative(999999); 356 } 357 358 359 362 else if (p_cmd.equals("Find")) 363 { 364 365 } 366 367 370 else if (p_cmd.equals("Refresh")) 371 { 372 ws.curTab.dataRefreshAll(); 373 } 374 375 378 else if (p_cmd.equals("Attachment")) 379 { 380 381 } 382 383 386 else if (p_cmd.equals("History")) 387 { 388 if (ws.mWindow.isTransaction() && ws.curTab.getWindowNo() == 0) 389 { 390 ws.curTab.query( !ws.curTab.isOnlyCurrentRows() ); 391 ws.curTab.navigate(0); 392 } 393 } 394 395 398 else if (p_cmd.equals("Report")) 399 { 400 401 } 402 403 406 else if (p_cmd.equals("Print")) 407 { 408 409 } 410 411 414 else if (p_cmd.equals("New")) 415 { 416 if (!ws.curTab.dataNew(false)) 417 ws.curTab.dataIgnore(); 418 } 419 420 423 else if (p_cmd.equals("Delete")) 424 { 425 ws.curTab.dataDelete(); 426 } 427 428 431 else if (p_cmd.equals("Save")) 432 { 433 executeSave (request, ws); 434 } 435 } 437 442 private void executeSave (HttpServletRequest request, WWindowStatus ws) 443 { 444 Log.trace(Log.l5_DData, "WWindow.save"); 445 boolean error = false; 446 Enumeration en = request.getParameterNames(); 448 while (en.hasMoreElements()) 449 { 450 String key = (String )en.nextElement(); 451 if (key.equals(P_Command) || key.equals(P_MR_RowNo) || key.equals(P_Tab)) 453 continue; 454 MField mField = ws.curTab.getField(key); 455 if (mField != null && mField.isEditable(true)) 457 { 458 String value = request.getParameter(key); 459 Object dbValue = mField.getValue(); 460 boolean fieldError = false; 461 Log.trace(Log.l6_Database, mField.getColumnName(), 462 dbValue==null ? "null" : dbValue.toString() + " -> " + value==null ? "null" : value.toString()); 463 if (dbValue == null && value == null) 465 continue; 466 else if (dbValue != null && value == null) 468 ws.curTab.setValue (mField, null); 469 else if (dbValue == null && value != null) 471 fieldError = !setFieldValue (ws, mField, value); 472 else if (dbValue.equals(value)) 474 continue; 475 else 476 fieldError = !setFieldValue (ws, mField, value); 477 if (!error && fieldError) 479 { 480 Log.trace(Log.l1_User, "WWindow.executeSave - Error", mField.getColumnName()); 481 error = fieldError; 482 } 483 } 484 } 486 Log.trace(Log.l5_DData, "WWindow.save - Mandatory check"); 488 int size = ws.curTab.getFieldCount(); 489 for (int i = 0; i < size; i++) 490 { 491 MField field = ws.curTab.getField(i); 492 if (field.isMandatory(true)) { 494 Object value = field.getValue(); 495 if (value == null || value.toString().length() == 0) 496 { 497 field.setInserting (true); field.setError(true); 499 field.setErrorValue(value == null ? null : value.toString()); 500 if (!error) 501 error = true; 502 Log.trace(Log.l1_User, "WWindow.executeSave - Mandatory Error", field.getColumnName()); 503 } 504 else 505 field.setError(false); 506 } 507 } 508 509 if (error) 510 { 511 Log.trace(Log.l4_Data, "WWindow.executeSave - Error"); 512 return; 513 } 514 515 if (!ws.curTab.dataSave(true)) 517 ws.curTab.dataIgnore(); 518 Log.trace(Log.l4_Data, "WWindow.executeSave - Done"); 519 } 521 528 private boolean setFieldValue(WWindowStatus ws, MField mField, String value) 529 { 530 Object newValue = getFieldValue (ws, mField, value); 531 if (ERROR.equals(newValue)) 532 { 533 mField.setErrorValue(value); 534 return false; 535 } 536 Object dbValue = mField.getValue(); 537 if ((newValue == null && dbValue != null) 538 || (newValue != null && !newValue.equals(dbValue))) 539 ws.curTab.setValue(mField, newValue); 540 return true; 541 } 543 551 private Object getFieldValue (WWindowStatus ws, MField mField, String value) 552 { 553 if (value == null || value.length() == 0) 554 return null; 555 556 int dt = mField.getDisplayType(); 557 558 if (DisplayType.isNumeric(dt)) 560 { 561 BigDecimal bd = null; 562 try 563 { 564 Number nn = null; 565 if (dt == DisplayType.Amount) 566 nn = ws.amountFormat.parse(value); 567 else if (dt == DisplayType.Quantity) 568 nn = ws.quantityFormat.parse(value); 569 else 570 nn = ws.numberFormat.parse(value); 571 if (nn instanceof BigDecimal ) 572 bd = (BigDecimal )nn; 573 else 574 bd = new BigDecimal (nn.toString()); 575 } 576 catch (Exception e) 577 { 578 Log.trace(Log.l6_Database, "BigDecimal", value + ERROR); 579 return ERROR; 580 } 581 Log.trace(Log.l6_Database, "WWindow.getFieldValue - BigDecimal", value + " -> " + bd); 582 return bd; 583 } 584 585 else if (DisplayType.isID(dt)) 587 { 588 Integer ii = null; 589 try 590 { 591 ii = new Integer (value); 592 } 593 catch (Exception e) 594 { 595 Log.error("WWindow.getFieldValue - ID=" + value, e); 596 ii = null; 597 } 598 if (ii.intValue() == -1) 600 ii = null; 601 Log.trace(Log.l6_Database, "WWindow.getFieldValue - ID", value + " -> " + ii); 602 return ii; 603 } 604 605 else if (DisplayType.isDate(dt)) 607 { 608 Timestamp ts = null; 609 try 610 { 611 java.util.Date d = null; 612 if (dt == DisplayType.Date) 613 d = ws.dateFormat.parse(value); 614 else 615 d = ws.dateTimeFormat.parse(value); 616 ts = new Timestamp(d.getTime()); 617 } 618 catch (Exception e) 619 { 620 Log.trace(Log.l6_Database, "WWindow.getFieldValue - Date", value + ERROR); 621 return ERROR; 622 } 623 Log.trace(Log.l6_Database, "WWindow.getFieldValue - Date", value + " -> " + ts); 624 return ts; 625 } 626 627 else if (dt == DisplayType.YesNo) 629 { 630 if (value.equals("true")) 631 return "Y"; 632 return "N"; 633 } 634 635 return value; 637 } 639 640 641 642 649 private form getSR_Form (String action, WWindowStatus ws, String loginInfo) 650 { 651 Log.trace(Log.l2_Sub, "WWindow.getSR_Form - Tab=" + ws.curTab.getTabNo()); 652 653 656 table table = new table().setAlign(AlignType.CENTER); 657 tr line = new tr(); 659 int noFields = ws.curTab.getFieldCount(); 660 for (int i = 0; i < noFields; i++) 661 { 662 MField field = ws.curTab.getField(i); 663 String colName = field.getColumnName(); 664 665 668 Object data = ws.curTab.getValue(field); 669 String info = null; 670 if (data == null) 671 info = ""; 672 else 673 { 674 switch(field.getDisplayType()) 675 { 676 case DisplayType.Date: 677 info = ws.dateFormat.format(data); 678 break; 679 case DisplayType.DateTime: 680 info = ws.dateTimeFormat.format(data); 681 break; 682 case DisplayType.Amount: 683 info = ws.amountFormat.format(data); 684 break; 685 case DisplayType.Number: 686 info = ws.numberFormat.format(data); 687 break; 688 case DisplayType.Quantity: 689 info = ws.quantityFormat.format(data); 690 break; 691 case DisplayType.Integer: 692 info = ws.integerFormat.format(data); 693 break; 694 695 default: 696 info = data.toString(); 697 } 698 } 699 if (info == null) 700 info = ""; 701 702 705 if (field.isDisplayed(false)) 706 { 707 if (!field.isSameLine()) 708 line = new tr(); 709 addField(line, field, data, info, false ); 711 table.addElement(line); 712 } 713 } 715 int rowNo = ws.curTab.getCurrentRow(); 717 String statusDB = String.valueOf(rowNo+1) + " # " + ws.curTab.getRowCount(); 718 719 return createLayout(action, table, ws, 720 loginInfo, "", statusDB); 721 } 723 724 725 726 733 private form getMR_Form (String action, WWindowStatus ws, String loginInfo) 734 { 735 Log.trace(Log.l2_Sub, "WWindow.getMR_Form - Tab=" + ws.curTab.getTabNo()); 736 737 int initRowNo = ws.curTab.getCurrentRow(); 738 739 742 table table = new table().setAlign(AlignType.CENTER); 743 table.setClass("MultiRow"); 744 table.setBorder(1); 745 table.setCellSpacing(1); 746 tr line = new tr(); 747 line.addElement(new th().addElement(" ")); 749 int noFields = ws.curTab.getFieldCount(); 751 for (int colNo = 0; colNo < noFields; colNo++) 752 { 753 MField field = ws.curTab.getField(colNo); 754 if (field.isDisplayed(false)) 755 { 756 th th = new th(); 757 th.addElement(field.getHeader()); th.setAbbr(field.getDescription()); line.addElement(th); 760 } 761 } table.addElement(new thead().addElement(line)); 763 764 767 int lastRow = initRowNo + MAX_LINES; 768 lastRow = Math.min(lastRow, ws.curTab.getRowCount()); 769 for (int lineNo = initRowNo; lineNo < lastRow; lineNo++) 770 { 771 ws.curTab.navigate(lineNo); 773 774 line = new tr(); 775 button selector = new button(); 777 selector.addElement(">"); selector.setOnClick("document." + FORM_NAME + "." + P_MR_RowNo + ".value='" + lineNo + "'; submit();"); 779 line.addElement(new td().addElement(selector)); 780 781 for (int colNo = 0; colNo < noFields; colNo++) 783 { 784 td td = new td(); 785 MField field = ws.curTab.getField(colNo); 787 if (!field.isDisplayed(false)) 788 continue; 789 790 Object data = ws.curTab.getValue(field.getColumnName()); 792 String info = null; 793 if (data == null) 795 info = ""; 796 else 797 { 798 int dt = field.getDisplayType(); 799 switch (dt) 800 { 801 case DisplayType.Date: 802 info = ws.dateFormat.format(data); 803 td.setAlign("right"); 804 break; 805 case DisplayType.DateTime: 806 info = ws.dateTimeFormat.format(data); 807 td.setAlign("right"); 808 break; 809 case DisplayType.Amount: 810 info = ws.amountFormat.format(data); 811 td.setAlign("right"); 812 break; 813 case DisplayType.Number: 814 info = ws.numberFormat.format(data); 815 td.setAlign("right"); 816 break; 817 case DisplayType.Quantity: 818 info = ws.quantityFormat.format(data); 819 td.setAlign("right"); 820 break; 821 case DisplayType.Integer: 822 info = ws.integerFormat.format(data); 823 td.setAlign("right"); 824 break; 825 case DisplayType.YesNo: 826 info = Msg.getMsg(ws.ctx, data.toString()); 827 break; 828 829 default: 830 if (DisplayType.isLookup(dt)) 831 info = field.getLookup().getDisplay(data); 832 else 833 info = data.toString(); 834 } 835 } 836 837 if (info == null || info.length() == 0) 839 info = " "; td.addElement(info); 842 line.addElement(td); 843 } table.addElement(line); 845 } 847 String statusDB = String.valueOf(initRowNo+1) + "-" + String.valueOf(lastRow) + " # " + ws.curTab.getRowCount(); 849 850 return createLayout(action, table, ws, 851 loginInfo, "", statusDB); 852 } 854 865 private static form createLayout (String action, table table, WWindowStatus ws, 866 String loginInfo, String statusInfo, String statusDB) 867 { 868 Log.trace(Log.l3_Util, "WWindow.createLayout"); 869 form myForm = null; 870 myForm = new form(action, form.post, form.ENC_DEFAULT); 871 myForm.setTarget(WEnv.TARGET_WINDOW); 872 String AD_Language = Env.getAD_Language(ws.ctx); 873 874 myForm.setName(FORM_NAME); 876 myForm.addElement(new input("hidden", P_Command, "")); myForm.addElement(new input("hidden", P_MR_RowNo, "")); String title = ws.mWindow.getName() + " - " + loginInfo; 880 myForm.addElement(new script("top.document.title='" + title + "';")); 881 882 myForm.addElement(createImage(AD_Language, "Ignore", "reset();", true, false)); 884 myForm.addElement(" "); 885 myForm.addElement(createImage(AD_Language, "Help")); 886 myForm.addElement(createImage(AD_Language, "New")); 887 myForm.addElement(createImage(AD_Language, "Delete", "if (confirm(deleteText)) submit();", true, false)); 888 myForm.addElement(createImage(AD_Language, "Save")); 889 myForm.addElement(" "); 890 myForm.addElement(createImage(AD_Language, "Find")); 891 myForm.addElement(createImage(AD_Language, "Refresh")); 892 myForm.addElement(createImage(AD_Language, "Attachment", null, ws.curTab.canHaveAttachment(), ws.curTab.hasAttachment())); 893 myForm.addElement(createImage(AD_Language, "Multi", null, true, !ws.curTab.isSingleRow())); 894 myForm.addElement(" "); 895 myForm.addElement(createImage(AD_Language, "History", null, 896 ws.mWindow.isTransaction()&&ws.curTab.getTabNo()==0, !ws.curTab.isOnlyCurrentRows())); 897 myForm.addElement(" "); 898 boolean isFirst = ws.curTab.getCurrentRow() < 1; 899 myForm.addElement(createImage(AD_Language, "First", null, !isFirst, false)); 900 myForm.addElement(createImage(AD_Language, "Previous", null, !isFirst, false)); 901 boolean isLast = ws.curTab.getCurrentRow()+1 == ws.curTab.getRowCount(); 902 myForm.addElement(createImage(AD_Language, "Next", null, !isLast, false)); 903 myForm.addElement(createImage(AD_Language, "Last", null, !isLast, false)); 904 myForm.addElement(" "); 905 myForm.addElement(createImage(AD_Language, "Report")); 906 myForm.addElement(createImage(AD_Language, "Print")); 907 myForm.addElement(" "); 908 myForm.addElement(createImage(AD_Language, "Exit")); 909 910 myForm.addElement(new br()); 912 myForm.addElement(new br()); 913 myForm.addElement(new input("hidden", P_Tab, "")); 914 for (int i = 0; i < ws.mWindow.getTabCount(); i++) 915 { 916 MTab tab = ws.mWindow.getTab(i); 917 big big = new big(tab.getName()); 918 if (ws.curTab.getTabNo() == i) 919 big.setID("tabSelected"); else 921 { 922 big.setID("tab"); big.setOnClick("alert('" + tab.getName() + "');"); 924 big.setOnClick("document." + FORM_NAME + "." + P_Tab + ".value='" + i + "';submit();"); 925 } 926 if (tab.getDescription().length() > 0) 928 big.setOnMouseOver("status='" + tab.getDescription() + "';return true;"); 929 myForm.addElement(big); 930 } 931 932 myForm.addElement(new hr()); 934 myForm.addElement(table); 935 936 tr statusline = new tr(); 938 statusline.addElement(new td().setWidth("85%").addElement(statusInfo)); 939 statusline.addElement(new td().setWidth("10%").setAlign("right").addElement(new small(statusDB))); 940 statusline.addElement(new td().setWidth("5%").setAlign("right").addElement(createImage(AD_Language, "Save"))); 941 myForm.addElement(new hr()); 943 myForm.addElement(new table().setWidth("100%").addElement(statusline)); 944 945 myForm.addElement("\n"); 947 948 return myForm; 950 } 952 953 954 963 private static img createImage (String AD_Language, String name, String js_command, boolean enabled, boolean pressed) 964 { 965 StringBuffer imgName = new StringBuffer (name); 966 if (!enabled) 967 imgName.append("D"); 968 else if (pressed) 969 imgName.append("X"); 970 imgName.append("24.gif"); 971 img img = new img (WEnv.getImageDirectory(imgName.toString()), name); 973 if (enabled) 974 img.setAlt(Msg.getMsg(AD_Language, name)); if (!pressed || !enabled) 977 img.setID("imgButton"); else 979 img.setID("imgButtonPressed"); if (js_command == null) 982 js_command = "submit();"; 983 if (js_command.length() > 0 && enabled) 984 img.setOnClick("document." + FORM_NAME + "." + P_Command + ".value='" + name + "';" + js_command); 985 return img; 987 } 989 995 private static img createImage (String AD_Language, String name) 996 { 997 return createImage (AD_Language, name, null, true, false); 998 } 1000 1001 1002 1010 private static void addField (tr line, MField field, Object oData, String data, boolean isDependant) 1011 { 1012 String columnName = field.getColumnName(); 1013 boolean readOnly = !field.isEditable(false); boolean mandatory = field.isMandatory(false); boolean error = field.isErrorValue(); 1017 if (error) 1018 data = field.getErrorValue(); 1019 if (data == null) 1020 data = ""; 1021 1022 1030 label label = new label(columnName).addElement(field.getHeader()); 1031 label.setID("ID_" + columnName); 1032 label.setTitle(field.getDescription()); 1033 int dt = field.getDisplayType(); 1034 1035 if (dt == DisplayType.String || DisplayType.isDate(dt)) 1037 { 1038 line.addElement(new td().addElement(label).setAlign(AlignType.RIGHT)); 1039 input string = new input(input.text, columnName, data); 1041 string.setSize(field.getDisplayLength()); 1042 if (dt == DisplayType.String) 1043 string.setMaxlength(field.getFieldLength()); 1044 else 1045 string.setMaxlength(field.getDisplayLength()); 1046 string.setID("ID_" + columnName); 1047 string.setDisabled(readOnly); 1048 if (error) 1049 string.setClass(C_ERROR); 1050 else if (mandatory) 1051 string.setClass(C_MANDATORY); 1052 if (isDependant) 1053 string.setOnChange("dynDisplay();"); 1054 td td = new td().addElement(string).setAlign(AlignType.LEFT); 1055 if (field.isLongField()) 1056 td.setColSpan(3); 1057 line.addElement(td); 1058 } 1059 else if (DisplayType.isNumeric(dt)) 1061 { 1062 line.addElement(new td().addElement(label).setAlign(AlignType.RIGHT)); 1063 input string = new input(input.text, columnName, data); 1065 string.setSize(field.getDisplayLength()); 1066 string.setID("ID_" + columnName); 1067 string.setDisabled(readOnly); 1068 if (error) 1069 string.setClass(C_ERROR); 1070 else if (mandatory) 1071 string.setClass(C_MANDATORY); 1072 if (isDependant) 1073 string.setOnChange("dynDisplay();"); 1074 line.addElement(new td().addElement(string).setAlign(AlignType.LEFT)); 1075 } 1076 else if (dt == DisplayType.Text) 1078 { 1079 line.addElement(new td().addElement(label).setAlign(AlignType.RIGHT).setVAlign(AlignType.TOP)); 1080 textarea text = new textarea(columnName, 3, field.getDisplayLength()).addElement(data); 1082 text.setID("ID_" + columnName); 1083 text.setDisabled(readOnly); 1084 if (error) 1085 text.setClass(C_ERROR); 1086 else if (mandatory) 1087 text.setClass(C_MANDATORY); 1088 if (isDependant) 1089 text.setOnChange("dynDisplay();"); 1090 td td = new td().addElement(text).setAlign(AlignType.LEFT); 1091 if (field.isLongField()) 1092 td.setColSpan(3); 1093 line.addElement(td); 1094 } 1095 else if (dt == DisplayType.Memo) 1096 { 1097 line.addElement(new td().addElement(label).setAlign(AlignType.RIGHT).setVAlign(AlignType.TOP)); 1098 textarea text = new textarea(columnName, 25, field.getDisplayLength()).addElement(data); 1100 text.setID("ID_" + columnName); 1101 text.setDisabled(readOnly); 1102 if (error) 1103 text.setClass(C_ERROR); 1104 else if (mandatory) 1105 text.setClass(C_MANDATORY); 1106 if (isDependant) 1107 text.setOnChange("dynDisplay();"); 1108 td td = new td().addElement(text).setAlign(AlignType.LEFT); 1109 if (field.isLongField()) 1110 td.setColSpan(3); 1111 line.addElement(td); 1112 } 1113 else if (dt == DisplayType.YesNo) 1115 { 1116 line.addElement(new td()); 1117 boolean check = data.equals("Y"); 1119 input cb = new input(input.checkbox, columnName, "true").setChecked(check).addElement(field.getHeader()); 1120 cb.setID("ID_" + columnName); 1121 cb.setDisabled(readOnly); 1122 if (error) 1123 cb.setClass(C_ERROR); 1124 if (isDependant) 1127 cb.setOnChange("dynDisplay();"); 1128 line.addElement(new td().addElement(cb).setAlign(AlignType.LEFT)); 1129 } 1130 else if (dt == DisplayType.Search) 1132 { 1133 line.addElement(new td().addElement(label).setAlign(AlignType.RIGHT)); 1134 input hidden = new input(input.hidden, columnName, data); 1136 String displayData = field.getLookup().getDisplay(oData); 1138 input display = new input(input.text, columnName + "_D", displayData); 1139 display.setID("ID_" + columnName); 1141 display.setReadOnly(true); 1142 input button = new input(input.image, columnName + "_B", "x"); 1144 String gif = "PickOpen10.gif"; 1145 if (columnName.equals("C_BPartner_ID")) 1146 gif = "BPartner10.gif"; 1147 else if (columnName.equals("M_Product_ID")) 1148 gif = "Product10.gif"; 1149 button.setSrc(WEnv.getImageDirectory(gif)); 1150 button.setBorder(1); 1151 button.setOnClick("return startLookup(" + columnName + ");"); 1152 if (error) 1153 display.setClass(C_ERROR); 1154 else if (mandatory) 1155 display.setClass(C_MANDATORY); 1156 if (isDependant) 1157 display.setOnChange("dynDisplay();"); 1158 td td = new td() 1159 .addElement(hidden) 1160 .addElement(display) 1161 .addElement(button) 1162 .setAlign(AlignType.LEFT); 1163 line.addElement(td); 1164 } 1165 else if (dt == DisplayType.Location) 1167 { 1168 line.addElement(new td().addElement(label).setAlign(AlignType.RIGHT)); 1169 input hidden = new input(input.hidden, columnName, data); 1171 String displayData = field.getLookup().getDisplay(oData); 1173 input display = new input(input.text, columnName + "_D", displayData); 1174 display.setID("ID_" + columnName); 1176 display.setReadOnly(true); 1177 input button = new input(input.image, columnName + "_B", "l"); 1179 button.setSrc(WEnv.getImageDirectory("Location10.gif")).setBorder(1); 1180 button.setOnClick("return startLocation(" + columnName + ");"); 1181 if (error) 1182 display.setClass(C_ERROR); 1183 else if (mandatory) 1184 display.setClass(C_MANDATORY); 1185 if (isDependant) 1186 display.setOnChange("dynDisplay();"); 1187 td td = new td() 1188 .addElement(hidden) 1189 .addElement(display) 1190 .addElement(button) 1191 .setAlign(AlignType.LEFT); 1192 line.addElement(td); 1193 } 1194 else if (dt == DisplayType.Account) 1196 { 1197 line.addElement(new td().addElement(label).setAlign(AlignType.RIGHT)); 1198 input hidden = new input(input.hidden, columnName, data); 1200 String displayData = field.getLookup().getDisplay(oData); 1202 input display = new input(input.text, columnName + "_D", displayData); 1203 display.setID("ID_" + columnName); 1205 display.setReadOnly(true); 1206 input button = new input(input.image, columnName + "_B", "x"); 1208 button.setSrc(WEnv.getImageDirectory("Account10.gif")); 1209 button.setBorder(1); 1210 button.setOnClick("return startAccount(" + columnName + ");"); 1211 if (error) 1212 display.setClass(C_ERROR); 1213 else if (mandatory) 1214 display.setClass(C_MANDATORY); 1215 if (isDependant) 1216 display.setOnChange("dynDisplay();"); 1217 td td = new td() 1218 .addElement(hidden) 1219 .addElement(display) 1220 .addElement(button) 1221 .setAlign(AlignType.LEFT); 1222 line.addElement(td); 1223 } 1224 else if (DisplayType.isLookup(dt) || dt == DisplayType.Locator) 1226 { 1227 line.addElement(new td().addElement(label).setAlign(AlignType.RIGHT)); 1228 Lookup lookup = field.getLookup(); 1230 Object [] list = lookup.getData(mandatory, true, false, false).toArray(); int size = list.length; 1232 option options[] = new option[size]; 1233 if (size > 0) 1234 { 1235 boolean isNumber = list[0] instanceof KeyNamePair; 1236 for (int i = 0; i < size; i++) 1237 { 1238 String key = null; 1239 if (dt == DisplayType.Locator) 1240 { 1241 MLocator loc = (MLocator)list[i]; 1242 key = String.valueOf(loc.getM_Locator_ID()); 1243 options[i] = new option(key).addElement(loc.getValue()); 1244 } 1245 else if (isNumber) 1246 { 1247 KeyNamePair p = (KeyNamePair)list[i]; 1248 key = String.valueOf(p.getKey()); 1249 options[i] = new option(key).addElement(p.getName()); 1250 } 1251 else 1252 { 1253 ValueNamePair p = (ValueNamePair)list[i]; 1254 key = p.getValue(); 1255 if (key == null || key.length() == 0) 1256 key = "??"; 1257 String name = p.getName(); 1258 if (name == null || name.length() == 0) 1259 name = "???"; 1260 options[i] = new option(key).addElement(name); 1261 } 1262 if (data.equals(key)) 1263 options[i].setSelected(true); 1264 } 1265 } 1266 select sel = new select(columnName, options); 1267 sel.setID("ID_" + columnName); 1268 sel.setDisabled(readOnly); 1269 if (error) 1270 sel.setClass(C_ERROR); 1271 else if (mandatory) 1272 sel.setClass(C_MANDATORY); 1273 if (isDependant) 1274 sel.setOnChange("dynDisplay();"); 1275 line.addElement(new td().addElement(sel)); 1276 } 1277 else if (dt == DisplayType.Button) 1279 { 1280 line.addElement(new td()); 1281 input b = new input(input.button, columnName, field.getHeader()); 1283 b.setID("ID_" + columnName); 1284 b.setDisabled(readOnly); 1285 line.addElement(new td().addElement(b).setAlign(AlignType.LEFT)); 1287 } 1288 1289 else 1291 { 1292 line.addElement(new td().addElement(label).setAlign(AlignType.RIGHT)); 1293 line.addElement(new td().addElement("[" + data + "]").setID("ID_" + columnName)); 1294 } 1295 1296 String dispLogic = field.getDisplayLogic(); 1298 if (dispLogic == null) 1299 dispLogic = ""; 1300 if (dispLogic.length() > 0) 1301 { 1302 dispLogic = dispLogic.replace('\'', '"'); String attrib = "document." + FORM_NAME + "." + columnName + ".displayLogic='" + dispLogic + "';"; 1304 line.addElement(new script(attrib)); 1305 } 1306 } 1308} | Popular Tags |