KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hsqldb > util > ZaurusEditor


1 /* Copyright (c) 2001-2005, The HSQL Development Group
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * Neither the name of the HSQL Development Group nor the names of its
15  * contributors may be used to endorse or promote products derived from this
16  * software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31
32 package org.hsqldb.util;
33
34 import java.sql.Connection JavaDoc;
35 import java.sql.DatabaseMetaData JavaDoc;
36 import java.sql.ResultSet JavaDoc;
37 import java.sql.SQLException JavaDoc;
38 import java.util.Enumeration JavaDoc;
39 import java.util.StringTokenizer JavaDoc;
40 import java.util.Vector JavaDoc;
41 import java.awt.BorderLayout JavaDoc;
42 import java.awt.Button JavaDoc;
43 import java.awt.CardLayout JavaDoc;
44 import java.awt.Checkbox JavaDoc;
45 import java.awt.CheckboxGroup JavaDoc;
46 import java.awt.Choice JavaDoc;
47 import java.awt.Font JavaDoc;
48 import java.awt.GridBagConstraints JavaDoc;
49 import java.awt.GridBagLayout JavaDoc;
50 import java.awt.GridLayout JavaDoc;
51 import java.awt.Insets JavaDoc;
52 import java.awt.Label JavaDoc;
53 import java.awt.Panel JavaDoc;
54 import java.awt.TextField JavaDoc;
55 import java.awt.event.ActionEvent JavaDoc;
56 import java.awt.event.ActionListener JavaDoc;
57
58 /**
59  * <code>ZaurusEditor</code> implements an search/input/edit form to
60  * search/view/update/insert table records.
61  *
62  * @author ulrivo@users
63  * @version 1.0
64  *
65  * <p>
66  * Starting on a search panel, one can choose a table from the actual
67  * database. The list contains only tables which have a primary key
68  * defined.
69  *
70  * One may provide one or more words which are to be contained in the
71  * rows of the table.
72  * <p>
73  * There are three options in searching these words:
74  * <ul>
75  * <li>Use search words: all or any
76  * <br>
77  * Only rows which contain <b>all</b> words in any column will be
78  * found. Alternatively, it is sufficient when <b>any</b> of the
79  * words is contained in one of the columns.
80  * <br>
81  * <li>Ignore case :
82  * <br>
83  * While searching, there is no difference between lower or upper case
84  * letters, if this optioned is set to 'yes',
85  * <br>
86  * <li>Match whole column:
87  * <br>
88  * It is sufficient that the given word is just a part of any
89  * column. For instance, the word 'ring' will be found as part of
90  * 'Stringer'. Alternatively, the column content must match the search
91  * word completely.
92  * </ul><p>
93  * After choosing a table, typing one or more search words and
94  * choosing some search options, the button <b>Search Rows</b> initiates
95  * the search through the table.
96  * <br>Alternatively, the button <b>New Row</b> will open an empty input
97  * panel for inserting a new row for the choosen table.<br>In both cases,
98  * a table specific panel with an entry field per column is shown.<br>
99  *
100  */

