querypanel.java

来自「数据仓库展示程序」· Java 代码 · 共 107 行

JAVA
107
字号
/*
 * QueryPanel.java
 *
 * Created on October 10, 2002, 11:11 PM
 */

package mondrian.gui;

import mondrian.olap.Connection;
import mondrian.olap.Query;
import mondrian.olap.Result;

/**
 *
 * @author  sean
 */
public class QueryPanel extends javax.swing.JPanel {
    Connection connection;

    /** Creates new form QueryPanel */
    public QueryPanel() {
        initComponents();
    }

    public void setConnection(Connection c) {
        connection = c;
    }

    public Connection getConnection() {
        return connection;
    }

    /** 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.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        jScrollPane3 = new javax.swing.JScrollPane();
        executeButton = new javax.swing.JButton();
        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        queryTextPane = new javax.swing.JTextPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        resultTextPane = new javax.swing.JTextPane();

        setLayout(new java.awt.BorderLayout());

        executeButton.setText("Execute");
        executeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                executeButtonActionPerformed(evt);
            }
        });

        add(executeButton, java.awt.BorderLayout.SOUTH);

        jSplitPane1.setDividerLocation(100);
        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        queryTextPane.setFont(new java.awt.Font("Courier New", 0, 12));
        queryTextPane.setText("select {[Measures].[Unit Sales]} on columns from Sales\n");
        jScrollPane1.setViewportView(queryTextPane);

        jSplitPane1.setTopComponent(jScrollPane1);

        resultTextPane.setEditable(false);
        resultTextPane.setFont(new java.awt.Font("Courier New", 0, 12));
        jScrollPane2.setViewportView(resultTextPane);

        jSplitPane1.setBottomComponent(jScrollPane2);

        add(jSplitPane1, java.awt.BorderLayout.CENTER);

    }//GEN-END:initComponents

    private void executeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_executeButtonActionPerformed
        //run the query, and show the results.
        try {
            Query q = connection.parseQuery(queryTextPane.getText());
            Result r = connection.execute(q);

            //document = DOMBuilder.build(getResult());
            java.io.StringWriter sw = new java.io.StringWriter();
            java.io.PrintWriter pw = new java.io.PrintWriter(sw);

            r.print(pw);

            resultTextPane.setText(sw.getBuffer().toString());
        } catch (Exception ex) {
            resultTextPane.setText(ex.getMessage());
        }

    }//GEN-LAST:event_executeButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextPane resultTextPane;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextPane queryTextPane;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JButton executeButton;
    // End of variables declaration//GEN-END:variables

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?