1 19 package org.netbeans.modules.db.sql.visualeditor.querybuilder; 20 21 import javax.swing.JLabel ; 22 import javax.swing.JPanel ; 23 import javax.swing.JList ; 24 import javax.swing.JScrollPane ; 25 import javax.swing.AbstractListModel ; 26 27 import java.awt.event.ActionListener ; 28 import java.awt.event.MouseListener ; 29 import java.awt.event.MouseAdapter ; 30 import java.awt.event.MouseEvent ; 31 import java.awt.event.ActionEvent ; 32 import java.awt.Dialog ; 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 45 public class AddTableDlg extends javax.swing.JPanel { 46 47 48 public static final int RET_CANCEL = 0; 49 50 51 public static final int RET_OK = 1; 52 53 private String [] _tableList; 55 56 private JPanel _mainPanel; 58 private JList _tableJList; 60 private JScrollPane _tableScrollPane; 61 63 private JLabel tableListLabel; 64 65 private int returnStatus = RET_CANCEL; 66 private Dialog dialog; 67 68 70 public AddTableDlg() { 71 this(null, true); 72 } 73 74 75 76 public AddTableDlg(String [] tableList, 77 boolean modal) 78 { 79 _tableList = tableList; 80 initComponents(); 81 82 ActionListener listener = new ActionListener () { 83 public void actionPerformed (ActionEvent evt) { 84 Object o = evt.getSource(); 85 if (o == NotifyDescriptor.CANCEL_OPTION) { 86 returnStatus = RET_CANCEL; 87 } else if (o == NotifyDescriptor.OK_OPTION) { 88 returnStatus = RET_OK; 90 } 91 } 92 }; 93 94 MouseListener mouseListener = new MouseAdapter () { 95 public void mouseClicked(MouseEvent 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"), modal, 109 listener); 110 dlg.setHelpCtx ( 111 new HelpCtx( "projrave_ui_elements_editors_about_query_editor" ) ); 113 dialog = DialogDisplayer.getDefault().createDialog(dlg); 114 dialog.setVisible(true); 115 } 116 117 118 public int getReturnStatus() { 119 return returnStatus; 120 } 121 122 public Object [] getSelectedValues() { 123 return _tableJList.getSelectedValues(); 124 } 125 126 public void setTableValues(String [] tableList) { 127 _tableList = tableList; 128 } 129 130 135 private void initComponents() { 137 java.awt.GridBagConstraints gridBagConstraints; 138 139 _mainPanel = new JPanel (); 140 _tableScrollPane = new JScrollPane (); 141 _tableJList = new JList (); 142 143 setLayout(new java.awt.GridBagLayout ()); 144 145 _mainPanel.setLayout(new java.awt.GridBagLayout ()); 146 147 _tableJList.setModel(new AbstractListModel () { 149 public int getSize() { return _tableList.length; } 150 public Object 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 (); 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 (); 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 (); 171 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 172 gridBagConstraints.insets = new java.awt.Insets (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 }} 182 | Popular Tags |