KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nqadmin > swingSet > SSDBNavImp


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

32
33 package com.nqadmin.swingSet;
34
35 import java.awt.*;
36 import javax.swing.*;
37
38 /**
39  * SSDBNavImp.java
40  *<p>
41  * SwingSet - Open Toolkit For Making Swing Controls Database-Aware
42  *<p><pre>
43  * Custom implementation of SSDBNav that clears/resets the various database-aware
44  * fields on a screen when the user adds a new record. To achieve this, special
45  * implementation of the performPreInsertOps() method is provided. An instance of
46  * this class can be created for the container where the fields are to be cleared
47  * and passed to the data navigator.
48  *
49  * The data navigator will call the performPreInsertOps() method whenever the
50  * user presses the insert button on the navigator. This fuctions recursively
51  * clears any JTextFields, JTextAreas, and SSCheckBoxes, and if their are any
52  * SSComboBoxes or SSDBComboBoxes they will be reset to the first item in the
53  * list.
54  *
55  * This recursive behavior performed on all the components inside the JPanel or
56  * JTabbedPane inside the specified container.
57  *</pre><p>
58  * @author $Author: prasanth $
59  * @version $Revision: 1.14 $
60  */

61 public class SSDBNavImp extends SSDBNavAdapter {
62
63     /**
64      * Screen where componets to be cleared are located.
65      */

66     protected Container container = null;
67
68     /**
69      * Constructs a SSDBNavImp with the specified container.
70      */

71     public SSDBNavImp(Container _container) {
72         container = _container;
73     }
74
75     /**
76      * Performs pre-insertion operations.
77      */

78     public void performPreInsertOps() {
79         
80         setComponents(container);
81
82     } // end public void performPreInsertOps() {
83

84     /**
85      * Clears all the JTextFields and resets the combo boxes to first item.
86      *
87      * This is done for all SwingSet components, text fields, & text areas,
88      * recursively looking in to the JTabbedPanes and JPanels inside the given
89      * container as needed.
90      *
91      * @param _container container in which to recursively initialize components
92      */

93     protected void setComponents(Container _container) {
94
95         Component[] comps = _container.getComponents();
96
97         for (int i=0; i< comps.length; i++ ) {
98             if (comps[i] instanceof JTextField) {
99             // IF IT IS A JTextField SET ITS TEXT TO EMPTY STRING
100
((JTextField)comps[i]).setText("");
101             } else if(comps[i] instanceof JTextArea) {
102             // IF IT IS A JTextArea, SET TO EMPTY STRING
103
((JTextArea)comps[i]).setText("");
104             } else if (comps[i] instanceof JComboBox) {
105             // IF IT IS A JComboBox THEN SET IT TO 'EMPTY' ITEM BEFORE FIRST ITEM
106
((JComboBox)comps[i]).setSelectedIndex(-1);
107             } else if(comps[i] instanceof SSImage) {
108             // IF IT IS A SSImage CLEAR THE IMAGE.
109
((SSImage)comps[i]).clearImage();
110             } else if(comps[i] instanceof JCheckBox) {
111             // IF IT IS A JCheckBox UNCHECK
112
((JCheckBox)comps[i]).setSelected(false);
113             } else if(comps[i] instanceof SSLabel) {
114             // IF IT IS A SSLabel, SET TO EMPTY STRING
115
((SSLabel)comps[i]).setText("");
116             } else if(comps[i] instanceof JSlider) {
117             // IF IT IS A JSlider, SET TO AVERAGE OF MIN/MAX VALUES
118
((JSlider)comps[i]).setValue((((JSlider)comps[i]).getMinimum() + ((JSlider)comps[i]).getMaximum()) / 2);
119             } else if(comps[i] instanceof JPanel) {
120             // IF IT IS A JPanel RECURSIVELY SET THE FIELDS
121
setComponents((Container)comps[i]);
122             } else if(comps[i] instanceof JTabbedPane) {
123             // IF IT IS A JTabbedPane RECURSIVELY SET THE FIELDS
124
setComponents((Container)comps[i]);
125             } else if(comps[i] instanceof JScrollPane) {
126             // IF IT IS A JScrollPane GET THE VIEW PORT AND RECURSIVELY SET THE FIELDS IN VIEW PORT
127
setComponents((Container) ((JScrollPane)comps[i]).getViewport());
128             }
129         }
130
131     } // end protected void setComponents(Container _container) {
132

133 } // end public class SSDBNavImp extends SSDBNavAdapter {
134

135
136
137 /*
138  * $Log: SSDBNavImp.java,v $
139  * Revision 1.14 2005/03/08 16:06:40 prasanth
140  * Added JScrollPane to the list of items to look for in setComponents function.
141  *
142  * Revision 1.13 2005/02/09 17:12:53 yoda2
143  * Consolidated logic, added text area, check box, slider, & SSLabel, and cleaned up JavaDoc.
144  *
145  * Revision 1.12 2005/02/04 23:05:02 yoda2
146  * no message
147  *
148  * Revision 1.11 2005/02/04 22:48:53 yoda2
149  * API cleanup & updated Copyright info.
150  *
151  * Revision 1.10 2005/01/19 16:46:11 yoda2
152  * Updated SSDBComboBox stuff to get rid of getComboBox() calls.
153  *
154  * Revision 1.9 2005/01/18 22:27:28 yoda2
155  * Changed to extend JComboBox rather than JComponent. Deprecated bind(), setSSRowSet(), & setColumnName().
156  *
157  * Revision 1.8 2005/01/18 21:00:47 prasanth
158  * Added support for SSImage in performPreInsertOps.
159  *
160  * Revision 1.7 2004/11/11 14:45:48 yoda2
161  * Using TextPad, converted all tabs to "soft" tabs comprised of four actual spaces.
162  *
163  * Revision 1.6 2004/08/10 22:06:58 yoda2
164  * Added/edited JavaDoc, made code layout more uniform across classes, made various small coding improvements suggested by PMD.
165  *
166  * Revision 1.5 2004/08/09 21:28:50 prasanth
167  * The default selection of first item is removed.
168  * Now no item will be selected (setting the selection to -1)
169  *
170  * Revision 1.4 2004/03/08 16:43:37 prasanth
171  * Updated copy right year.
172  *
173  * Revision 1.3 2003/12/16 18:01:40 prasanth
174  * Documented versions for release 0.6.0
175  *
176  * Revision 1.2 2003/09/25 14:27:45 yoda2
177  * Removed unused Import statements and added preformatting tags to JavaDoc descriptions.
178  *
179  * Revision 1.1.1.1 2003/09/25 13:56:43 yoda2
180  * Initial CVS import for SwingSet.
181  *
182  */
Popular Tags