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 / JDPLayout12.java < prev    next >
Encoding:
Text File  |  1999-04-09  |  11.2 KB  |  380 lines

  1. \*    //
  2.     //  Main initialization method
  3.     //
  4.     public void <compName>Main() {
  5.  
  6.         <compName>SetGridSettings();
  7. //        <compName>LoadGrid(new String[0]);
  8.  
  9.     }
  10.  
  11. \*    //
  12.     //  Load the grid with the specified parameters and selected data
  13.     //
  14.     public void <compName>LoadGridFromWhereClause(String whereClause) {
  15.  
  16.         int fPos = whereClause.indexOf("WHERE ");
  17.         whereClause = " AND" + whereClause.substring(fPos+5);
  18.         String[] keys = new String[0];
  19.  
  20.         <compName>LoadGridMain(keys, whereClause);
  21.     }
  22.  
  23. \*    //
  24.     //  Load the grid with the specified parameters and selected data
  25.     //
  26.     public void <compName>LoadGrid(String[] keys) {
  27.  
  28.         <compName>LoadGridMain(keys, null);
  29.     }
  30.  
  31. \*R    //
  32.     //  Load the grid with the specified parameters and selected data
  33.     //
  34.     void <compName>LoadGridMain(String[] keys, String whereClause) {
  35.  
  36.         JDPTextGrid tableContents = <compName>;
  37.  
  38.         StringTokenizer stok;
  39.         int recCount = 0;
  40.         Vector results = new Vector();
  41.         String sep = jaggSQL.getSEP();
  42.         int actualRows = 0;
  43.         String row;
  44. >119        int columnCount = <columnCount>;
  45.  
  46.         Vector columns = new Vector();
  47.         Vector indexes = new Vector();
  48.  
  49. >100        String SQL = <SELECT>;
  50.         if (whereClause != null) {
  51.             SQL += whereClause;
  52.         }
  53.  
  54.         user.mainmsg.setStatusMsg(JDPLang.get("Message0"), 0);
  55.  
  56. <jaggPrefs>
  57.         recCount = jaggSQL.execSQL(SQL, results);
  58.  
  59.         if(recCount == -1) {
  60.             user.u.setSqlMessage(jaggSQL,SQL);
  61.             return;
  62.         }
  63.  
  64.         //
  65.         //  Initialise result arrays
  66.         //
  67.         tableContents.totalDataRows = jaggSQL.getRowCount();
  68.         actualRows = jaggSQL.getRowCount()+20;
  69.         tableContents.currentText = new String[columnCount][actualRows];
  70.  
  71.         tableContents.cellChanged = null;
  72.         tableContents.rowChanged = null;
  73.         tableContents.columnSelected = null;
  74. >120        int keyCount = <keycount>;
  75.         tableContents.rowKey = new String[actualRows][keyCount];
  76.         tableContents.recordLockValue = new String[actualRows];
  77.         
  78.         //
  79.         //  Load key array and grid array
  80.         //
  81.         String tempText;
  82.         for (int ix=0; ix<actualRows-20; ix++) {
  83.             row = (String)results.elementAt(ix);
  84.             if ((row != null) && (row.trim().compareTo("") != 0)) {
  85.                 stok = new StringTokenizer(row,sep);
  86. >162                tableContents.recordLockValue[ix] = stok.nextToken().trim();
  87.                 for (int iy=0; iy<keyCount; iy++) {
  88.                     tableContents.rowKey[ix][iy] = stok.nextToken().trim();
  89.                 }
  90.                 for (int iy=0; iy<columnCount; iy++) {
  91.                     tempText = stok.nextToken().trim();
  92.                     tableContents.currentText[iy][ix] = tempText;
  93. >053                    if ((iy == <1>) && (tableContents.pullDownValue[<1>][0].indexOf(tempText) >= 0)) tableContents.currentText[iy][ix] = tableContents.pullDownList[<1>][0].getItem(tableContents.pullDownValue[<1>][0].indexOf(tempText));
  94. >071                    if (iy == <1>) tableContents.currentText[iy][ix] = (tableContents.currentText[iy][ix].equals("<checkedValue>"))?"Y":"N";
  95. >069                    if (iy == <1>) JDPMaskEditMain.format<String>(tableContents,iy,ix,"<mask>");
  96. >069                    if (iy == <1>) tableContents.setEditMask("<String>",iy,"<mask>");
  97.                 }
  98.             }
  99.         }
  100.         for (int ix=actualRows-20; ix<actualRows; ix++) {
  101.             for (int iy=0; iy<keys.length; iy++) {
  102.                 tableContents.rowKey[ix][iy] = keys[iy];
  103.             }
  104.         }
  105.  
  106.         tableContents.newTable();
  107.  
  108.         //
  109.         //  Clear status message
  110.         //
  111.         user.mainmsg.clearStatusMsg();
  112.     }
  113.  
  114. \*    //
  115.     //  Check each row that has changed and issue an update to the database
  116.     //
  117.     public void <compName>UpdateRowsFromWhereClause(String whereClause) {
  118.  
  119.         int fPos = whereClause.indexOf("WHERE ");
  120.         whereClause = " AND" + whereClause.substring(fPos+5);
  121.         String[] keys = new String[0];
  122.  
  123.         <compName>UpdateRowsMain(keys, whereClause);
  124.     }
  125.  
  126. \*    //
  127.     //  Check each row that has changed and issue an update to the database
  128.     //
  129.     public void <compName>UpdateRows(String[] keys) {
  130.  
  131.         <compName>UpdateRowsMain(keys, null);
  132.     }
  133.  
  134. \*    //
  135.     //  Check each row that has changed and issue an update to the database
  136.     //
  137.     void <compName>UpdateRowsMain(String[] keys, String whereClause) {
  138.  
  139.         JDPTextGrid tableContents = <compName>;
  140.  
  141.         int changedCount = 0;
  142.         int insertedCount = 0;
  143.         int cCount = 1;
  144.         int iCount = 1;
  145.         boolean reload = false;
  146.         
  147.         for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  148.             if (tableContents.rowChanged[ix]) {
  149.                 if (ix >= tableContents.totalDataRows) {
  150.                     insertedCount++;
  151.                 } else {
  152.                     changedCount++;
  153.                 }
  154.             }
  155.         }
  156.         for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  157.             if (tableContents.rowChanged[ix]) {
  158.                 if (ix >= tableContents.totalDataRows) {
  159.                     user.mainmsg.setStatusMsg(JDPLang.get("Message7",iCount++,insertedCount), 0);
  160.                     <compName>SaveData(ix,"I");
  161.                 } else {
  162.                     user.mainmsg.setStatusMsg(JDPLang.get("Message8",cCount++,changedCount), 0);
  163.                     if (<compName>SaveData(ix,"U")) {
  164.                         reload = true;
  165.                     }
  166.                 }
  167.                 tableContents.rowChanged[ix] = false;
  168.             }
  169.         }
  170.         if (insertedCount > 0 || reload) {
  171.             <compName>LoadGridMain(keys, whereClause);
  172.         }
  173.     }
  174.  
  175. \*    //
  176.     //  Delete any of the selected rows
  177.     //
  178.     public void <compName>DeleteRowsFromWhereClause(String whereClause) {
  179.  
  180.     int fPos = whereClause.indexOf("WHERE ");
  181.         whereClause = " AND" + whereClause.substring(fPos+5);
  182.         String[] keys = new String[0];
  183.  
  184.         <compName>DeleteRowsMain(keys, whereClause);
  185.     }
  186.  
  187. \*    //
  188.     //  Check each row that has changed and issue an update to the database
  189.     //
  190.     public void <compName>DeleteRows(String[] keys) {
  191.  
  192.         <compName>DeleteRowsMain(keys, null);
  193.     }
  194.  
  195. \*    //
  196.     //  Check each row that has changed and issue an update to the database
  197.     //
  198.     void <compName>DeleteRowsMain(String[] keys, String whereClause) {
  199.  
  200.         JDPTextGrid tableContents = <compName>;
  201.  
  202.         int deletedCount = 0;
  203.         int cCount = 1;
  204.         int iCount = 1;
  205.         
  206.         for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  207.             if (tableContents.rowSelected[ix]) {
  208.                 deletedCount++;
  209.             } 
  210.         }
  211.         for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  212.             if (tableContents.rowSelected[ix]) {
  213.                 user.mainmsg.setStatusMsg(JDPLang.get("Message9",iCount++,deletedCount), 0);
  214.                 <compName>SaveData(ix,"D");
  215.             }
  216.         }
  217.         if (deletedCount > 0) {
  218.             <compName>LoadGridMain(keys, whereClause);
  219.         }
  220.     }
  221.  
  222. \*R    //
  223.     //  Save the selected item
  224.     //
  225.     boolean <compName>SaveData(int tableRow, String action) {
  226.  
  227.         JDPTextGrid tableContents = <compName>;
  228.         int recCount = 0;
  229.         Vector results = new Vector();
  230.         String sep = jaggSQL.getSEP();
  231.         String SQL = "";
  232.         String prevSQL = null;
  233.  
  234. <jaggPrefs>
  235.         if (action.equals("I")) {
  236. >121            SQL = <INSERT INTO >;
  237.         } else {
  238.             if (action.equals("D")) {
  239. >122                SQL = <DELETE FROM >;
  240.                 if (tableContents.recordLockValue[tableRow] != null) {
  241.                     prevSQL = SQL;
  242. >163                    SQL += " AND <colname> = " + tableContents.recordLockValue[tableRow];
  243.                 }
  244.             } else {
  245. >123                SQL = <UPDATE >;
  246.                 if (tableContents.recordLockValue[tableRow] != null) {
  247.                     prevSQL = SQL;
  248. >163                    SQL += " AND <colname> = " + tableContents.recordLockValue[tableRow];
  249.                 }
  250.             }
  251.         }
  252.  
  253.         recCount = jaggSQL.execSQL(SQL, results);
  254.  
  255.         if (user.DEBUG) System.out.println("saveData CNT: "+Integer.toString(recCount));
  256.  
  257.         if (recCount == 0 && prevSQL != null) {
  258.             String[] buttons = {"Reload","Update"};
  259.             int[] icons = {JDPButton.UNDO,JDPButton.SAVE};
  260.             JDPMessageDialog d = new JDPMessageDialog(user, user.jdpMainWindow, JDPLang.get("Dialog0"), JDPLang.get("Dialog1"), buttons, icons);
  261.             d.display();
  262.             if (d.getPressedButton() == 1) {
  263.                 results = new Vector();
  264.                 recCount = jaggSQL.execSQL(prevSQL, results);
  265.             } else {
  266.                 return true;
  267.             }
  268.         }
  269.  
  270.         if(recCount == -1) {
  271.             user.u.setSqlMessage(jaggSQL,SQL);
  272.             return false;
  273.         }
  274.         if(recCount == 1) {
  275.             if (action.equals("I")) {
  276.                 user.mainmsg.setStatusMsg(JDPLang.get("Message4"),3);
  277.             } else 
  278.             if (action.equals("D")) {
  279.                 user.mainmsg.setStatusMsg(JDPLang.get("Message5"),3);
  280.             } else {
  281.                 user.mainmsg.setStatusMsg(JDPLang.get("Message6"),3);
  282.             }
  283.         } else {
  284.             user.u.setSqlMessage(jaggSQL,SQL);
  285.         }
  286.         if (prevSQL != null) {
  287.             return true;
  288.         }
  289.         return false;
  290.  
  291.     }
  292.  
  293. \*R    //
  294.     //  Load the grid with the blank rows to allow data entry
  295.     //
  296.     public void <compName>LoadEmptyGrid() {
  297.  
  298.         JDPTextGrid tableContents = <compName>;
  299. >119        int columnCount = <columnCount>;
  300.  
  301.         tableContents.currentText = new String[columnCount][50];
  302.         tableContents.cellChanged = null;
  303.         tableContents.rowChanged = null;
  304.         tableContents.columnSelected = null;
  305.         tableContents.rowKey = new String[50][1];
  306.         tableContents.newTable();
  307.         tableContents.totalDataRows = 0;
  308.         tableContents.setSortingEnabled(true);
  309.     }
  310.  
  311. \*R    //
  312.     //  Set up the parameters for this grid
  313.     //
  314.     void <compName>SetGridSettings() {
  315.  
  316.         if (<compName> == null) {
  317.             <compName> = new JDPTextGrid(user);
  318.         } 
  319.         JDPTextGrid tableContents = <compName>;
  320. >119        int columnCount = <columnCount>;
  321.  
  322.         tableContents.fieldTypeCol = new int[columnCount];
  323.         tableContents.columnHeader = new String[columnCount];
  324.         tableContents.columnHeaderStyle = new int[columnCount];
  325.         tableContents.columnStyle = new int[columnCount];
  326.         tableContents.columnHeaderColor = new Color[columnCount];
  327.         tableContents.columnColor = new Color[columnCount];
  328.         tableContents.columnBGColor = new Color[columnCount];
  329.         tableContents.columnProtected = new boolean[columnCount];
  330.         tableContents.columnDisabled = new boolean[columnCount];
  331.         tableContents.columnWidth = new int[columnCount];
  332.         tableContents.rightJustify = new boolean[columnCount];
  333.         tableContents.rowHeader = null;
  334.         tableContents.columnHeight = null;
  335.         for (int ix=0; ix<columnCount; ix++) {
  336.             tableContents.columnHeaderStyle[ix] = Font.BOLD;
  337.             tableContents.columnStyle[ix] = Font.PLAIN;
  338.             tableContents.columnHeaderColor[ix] = Color.black;
  339.             tableContents.columnColor[ix] = Color.black;
  340.             tableContents.columnBGColor[ix] = Color.white;
  341.             tableContents.columnStyle[ix] = Font.PLAIN;
  342.         }
  343. >110        tableContents.setFieldTypeCol(<ix>,JDPTextGrid.<TEXTFIELD>);
  344. >107        tableContents.columnProtected[<ix>] = <>;
  345. >107        tableContents.columnDisabled[<ix>] = <>;
  346. >108        tableContents.columnWidth[<ix>] = <>;
  347. >109        tableContents.rightJustify[<ix>] = <>;
  348. >101        tableContents.columnHeader[<ix>] = "<>";
  349. >102        tableContents.columnHeaderStyle[<ix>] = <>;
  350. >103        tableContents.columnStyle[<ix>] = <>;
  351. >104        tableContents.columnHeaderColor[<ix>] = user.u._cvtcolor("<>");
  352. >105        tableContents.columnColor[<ix>] = user.u._cvtcolor("<>");
  353. >106        tableContents.columnBGColor[<ix>] = user.u._cvtcolor("<>");
  354.  
  355.         <compName>LoadEmptyGrid();
  356.         <compName>LoadChoices();
  357.     }
  358.  
  359. \*R    //
  360.     //  Load all of the Screen Choices
  361.     //
  362.     void <compName>LoadChoices() {
  363.  
  364.         JDPTextGrid tableContents = <compName>;
  365. >119        int columnCount = <columnCount>;
  366.  
  367. <jaggPrefs>
  368.         tableContents.isPullDownCol = new boolean[columnCount];
  369.         tableContents.pullDownColType = new int[columnCount];
  370.         tableContents.pullDownList = new List[columnCount][1];
  371. >049        tableContents.isPullDownCol[<1>] = true;
  372. >049        tableContents.pullDownColType[<1>] = JDPTextGrid.REGULAR;
  373. >049        tableContents.pullDownList[<1>][0] = new List();
  374. >070        tableContents.isPullDownCol[<1>] = true;
  375. >070        tableContents.pullDownColType[<1>] = JDPTextGrid.DATE;
  376. >050
  377. >051        new JDPLoadChoice(user,jaggSQL,tableContents.pullDownList[<1>][0],"<choicecolumnname>","<actualcolumnname>","<tablename>","<whereclause>",tableContents.pullDownValue[<1>][0]);
  378.     }
  379.  
  380.