PageRenderTime 64ms CodeModel.GetById 49ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mpv5/ui/panels/QueryPanel.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 228 lines | 168 code | 24 blank | 36 comment | 3 complexity | a3d702e9e22ca8297518b4dd1e3fd709 MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  1. /*
  2. * This file is part of YaBS.
  3. *
  4. * YaBS is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * YaBS is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with YaBS. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /*
  18. * GeneralListPanel.java
  19. *
  20. * Created on 03.04.2009, 15:26:37
  21. */
  22. package mpv5.ui.panels;
  23. import java.awt.Component;
  24. import javax.swing.JComponent;
  25. import javax.swing.JTable;
  26. import javax.swing.table.TableCellRenderer;
  27. import mpv5.db.common.QueryHandler;
  28. import mpv5.db.common.ReturnValue;
  29. import mpv5.ui.dialogs.DialogForFile;
  30. import mpv5.ui.dialogs.Popup;
  31. import mpv5.ui.misc.MPTable;
  32. import mpv5.usermanagement.MPSecurityManager;
  33. import mpv5.utils.files.FileReaderWriter;
  34. import mpv5.utils.models.MPTableModel;
  35. import mpv5.ui.misc.TableViewPersistenceHandler;
  36. /**
  37. *
  38. *
  39. */
  40. public class QueryPanel extends javax.swing.JPanel {
  41. private static final long serialVersionUID = 1L;
  42. private java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();
  43. /**
  44. *
  45. */
  46. public QueryPanel() {
  47. initComponents();
  48. prinitingComboBox1.init(jTable1);
  49. ((MPTable) jTable1).setPersistanceHandler(new TableViewPersistenceHandler((MPTable)jTable1, this));
  50. }
  51. /** This method is called from within the constructor to
  52. * initialize the form.
  53. * WARNING: Do NOT modify this code. The content of this method is
  54. * always regenerated by the Form Editor.
  55. */
  56. @SuppressWarnings("unchecked")
  57. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  58. private void initComponents() {
  59. jScrollPane1 = new javax.swing.JScrollPane();
  60. jTable1 = new mpv5.ui.misc.MPTable(this) {
  61. public Component prepareRenderer(TableCellRenderer renderer,
  62. int rowIndex, int vColIndex) {
  63. Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
  64. if (c instanceof JComponent) {
  65. JComponent jc = (JComponent)c;
  66. jc.setToolTipText(String.valueOf(getValueAt(rowIndex, vColIndex)));
  67. }
  68. return c;
  69. }
  70. };
  71. labeledTextChooser1 = new mpv5.ui.beans.LabeledTextChooser();
  72. jButton1 = new javax.swing.JButton();
  73. jButton2 = new javax.swing.JButton();
  74. jScrollPane2 = new javax.swing.JScrollPane();
  75. jTextArea1 = new javax.swing.JTextArea();
  76. jButton3 = new javax.swing.JButton();
  77. prinitingComboBox1 = new mpv5.ui.beans.PrinitingComboBox();
  78. mpv5.i18n.LanguageManager.getBundle();
  79. setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("QueryPanel.border.title"))); // NOI18N
  80. setName("Form"); // NOI18N
  81. jScrollPane1.setName("jScrollPane1"); // NOI18N
  82. jTable1.setAutoCreateRowSorter(true);
  83. jTable1.setModel(new javax.swing.table.DefaultTableModel(
  84. new Object [][] {
  85. {},
  86. {},
  87. {},
  88. {}
  89. },
  90. new String [] {
  91. }
  92. ));
  93. jTable1.setName("jTable1"); // NOI18N
  94. jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
  95. public void mouseClicked(java.awt.event.MouseEvent evt) {
  96. jTable1MouseClicked(evt);
  97. }
  98. });
  99. jScrollPane1.setViewportView(jTable1);
  100. labeledTextChooser1.set_Label(bundle.getString("QueryPanel.labeledTextChooser1._Label")); // NOI18N
  101. labeledTextChooser1.setFilter(DialogForFile.SQL_FILES);
  102. labeledTextChooser1.setName("labeledTextChooser1"); // NOI18N
  103. jButton1.setText(bundle.getString("QueryPanel.jButton1.text")); // NOI18N
  104. jButton1.setName("jButton1"); // NOI18N
  105. jButton1.addActionListener(new java.awt.event.ActionListener() {
  106. public void actionPerformed(java.awt.event.ActionEvent evt) {
  107. jButton1ActionPerformed(evt);
  108. }
  109. });
  110. jButton2.setText(bundle.getString("QueryPanel.jButton2.text")); // NOI18N
  111. jButton2.setName("jButton2"); // NOI18N
  112. jButton2.addActionListener(new java.awt.event.ActionListener() {
  113. public void actionPerformed(java.awt.event.ActionEvent evt) {
  114. jButton2ActionPerformed(evt);
  115. }
  116. });
  117. jScrollPane2.setName("jScrollPane2"); // NOI18N
  118. jTextArea1.setColumns(20);
  119. jTextArea1.setRows(5);
  120. jTextArea1.setName("jTextArea1"); // NOI18N
  121. jScrollPane2.setViewportView(jTextArea1);
  122. jButton3.setText(bundle.getString("QueryPanel.jButton3.text")); // NOI18N
  123. jButton3.setName("jButton3"); // NOI18N
  124. jButton3.addActionListener(new java.awt.event.ActionListener() {
  125. public void actionPerformed(java.awt.event.ActionEvent evt) {
  126. jButton3ActionPerformed(evt);
  127. }
  128. });
  129. prinitingComboBox1.setName("prinitingComboBox1"); // NOI18N
  130. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
  131. this.setLayout(layout);
  132. layout.setHorizontalGroup(
  133. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  134. .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
  135. .addGroup(layout.createSequentialGroup()
  136. .addComponent(labeledTextChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  137. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  138. .addComponent(jButton3)
  139. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 97, Short.MAX_VALUE)
  140. .addComponent(jButton2)
  141. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  142. .addComponent(jButton1)
  143. .addContainerGap())
  144. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  145. .addContainerGap(338, Short.MAX_VALUE)
  146. .addComponent(prinitingComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  147. .addContainerGap())
  148. .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
  149. );
  150. layout.setVerticalGroup(
  151. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  152. .addGroup(layout.createSequentialGroup()
  153. .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
  154. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  155. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
  156. .addComponent(labeledTextChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  157. .addComponent(jButton3)
  158. .addComponent(jButton2)
  159. .addComponent(jButton1))
  160. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  161. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
  162. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  163. .addComponent(prinitingComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  164. );
  165. }// </editor-fold>//GEN-END:initComponents
  166. private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
  167. }//GEN-LAST:event_jTable1MouseClicked
  168. private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
  169. try {
  170. jTextArea1.setText(new FileReaderWriter(labeledTextChooser1.get_Text(true)).read());
  171. } catch (Exception e) {
  172. }
  173. }//GEN-LAST:event_jButton3ActionPerformed
  174. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  175. run();
  176. }//GEN-LAST:event_jButton1ActionPerformed
  177. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
  178. DialogForFile dialog = new DialogForFile(DialogForFile.FILES_ONLY);
  179. if (dialog.saveFile()) {
  180. new FileReaderWriter(dialog.getFile()).write(jTextArea1.getText());
  181. }
  182. }//GEN-LAST:event_jButton2ActionPerformed
  183. // Variables declaration - do not modify//GEN-BEGIN:variables
  184. private javax.swing.JButton jButton1;
  185. private javax.swing.JButton jButton2;
  186. private javax.swing.JButton jButton3;
  187. private javax.swing.JScrollPane jScrollPane1;
  188. private javax.swing.JScrollPane jScrollPane2;
  189. private javax.swing.JTable jTable1;
  190. private javax.swing.JTextArea jTextArea1;
  191. private mpv5.ui.beans.LabeledTextChooser labeledTextChooser1;
  192. private mpv5.ui.beans.PrinitingComboBox prinitingComboBox1;
  193. // End of variables declaration//GEN-END:variables
  194. private void run() {
  195. try {
  196. ReturnValue data = QueryHandler.getConnection().freeSelectQuery(jTextArea1.getText(), MPSecurityManager.VIEW, null);
  197. if (data.hasData()) {
  198. jTable1.setModel(new MPTableModel(data.getData(), data.getColumnnames()));
  199. }
  200. } catch (Exception e) {
  201. Popup.error(e);
  202. }
  203. }
  204. }