home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / JDesignerPro / Jdp3_0.exe / data1.cab / Program_Files / Applications / Layouts / JDPLayout2.java < prev    next >
Encoding:
Text File  |  1999-04-09  |  14.5 KB  |  510 lines

  1. >XXX0454  Total lines for the build status message calculation
  2. //--------------------------------------------------------------------
  3. //                                                                    
  4. >001//  Module:       <JDPModule>                                       
  5. >002//  Description:  <Class Description>
  6. //                                                                    
  7. //--------------------------------------------------------------------
  8.  
  9. import java.awt.*;
  10. import java.applet.*;
  11. import java.util.*;
  12.  
  13.  
  14. >003public class <JDPUserBill> extends JDPClassLayout {
  15.  
  16.     JDPUser user;
  17.     JDPJagg jaggSQL;
  18.     JDPTextGrid tableContents;
  19.     JDPWhereClause jdpWhereClause;
  20.     JDPPopupMessage popuppanel;
  21.     JDPMaskEdit JDPMaskEditMain;
  22.  
  23.     String[] psortChoice;
  24.     String[] pdisplayChoice;
  25.     int itemIndex;
  26.     boolean insertRequested = false;
  27.     boolean deleteRequested = false;
  28.     String pfromWhereClause;
  29.     String[][] rowKey;
  30.     int totalRows;
  31.     int keyCount;
  32.     int prevColumnCount;
  33. >119    int columnCount = <columnCount>;
  34. >052    Vector value<name>;
  35.  
  36.     Vector pmatchUsing;
  37.     Vector pactualmatchUsing;
  38.  
  39.     public void InitClass(JDPUser user, Panel targetPanel, String moduleParameter) {
  40.  
  41.         this.user = user;
  42.         //
  43.         //  Set JAGG settings for this class
  44.         //
  45.         jaggSQL = new JDPJagg(user.jaggPath);
  46.         jaggSQL.setNULL("space");
  47. >996        jaggSQL.setMRW("<maxRows>");
  48. >998        jaggSQL.setDSN("<datasource>");
  49. >984        jaggSQL.setUID("<>");
  50. >985        jaggSQL.setPWD("<>");
  51.  
  52.         setLayout(new BorderLayout());
  53.         setFont(user.plainFont);
  54.          popuppanel = new JDPPopupMessage(user,targetPanel);
  55.         targetPanel.add(popuppanel);
  56.  
  57.         Panel mainPanel = new Panel();
  58.         mainPanel.setLayout(new BorderLayout());
  59.         Panel centerMainPanel = new Panel();
  60.         centerMainPanel.setLayout(new BorderLayout());
  61.  
  62.         //
  63.         //  Create a new instance of a Grid
  64.         //
  65.         tableContents = new JDPTextGrid(user);
  66.         mainPanel.add("Center",tableContents);
  67.         centerMainPanel.add("Center",mainPanel);
  68.         //
  69.         //  Add buttons to the bottom of the panel
  70.         //
  71.         if (moduleParameter.compareTo("Inquiry") == 0) {
  72.         } else {
  73. >015            String buttons[] = {<"   Apply   ","Reset","New","Copy","Remove">};
  74. >047            int icons[] = {<>};
  75.             JDPButtons btns = new JDPButtons(user, buttons, icons, JDPButtons.HORIZONTAL);
  76.             centerMainPanel.add("South",btns);
  77. >046            popuppanel.addComponent(btns.button[<0>],"<>","<>");
  78.         }
  79.         
  80.         //
  81.         //  Define parameters for JDPWhereClause
  82.         //
  83. >016        String[] pchooseFrom = new String[<7>];
  84. >017        pchooseFrom[<0>] = "<Account Name>";
  85.  
  86. >018        String[] pactualchooseFrom = new String[<7>];
  87. >019        pactualchooseFrom[<0>] = "<username>";
  88.  
  89. >024        boolean[] constantIsString = new boolean[<7>];
  90. >025        constantIsString[<0>] = <true>;
  91.  
  92. >026        int[] constantLength = new int[<7>];
  93. >027        constantLength[<0>] = <20>;
  94.  
  95.         loadMatchUsing();
  96.         //
  97.         //  Add JDPWhereClause search panel
  98.         //
  99.         if (pchooseFrom.length > 0) {
  100. >028            jdpWhereClause = new JDPWhereClause(user, targetPanel, "<UserBill>", false, "<pinitChoice>", pchooseFrom, pactualchooseFrom,
  101.                                                 pmatchUsing, pactualmatchUsing, null, null,
  102.                                                 constantLength, constantIsString);
  103.             centerMainPanel.add("North",jdpWhereClause);
  104.         }
  105.  
  106. >030        add("Center",new JDPChiselFramePanel(user,"<User Billing Details>",centerMainPanel,"North"));
  107.         setGridSettings();
  108.         JDPMaskEditMain = new JDPMaskEdit();
  109.         loadGrid();
  110.  
  111.         //
  112.         //  Add the handle to this panel to the global vector so other panels can
  113.         //  access this one
  114.         //
  115.         user.gParm.addElement(this);
  116.     }
  117.  
  118.     //
  119.     //  Handle screen events
  120.     //
  121.     public boolean handleEvent(Event e) {
  122.  
  123.         switch (e.id) {
  124.         case Event.ACTION_EVENT:
  125.             if (e.target instanceof Button) {
  126.                 String choice = (String)e.arg;
  127.                 if (choice.trim().compareTo("Apply") == 0) {
  128.                     if (checkFields()) {
  129.                         checkRows();
  130.                     }
  131.                     return true;
  132.                 }
  133.                 if (choice.trim().compareTo("Reset") == 0) {
  134.                     loadGrid();
  135.                     return true;
  136.                 }
  137.                 if (choice.trim().compareTo("Remove") == 0) {
  138. >054                    String removeMsg = "<>";
  139.                     if (removeMsg.equals("") || user.mainmsg.getStatusMsg().equals(removeMsg)) {
  140.                         deleteRequested = true;
  141.                         checkRows();
  142.                     } else {
  143.                         user.mainmsg.setStatusMsg(removeMsg,15);
  144.                     }
  145.                     return true;
  146.                 }
  147.                 if (choice.trim().compareTo("Search") == 0) {
  148.                     newSearch();
  149.                     return true;
  150.                 }
  151.                 return false;
  152.             }
  153.             if (e.target instanceof Choice) {
  154.                 return true;
  155.             }
  156.             if (e.target instanceof TextField) {
  157.                 if ((jdpWhereClause != null) && (e.target.equals(jdpWhereClause.matchConstant))) {
  158.                     newSearch();
  159.                     return true;
  160.                 }
  161.                 checkFields();
  162.                 return true;
  163.             }
  164.             return false;
  165.  
  166.         case Event.KEY_RELEASE:
  167. >069            if (e.target.equals(tableContents) && tableContents.getCurrentColumn() == <colNo>) JDPMaskEditMain.format<String>(tableContents,"<mask>");
  168.             return true;
  169.  
  170.         case Event.WINDOW_EXPOSE:
  171.             if (e.target instanceof JDPTabSelectPanel) {
  172.                 //
  173.                 //  This is where you place code to get executed when this panel is
  174.                 //  reactivated from the tab menu
  175.                 //
  176.                 return true;
  177.             }
  178.             return false;
  179.  
  180.           case Event.MOUSE_MOVE:
  181.          case Event.MOUSE_ENTER:
  182.          case Event.MOUSE_EXIT:
  183.             popuppanel.postEvent(e);
  184.             return false;
  185.  
  186.         default:
  187.             return false;
  188.  
  189.         }
  190.     }
  191.  
  192.     //
  193.     //  Retrieve the handle to another panel so as to be able to interact with it
  194.     //
  195.     public void retrieveHandle() {
  196.  
  197.         for (int ix=0; ix<user.gParm.size(); ix++) {
  198.             //
  199.             //  Activate the next four lines of code to retrieve the handle to another 
  200.             //  Panel within your JDP system. Of course you should declare the variable 
  201.             //  at the top of this source instead of within this method so you can 
  202.             //  access it from all the methods within this class. You only need to 
  203.             //  substitute DemoClass with the name ouf your class. You should call this 
  204.             //  method from somewhere else in this class. To access a variable from 
  205.             //  your resulting class use:
  206.             //     if (DemoClassHandle != null) mynewvar = demoClassHandle.variable;
  207.             //
  208. //            if (user.gParm.elementAt(ix) instanceof DemoClass19) {
  209. //                DemoClass19 DemoClassHandle = (DemoClass19)user.gParm.elementAt(ix);
  210. //                return;
  211. //            }
  212.         }
  213.     }
  214.  
  215.     //
  216.     //  The search button was pressed so rerun the query with the new search criteria
  217.     //
  218.     public void newSearch() {
  219.  
  220.         loadGrid();
  221.     }
  222.  
  223.     //
  224.     //  The check each rows that has changed and issue an update to the database
  225.     //
  226.     public void checkRows() {
  227.  
  228.         int changedCount = 0;
  229.         int insertedCount = 0;
  230.         int deletedCount = 0;
  231.         int cCount = 1;
  232.         int iCount = 1;
  233.         boolean reload = false;
  234.         
  235.         for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  236.             if (deleteRequested && tableContents.rowSelected[ix]) {
  237.                 deletedCount++;
  238.             } else
  239.             if (tableContents.rowChanged[ix]) {
  240.                 if (ix >= totalRows) {
  241.                     insertedCount++;
  242.                 } else {
  243.                     changedCount++;
  244.                 }
  245.             }
  246.         }
  247.         for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  248.             if (deleteRequested && tableContents.rowSelected[ix]) {
  249.                 user.mainmsg.setStatusMsg("Deleting row " + Integer.toString(iCount++) + " of " + Integer.toString(deletedCount) + "...", 0);
  250.                 saveData(ix);
  251.             } else
  252.             if (tableContents.rowChanged[ix]) {
  253.                 insertRequested = false;
  254.                 if (ix >= totalRows) {
  255.                     insertRequested = true;
  256.                     user.mainmsg.setStatusMsg("Inserting row " + Integer.toString(iCount++) + " of " + Integer.toString(insertedCount) + "...", 0);
  257.                 } else {
  258.                     user.mainmsg.setStatusMsg("Updating row " + Integer.toString(cCount++) + " of " + Integer.toString(changedCount) + "...", 0);
  259.                 }
  260.                 if (saveData(ix)) {
  261.                     reload = true;
  262.                 }
  263.                 insertRequested = false;
  264.                 tableContents.rowChanged[ix] = false;
  265.             }
  266.         }
  267.         if ((deletedCount > 0) || (insertedCount > 0) || reload) {
  268.             loadGrid();
  269.         }
  270.         deleteRequested = false;
  271.     }
  272.  
  273.     //
  274.     //  Save the selected item
  275.     //
  276.     boolean saveData(int tableRow) {
  277.  
  278.         int recCount = 0;
  279.         Vector results = new Vector();
  280.         String sep = jaggSQL.getSEP();
  281.         String SQL = "";
  282.         String prevSQL = null;
  283.  
  284.         if (insertRequested) {
  285. >121            SQL = <INSERT INTO >;
  286.         } else {
  287.             if (deleteRequested) {
  288. >122                SQL = <DELETE FROM >;
  289.                 if (tableContents.recordLockValue[tableRow] != null) {
  290.                     prevSQL = SQL;
  291. >163                    SQL += " AND <colname> = " + tableContents.recordLockValue[tableRow];
  292.                 }
  293.             } else {
  294. >123                SQL = <UPDATE >;
  295.                 if (tableContents.recordLockValue[tableRow] != null) {
  296.                     prevSQL = SQL;
  297. >163                    SQL += " AND <colname> = " + tableContents.recordLockValue[tableRow];
  298.                 }
  299.             }
  300.         }
  301.  
  302.         recCount = jaggSQL.execSQL(SQL, results);
  303.  
  304.         if (user.DEBUG) System.out.println("saveData CNT: "+Integer.toString(recCount));
  305.  
  306.         if (recCount == 0 && prevSQL != null) {
  307.             String[] buttons = {"Reload","Update"};
  308.             int[] icons = {JDPButton.UNDO,JDPButton.SAVE};
  309.             JDPMessageDialog d = new JDPMessageDialog(user, user.jdpMainWindow, "Update failed...", "The record has been changed by another user...",buttons, icons);
  310.             d.display();
  311.             if (d.getPressedButton() == 1) {
  312.                 results = new Vector();
  313.                 recCount = jaggSQL.execSQL(prevSQL, results);
  314.             } else {
  315.                 return true;
  316.             }
  317.         }
  318.  
  319.         if(recCount == -1) {
  320.             user.u.setSqlMessage(jaggSQL,SQL);
  321.             return false;
  322.         }
  323.         if(recCount == 1) {
  324.             if (insertRequested) {
  325.                 user.mainmsg.setStatusMsg("Record successfully added.",3);
  326.             } else 
  327.             if (deleteRequested) {
  328.                 user.mainmsg.setStatusMsg("Record successfully removed.",3);
  329.             } else {
  330.                 user.mainmsg.setStatusMsg("Record successfully updated.",3);
  331.             }
  332.         } else {
  333.             user.u.setSqlMessage(jaggSQL,SQL);
  334.         }
  335.         if (prevSQL != null) {
  336.             return true;
  337.         }
  338.         return false;
  339.  
  340.     }
  341.  
  342.     //
  343.     //  Load the grid with the specified parameters and selected data
  344.     //
  345.     public void loadGrid() {
  346.  
  347.         StringTokenizer stok;
  348.         int recCount = 0;
  349.         Vector results = new Vector();
  350.         String sep = jaggSQL.getSEP();
  351.         int actualRows = 0;
  352.         String row;
  353.  
  354.         Vector columns = new Vector();
  355.         Vector indexes = new Vector();
  356.  
  357. >100        String SQL = <SELECT>;
  358.  
  359.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  360.  
  361.         recCount = jaggSQL.execSQL(SQL, results);
  362.  
  363.         if(recCount == -1) {
  364.             user.u.setSqlMessage(jaggSQL,SQL);
  365.             return;
  366.         }
  367.  
  368.         //
  369.         //  If we haven't already initialise the grid settings
  370.         //
  371.         if (columnCount != prevColumnCount) {
  372.             prevColumnCount = columnCount;
  373.             setGridSettings();
  374.         }
  375.         //
  376.         //  Initialise result arrays
  377.         //
  378.         totalRows = jaggSQL.getRowCount();
  379.         actualRows = jaggSQL.getRowCount()+20;
  380.  
  381.         tableContents.currentText = new String[columnCount][actualRows];
  382.         tableContents.cellChanged = null;
  383.         tableContents.rowChanged = null;
  384.         tableContents.columnSelected = null;
  385. >120        keyCount = <keycount>;
  386.         rowKey = new String[actualRows][keyCount];
  387.         tableContents.recordLockValue = new String[actualRows];
  388.         
  389.         //
  390.         //  Load key array and grid array
  391.         //
  392.         String tempText;
  393.         for (int ix=0; ix<actualRows-20; ix++) {
  394.             row = (String)results.elementAt(ix);
  395.             if ((row != null) && (row.trim().compareTo("") != 0)) {
  396.                 stok = new StringTokenizer(row,sep);
  397. >162                tableContents.recordLockValue[ix] = stok.nextToken().trim();
  398.                 for (int iy=0; iy<keyCount; iy++) {
  399.                     rowKey[ix][iy] = stok.nextToken().trim();
  400.                 }
  401.                 for (int iy=0; iy<columnCount; iy++) {
  402.                     tempText = stok.nextToken().trim();
  403.                     tableContents.currentText[iy][ix] = tempText;
  404. >053                    if ((iy == <1>) && (value<field>.indexOf(tempText) >= 0)) tableContents.currentText[iy][ix] = tableContents.pullDownList[<1>][0].getItem(value<field>.indexOf(tempText));
  405. >069                    if (iy == <1>) JDPMaskEditMain.format<String>(tableContents,iy,ix,"<mask>");
  406.                 }
  407.             }
  408.         }
  409.  
  410.         tableContents.newTable();
  411.  
  412.         //
  413.         //  Clear status message
  414.         //
  415.         user.mainmsg.clearStatusMsg();
  416.     }
  417.  
  418.     //
  419.     //  Load the grid with the blank rows to allow data entry
  420.     //
  421.     public void loadEmptyGrid() {
  422.  
  423.         tableContents.currentText = new String[columnCount][50];
  424.         tableContents.cellChanged = null;
  425.         tableContents.rowChanged = null;
  426.         tableContents.columnSelected = null;
  427.         rowKey = new String[50][keyCount];
  428.         tableContents.newTable();
  429.         totalRows = 0;
  430.     }
  431.  
  432.     //
  433.     //  Set up the parameters for this grid
  434.     //
  435.     void setGridSettings() {
  436.  
  437.         tableContents.columnHeader = new String[columnCount];
  438.         tableContents.columnHeaderStyle = new int[columnCount];
  439.         tableContents.columnStyle = new int[columnCount];
  440.         tableContents.columnHeaderColor = new Color[columnCount];
  441.         tableContents.columnColor = new Color[columnCount];
  442.         tableContents.columnBGColor = new Color[columnCount];
  443.         tableContents.columnProtected = new boolean[columnCount];
  444.         tableContents.columnWidth = new int[columnCount];
  445.         tableContents.rightJustify = new boolean[columnCount];
  446.         tableContents.rowHeader = null;
  447.         tableContents.columnHeight = null;
  448.         for (int ix=0; ix<columnCount; ix++) {
  449.             tableContents.columnHeaderStyle[ix] = Font.BOLD;
  450.             tableContents.columnStyle[ix] = Font.PLAIN;
  451.             tableContents.columnHeaderColor[ix] = Color.black;
  452.             tableContents.columnColor[ix] = Color.black;
  453.             tableContents.columnBGColor[ix] = Color.white;
  454.             tableContents.columnStyle[ix] = Font.PLAIN;
  455.         }
  456. >101        tableContents.columnHeader[<ix>] = "<>";
  457. >102        tableContents.columnHeaderStyle[<ix>] = <>;
  458. >103        tableContents.columnStyle[<ix>] = <>;
  459. >104        tableContents.columnHeaderColor[<ix>] = user.u._cvtcolor("<>");
  460. >105        tableContents.columnColor[<ix>] = user.u._cvtcolor("<>");
  461. >106        tableContents.columnBGColor[<ix>] = user.u._cvtcolor("<>");
  462. >107        tableContents.columnProtected[<ix>] = <>;
  463. >108        tableContents.columnWidth[<ix>] = <>;
  464. >109        tableContents.rightJustify[<ix>] = <>;
  465.  
  466.         loadChoices();
  467.         loadEmptyGrid();
  468.     }
  469.  
  470.     //
  471.     //  Load the Search Layout pulldown choices
  472.     //
  473.     void loadMatchUsing() {
  474.  
  475.         pmatchUsing = new Vector();
  476.         pactualmatchUsing = new Vector();
  477. >020        pmatchUsing.addElement(new Vector());
  478. >022        pactualmatchUsing.addElement(new Vector());
  479. >021        ((Vector)pmatchUsing.elementAt(<0>)).addElement("<Begins with>");
  480. >023        ((Vector)pactualmatchUsing.elementAt(<0>)).addElement("< like >");
  481.  
  482.     }
  483.  
  484.     //
  485.     //  Load all of the Screen Choices
  486.     //
  487.     public void loadChoices() {
  488.  
  489.         tableContents.isPullDownCol = new boolean[columnCount];
  490.         tableContents.pullDownList = new List[columnCount][1];
  491. >049        tableContents.isPullDownCol[<1>] = true;
  492. >049        tableContents.pullDownList[<1>][0] = new List();
  493. >050
  494. >051        new JDPLoadChoice(user,jaggSQL,tableContents.pullDownList[<1>][0],"<choicecolumnname>","<actualcolumnname>","<tablename>","<whereclause>",value<columnname>);
  495.     }
  496.  
  497.     //
  498.     //  Perform component validations
  499.     //
  500.     public boolean checkFields() {
  501.  
  502.         return true;
  503.  
  504.     }
  505.  
  506.  
  507. }
  508.  
  509.  
  510.