KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > sql > visualeditor > querybuilder > QueryBuilderPane


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.db.sql.visualeditor.querybuilder;
20
21 import javax.swing.JViewport JavaDoc;
22 import javax.swing.JPanel JavaDoc;
23 import javax.swing.JComponent JavaDoc;
24 import javax.swing.JFrame JavaDoc;
25 import javax.swing.JDialog JavaDoc;
26 import javax.swing.JSplitPane JavaDoc;
27 import javax.swing.JScrollPane JavaDoc;
28 import javax.swing.JButton JavaDoc;
29 import javax.swing.JLabel JavaDoc;
30 import javax.swing.BorderFactory JavaDoc;
31
32 import javax.swing.table.DefaultTableModel JavaDoc;
33
34 import javax.swing.event.*;
35
36 import java.util.Hashtable JavaDoc;
37
38 import java.awt.Rectangle JavaDoc;
39 import java.awt.Color JavaDoc;
40 import java.awt.Dimension JavaDoc;
41 import java.awt.GridLayout JavaDoc;
42 import java.awt.GridBagLayout JavaDoc;
43 import java.awt.GridBagConstraints JavaDoc;
44 import java.awt.Font JavaDoc;
45 import java.awt.event.*;
46
47 import org.openide.util.NbBundle;
48
49 import org.openide.ErrorManager;
50 import org.openide.NotifyDescriptor;
51 import org.openide.DialogDisplayer;
52
53 import org.netbeans.modules.db.sql.visualeditor.Log;
54
55 /**
56  *
57  * @author Sanjay Dhamankar
58  */