101 public class ZaurusEditor extends Panel JavaDoc implements ActionListener JavaDoc {
102
103     // class variables
104
// status line
105
static TextField JavaDoc tStatus;
106
107     // instance variables
108
// connection to database - brought via the refresh method
109
Connection JavaDoc cConn;
110     DatabaseMetaData JavaDoc dbmeta;
111
112     // buttons in Editor
113
Button JavaDoc bSearchRow, bNewRow;
114     Button JavaDoc bCancel1, bPrev, bNext, bDelete, bNewSearch;
115     Button JavaDoc bCancel2, bNewInsert, bNewSearch1;
116
117     // button boxes
118
Panel JavaDoc pSearchButs, pEditButs, pInsertButs;
119
120     // the list of used table names
121
Vector JavaDoc vHoldTableNames;
122
123     // the list of corresponding table forms
124
Vector JavaDoc vHoldForms;
125
126     // the pointer into the vHold.... for the actual table
127
int aktHoldNr;
128
129     // pForm and pButton with CardLayout
130
Panel JavaDoc pForm, pButton;
131     CardLayout JavaDoc lForm, lButton;
132     /*
133       ZaurusEditor holds two card panels:
134
135       1. pForm holds the different forms
136       pForm shows initially a search form to select a table and to
137       input some search words.
138       For every table which should be used in the editor, there is an own
139       ZaurusTableForm added to the card panel pForm
140
141       2. pButton holds the different button boxes
142       For the search form, there are buttons search row, new row - all in the panel pSearchButs
143       For a table in the editor, there are alternatively:
144       a) cancel, prev, next, delete row, new search - for editing a row - in panel pEditButs
145       b) cancel, new insert, new search - for inserting a new row - pInsertButs
146      */

147
148     // text field with search words
149
TextField JavaDoc fSearchWords;
150
151     // the choice of all tables
152
Choice JavaDoc cTables;
153
154     // the checkbox group for using any/all search words
155
CheckboxGroup JavaDoc gAllWords;
156
157     // the checkbox group for ignoring the case of search words
158
CheckboxGroup JavaDoc gIgnoreCase;
159
160     // the checkbox group for matching the whole column i. e. not using LIKE
161
CheckboxGroup JavaDoc gNoMatchWhole;
162
163     // one needs a double press of the delete button to delete a row
164
boolean lastButtonDelete;
165
166     /**
167      * <code>printStatus</code> prints a text into the status line below the panel.
168      *
169      * @param text a <code>String</code> value will be shown
170      */

171     public static void printStatus(String JavaDoc text) {
172         tStatus.setText(text);
173     }
174
175     /**
176      * The class method <code>clearStatus</code> deletes the status line.
177      *
178      */

179     public static void clearStatus() {
180         tStatus.setText("");
181     }
182
183     /**
184      * Constructor declaration
185      *
186      */

187     public ZaurusEditor() {
188
189         super();
190
191         initGUI();
192     }
193
194     /**
195      * <code>actionPerformed</code> method is the main entry point
196      * which interprets the buttons and initiates the actions.
197      *
198      * @param e an <code>ActionEvent</code> value is been sent to ZaurusEditor as ActionListener
199      *
200      * <p>The possible events are:<ul> <li>Buttons on the <b>search
201      * panel:</b> <dl><dt>Search Row<dd> Starts the search of rows in
202      * the choosen table with the given search words and search
203      * options. Without any search words, all rows will be found.<br>
204      * If no row meets the criteria, there will be a message in the
205      * status line. <dt>New Row<dd> An empty input panel for the
206      * choosen table is given. Any search words are
207      * ignored.</dl><li>Buttons on the <b>edit panel:</b><br>Any
208      * changes to field values on this panel will be updated to the
209      * table when the actual row is left, i. e. when pressing one of
210      * the buttons 'Prev', 'Next' or
211      * 'Search'. <br><dl><dt>Cancel<dd>Any changes to field contents
212      * are canceled and reset to the previous values.<dt>Prev<dd>Show
213      * the previous row which meets the search
214      * criteria.<dt>Next<dd>Show the next row which meets the search
215      * criteria.<dt>Delete<dd>This button has to be clicked twice and
216      * the shown row will be deleted from the table<dt>Search<dd>With
217      * this button a new search is initiated. Any changes made to
218      * field contents are saved</dl><li>Buttons on the <b>insert
219      * panel:</b><dl><dt>Cancel Insert<dd>After beginning to fill a
220      * new row, the insert may be cancelled. The search panel will be
221      * shown next.<dt>New Insert<dd>The new row is inserted into the
222      * table and a new empty insert panel is shown.<dt>New
223      * Search<dd>The new row is inserted into the table and the search
224      * panel is shown again.</ul>
225      */

226     public void actionPerformed(ActionEvent JavaDoc e) {
227
228         Button JavaDoc button = (Button JavaDoc) e.getSource();
229
230         if (button == bSearchRow) {
231             this.resetLastButtonDelete();
232
233             // System.out.println("pressed search");
234
aktHoldNr = getChoosenTableIndex();
235
236             // search all rows
237
int numberOfRows =
238                 ((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr))
239                     .searchRows(this
240                         .getWords(), (gAllWords.getSelectedCheckbox()
241                             .getLabel().equals("all")), (gIgnoreCase
242                             .getSelectedCheckbox().getLabel()
243                             .equals("yes")), (gNoMatchWhole
244                             .getSelectedCheckbox().getLabel().equals("no")));
245             String JavaDoc tableName = (String JavaDoc) vHoldTableNames.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 JavaDoc) vHoldTableNames.elementAt(aktHoldNr));
268             lButton.show(pButton, "insert");
269             ((ZaurusTableForm) vHoldForms.elementAt(
270                 aktHoldNr)).insertNewRow();
271         } else if (button == bNewInsert) {
272             this.resetLastButtonDelete();
273
274             // new search in edit row
275
if (((ZaurusTableForm) vHoldForms.elementAt(
276                     aktHoldNr)).saveNewRow()) {
277
278                 // System.out.println("pressed new insert");
279
((ZaurusTableForm) vHoldForms.elementAt(
280                     aktHoldNr)).insertNewRow();
281             }
282         } else if (button == bNewSearch) {
283             this.resetLastButtonDelete();
284
285             // new search in edit row
286
if (((ZaurusTableForm) vHoldForms.elementAt(
287                     aktHoldNr)).saveChanges()) {
288
289                 // System.out.println("pressed new search");
290
lForm.show(pForm, "search");
291                 lButton.show(pButton, "search");
292             }
293         } else if (button == bNewSearch1) {
294             this.resetLastButtonDelete();
295
296             // new search in insert row, succeeds if the saving is successfull
297
if (((ZaurusTableForm) vHoldForms.elementAt(
298                     aktHoldNr)).saveNewRow()) {
299
300                 // System.out.println("pressed new search");
301
lForm.show(pForm, "search");
302                 lButton.show(pButton, "search");
303             }
304         } else if ((button == bNext)) {
305             this.resetLastButtonDelete();
306             ZaurusEditor.clearStatus();
307
308             if (((ZaurusTableForm) vHoldForms.elementAt(
309                     aktHoldNr)).saveChanges()) {
310                 bPrev.setEnabled(true);
311
312                 if (!((ZaurusTableForm) vHoldForms.elementAt(
313                         aktHoldNr)).nextRow()) {
314                     bNext.setEnabled(false);
315                 }
316             }
317         } else if ((button == bPrev)) {
318             this.resetLastButtonDelete();
319             ZaurusEditor.clearStatus();
320
321             if (((ZaurusTableForm) vHoldForms.elementAt(
322                     aktHoldNr)).saveChanges()) {
323                 bNext.setEnabled(true);
324
325                 if (!((ZaurusTableForm) vHoldForms.elementAt(
326                         aktHoldNr)).prevRow()) {
327                     bPrev.setEnabled(false);
328                 }
329             }
330         } else if ((button == bCancel1)) {
331
332             // cancel in edit panel
333
this.resetLastButtonDelete();
334             ((ZaurusTableForm) vHoldForms.elementAt(
335                 aktHoldNr)).cancelChanges();
336         } else if ((button == bCancel2)) {
337             this.resetLastButtonDelete();
338
339             // cancel in insert panel, just show the search panel again
340
lForm.show(pForm, "search");
341             lButton.show(pButton, "search");
342         } else if (button == bDelete) {
343             if (lastButtonDelete) {
344
345                 // delete and determine follow up actions, see comment in ZaurusTableForm.deleteRow()
346
switch (((ZaurusTableForm) vHoldForms.elementAt(
347                         aktHoldNr)).deleteRow()) {
348
349                     case 1 :
350                         lForm.show(pForm, "search");
351                         lButton.show(pButton, "search");
352                         break;
353
354                     case 2 :
355                         bPrev.setEnabled(false);
356                         break;
357
358                     case 3 :
359                         bNext.setEnabled(false);
360                         break;
361
362                     default :
363                         break;
364                 } // end of switch (((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr)).deleteRow())
365

366                 lastButtonDelete = false;
367             } else {
368                 ZaurusEditor.printStatus(
369                     "Press 'Delete' a second time to delete row.");
370
371                 lastButtonDelete = true;
372             } // end of if (lastButtonDelete)
373
} // end of if (button == Rest)
374
}
375
376     // when tree is refreshed ZaurusEditor.refresh() is called, too
377

