KickJava   Java API By Example, From Geeks To Geeks.

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


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.JLabel JavaDoc;
22 import javax.swing.JPanel JavaDoc;
23 import javax.swing.JList JavaDoc;
24 import javax.swing.JScrollPane JavaDoc;
25 import javax.swing.AbstractListModel JavaDoc;
26
27 import java.awt.event.ActionListener JavaDoc;
28 import java.awt.event.MouseListener JavaDoc;
29 import java.awt.event.MouseAdapter JavaDoc;
30 import java.awt.event.MouseEvent JavaDoc;
31 import java.awt.event.ActionEvent JavaDoc;
32 import java.awt.Dialog JavaDoc;
33
34 import org.openide.util.NbBundle;
35 import org.openide.util.HelpCtx ;
36 import org.openide.NotifyDescriptor;
37 import org.openide.DialogDisplayer;
38 import org.openide.DialogDescriptor;
39
40 /**
41  * A JPanel that presents a list of tables for selection
42  *
43  * @author jhoff
44  */

45 public class AddTableDlg extends javax.swing.JPanel JavaDoc {
46
47     /** A return status code - returned if Cancel button has been pressed */
48     public static final int RET_CANCEL = 0;
49
50     /** A return status code - returned if OK button has been pressed */
51     public static final int RET_OK = 1;
52
53     // The model for the JList component - a String array
54
private String JavaDoc[] _tableList;
55
56     // Variables declaration - do not modify//GEN-BEGIN:variables
57
private JPanel JavaDoc _mainPanel;
58     // The Swing component whose model is the _tableList
59
private JList JavaDoc _tableJList;
60     private JScrollPane JavaDoc _tableScrollPane;
61     // End of variables declaration//GEN-END:variables
62

63     private JLabel JavaDoc tableListLabel;
64
65     private int returnStatus = RET_CANCEL;
66     private Dialog JavaDoc dialog;
67
68     // Default Constructor
69

70     public AddTableDlg() {
71         this(null, true);
72     }
73
74     /** Creates new form AddTableDlg */
75
76     public AddTableDlg(String JavaDoc[] tableList,
77                        boolean modal)
78     {
79         _tableList = tableList;
80         initComponents();
81
82         ActionListener JavaDoc listener = new ActionListener JavaDoc () {
83                 public void actionPerformed (ActionEvent JavaDoc evt) {
84                     Object JavaDoc o = evt.getSource();
85                     if (o == NotifyDescriptor.CANCEL_OPTION) {
86                         returnStatus = RET_CANCEL;
87                     } else if (o == NotifyDescriptor.OK_OPTION) {
88                         // do something useful
89
returnStatus = RET_OK;
90                     }
91                 }
92             };
93
94         MouseListener JavaDoc mouseListener = new MouseAdapter JavaDoc() {
95             public void mouseClicked(MouseEvent JavaDoc e) {
96                 if (e.getClickCount() == 2) {
97                     returnStatus = RET_OK;
98                     dialog.setVisible(false);
99                 }
100             }
101         };
102         _tableJList.addMouseListener(mouseListener);
103
104
105         DialogDescriptor dlg =
106             new DialogDescriptor(this,
107                                  NbBundle.getMessage(AddTableDlg.class, "Add_Table_Title"), // NOI18N
108
modal,
109                                  listener);
110         dlg.setHelpCtx (
111             new HelpCtx( "projrave_ui_elements_editors_about_query_editor" ) ); // NOI18N
112

113         dialog = DialogDisplayer.getDefault().createDialog(dlg);
114         dialog.setVisible(true);
115     }
116
117     /** @return the return status of this dialog - one of RET_OK or RET_CANCEL */
118     public int getReturnStatus() {
119         return returnStatus;
120     }
121
122     public Object JavaDoc[] getSelectedValues() {
123         return _tableJList.getSelectedValues();
124     }
125
126     public void setTableValues(String JavaDoc[] tableList) {
127         _tableList = tableList;
128     }
129
130     /** This method is called from within the constructor to
131      * initialize the form.
132      * WARNING: Do NOT modify this code. The content of this method is
133      * always regenerated by the Form Editor.
134      */

135     private void initComponents() {//GEN-BEGIN:initComponents
136

137         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
138
139         _mainPanel = new JPanel JavaDoc();
140         _tableScrollPane = new JScrollPane JavaDoc();
141         _tableJList = new JList JavaDoc();
142
143         setLayout(new java.awt.GridBagLayout JavaDoc());
144
145         _mainPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
146
147         // Set the model to be the array that was passed to it
148
_tableJList.setModel(new AbstractListModel JavaDoc() {
149             public int getSize() { return _tableList.length; }
150             public Object JavaDoc getElementAt(int i) { return _tableList[i]; }
151         });
152         _tableJList.getAccessibleContext().
153             setAccessibleName(NbBundle.getMessage(AddTableDlg.class, "TABLE_LIST_a11yName"));
154         _tableJList.getAccessibleContext().
155             setAccessibleDescription(NbBundle.getMessage(AddTableDlg.class, "TABLE_LIST_a11yDescription"));
156         tableListLabel = new JLabel JavaDoc();
157         tableListLabel.setText(NbBundle.getMessage(AddTableDlg.class, "TABLE_LIST_label"));
158         tableListLabel.setLabelFor(_tableJList);
159         _tableScrollPane.setViewportView(_tableJList);
160
161         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
162         gridBagConstraints.gridx = 0;
163         gridBagConstraints.gridy = 0;
164         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
165         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
166         gridBagConstraints.weightx = 1.0;
167         gridBagConstraints.weighty = 1.0;
168         _mainPanel.add(_tableScrollPane, gridBagConstraints);
169
170         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
171         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
172         gridBagConstraints.insets = new java.awt.Insets JavaDoc(10, 10, 0, 10);
173         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
174         gridBagConstraints.weightx = 1.0;
175         gridBagConstraints.weighty = 1.0;
176
177         add(_mainPanel, gridBagConstraints);
178
179
180     }//GEN-END:initComponents
181
}
182
Popular Tags