Source Code Cross Referenced for ZaurusEditor.java in  » Database-DBMS » hsql » org » hsqldb » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » hsql » org.hsqldb.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (c) 2001-2005, The HSQL Development Group
002:         * All rights reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without
005:         * modification, are permitted provided that the following conditions are met:
006:         *
007:         * Redistributions of source code must retain the above copyright notice, this
008:         * list of conditions and the following disclaimer.
009:         *
010:         * Redistributions in binary form must reproduce the above copyright notice,
011:         * this list of conditions and the following disclaimer in the documentation
012:         * and/or other materials provided with the distribution.
013:         *
014:         * Neither the name of the HSQL Development Group nor the names of its
015:         * contributors may be used to endorse or promote products derived from this
016:         * software without specific prior written permission.
017:         *
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021:         * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
022:         * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025:         * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028:         * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029:         */
030:
031:        package org.hsqldb.util;
032:
033:        import java.sql.Connection;
034:        import java.sql.DatabaseMetaData;
035:        import java.sql.ResultSet;
036:        import java.sql.SQLException;
037:        import java.util.Enumeration;
038:        import java.util.StringTokenizer;
039:        import java.util.Vector;
040:        import java.awt.BorderLayout;
041:        import java.awt.Button;
042:        import java.awt.CardLayout;
043:        import java.awt.Checkbox;
044:        import java.awt.CheckboxGroup;
045:        import java.awt.Choice;
046:        import java.awt.Font;
047:        import java.awt.GridBagConstraints;
048:        import java.awt.GridBagLayout;
049:        import java.awt.GridLayout;
050:        import java.awt.Insets;
051:        import java.awt.Label;
052:        import java.awt.Panel;
053:        import java.awt.TextField;
054:        import java.awt.event.ActionEvent;
055:        import java.awt.event.ActionListener;
056:
057:        /**
058:         * <code>ZaurusEditor</code> implements an search/input/edit form to
059:         * search/view/update/insert table records.
060:         *
061:         * @author ulrivo@users
062:         * @version 1.0
063:         *
064:         * <p>
065:         * Starting on a search panel, one can choose a table from the actual
066:         * database. The list contains only tables which have a primary key
067:         * defined.
068:         *
069:         * One may provide one or more words which are to be contained in the
070:         * rows of the table.
071:         * <p>
072:         * There are three options in searching these words:
073:         * <ul>
074:         * <li>Use search words: all or any
075:         * <br>
076:         * Only rows which contain <b>all</b> words in any column will be
077:         * found. Alternatively, it is sufficient when <b>any</b> of the
078:         * words is contained in one of the columns.
079:         * <br>
080:         * <li>Ignore case :
081:         * <br>
082:         * While searching, there is no difference between lower or upper case
083:         * letters, if this optioned is set to 'yes',
084:         * <br>
085:         * <li>Match whole column:
086:         * <br>
087:         * It is sufficient that the given word is just a part of any
088:         * column. For instance, the word 'ring' will be found as part of
089:         * 'Stringer'. Alternatively, the column content must match the search
090:         * word completely.
091:         * </ul><p>
092:         * After choosing a table, typing one or more search words and
093:         * choosing some search options, the button <b>Search Rows</b> initiates
094:         * the search through the table.
095:         * <br>Alternatively, the button <b>New Row</b> will open an empty input
096:         * panel for inserting a new row for the  choosen table.<br>In both cases,
097:         * a table specific panel with an entry field per column is shown.<br>
098:         *
099:         */
100:        public class ZaurusEditor extends Panel implements  ActionListener {
101:
102:            // class variables
103:            // status line
104:            static TextField tStatus;
105:
106:            // instance variables
107:            // connection to database - brought via the refresh method
108:            Connection cConn;
109:            DatabaseMetaData dbmeta;
110:
111:            // buttons in Editor
112:            Button bSearchRow, bNewRow;
113:            Button bCancel1, bPrev, bNext, bDelete, bNewSearch;
114:            Button bCancel2, bNewInsert, bNewSearch1;
115:
116:            // button boxes
117:            Panel pSearchButs, pEditButs, pInsertButs;
118:
119:            // the list of used table names
120:            Vector vHoldTableNames;
121:
122:            // the list of corresponding table forms
123:            Vector vHoldForms;
124:
125:            // the pointer into the vHold.... for the actual table
126:            int aktHoldNr;
127:
128:            //  pForm and pButton with CardLayout
129:            Panel pForm, pButton;
130:            CardLayout lForm, lButton;
131:            /*
132:              ZaurusEditor holds two card panels:
133:
134:              1. pForm holds the different forms
135:              pForm shows initially a search form to select a table and to
136:              input some search words.
137:              For every table which should be used in the editor, there is an own
138:              ZaurusTableForm added to the card panel pForm
139:
140:              2. pButton holds the different button boxes
141:              For the search form, there are buttons search row, new row  - all in the panel pSearchButs
142:              For a table in the editor, there are alternatively:
143:              a) cancel, prev, next, delete row, new search - for editing a row - in panel pEditButs
144:              b) cancel, new insert, new search - for inserting a new row - pInsertButs
145:             */
146:
147:            // text field with search words
148:            TextField fSearchWords;
149:
150:            // the choice of all tables
151:            Choice cTables;
152:
153:            // the checkbox group for using any/all search words
154:            CheckboxGroup gAllWords;
155:
156:            // the checkbox group for ignoring the case of search words
157:            CheckboxGroup gIgnoreCase;
158:
159:            // the checkbox group for  matching the whole column i. e. not using LIKE
160:            CheckboxGroup gNoMatchWhole;
161:
162:            // one needs a double press of the delete button to delete a row
163:            boolean lastButtonDelete;
164:
165:            /**
166:             * <code>printStatus</code> prints a text into the status line below the panel.
167:             *
168:             * @param text a <code>String</code> value will be shown
169:             */
170:            public static void printStatus(String text) {
171:                tStatus.setText(text);
172:            }
173:
174:            /**
175:             * The class method <code>clearStatus</code> deletes the status line.
176:             *
177:             */
178:            public static void clearStatus() {
179:                tStatus.setText("");
180:            }
181:
182:            /**
183:             * Constructor declaration
184:             *
185:             */
186:            public ZaurusEditor() {
187:
188:                super ();
189:
190:                initGUI();
191:            }
192:
193:            /**
194:             *  <code>actionPerformed</code> method is the main entry point
195:             * which interprets the buttons and initiates the actions.
196:             *
197:             * @param e an <code>ActionEvent</code> value is been sent to ZaurusEditor as ActionListener
198:             *
199:             * <p>The possible events are:<ul> <li>Buttons on the <b>search
200:             * panel:</b> <dl><dt>Search Row<dd> Starts the search of rows in
201:             * the choosen table with the given search words and search
202:             * options. Without any search words, all rows will be found.<br>
203:             * If no row meets the criteria, there will be a message in the
204:             * status line.  <dt>New Row<dd> An empty input panel for the
205:             * choosen table is given. Any search words are
206:             * ignored.</dl><li>Buttons on the <b>edit panel:</b><br>Any
207:             * changes to field values on this panel will be updated to the
208:             * table when the actual row is left, i. e. when pressing one of
209:             * the buttons 'Prev', 'Next' or
210:             * 'Search'. <br><dl><dt>Cancel<dd>Any changes to field contents
211:             * are canceled and reset to the previous values.<dt>Prev<dd>Show
212:             * the previous row which meets the search
213:             * criteria.<dt>Next<dd>Show the next row which meets the search
214:             * criteria.<dt>Delete<dd>This button has to be clicked twice and
215:             * the shown row will be deleted from the table<dt>Search<dd>With
216:             * this button a new search is initiated. Any changes made to
217:             * field contents are saved</dl><li>Buttons on the <b>insert
218:             * panel:</b><dl><dt>Cancel Insert<dd>After beginning to fill a
219:             * new row, the insert may be cancelled. The search panel will be
220:             * shown next.<dt>New Insert<dd>The new row is inserted into the
221:             * table and a new empty insert panel is shown.<dt>New
222:             * Search<dd>The new row is inserted into the table and the search
223:             * panel is shown again.</ul>
224:             */
225:            public void actionPerformed(ActionEvent e) {
226:
227:                Button button = (Button) e.getSource();
228:
229:                if (button == bSearchRow) {
230:                    this .resetLastButtonDelete();
231:
232:                    // System.out.println("pressed search");
233:                    aktHoldNr = getChoosenTableIndex();
234:
235:                    // search all rows
236:                    int numberOfRows = ((ZaurusTableForm) vHoldForms
237:                            .elementAt(aktHoldNr)).searchRows(this .getWords(),
238:                            (gAllWords.getSelectedCheckbox().getLabel()
239:                                    .equals("all")), (gIgnoreCase
240:                                    .getSelectedCheckbox().getLabel()
241:                                    .equals("yes")), (gNoMatchWhole
242:                                    .getSelectedCheckbox().getLabel()
243:                                    .equals("no")));
244:                    String tableName = (String) vHoldTableNames
245:                            .elementAt(aktHoldNr);
246:
247:                    if (numberOfRows > 0) {
248:                        lForm.show(pForm, tableName);
249:                        lButton.show(pButton, "edit");
250:                        bPrev.setEnabled(false);
251:
252:                        // if there is more than one row, enable the next button
253:                        bNext.setEnabled(numberOfRows != 1);
254:                        ZaurusEditor.printStatus("found " + numberOfRows
255:                                + " rows in table " + tableName);
256:                    } else if (numberOfRows == 0) {
257:                        ZaurusEditor.printStatus("no rows found in table "
258:                                + tableName);
259:
260:                        // numberOfRows could be -1 as well, if an SQL exception was encountered
261:                    } // end of if (numberOfRows > 0)
262:                } else if ((button == bNewRow)) {
263:
264:                    // System.out.println("pressed new");
265:                    aktHoldNr = getChoosenTableIndex();
266:
267:                    lForm.show(pForm, (String) vHoldTableNames
268:                            .elementAt(aktHoldNr));
269:                    lButton.show(pButton, "insert");
270:                    ((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr))
271:                            .insertNewRow();
272:                } else if (button == bNewInsert) {
273:                    this .resetLastButtonDelete();
274:
275:                    // new search in edit row
276:                    if (((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr))
277:                            .saveNewRow()) {
278:
279:                        // System.out.println("pressed new insert");
280:                        ((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr))
281:                                .insertNewRow();
282:                    }
283:                } else if (button == bNewSearch) {
284:                    this .resetLastButtonDelete();
285:
286:                    // new search in edit row
287:                    if (((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr))
288:                            .saveChanges()) {
289:
290:                        // System.out.println("pressed new search");
291:                        lForm.show(pForm, "search");
292:                        lButton.show(pButton, "search");
293:                    }
294:                } else if (button == bNewSearch1) {
295:                    this .resetLastButtonDelete();
296:
297:                    // new search in insert row, succeeds if the saving is successfull
298:                    if (((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr))
299:                            .saveNewRow()) {
300:
301:                        // System.out.println("pressed new search");
302:                        lForm.show(pForm, "search");
303:                        lButton.show(pButton, "search");
304:                    }
305:                } else if ((button == bNext)) {
306:                    this .resetLastButtonDelete();
307:                    ZaurusEditor.clearStatus();
308:
309:                    if (((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr))
310:                            .saveChanges()) {
311:                        bPrev.setEnabled(true);
312:
313:                        if (!((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr))
314:                                .nextRow()) {
315:                            bNext.setEnabled(false);
316:                        }
317:                    }
318:                } else if ((button == bPrev)) {
319:                    this .resetLastButtonDelete();
320:                    ZaurusEditor.clearStatus();
321:
322:                    if (((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr))
323:                            .saveChanges()) {
324:                        bNext.setEnabled(true);
325:
326:                        if (!((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr))
327:                                .prevRow()) {
328:                            bPrev.setEnabled(false);
329:                        }
330:                    }
331:                } else if ((button == bCancel1)) {
332:
333:                    // cancel in edit panel
334:                    this .resetLastButtonDelete();
335:                    ((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr))
336:                            .cancelChanges();
337:                } else if ((button == bCancel2)) {
338:                    this .resetLastButtonDelete();
339:
340:                    // cancel in insert panel, just show the search panel again
341:                    lForm.show(pForm, "search");
342:                    lButton.show(pButton, "search");
343:                } else if (button == bDelete) {
344:                    if (lastButtonDelete) {
345:
346:                        // delete and determine follow up actions, see comment in ZaurusTableForm.deleteRow()
347:                        switch (((ZaurusTableForm) vHoldForms
348:                                .elementAt(aktHoldNr)).deleteRow()) {
349:
350:                        case 1:
351:                            lForm.show(pForm, "search");
352:                            lButton.show(pButton, "search");
353:                            break;
354:
355:                        case 2:
356:                            bPrev.setEnabled(false);
357:                            break;
358:
359:                        case 3:
360:                            bNext.setEnabled(false);
361:                            break;
362:
363:                        default:
364:                            break;
365:                        } // end of switch (((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr)).deleteRow())
366:
367:                        lastButtonDelete = false;
368:                    } else {
369:                        ZaurusEditor
370:                                .printStatus("Press 'Delete' a second time to delete row.");
371:
372:                        lastButtonDelete = true;
373:                    } // end of if (lastButtonDelete)
374:                } // end of if (button == Rest)
375:            }
376:
377:            // when tree is refreshed ZaurusEditor.refresh() is called, too
378:
379:            /**
380:             *  <code>refresh</code> will read again the meta data of the
381:             * actual database. This is useful after changes of the table
382:             * structures for instance creating or dropping tables, or
383:             * altering tabel. The method will be called if one asks to
384:             * refresh the tree or if the connection to the database is
385:             * changed.
386:             *
387:             * @param c a <code>Connection</code> is the actual connection to
388:             * the database
389:             */
390:            public void refresh(Connection c) {
391:
392:                cConn = c;
393:
394:                if (vHoldForms == null) {
395:                    this .initGUI();
396:
397:                    // System.out.println("initGUI <<<<<<<<<<<<<<<<<<<<<<");
398:                } else {
399:                    this .resetTableForms();
400:
401:                    // System.out.println("reset >>>>>>>>>>>>>>>>>");
402:                }
403:            }
404:
405:            private void initGUI() {
406:
407:                // without connection there are no tables
408:                // vAllTables is a local variable with all table names in the database
409:                // vHoldTableNames holds the table names which have a ZaurusTableForm
410:                Vector vAllTables = getAllTables();
411:
412:                if (vAllTables == null) {
413:                    return;
414:                }
415:
416:                // initialize a new list for the table names which have a form in pForm
417:                vHoldTableNames = new Vector(20);
418:                vHoldForms = new Vector(20);
419:
420:                // this holds the card panel pForm for the forms in the top
421:                // a card panel pButton below
422:                // the both card panels form a panel which is centered in this
423:                // and a status line in the south
424:                this .setLayout(new BorderLayout(3, 3));
425:
426:                // >>> the top of this: the entry forms in pForm
427:                // pFormButs holds in the center the forms card panel pForm and
428:                // in the south the button card panel pButton
429:                Panel pFormButs = new Panel();
430:
431:                pFormButs.setLayout(new BorderLayout(3, 3));
432:
433:                pForm = new Panel();
434:                lForm = new CardLayout(2, 2);
435:
436:                pForm.setLayout(lForm);
437:
438:                // the search panel containing the list of all tables and
439:                // the entry fields for search words in the Center
440:                Panel pEntry = new Panel();
441:
442:                pEntry.setLayout(new GridBagLayout());
443:
444:                GridBagConstraints c = new GridBagConstraints();
445:
446:                c.fill = GridBagConstraints.HORIZONTAL;
447:                c.insets = new Insets(3, 3, 3, 3);
448:                c.gridwidth = 1;
449:                c.gridheight = 1;
450:                c.weightx = c.weighty = 1;
451:                c.anchor = GridBagConstraints.WEST;
452:                c.gridy = 0;
453:                c.gridx = 0;
454:
455:                pEntry.add(new Label("Search table"), c);
456:
457:                c.gridx = 1;
458:
459:                // get all table names and show a drop down list of them in cTables
460:                cTables = new Choice();
461:
462:                for (Enumeration e = vAllTables.elements(); e.hasMoreElements();) {
463:                    cTables.addItem((String) e.nextElement());
464:                }
465:
466:                c.gridwidth = 2;
467:
468:                pEntry.add(cTables, c);
469:
470:                c.gridy = 1;
471:                c.gridx = 0;
472:                c.gridwidth = 1;
473:
474:                pEntry.add(new Label("Search words"), c);
475:
476:                c.gridx = 1;
477:                c.gridwidth = 2;
478:                fSearchWords = new TextField(8);
479:
480:                pEntry.add(fSearchWords, c);
481:
482:                // use search words
483:                c.gridwidth = 1;
484:                c.gridy = 2;
485:                c.gridx = 0;
486:
487:                pEntry.add(new Label("Use search words"), c);
488:
489:                gAllWords = new CheckboxGroup();
490:
491:                Checkbox[] checkboxes = new Checkbox[2];
492:
493:                checkboxes[0] = new Checkbox("all", gAllWords, true);
494:                c.gridx = 1;
495:
496:                pEntry.add(checkboxes[0], c);
497:
498:                checkboxes[1] = new Checkbox("any ", gAllWords, false);
499:                c.gridx = 2;
500:
501:                pEntry.add(checkboxes[1], c);
502:
503:                // ignore case
504:                c.gridy = 3;
505:                c.gridx = 0;
506:
507:                pEntry.add(new Label("Ignore case"), c);
508:
509:                gIgnoreCase = new CheckboxGroup();
510:
511:                Checkbox[] checkboxes1 = new Checkbox[2];
512:
513:                checkboxes1[0] = new Checkbox("yes", gIgnoreCase, true);
514:                c.gridx = 1;
515:
516:                pEntry.add(checkboxes1[0], c);
517:
518:                checkboxes1[1] = new Checkbox("no", gIgnoreCase, false);
519:                c.gridx = 2;
520:
521:                pEntry.add(checkboxes1[1], c);
522:
523:                // Match column exactly
524:                c.gridy = 4;
525:                c.gridx = 0;
526:
527:                pEntry.add(new Label("Match whole col"), c);
528:
529:                gNoMatchWhole = new CheckboxGroup();
530:
531:                Checkbox[] checkboxes2 = new Checkbox[2];
532:
533:                checkboxes2[0] = new Checkbox("no", gNoMatchWhole, true);
534:                c.gridx = 1;
535:
536:                pEntry.add(checkboxes2[0], c);
537:
538:                checkboxes2[1] = new Checkbox("yes ", gNoMatchWhole, false);
539:                c.gridx = 2;
540:
541:                pEntry.add(checkboxes2[1], c);
542:                pForm.add("search", pEntry);
543:                pFormButs.add("Center", pForm);
544:
545:                // the buttons
546:                this .initButtons();
547:
548:                pButton = new Panel();
549:                lButton = new CardLayout(2, 2);
550:
551:                pButton.setLayout(lButton);
552:                pButton.add("search", pSearchButs);
553:                pButton.add("edit", pEditButs);
554:                pButton.add("insert", pInsertButs);
555:                pFormButs.add("South", pButton);
556:                this .add("Center", pFormButs);
557:
558:                // >>> the South: status line at the bottom
559:                Font fFont = new Font("Dialog", Font.PLAIN, 10);
560:
561:                ZaurusEditor.tStatus = new TextField("");
562:
563:                ZaurusEditor.tStatus.setEditable(false);
564:                this .add("South", ZaurusEditor.tStatus);
565:            }
566:
567:            // process the buttons events
568:            // *******************************************************
569:            // private methods
570:            // *******************************************************
571:            // read all table names over the current database connection
572:            // exclude tables without primary key
573:            private Vector getAllTables() {
574:
575:                Vector result = new Vector(20);
576:
577:                try {
578:                    if (cConn == null) {
579:                        return null;
580:                    }
581:
582:                    dbmeta = cConn.getMetaData();
583:
584:                    String[] tableTypes = { "TABLE" };
585:                    ResultSet allTables = dbmeta.getTables(null, null, null,
586:                            tableTypes);
587:
588:                    while (allTables.next()) {
589:                        String aktTable = allTables.getString("TABLE_NAME");
590:                        ResultSet primKeys = dbmeta.getPrimaryKeys(null, null,
591:                                aktTable);
592:
593:                        // take only table with a primary key
594:                        if (primKeys.next()) {
595:                            result.addElement(aktTable);
596:                        }
597:
598:                        primKeys.close();
599:                    }
600:
601:                    allTables.close();
602:                } catch (SQLException e) {
603:
604:                    // System.out.println("SQL Exception: " + e.getMessage());
605:                }
606:
607:                return result;
608:            }
609:
610:            // determine the index of the choosen table in Vector vHoldTableNames
611:            // if the table name is not in vHoldTableNames, create a ZaurusTableForm for it
612:            private int getChoosenTableIndex() {
613:
614:                String tableName = cTables.getSelectedItem();
615:
616:                // System.out.println("in getChoosenTableIndex, selected Item is "+tableName);
617:                int index = getTableIndex(tableName);
618:
619:                if (index >= 0) {
620:
621:                    // System.out.println("table found, index: " + index);
622:                    return index;
623:                } // end of if (index >= 0)
624:
625:                ZaurusTableForm tableForm = new ZaurusTableForm(tableName,
626:                        cConn);
627:
628:                pForm.add(tableName, tableForm);
629:                vHoldTableNames.addElement(tableName);
630:                vHoldForms.addElement(tableForm);
631:
632:                // System.out.println("new tableform for table "+tableName+", index: " + index);
633:                return vHoldTableNames.size() - 1;
634:            }
635:
636:            // determine the index of the given tableName in Vector vHoldTableNames
637:            // if the name is not in vHoldTableNames, answer -1
638:            private int getTableIndex(String tableName) {
639:
640:                int index;
641:
642:                // System.out.println("begin searching for "+tableName);
643:                for (index = 0; index < vHoldTableNames.size(); index++) {
644:
645:                    // System.out.println("in getTableIndex searching for "+tableName+", index: "+index);
646:                    if (tableName.equals((String) vHoldTableNames
647:                            .elementAt(index))) {
648:                        return index;
649:                    } // end of if (tableName.equals(vHoldTableNames.elementAt(index)))
650:                } // end of for (index = 0; index < vHoldTableNames.size(); index ++)
651:
652:                return -1;
653:            }
654:
655:            // convert the search words in the textfield to an array of words
656:            private String[] getWords() {
657:
658:                StringTokenizer tokenizer = new StringTokenizer(fSearchWords
659:                        .getText());
660:                String[] result = new String[tokenizer.countTokens()];
661:                int i = 0;
662:
663:                while (tokenizer.hasMoreTokens()) {
664:                    result[i++] = tokenizer.nextToken();
665:                } // end of while ((tokenizer.hasMoreTokens()))
666:
667:                return result;
668:            }
669:
670:            // init the three boxes for buttons
671:            private void initButtons() {
672:
673:                // the buttons for the search form
674:                bSearchRow = new Button("Search Rows");
675:                bNewRow = new Button("Insert New Row");
676:
677:                bSearchRow.addActionListener(this );
678:                bNewRow.addActionListener(this );
679:
680:                pSearchButs = new Panel();
681:
682:                pSearchButs.setLayout(new GridLayout(1, 0, 4, 4));
683:                pSearchButs.add(bSearchRow);
684:                pSearchButs.add(bNewRow);
685:
686:                // the buttons for editing a row
687:                bCancel1 = new Button("Cancel");
688:                bPrev = new Button("Prev");
689:                bNext = new Button("Next");
690:                bDelete = new Button("Delete");
691:                lastButtonDelete = false;
692:                bNewSearch = new Button("Search");
693:
694:                bCancel1.addActionListener(this );
695:                bPrev.addActionListener(this );
696:                bNext.addActionListener(this );
697:                bDelete.addActionListener(this );
698:                bNewSearch.addActionListener(this );
699:
700:                pEditButs = new Panel();
701:
702:                pEditButs.setLayout(new GridLayout(1, 0, 4, 4));
703:                pEditButs.add(bCancel1);
704:                pEditButs.add(bPrev);
705:                pEditButs.add(bNext);
706:                pEditButs.add(bDelete);
707:                pEditButs.add(bNewSearch);
708:
709:                // the buttons for inserting a new row
710:                pInsertButs = new Panel();
711:
712:                pInsertButs.setLayout(new GridLayout(1, 0, 4, 4));
713:
714:                bCancel2 = new Button("Cancel Insert");
715:                bNewInsert = new Button("New Insert");
716:                bNewSearch1 = new Button("Search");
717:
718:                bCancel2.addActionListener(this );
719:                bNewInsert.addActionListener(this );
720:                bNewSearch1.addActionListener(this );
721:                pInsertButs.add(bCancel2);
722:                pInsertButs.add(bNewInsert);
723:                pInsertButs.add(bNewSearch1);
724:            }
725:
726:            // check whether the last button pressed was delete
727:            // if so, clear status line and reset the flag
728:            private void resetLastButtonDelete() {
729:
730:                if (lastButtonDelete) {
731:                    ZaurusEditor.printStatus("");
732:
733:                    lastButtonDelete = false;
734:                } // end of if (lastButtonDelete)
735:            }
736:
737:            // reset  everything after changes in the database
738:            private void resetTableForms() {
739:
740:                lForm.show(pForm, "search");
741:                lButton.show(pButton, "search");
742:
743:                Vector vAllTables = getAllTables();
744:
745:                // fill the drop down list again
746:                // get all table names and show a drop down list of them in cTables
747:                cTables.removeAll();
748:
749:                for (Enumeration e = vAllTables.elements(); e.hasMoreElements();) {
750:                    cTables.addItem((String) e.nextElement());
751:                }
752:
753:                // remove all form panels from pForm
754:                for (Enumeration e = vHoldForms.elements(); e.hasMoreElements();) {
755:                    pForm.remove((ZaurusTableForm) e.nextElement());
756:                } // end of while (Enumeration e = vHoldForms.elements(); e.hasMoreElements();)
757:
758:                // initialize a new list for the table names which have a form in pForm
759:                vHoldTableNames = new Vector(20);
760:                vHoldForms = new Vector(20);
761:            }
762:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.