378     /**
379      * <code>refresh</code> will read again the meta data of the
380      * actual database. This is useful after changes of the table
381      * structures for instance creating or dropping tables, or
382      * altering tabel. The method will be called if one asks to
383      * refresh the tree or if the connection to the database is
384      * changed.
385      *
386      * @param c a <code>Connection</code> is the actual connection to
387      * the database
388      */

389     public void refresh(Connection JavaDoc c) {
390
391         cConn = c;
392
393         if (vHoldForms == null) {
394             this.initGUI();
395
396             // System.out.println("initGUI <<<<<<<<<<<<<<<<<<<<<<");
397
} else {
398             this.resetTableForms();
399
400             // System.out.println("reset >>>>>>>>>>>>>>>>>");
401
}
402     }
403
404     private void initGUI() {
405
406         // without connection there are no tables
407
// vAllTables is a local variable with all table names in the database
408
// vHoldTableNames holds the table names which have a ZaurusTableForm
409
Vector JavaDoc vAllTables = getAllTables();
410
411         if (vAllTables == null) {
412             return;
413         }
414
415         // initialize a new list for the table names which have a form in pForm
416
vHoldTableNames = new Vector JavaDoc(20);
417         vHoldForms = new Vector JavaDoc(20);
418
419         // this holds the card panel pForm for the forms in the top
420
// a card panel pButton below
421
// the both card panels form a panel which is centered in this
422
// and a status line in the south
423
this.setLayout(new BorderLayout JavaDoc(3, 3));
424
425         // >>> the top of this: the entry forms in pForm
426
// pFormButs holds in the center the forms card panel pForm and
427
// in the south the button card panel pButton
428
Panel JavaDoc pFormButs = new Panel JavaDoc();
429
430         pFormButs.setLayout(new BorderLayout JavaDoc(3, 3));
431
432         pForm = new Panel JavaDoc();
433         lForm = new CardLayout JavaDoc(2, 2);
434
435         pForm.setLayout(lForm);
436
437         // the search panel containing the list of all tables and
438
// the entry fields for search words in the Center
439
Panel JavaDoc pEntry = new Panel JavaDoc();
440
441         pEntry.setLayout(new GridBagLayout JavaDoc());
442
443         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
444
445         c.fill = GridBagConstraints.HORIZONTAL;
446         c.insets = new Insets JavaDoc(3, 3, 3, 3);
447         c.gridwidth = 1;
448         c.gridheight = 1;
449         c.weightx = c.weighty = 1;
450         c.anchor = GridBagConstraints.WEST;
451         c.gridy = 0;
452         c.gridx = 0;
453
454         pEntry.add(new Label JavaDoc("Search table"), c);
455
456         c.gridx = 1;
457
458         // get all table names and show a drop down list of them in cTables
459
cTables = new Choice JavaDoc();
460
461         for (Enumeration JavaDoc e = vAllTables.elements(); e.hasMoreElements(); ) {
462             cTables.addItem((String JavaDoc) e.nextElement());
463         }
464
465         c.gridwidth = 2;
466
467         pEntry.add(cTables, c);
468
469         c.gridy = 1;
470         c.gridx = 0;
471         c.gridwidth = 1;
472
473         pEntry.add(new Label JavaDoc("Search words"), c);
474
475         c.gridx = 1;
476         c.gridwidth = 2;
477         fSearchWords = new TextField JavaDoc(8);
478
479         pEntry.add(fSearchWords, c);
480
481         // use search words
482
c.gridwidth = 1;
483         c.gridy = 2;
484         c.gridx = 0;
485
486         pEntry.add(new Label JavaDoc("Use search words"), c);
487
488         gAllWords = new CheckboxGroup JavaDoc();
489
490         Checkbox JavaDoc[] checkboxes = new Checkbox JavaDoc[2];
491
492         checkboxes[0] = new Checkbox JavaDoc("all", gAllWords, true);
493         c.gridx = 1;
494
495         pEntry.add(checkboxes[0], c);
496
497         checkboxes[1] = new Checkbox JavaDoc("any ", gAllWords, false);
498         c.gridx = 2;
499
500         pEntry.add(checkboxes[1], c);
501
502         // ignore case
503
c.gridy = 3;
504         c.gridx = 0;
505
506         pEntry.add(new Label JavaDoc("Ignore case"), c);
507
508         gIgnoreCase = new CheckboxGroup JavaDoc();
509
510         Checkbox JavaDoc[] checkboxes1 = new Checkbox JavaDoc[2];
511
512         checkboxes1[0] = new Checkbox JavaDoc("yes", gIgnoreCase, true);
513         c.gridx = 1;
514
515         pEntry.add(checkboxes1[0], c);
516
517         checkboxes1[1] = new Checkbox JavaDoc("no", gIgnoreCase, false);
518         c.gridx = 2;
519
520         pEntry.add(checkboxes1[1], c);
521
522         // Match column exactly
523
c.gridy = 4;
524         c.gridx = 0;
525
526         pEntry.add(new Label JavaDoc("Match whole col"), c);
527
528         gNoMatchWhole = new CheckboxGroup JavaDoc();
529
530         Checkbox JavaDoc[] checkboxes2 = new Checkbox JavaDoc[2];
531
532         checkboxes2[0] = new Checkbox JavaDoc("no", gNoMatchWhole, true);
533         c.gridx = 1;
534
535         pEntry.add(checkboxes2[0], c);
536
537         checkboxes2[1] = new Checkbox JavaDoc("yes ", gNoMatchWhole, false);
538         c.gridx = 2;
539
540         pEntry.add(checkboxes2[1], c);
541         pForm.add("search", pEntry);
542         pFormButs.add("Center", pForm);
543
544         // the buttons
545
this.initButtons();
546
547         pButton = new Panel JavaDoc();
548         lButton = new CardLayout JavaDoc(2, 2);
549
550         pButton.setLayout(lButton);
551         pButton.add("search", pSearchButs);
552         pButton.add("edit", pEditButs);
553         pButton.add("insert", pInsertButs);
554         pFormButs.add("South", pButton);
555         this.add("Center", pFormButs);
556
557         // >>> the South: status line at the bottom
558
Font JavaDoc fFont = new Font JavaDoc("Dialog", Font.PLAIN, 10);
559
560         ZaurusEditor.tStatus = new TextField JavaDoc("");
561
562         ZaurusEditor.tStatus.setEditable(false);
563         this.add("South", ZaurusEditor.tStatus);
564     }
565
566     // process the buttons events
567
// *******************************************************
568
// private methods
569
// *******************************************************
570
// read all table names over the current database connection
571
// exclude tables without primary key
572
private Vector JavaDoc getAllTables() {
573
574         Vector JavaDoc result = new Vector JavaDoc(20);
575
576         try {
577             if (cConn == null) {
578                 return null;
579             }
580
581             dbmeta = cConn.getMetaData();
582
583             String JavaDoc[] tableTypes = { "TABLE" };
584             ResultSet JavaDoc allTables = dbmeta.getTables(null, null, null,
585                                                    tableTypes);
586
587             while (allTables.next()) {
588                 String JavaDoc aktTable = allTables.getString("TABLE_NAME");
589                 ResultSet JavaDoc primKeys = dbmeta.getPrimaryKeys(null, null,
590                     aktTable);
591
592                 // take only table with a primary key
593
if (primKeys.next()) {
594                     result.addElement(aktTable);
595                 }
596
597                 primKeys.close();
598             }
599
600             allTables.close();
601         } catch (SQLException JavaDoc e) {
602
603             // System.out.println("SQL Exception: " + e.getMessage());
604
}
605
606         return result;
607     }
608
609     // determine the index of the choosen table in Vector vHoldTableNames
610
// if the table name is not in vHoldTableNames, create a ZaurusTableForm for it
611
private int getChoosenTableIndex() {
612
613         String JavaDoc tableName = cTables.getSelectedItem();
614
615         // System.out.println("in getChoosenTableIndex, selected Item is "+tableName);
616
int index = getTableIndex(tableName);
617
618         if (index >= 0) {
619
620             // System.out.println("table found, index: " + index);
621
return index;
622         } // end of if (index >= 0)
623

624         ZaurusTableForm tableForm = new ZaurusTableForm(tableName, cConn);
625
626         pForm.add(tableName, tableForm);
627         vHoldTableNames.addElement(tableName);
628         vHoldForms.addElement(tableForm);
629
630         // System.out.println("new tableform for table "+tableName+", index: " + index);
631
return vHoldTableNames.size() - 1;
632     }
633
634     // determine the index of the given tableName in Vector vHoldTableNames
635
// if the name is not in vHoldTableNames, answer -1
636
private int getTableIndex(String JavaDoc tableName) {
637
638         int index;
639
640         // System.out.println("begin searching for "+tableName);
641
for (index = 0; index < vHoldTableNames.size(); index++) {
642
643             // System.out.println("in getTableIndex searching for "+tableName+", index: "+index);
644
if (tableName.equals((String JavaDoc) vHoldTableNames.elementAt(index))) {
645                 return index;
646             } // end of if (tableName.equals(vHoldTableNames.elementAt(index)))
647
} // end of for (index = 0; index < vHoldTableNames.size(); index ++)
648

649         return -1;
650     }
651
652     // convert the search words in the textfield to an array of words
653
private String JavaDoc[] getWords() {
654
655         StringTokenizer JavaDoc tokenizer =
656             new StringTokenizer JavaDoc(fSearchWords.getText());
657         String JavaDoc[] result = new String JavaDoc[tokenizer.countTokens()];
658         int i = 0;
659
660         while (tokenizer.hasMoreTokens()) {
661             result[i++] = tokenizer.nextToken();
662         } // end of while ((tokenizer.hasMoreTokens()))
663

664         return result;
665     }
666
667     // init the three boxes for buttons
668
private void initButtons() {
669
670         // the buttons for the search form
671
bSearchRow = new Button JavaDoc("Search Rows");
672         bNewRow = new Button JavaDoc("Insert New Row");
673
674         bSearchRow.addActionListener(this);
675         bNewRow.addActionListener(this);
676
677         pSearchButs = new Panel JavaDoc();
678
679         pSearchButs.setLayout(new GridLayout JavaDoc(1, 0, 4, 4));
680         pSearchButs.add(bSearchRow);
681         pSearchButs.add(bNewRow);
682
683         // the buttons for editing a row
684
bCancel1 = new Button JavaDoc("Cancel");
685         bPrev = new Button JavaDoc("Prev");
686         bNext = new Button JavaDoc("Next");
687         bDelete = new Button JavaDoc("Delete");
688         lastButtonDelete = false;
689         bNewSearch = new Button JavaDoc("Search");
690
691         bCancel1.addActionListener(this);
692         bPrev.addActionListener(this);
693         bNext.addActionListener(this);
694         bDelete.addActionListener(this);
695         bNewSearch.addActionListener(this);
696
697         pEditButs = new Panel JavaDoc();
698
699         pEditButs.setLayout(new GridLayout JavaDoc(1, 0, 4, 4));
700         pEditButs.add(bCancel1);
701         pEditButs.add(bPrev);
702         pEditButs.add(bNext);
703         pEditButs.add(bDelete);
704         pEditButs.add(bNewSearch);
705
706         // the buttons for inserting a new row
707
pInsertButs = new Panel JavaDoc();
708
709         pInsertButs.setLayout(new GridLayout JavaDoc(1, 0, 4, 4));
710
711         bCancel2 = new Button JavaDoc("Cancel Insert");
712         bNewInsert = new Button JavaDoc("New Insert");
713         bNewSearch1 = new Button JavaDoc("Search");
714
715         bCancel2.addActionListener(this);
716         bNewInsert.addActionListener(this);
717         bNewSearch1.addActionListener(this);
718         pInsertButs.add(bCancel2);
719         pInsertButs.add(bNewInsert);
720         pInsertButs.add(bNewSearch1);
721     }
722
723     // check whether the last button pressed was delete
724
// if so, clear status line and reset the flag
725
private void resetLastButtonDelete() {
726
727         if (lastButtonDelete) {
728             ZaurusEditor.printStatus("");
729
730             lastButtonDelete = false;
731         } // end of if (lastButtonDelete)
732
}
733
734     // reset everything after changes in the database
735
private void resetTableForms() {
736
737         lForm.show(pForm, "search");
738         lButton.show(pButton, "search");
739
740         Vector JavaDoc vAllTables = getAllTables();
741
742         // fill the drop down list again
743
// get all table names and show a drop down list of them in cTables
744
cTables.removeAll();
745
746         for (Enumeration JavaDoc e = vAllTables.elements(); e.hasMoreElements(); ) {
747             cTables.addItem((String JavaDoc) e.nextElement());
748         }
749
750         // remove all form panels from pForm
751
for (Enumeration JavaDoc e = vHoldForms.elements(); e.hasMoreElements(); ) {
752             pForm.remove((ZaurusTableForm) e.nextElement());
753         } // end of while (Enumeration e = vHoldForms.elements(); e.hasMoreElements();)
754

755         // initialize a new list for the table names which have a form in pForm
756
vHoldTableNames = new Vector JavaDoc(20);
757         vHoldForms = new Vector JavaDoc(20);
758     }
759 }
760
Popular Tags