/src/mpv5/ui/panels/QueryPanel.java
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
- /*
- * This file is part of YaBS.
- *
- * YaBS is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * YaBS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with YaBS. If not, see <http://www.gnu.org/licenses/>.
- */
- /*
- * GeneralListPanel.java
- *
- * Created on 03.04.2009, 15:26:37
- */
- package mpv5.ui.panels;
- import java.awt.Component;
- import javax.swing.JComponent;
- import javax.swing.JTable;
- import javax.swing.table.TableCellRenderer;
- import mpv5.db.common.QueryHandler;
- import mpv5.db.common.ReturnValue;
- import mpv5.ui.dialogs.DialogForFile;
- import mpv5.ui.dialogs.Popup;
- import mpv5.ui.misc.MPTable;
- import mpv5.usermanagement.MPSecurityManager;
- import mpv5.utils.files.FileReaderWriter;
- import mpv5.utils.models.MPTableModel;
- import mpv5.ui.misc.TableViewPersistenceHandler;
- /**
- *
- *
- */
- public class QueryPanel extends javax.swing.JPanel {
- private static final long serialVersionUID = 1L;
- private java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();
- /**
- *
- */
- public QueryPanel() {
- initComponents();
- prinitingComboBox1.init(jTable1);
- ((MPTable) jTable1).setPersistanceHandler(new TableViewPersistenceHandler((MPTable)jTable1, this));
- }
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
- private void initComponents() {
- jScrollPane1 = new javax.swing.JScrollPane();
- jTable1 = new mpv5.ui.misc.MPTable(this) {
- public Component prepareRenderer(TableCellRenderer renderer,
- int rowIndex, int vColIndex) {
- Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
- if (c instanceof JComponent) {
- JComponent jc = (JComponent)c;
- jc.setToolTipText(String.valueOf(getValueAt(rowIndex, vColIndex)));
- }
- return c;
- }
- };
- labeledTextChooser1 = new mpv5.ui.beans.LabeledTextChooser();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jScrollPane2 = new javax.swing.JScrollPane();
- jTextArea1 = new javax.swing.JTextArea();
- jButton3 = new javax.swing.JButton();
- prinitingComboBox1 = new mpv5.ui.beans.PrinitingComboBox();
- mpv5.i18n.LanguageManager.getBundle();
- setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("QueryPanel.border.title"))); // NOI18N
- setName("Form"); // NOI18N
- jScrollPane1.setName("jScrollPane1"); // NOI18N
- jTable1.setAutoCreateRowSorter(true);
- jTable1.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {},
- {},
- {},
- {}
- },
- new String [] {
- }
- ));
- jTable1.setName("jTable1"); // NOI18N
- jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jTable1MouseClicked(evt);
- }
- });
- jScrollPane1.setViewportView(jTable1);
- labeledTextChooser1.set_Label(bundle.getString("QueryPanel.labeledTextChooser1._Label")); // NOI18N
- labeledTextChooser1.setFilter(DialogForFile.SQL_FILES);
- labeledTextChooser1.setName("labeledTextChooser1"); // NOI18N
- jButton1.setText(bundle.getString("QueryPanel.jButton1.text")); // NOI18N
- jButton1.setName("jButton1"); // NOI18N
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setText(bundle.getString("QueryPanel.jButton2.text")); // NOI18N
- jButton2.setName("jButton2"); // NOI18N
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jScrollPane2.setName("jScrollPane2"); // NOI18N
- jTextArea1.setColumns(20);
- jTextArea1.setRows(5);
- jTextArea1.setName("jTextArea1"); // NOI18N
- jScrollPane2.setViewportView(jTextArea1);
- jButton3.setText(bundle.getString("QueryPanel.jButton3.text")); // NOI18N
- jButton3.setName("jButton3"); // NOI18N
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton3ActionPerformed(evt);
- }
- });
- prinitingComboBox1.setName("prinitingComboBox1"); // NOI18N
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
- this.setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
- .addGroup(layout.createSequentialGroup()
- .addComponent(labeledTextChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton3)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 97, Short.MAX_VALUE)
- .addComponent(jButton2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton1)
- .addContainerGap())
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(338, Short.MAX_VALUE)
- .addComponent(prinitingComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap())
- .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
- .addComponent(labeledTextChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton3)
- .addComponent(jButton2)
- .addComponent(jButton1))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(prinitingComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- );
- }// </editor-fold>//GEN-END:initComponents
- private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
- }//GEN-LAST:event_jTable1MouseClicked
- private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
- try {
- jTextArea1.setText(new FileReaderWriter(labeledTextChooser1.get_Text(true)).read());
- } catch (Exception e) {
- }
- }//GEN-LAST:event_jButton3ActionPerformed
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
- run();
- }//GEN-LAST:event_jButton1ActionPerformed
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
- DialogForFile dialog = new DialogForFile(DialogForFile.FILES_ONLY);
- if (dialog.saveFile()) {
- new FileReaderWriter(dialog.getFile()).write(jTextArea1.getText());
- }
- }//GEN-LAST:event_jButton2ActionPerformed
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JScrollPane jScrollPane2;
- private javax.swing.JTable jTable1;
- private javax.swing.JTextArea jTextArea1;
- private mpv5.ui.beans.LabeledTextChooser labeledTextChooser1;
- private mpv5.ui.beans.PrinitingComboBox prinitingComboBox1;
- // End of variables declaration//GEN-END:variables
- private void run() {
- try {
- ReturnValue data = QueryHandler.getConnection().freeSelectQuery(jTextArea1.getText(), MPSecurityManager.VIEW, null);
- if (data.hasData()) {
- jTable1.setModel(new MPTableModel(data.getData(), data.getColumnnames()));
- }
- } catch (Exception e) {
- Popup.error(e);
- }
- }
- }