59 public class QueryBuilderPane extends JSplitPane JavaDoc {
60
61     // Variables
62

63     private boolean DEBUG = false;
64
65     private int DIVIDER_SIZE = 7;
66
67     // Make these package access, so components can access each other
68
// through here
69

70     private QueryBuilderResultTable _queryBuilderResultTable;
71     private QueryBuilderGraphFrame _queryBuilderGraphFrame;
72     private QueryBuilderInputTable _queryBuilderInputTable;
73     private QueryBuilderSqlTextArea _queryBuilderSqlTextArea;
74
75     private QueryBuilder _queryBuilder;
76
77     private JLabel JavaDoc qbitLabel;
78     private JLabel JavaDoc qbstaLabel;
79     private JLabel JavaDoc qbgfLabel;
80
81     // Use these to store the current state and to avoid the expensive
82
// recursive calls
83
private boolean graphScrollPaneEnabled;
84     private boolean qbInputTableSPEnabled;
85
86     private JScrollPane JavaDoc graphScrollPane;
87     private JScrollPane JavaDoc qbInputTableSP;
88
89     private JPanel JavaDoc bottomPanel;
90     private JPanel JavaDoc buttonPanel;
91     private boolean _keyTyped = false;
92
93
94     // Constructor
95

96     public QueryBuilderPane(QueryBuilder queryBuilder)
97     {
98
99 /*
100         ---------------------------------------------------------
101         | graphScrollPane |
102         ---------------------------------------------------------
103         ---------------------------------------------------------
104         | qbInputTableSP |
105         ---------------------------------------------------------
106         ---------------------------------------------------------
107         | qbSqlTextAreaSP |
108         ---------------------------------------------------------
109         ---------------------------------------------------------
110         | qbResultTableSP |
111         ---------------------------------------------------------
112
113      firstSplitPane ==> qbSqlTextAreaSP and qbResultTableSP
114      secondSplitPane ==> qbInputTableSP and firstSplitPane
115      this ==> graphScrollPane and secondSplitPane
116 */

117
118         super(JSplitPane.VERTICAL_SPLIT);
119         Log.err.log(ErrorManager.INFORMATIONAL, "Entering QueryBuilderPane ctor"); // NOI18N
120

121         _queryBuilder = queryBuilder;
122
123         graphScrollPaneEnabled = true;
124         qbInputTableSPEnabled = true;
125
126         //Make sure we have nice window decorations.
127
JFrame.setDefaultLookAndFeelDecorated(true);
128         JDialog.setDefaultLookAndFeelDecorated(true);
129
130         // Create the four panes that provide the main functionality
131

132         _queryBuilderInputTable = new QueryBuilderInputTable(_queryBuilder);
133         _queryBuilderInputTable.setFocusable ( true );
134         _queryBuilderInputTable.getAccessibleContext().setAccessibleName(
135             NbBundle.getMessage(QueryBuilderPane.class, "QBP_QBIT_a11yName"));
136         _queryBuilderInputTable.getAccessibleContext().setAccessibleDescription(
137             NbBundle.getMessage(QueryBuilderPane.class, "QBP_QBIT_a11yDescription"));
138         qbitLabel = new JLabel JavaDoc();
139         qbitLabel.setText(NbBundle.getMessage(QueryBuilderPane.class, "QBP_QBIT_label"));
140         qbitLabel.setLabelFor(_queryBuilderInputTable);
141
142         _queryBuilderSqlTextArea = new QueryBuilderSqlTextArea(_queryBuilder);
143         _queryBuilderSqlTextArea.setFocusable ( true );
144         _queryBuilderSqlTextArea.getAccessibleContext().setAccessibleName(
145             NbBundle.getMessage(QueryBuilderPane.class, "QBP_QBSTA_a11yName"));
146         _queryBuilderSqlTextArea.getAccessibleContext().setAccessibleDescription(
147             NbBundle.getMessage(QueryBuilderPane.class, "QBP_QBSTA_a11yDescription"));
148         qbstaLabel = new JLabel JavaDoc();
149         qbstaLabel.setText(NbBundle.getMessage(QueryBuilderPane.class, "QBP_QBSTA_label"));
150         qbstaLabel.setLabelFor(_queryBuilderSqlTextArea);
151
152         _queryBuilderResultTable = new QueryBuilderResultTable(_queryBuilder);
153         _queryBuilderResultTable.setFocusable ( true );
154
155         // When constructing the diagram pane, pass in the other three panes
156
// (or their models)
157
// ToDo: revisit this decision.
158
_queryBuilderGraphFrame = new QueryBuilderGraphFrame(
159             _queryBuilder,
160             _queryBuilderInputTable,
161             _queryBuilderSqlTextArea,
162             (DefaultTableModel JavaDoc) _queryBuilderResultTable.getModel()
163             );
164         _queryBuilderGraphFrame.setFocusable ( true );
165         _queryBuilderGraphFrame.getAccessibleContext().setAccessibleName(
166                             NbBundle.getMessage(QueryBuilderPane.class, "QBP_QBGF_a11yName"));
167         _queryBuilderGraphFrame.getAccessibleContext().setAccessibleDescription(
168                             NbBundle.getMessage(QueryBuilderPane.class, "QBP_QBGF_a11yDescription"));
169         qbgfLabel = new JLabel JavaDoc();
170         qbgfLabel.setText(NbBundle.getMessage(QueryBuilderPane.class, "QBP_QBGF_label"));
171         qbgfLabel.setLabelFor(_queryBuilderGraphFrame);
172
173         // Wrap the diagram into a scroll pane, and make it the
174
// top component in the split pane
175
graphScrollPane = new JScrollPane JavaDoc(_queryBuilderGraphFrame);
176         graphScrollPane.setMinimumSize ( new java.awt.Dimension JavaDoc ( this.getWidth(), 40 ) );
177         this.setTopComponent(graphScrollPane);
178
179         JSplitPane JavaDoc firstSplitPane = new JSplitPane JavaDoc(JSplitPane.VERTICAL_SPLIT);
180         JSplitPane JavaDoc secondSplitPane = new JSplitPane JavaDoc(JSplitPane.VERTICAL_SPLIT);
181
182         // Create a JPanel for the bottom pane, and add the other three panes
183
// to it (input table, text query, result table)
184
bottomPanel = new JPanel JavaDoc();
185         GridBagLayout JavaDoc gridbag = new GridBagLayout JavaDoc();
186         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
187         c.gridwidth = 1;
188         c.gridheight = 1;
189         c.weightx = 1;
190         c.weighty = 1;
191         c.fill = GridBagConstraints.BOTH;
192
193         bottomPanel.setLayout(gridbag);
194
195         // Wrap the input table in a scroll pane, and add to bottom panel
196
qbInputTableSP = new JScrollPane JavaDoc(_queryBuilderInputTable,
197                                          JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
198                                          JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
199         qbInputTableSP.getViewport().setBackground(Color.white);
200         qbInputTableSP.setMinimumSize ( new java.awt.Dimension JavaDoc ( this.getWidth(), 40 ) );
201         c.gridx = 0;
202         c.gridy = 0;
203         gridbag.setConstraints(qbInputTableSP, c);
204
205 // bottomPanel.add(qbInputTableSP);
206

207
208         // Wrap the SQL text area in a scroll pane, and add to bottom panel
209
JScrollPane JavaDoc qbSqlTextAreaSP = new JScrollPane JavaDoc(_queryBuilderSqlTextArea,
210                                                       JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
211                                                       JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
212         c.gridx = 0;
213         c.gridy = 1;
214         gridbag.setConstraints(qbSqlTextAreaSP, c);
215         qbSqlTextAreaSP.setMinimumSize ( new java.awt.Dimension JavaDoc ( this.getWidth(), 40 ) );
216         // ToDo: Should we do: qbSqlTextAreaSP.setBackground(Color.white);
217

218         // Wrap the result table in a scroll pane, and add to bottom panel
219
JScrollPane JavaDoc qbResultTableSP = new JScrollPane JavaDoc(_queryBuilderResultTable,
220                                                       JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
221                                                       JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
222         qbResultTableSP.getViewport().setBackground(Color.white);
223         qbResultTableSP.setMinimumSize ( new java.awt.Dimension JavaDoc ( this.getWidth(), 40 ) );
224         c.gridx = 0;
225         c.gridy = 3;
226         gridbag.setConstraints(qbResultTableSP, c);
227         
228         firstSplitPane.setTopComponent ( qbSqlTextAreaSP );
229         firstSplitPane.setBottomComponent ( qbResultTableSP );
230         firstSplitPane.setDividerSize(DIVIDER_SIZE);
231         firstSplitPane.setOneTouchExpandable(true);
232         firstSplitPane.setResizeWeight(0.5);
233
234         secondSplitPane.setTopComponent ( qbInputTableSP );
235         secondSplitPane.setBottomComponent ( firstSplitPane );
236         secondSplitPane.setDividerSize(DIVIDER_SIZE);
237         secondSplitPane.setOneTouchExpandable(true);
238         secondSplitPane.setResizeWeight(0.5);
239
240         this.setBottomComponent(secondSplitPane);
241         this.setDividerSize(DIVIDER_SIZE);
242         this.setResizeWeight(0.5);
243         this.setOneTouchExpandable(true);
244         this.setVisible(true);
245     }
246
247
248     /**
249      * Return the current query text
250      */

251     String JavaDoc getSqlTextAreaText()
252     {
253         return _queryBuilderSqlTextArea.getText();
254     }
255
256     /**
257      * Return the query builder result table
258      */

259     QueryBuilderResultTable getQueryBuilderResultTable()
260     {
261         return _queryBuilderResultTable;
262     }
263
264     /**
265      * Return the query builder graph frame
266      */

267     QueryBuilderGraphFrame getQueryBuilderGraphFrame()
268     {
269         return _queryBuilderGraphFrame;
270     }
271
272     /**
273      * Return the query builder input table
274      */

275     QueryBuilderInputTable getQueryBuilderInputTable()
276     {
277         return _queryBuilderInputTable;
278     }
279     /**
280      * Return the query builder sql text area
281      */

282     QueryBuilderSqlTextArea getQueryBuilderSqlTextArea()
283     {
284         return _queryBuilderSqlTextArea;
285     }
286
287     /**
288      * Clear each of the panes or their models
289      */

290     void clear()
291     {
292         _queryBuilderInputTable.clearModel();
293         _queryBuilderSqlTextArea.clear();
294         _queryBuilderResultTable.clearModel();
295         _queryBuilderGraphFrame.clearGraph();
296     }
297
298     /**
299      * Enable / Disable the container and its children.
300      */

301     public void setEnableContainer ( java.awt.Container JavaDoc c , boolean value ) {
302         java.awt.Component JavaDoc[] components = c.getComponents();
303         for(int i=0; i<components.length; i++) {
304             components[i].setEnabled(value);
305             if(components[i] instanceof java.awt.Container JavaDoc) {
306                 setEnableContainer((java.awt.Container JavaDoc)components[i], value);
307             }
308         }
309     }
310
311     /**
312      * Enable / Disable the graph scrolled pane and its children.
313      * We store the state to avoid the expensive recursive call to
314      * setEnableContainer.
315      */

316     /*
317     public void setQueryBuilderGraphFrameEnabled ( boolean value )
318     {
319         if ( graphScrollPaneEnabled == value ) return;
320         if ( graphScrollPane != null ) {
321             setEnableContainer ( graphScrollPane , value );
322             graphScrollPaneEnabled = value;
323         }
324     }
325     */

326
327     /**
328      * Enable / Disable the input table scrolled pane and its children.
329      * We store the state to avoid the expensive recursive call to
330      * setEnableContainer.
331      */

332     public void setQueryBuilderInputTableEnabled ( boolean value ) {
333         if ( qbInputTableSPEnabled == value ) return;
334         if ( qbInputTableSP != null ) {
335             setEnableContainer ( qbInputTableSP , value );
336             qbInputTableSPEnabled = value ;
337         }
338     }
339 }
340
Popular Tags