PageRenderTime 91ms CodeModel.GetById 43ms app.highlight 37ms RepoModel.GetById 4ms 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
  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 */
 22package mpv5.ui.panels;
 23
 24import java.awt.Component;
 25import javax.swing.JComponent;
 26import javax.swing.JTable;
 27import javax.swing.table.TableCellRenderer;
 28import mpv5.db.common.QueryHandler;
 29import mpv5.db.common.ReturnValue;
 30import mpv5.ui.dialogs.DialogForFile;
 31import mpv5.ui.dialogs.Popup;
 32import mpv5.ui.misc.MPTable;
 33import mpv5.usermanagement.MPSecurityManager;
 34import mpv5.utils.files.FileReaderWriter;
 35import mpv5.utils.models.MPTableModel;
 36import mpv5.ui.misc.TableViewPersistenceHandler;
 37
 38/**
 39 *
 40 *  
 41 */
 42public class QueryPanel extends javax.swing.JPanel {
 43
 44    private static final long serialVersionUID = 1L;
 45
 46    private java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();
 47    /**
 48     * 
 49     */
 50    public QueryPanel() {
 51        initComponents();
 52        prinitingComboBox1.init(jTable1);
 53        ((MPTable) jTable1).setPersistanceHandler(new TableViewPersistenceHandler((MPTable)jTable1, this));
 54    }
 55
 56    /** This method is called from within the constructor to
 57     * initialize the form.
 58     * WARNING: Do NOT modify this code. The content of this method is
 59     * always regenerated by the Form Editor.
 60     */
 61    @SuppressWarnings("unchecked")
 62    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 63    private void initComponents() {
 64
 65        jScrollPane1 = new javax.swing.JScrollPane();
 66        jTable1 = new  mpv5.ui.misc.MPTable(this) {
 67            public Component prepareRenderer(TableCellRenderer renderer,
 68                int rowIndex, int vColIndex) {
 69                Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
 70                if (c instanceof JComponent) {
 71                    JComponent jc = (JComponent)c;
 72                    jc.setToolTipText(String.valueOf(getValueAt(rowIndex, vColIndex)));
 73                }
 74                return c;
 75            }
 76        };
 77        labeledTextChooser1 = new mpv5.ui.beans.LabeledTextChooser();
 78        jButton1 = new javax.swing.JButton();
 79        jButton2 = new javax.swing.JButton();
 80        jScrollPane2 = new javax.swing.JScrollPane();
 81        jTextArea1 = new javax.swing.JTextArea();
 82        jButton3 = new javax.swing.JButton();
 83        prinitingComboBox1 = new mpv5.ui.beans.PrinitingComboBox();
 84
 85        mpv5.i18n.LanguageManager.getBundle();
 86        setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("QueryPanel.border.title"))); // NOI18N
 87        setName("Form"); // NOI18N
 88
 89        jScrollPane1.setName("jScrollPane1"); // NOI18N
 90
 91        jTable1.setAutoCreateRowSorter(true);
 92        jTable1.setModel(new javax.swing.table.DefaultTableModel(
 93            new Object [][] {
 94                {},
 95                {},
 96                {},
 97                {}
 98            },
 99            new String [] {
100
101            }
102        ));
103        jTable1.setName("jTable1"); // NOI18N
104        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
105            public void mouseClicked(java.awt.event.MouseEvent evt) {
106                jTable1MouseClicked(evt);
107            }
108        });
109        jScrollPane1.setViewportView(jTable1);
110
111        labeledTextChooser1.set_Label(bundle.getString("QueryPanel.labeledTextChooser1._Label")); // NOI18N
112        labeledTextChooser1.setFilter(DialogForFile.SQL_FILES);
113        labeledTextChooser1.setName("labeledTextChooser1"); // NOI18N
114
115        jButton1.setText(bundle.getString("QueryPanel.jButton1.text")); // NOI18N
116        jButton1.setName("jButton1"); // NOI18N
117        jButton1.addActionListener(new java.awt.event.ActionListener() {
118            public void actionPerformed(java.awt.event.ActionEvent evt) {
119                jButton1ActionPerformed(evt);
120            }
121        });
122
123        jButton2.setText(bundle.getString("QueryPanel.jButton2.text")); // NOI18N
124        jButton2.setName("jButton2"); // NOI18N
125        jButton2.addActionListener(new java.awt.event.ActionListener() {
126            public void actionPerformed(java.awt.event.ActionEvent evt) {
127                jButton2ActionPerformed(evt);
128            }
129        });
130
131        jScrollPane2.setName("jScrollPane2"); // NOI18N
132
133        jTextArea1.setColumns(20);
134        jTextArea1.setRows(5);
135        jTextArea1.setName("jTextArea1"); // NOI18N
136        jScrollPane2.setViewportView(jTextArea1);
137
138        jButton3.setText(bundle.getString("QueryPanel.jButton3.text")); // NOI18N
139        jButton3.setName("jButton3"); // NOI18N
140        jButton3.addActionListener(new java.awt.event.ActionListener() {
141            public void actionPerformed(java.awt.event.ActionEvent evt) {
142                jButton3ActionPerformed(evt);
143            }
144        });
145
146        prinitingComboBox1.setName("prinitingComboBox1"); // NOI18N
147
148        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
149        this.setLayout(layout);
150        layout.setHorizontalGroup(
151            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
152            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
153            .addGroup(layout.createSequentialGroup()
154                .addComponent(labeledTextChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
155                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
156                .addComponent(jButton3)
157                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 97, Short.MAX_VALUE)
158                .addComponent(jButton2)
159                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
160                .addComponent(jButton1)
161                .addContainerGap())
162            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
163                .addContainerGap(338, Short.MAX_VALUE)
164                .addComponent(prinitingComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
165                .addContainerGap())
166            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
167        );
168        layout.setVerticalGroup(
169            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
170            .addGroup(layout.createSequentialGroup()
171                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
172                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
173                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
174                    .addComponent(labeledTextChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
175                    .addComponent(jButton3)
176                    .addComponent(jButton2)
177                    .addComponent(jButton1))
178                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
179                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
180                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
181                .addComponent(prinitingComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
182        );
183    }// </editor-fold>//GEN-END:initComponents
184
185    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
186    }//GEN-LAST:event_jTable1MouseClicked
187
188    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
189        try {
190            jTextArea1.setText(new FileReaderWriter(labeledTextChooser1.get_Text(true)).read());
191        } catch (Exception e) {
192        }
193    }//GEN-LAST:event_jButton3ActionPerformed
194
195    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
196        run();
197
198    }//GEN-LAST:event_jButton1ActionPerformed
199
200    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
201        DialogForFile dialog = new DialogForFile(DialogForFile.FILES_ONLY);
202        if (dialog.saveFile()) {
203            new FileReaderWriter(dialog.getFile()).write(jTextArea1.getText());
204        }
205    }//GEN-LAST:event_jButton2ActionPerformed
206    // Variables declaration - do not modify//GEN-BEGIN:variables
207    private javax.swing.JButton jButton1;
208    private javax.swing.JButton jButton2;
209    private javax.swing.JButton jButton3;
210    private javax.swing.JScrollPane jScrollPane1;
211    private javax.swing.JScrollPane jScrollPane2;
212    private javax.swing.JTable jTable1;
213    private javax.swing.JTextArea jTextArea1;
214    private mpv5.ui.beans.LabeledTextChooser labeledTextChooser1;
215    private mpv5.ui.beans.PrinitingComboBox prinitingComboBox1;
216    // End of variables declaration//GEN-END:variables
217
218    private void run() {
219        try {
220            ReturnValue data = QueryHandler.getConnection().freeSelectQuery(jTextArea1.getText(), MPSecurityManager.VIEW, null);
221            if (data.hasData()) {
222                jTable1.setModel(new MPTableModel(data.getData(), data.getColumnnames()));
223            }
224        } catch (Exception e) {
225            Popup.error(e);
226        }
227    }
228}