/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Management.java
 *
 * Created on 04-Apr-2009, 01:24:43
 */

package desktop;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node ;
import org.w3c.dom.NamedNodeMap ;
import core.*;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.apache.xerces.dom.DocumentImpl;

import java.io.*;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.application.Action;
/**
 *
 * @author user
 */
public class Management extends javax.swing.JFrame {
    private Newrule n;
    public String str, ss1, ss2, ss3, ss4;
    private String newRSetName;
    public DefaultTableModel aModel= new DefaultTableModel();
    static public DB db = new DB();
    static Connection connu = db.dbConnect("jdbc:mysql://localhost:3306/Mockware_Factset", "root", "qropadb");

    /** Creates new form Management */
    public Management(java.awt.Frame parent) {
        try {
            //super(parent);
            Statement stat = connu.createStatement();
            ResultSet rs = stat.executeQuery("Select * From Person");
            ResultSetMetaData rsmd = rs.getMetaData();
            aModel.setColumnCount(0);
            aModel.setRowCount(0);
            initComponents();
        } catch (SQLException ex) {
            Logger.getLogger(Management.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
/**/

    /** 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() {

        newRuleset = new javax.swing.JFrame();
        rulesetName = new java.awt.TextField();
        addRuleset = new java.awt.Button();
        newRulesetLabel = new java.awt.Label();
        newRulesetColumns = new javax.swing.JFrame();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        addColumn = new java.awt.Button();
        addRuleSetButton = new javax.swing.JButton();
        newRuleFrame = new javax.swing.JFrame();
        newRuleNameBox = new java.awt.TextField();
        addNewRuleButton = new java.awt.Button();
        addNewRuleLAbel = new java.awt.Label();
        newRuleCreation = new javax.swing.JFrame();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        add = new java.awt.Button();
        addRules = new java.awt.Button();
        managers = new javax.swing.JTabbedPane();
        try {
            rulemanage =(javax.swing.JPanel)java.beans.Beans.instantiate(getClass().getClassLoader(), "desktop.Management_jPanel1");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
        ruleset = new javax.swing.JButton();
        rulegenel = new javax.swing.JPanel();
        rulesetismi = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        factmanage = new javax.swing.JPanel();
        querymanage = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        request = new javax.swing.JPanel();
        allRequests = new java.awt.TextArea();
        refresh = new java.awt.Button();

        newRuleset.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(desktop.DesktopApp.class).getContext().getResourceMap(Management.class);
        newRuleset.setTitle(resourceMap.getString("newRuleset.title")); // NOI18N
        newRuleset.setName("newRuleset"); // NOI18N

        rulesetName.setName("rulesetName"); // NOI18N
        rulesetName.setText(resourceMap.getString("rulesetName.text")); // NOI18N

        addRuleset.setLabel(resourceMap.getString("addRuleset.label")); // NOI18N
        addRuleset.setName("addRuleset"); // NOI18N
        addRuleset.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                addRulesetMouseReleased(evt);
            }
        });

        newRulesetLabel.setName("newRulesetLabel"); // NOI18N
        newRulesetLabel.setText(resourceMap.getString("newRulesetLabel.text")); // NOI18N

        javax.swing.GroupLayout newRulesetLayout = new javax.swing.GroupLayout(newRuleset.getContentPane());
        newRuleset.getContentPane().setLayout(newRulesetLayout);
        newRulesetLayout.setHorizontalGroup(
            newRulesetLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newRulesetLayout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(newRulesetLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(newRulesetLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(newRulesetLayout.createSequentialGroup()
                        .addComponent(rulesetName, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(67, 67, 67)
                        .addComponent(addRuleset, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(75, Short.MAX_VALUE))
        );
        newRulesetLayout.setVerticalGroup(
            newRulesetLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newRulesetLayout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(newRulesetLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(newRulesetLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(addRuleset, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rulesetName, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(48, Short.MAX_VALUE))
        );

        newRulesetColumns.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        newRulesetColumns.setTitle(resourceMap.getString("newRulesetColumns.title")); // NOI18N
        newRulesetColumns.setName("newRulesetColumns"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Column Name", "Type", "Size"
            }
        ));
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane2.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable1.columnModel.title0")); // NOI18N
        jTable1.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable1.columnModel.title1")); // NOI18N
        jTable1.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTable1.columnModel.title2")); // NOI18N

        addColumn.setLabel(resourceMap.getString("addColumn.label")); // NOI18N
        addColumn.setName("addColumn"); // NOI18N
        addColumn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                addColumnMouseReleased(evt);
            }
        });

        addRuleSetButton.setText(resourceMap.getString("addRuleSetButton.text")); // NOI18N
        addRuleSetButton.setName("addRuleSetButton"); // NOI18N
        addRuleSetButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                addRuleSetButtonMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout newRulesetColumnsLayout = new javax.swing.GroupLayout(newRulesetColumns.getContentPane());
        newRulesetColumns.getContentPane().setLayout(newRulesetColumnsLayout);
        newRulesetColumnsLayout.setHorizontalGroup(
            newRulesetColumnsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newRulesetColumnsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 413, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(newRulesetColumnsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(newRulesetColumnsLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                        .addComponent(addColumn, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(45, 45, 45))
                    .addGroup(newRulesetColumnsLayout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addComponent(addRuleSetButton)
                        .addContainerGap())))
        );
        newRulesetColumnsLayout.setVerticalGroup(
            newRulesetColumnsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newRulesetColumnsLayout.createSequentialGroup()
                .addGap(67, 67, 67)
                .addGroup(newRulesetColumnsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(newRulesetColumnsLayout.createSequentialGroup()
                        .addComponent(addColumn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(65, 65, 65)
                        .addComponent(addRuleSetButton)))
                .addContainerGap(102, Short.MAX_VALUE))
        );

        newRuleFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        newRuleFrame.setTitle(resourceMap.getString("newRuleFrame.title")); // NOI18N
        newRuleFrame.setName("newRuleFrame"); // NOI18N

        newRuleNameBox.setName("newRuleNameBox"); // NOI18N
        newRuleNameBox.setText(resourceMap.getString("newRuleNameBox.text")); // NOI18N

        addNewRuleButton.setLabel(resourceMap.getString("addNewRuleButton.label")); // NOI18N
        addNewRuleButton.setName("addNewRuleButton"); // NOI18N
        addNewRuleButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                addNewRuleButtonMouseReleased(evt);
            }
        });

        addNewRuleLAbel.setName("addNewRuleLAbel"); // NOI18N
        addNewRuleLAbel.setText(resourceMap.getString("addNewRuleLAbel.text")); // NOI18N

        javax.swing.GroupLayout newRuleFrameLayout = new javax.swing.GroupLayout(newRuleFrame.getContentPane());
        newRuleFrame.getContentPane().setLayout(newRuleFrameLayout);
        newRuleFrameLayout.setHorizontalGroup(
            newRuleFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newRuleFrameLayout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addGroup(newRuleFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(addNewRuleLAbel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(newRuleFrameLayout.createSequentialGroup()
                        .addComponent(newRuleNameBox, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(79, 79, 79)
                        .addComponent(addNewRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(50, Short.MAX_VALUE))
        );
        newRuleFrameLayout.setVerticalGroup(
            newRuleFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newRuleFrameLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(addNewRuleLAbel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(newRuleFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(addNewRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(newRuleNameBox, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(81, Short.MAX_VALUE))
        );

        newRuleCreation.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        newRuleCreation.setTitle(resourceMap.getString("newRuleCreation.title")); // NOI18N
        newRuleCreation.setName("newRuleCreation"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, ""}
            },
            new String [] {
                "RuleID", "RuleType", "RuleName"
            }
        ));
        jTable2.setFocusCycleRoot(true);
        jTable2.setName("jTable2"); // NOI18N
        jScrollPane3.setViewportView(jTable2);
        jTable2.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable2.columnModel.title0")); // NOI18N
        jTable2.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable2.columnModel.title1")); // NOI18N
        jTable2.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTable2.columnModel.title2")); // NOI18N

        add.setLabel(resourceMap.getString("add.label")); // NOI18N
        add.setName("add"); // NOI18N
        add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addActionPerformed(evt);
            }
        });

        addRules.setLabel(resourceMap.getString("addRules.label")); // NOI18N
        addRules.setName("addRules"); // NOI18N
        addRules.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                addRulesMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout newRuleCreationLayout = new javax.swing.GroupLayout(newRuleCreation.getContentPane());
        newRuleCreation.getContentPane().setLayout(newRuleCreationLayout);
        newRuleCreationLayout.setHorizontalGroup(
            newRuleCreationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newRuleCreationLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 452, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(newRuleCreationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(addRules, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(add, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(49, 49, 49))
        );
        newRuleCreationLayout.setVerticalGroup(
            newRuleCreationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, newRuleCreationLayout.createSequentialGroup()
                .addContainerGap(25, Short.MAX_VALUE)
                .addGroup(newRuleCreationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(newRuleCreationLayout.createSequentialGroup()
                        .addComponent(add, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(55, 55, 55)
                        .addComponent(addRules, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(146, 146, 146))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setAlwaysOnTop(true);
        setName("Form"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        managers.setBackground(resourceMap.getColor("background")); // NOI18N
        managers.setForeground(resourceMap.getColor("foreground")); // NOI18N
        managers.setFont(resourceMap.getFont("managers.font")); // NOI18N
        managers.setName(""); // NOI18N

        ruleset.setForeground(resourceMap.getColor("ruleset.foreground")); // NOI18N
        ruleset.setText(resourceMap.getString("ruleset.text")); // NOI18N
        ruleset.setName("ruleset"); // NOI18N
        ruleset.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                rulesetMouseReleased(evt);
            }
        });

        rulegenel.setName("rulegenel"); // NOI18N

        rulesetismi.setText(resourceMap.getString("rulesetismi.text")); // NOI18N
        rulesetismi.setName("rulesetismi"); // NOI18N

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "miras", "customer_scoring" }));
        jComboBox1.setName("jComboBox1"); // NOI18N

        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N

        jPanel6.setName("jPanel6"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jComboBox2.setName("jComboBox2"); // NOI18N

        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
        jButton5.setName("jButton5"); // NOI18N

        jButton6.setText(resourceMap.getString("jButton6.text")); // NOI18N
        jButton6.setName("jButton6"); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
        jButton4.setAutoscrolls(true);
        jButton4.setName("jButton4"); // NOI18N
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButton4MouseReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton4)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(34, 34, 34)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton5)
                        .addGap(30, 30, 30)
                        .addComponent(jButton6)))
                .addContainerGap(41, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(390, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(84, 84, 84))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addComponent(jButton4)
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton5)
                    .addComponent(jButton6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 61, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(59, 59, 59))
        );

        jButton4.getAccessibleContext().setAccessibleParent(this);

        javax.swing.GroupLayout rulegenelLayout = new javax.swing.GroupLayout(rulegenel);
        rulegenel.setLayout(rulegenelLayout);
        rulegenelLayout.setHorizontalGroup(
            rulegenelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rulegenelLayout.createSequentialGroup()
                .addGroup(rulegenelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(rulegenelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(rulegenelLayout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(rulesetismi)
                        .addGap(26, 26, 26)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2)
                        .addGap(18, 18, 18)
                        .addComponent(jButton3)))
                .addContainerGap())
        );
        rulegenelLayout.setVerticalGroup(
            rulegenelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rulegenelLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(rulegenelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rulesetismi)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addGap(60, 60, 60)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout rulemanageLayout = new javax.swing.GroupLayout(rulemanage);
        rulemanage.setLayout(rulemanageLayout);
        rulemanageLayout.setHorizontalGroup(
            rulemanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rulemanageLayout.createSequentialGroup()
                .addGroup(rulemanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(rulemanageLayout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(ruleset))
                    .addGroup(rulemanageLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(rulegenel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        rulemanageLayout.setVerticalGroup(
            rulemanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rulemanageLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(ruleset)
                .addGap(3, 3, 3)
                .addComponent(rulegenel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        managers.addTab(resourceMap.getString("rulemanage.TabConstraints.tabTitle"), rulemanage); // NOI18N

        factmanage.setName("factmanage"); // NOI18N

        javax.swing.GroupLayout factmanageLayout = new javax.swing.GroupLayout(factmanage);
        factmanage.setLayout(factmanageLayout);
        factmanageLayout.setHorizontalGroup(
            factmanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 579, Short.MAX_VALUE)
        );
        factmanageLayout.setVerticalGroup(
            factmanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 393, Short.MAX_VALUE)
        );

        managers.addTab(resourceMap.getString("factmanage.TabConstraints.tabTitle"), factmanage); // NOI18N

        querymanage.setName("querymanage"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jButton7.setText(resourceMap.getString("jButton7.text")); // NOI18N
        jButton7.setName("jButton7"); // NOI18N
        jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButton7MouseReleased(evt);
            }
        });

        jButton8.setText(resourceMap.getString("jButton8.text")); // NOI18N
        jButton8.setName("jButton8"); // NOI18N
        jButton8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButton8MouseReleased(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTextArea1.setColumns(20);
        jTextArea1.setFont(resourceMap.getFont("jTextArea1.font")); // NOI18N
        jTextArea1.setRows(5);
        jTextArea1.setName("jTextArea1"); // NOI18N
        jScrollPane1.setViewportView(jTextArea1);

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        jTable3.setModel(aModel);
        jTable3.setName("jTable3"); // NOI18N
        jScrollPane4.setViewportView(jTable3);

        javax.swing.GroupLayout querymanageLayout = new javax.swing.GroupLayout(querymanage);
        querymanage.setLayout(querymanageLayout);
        querymanageLayout.setHorizontalGroup(
            querymanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(querymanageLayout.createSequentialGroup()
                .addGroup(querymanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, querymanageLayout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(querymanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addGroup(querymanageLayout.createSequentialGroup()
                                .addGap(346, 346, 346)
                                .addComponent(jButton8)
                                .addGap(18, 18, 18)
                                .addComponent(jButton7))))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, querymanageLayout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(querymanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 485, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1))))
                .addContainerGap(57, Short.MAX_VALUE))
        );
        querymanageLayout.setVerticalGroup(
            querymanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(querymanageLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(querymanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton7)
                    .addComponent(jButton8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        managers.addTab(resourceMap.getString("querymanage.TabConstraints.tabTitle"), querymanage); // NOI18N

        request.setName("request"); // NOI18N

        allRequests.setFont(resourceMap.getFont("allRequests.font")); // NOI18N
        allRequests.setName("allRequests"); // NOI18N

        refresh.setLabel(resourceMap.getString("refresh.label")); // NOI18N
        refresh.setName("refresh"); // NOI18N
        refresh.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                refreshMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout requestLayout = new javax.swing.GroupLayout(request);
        request.setLayout(requestLayout);
        requestLayout.setHorizontalGroup(
            requestLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(requestLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(requestLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(allRequests, javax.swing.GroupLayout.PREFERRED_SIZE, 528, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(refresh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19))
        );
        requestLayout.setVerticalGroup(
            requestLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(requestLayout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(refresh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34)
                .addComponent(allRequests, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(180, Short.MAX_VALUE))
        );

        managers.addTab(resourceMap.getString("request.TabConstraints.tabTitle"), request); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(managers, javax.swing.GroupLayout.DEFAULT_SIZE, 584, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(managers, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        this.dispose();// TODO add your handling code here:
        JFrame mainFrame = DesktopApp.getApplication().getMainFrame();
        mainFrame.setVisible(true);// TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosing

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        this.show();
        JFrame mainFrame = DesktopApp.getApplication().getMainFrame();
        mainFrame.setVisible(false);// TODO add your handling code here:
    }//GEN-LAST:event_formWindowOpened

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        this.show();
        JFrame mainFrame = DesktopApp.getApplication().getMainFrame();
        mainFrame.setVisible(false);// TODO add your handling code here:
    }//GEN-LAST:event_formWindowActivated

    @Action
    public void createxml(String outFile){
        try{

		FileOutputStream output = new FileOutputStream(outFile);
		PrintStream outF;
		outF = new PrintStream(output);

		Document doc = new DocumentImpl() ;

		Element root = doc.createElement("rulebase");

		root.setAttribute("name", str);

		Element cond = doc.createElement("cond");
        Element obje1 = doc.createElement("object");
        obje1.setAttribute("name", ss1);
        obje1.appendChild(doc.createTextNode(ss3));
        cond.appendChild(obje1);
        root.appendChild(cond);
        Element then = doc.createElement("then");
        Element obje2 = doc.createElement("object");
        obje2.setAttribute("name", ss2);
        obje2.appendChild(doc.createTextNode(ss4));
        then.appendChild(obje2);
        root.appendChild(then);
        doc.appendChild(root);

		    OutputFormat    format  = new OutputFormat( doc );   //Serialize DOM
            StringWriter  stringOut = new StringWriter();        //Writer will be a String
            XMLSerializer    serial = new XMLSerializer( stringOut, format );				//Bu kısım xml'den database kısmı
            serial.asDOMSerializer();                            // As a DOM Serializer
            serial.serialize( doc.getDocumentElement() );
            outF.print(stringOut.toString() ); //Spit out DOM as a String


		}catch( Exception e ) {
				  System.out.println("Cannot select table from the database!!!");
				  System.out.println(e.getMessage());
				}
    }
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
         ss1 = n.s1;
         System.out.println(ss1);
         ss2 = n.s2;
         System.out.println(ss2);
         ss3 = n.s3;
         ss4 = n.s4;
         createxml("rule.xml");// TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void refreshMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_refreshMouseReleased
        // TODO add your handling code here:
         try {
        BufferedReader out = new BufferedReader(new FileReader("outfilename"));
        String st;
        while ((st = out.readLine()) != null) {
            this.allRequests.setText(this.allRequests.getText()+'\n'+st);
        }
        out.close();
    } catch (IOException e) {
    }

    }//GEN-LAST:event_refreshMouseReleased

    private void rulesetMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rulesetMouseReleased
        // TODO add your handling code here:
        this.newRuleset.show();
        this.newRuleset.setSize(400, 200);
        
    }//GEN-LAST:event_rulesetMouseReleased

    private void addRulesetMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addRulesetMouseReleased
        // TODO add your handling code here:
        newRSetName =this.rulesetName.getText();
        this.newRulesetColumns.show();
        this.newRulesetColumns.setSize(600, 500);
        

    }//GEN-LAST:event_addRulesetMouseReleased

    private void addColumnMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addColumnMouseReleased
        // TODO add your handling code here:

        ((DefaultTableModel)this.jTable1.getModel()).addRow(new Vector());
        
    }//GEN-LAST:event_addColumnMouseReleased

    private void jButton4MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton4MouseReleased
        // TODO add your handling code here:
        this.newRuleFrame.setSize(450, 200);
        this.newRuleFrame.show();
    }//GEN-LAST:event_jButton4MouseReleased

    private void addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_addActionPerformed

    private void jButton8MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton8MouseReleased
        jTextArea1.setText("");
       jTextArea1.setCaretPosition(0);// TODO add your handling code here:
    }//GEN-LAST:event_jButton8MouseReleased

    private void jButton7MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton7MouseReleased
        Vector <String> Res = new Vector <String>() ;
        Res.addAll(Reason.Taken(jTextArea1.getText()));
        aModel.setRowCount(0);
        aModel = (DefaultTableModel) jTable3.getModel();
        aModel.setColumnCount(1);
        int i=0;
        Object[] objects = new Object[1];
        for(i=0;i<Res.size();i++)
        {
            objects[0]=(Object) Res.elementAt(i);
            aModel.addRow(objects);
        }
        jTable3.setModel(aModel);// TODO add your handling code here:
    }//GEN-LAST:event_jButton7MouseReleased

    private void addRuleSetButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addRuleSetButtonMouseReleased
        // TODO add your handling code here:
        DefaultTableModel mymode;mymode = (DefaultTableModel) this.jTable1.getModel();
        Vector <String> dd = new Vector <String>();
        Vector <String> de = new Vector <String>();
        Vector <String> df = new Vector <String>();
        String dk = "" ;

        int i=0;
        for(i=1;i<mymode.getRowCount()+1;i++)
        dd.add((String) mymode.getValueAt(1,i));
        for(i=1;i<mymode.getRowCount()+1;i++)
        de.add((String) mymode.getValueAt(2,i));
        for(i=0;i<dd.size();i++)
            dk+=" "+dd.elementAt(i)+" "+de.elementAt(i)+", ";
        Connection mycon = db.dbConnect("jdbc:mysql://localhost:3306/Mockware", "root", "qropadb");
        try {
            Statement mystat = mycon.createStatement();
            mystat.execute("CREATE TABLE "+ newRSetName  + " ( " +dk+ " )");
        } catch (SQLException ex) {
            Logger.getLogger(Management.class.getName()).log(Level.SEVERE, null, ex);
        }




    }//GEN-LAST:event_addRuleSetButtonMouseReleased

    private void addRulesMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addRulesMouseReleased
        try {
            DefaultTableModel mymode;
            mymode = (DefaultTableModel) this.jTable1.getModel();
            String mino = "";
            int i;
            int j;
            for (i = 1; i < mymode.getRowCount() + 1; i++) {
                for (j = 1; j < mymode.getColumnCount() + 1; j++) {
                    if (j == 1) {
                        mino += " ( " + mymode.getValueAt(i, j) + " , ";
                    } else if (mymode.getColumnCount() == j + 2) {
                        mino += mymode.getValueAt(i, j) + " ) ";
                    } else {
                        mino += mymode.getValueAt(i, j) + ", ";
                    }
                }
            }
            Connection mycon = db.dbConnect("jdbc:mysql://localhost:3306/Mockware", "root", "qropadb");
            Statement mystat = mycon.createStatement();
            mystat.execute("INSERT INTO askerlik VALUES " + mino);
        } catch (SQLException ex) {
            Logger.getLogger(Management.class.getName()).log(Level.SEVERE, null, ex);
        }

        // TODO add your handling code here:
    }//GEN-LAST:event_addRulesMouseReleased

    private void addNewRuleButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addNewRuleButtonMouseReleased
        try {
            // TODO add your handling code here:
            this.newRuleCreation.show();
            this.newRuleCreation.setSize(600, 400);
            Connection mycon = db.dbConnect("jdbc:mysql://localhost:3306/Mockware", "root", "qropadb");
            Statement mystat = mycon.createStatement();
            ResultSet dd = mystat.executeQuery("Select * From askerlik");
            ResultSetMetaData md = dd.getMetaData();
            DefaultTableModel aModel= new DefaultTableModel();

            aModel.setRowCount(1);
            int h=0;
            for(h=1;h<md.getColumnCount()+1;h++)
            aModel.addColumn(md.getColumnName(h));
            jTable2.setModel(aModel);


        } catch (SQLException ex) {
            Logger.getLogger(Management.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_addNewRuleButtonMouseReleased

    

     
        
        //else if(this.jComboBox1.getSelectedItem().equals("customer_scoring")) opencustomermodule();
 
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Button add;
    private java.awt.Button addColumn;
    private java.awt.Button addNewRuleButton;
    private java.awt.Label addNewRuleLAbel;
    private javax.swing.JButton addRuleSetButton;
    private java.awt.Button addRules;
    private java.awt.Button addRuleset;
    private java.awt.TextArea allRequests;
    private javax.swing.JPanel factmanage;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTabbedPane managers;
    private javax.swing.JFrame newRuleCreation;
    private javax.swing.JFrame newRuleFrame;
    private java.awt.TextField newRuleNameBox;
    private javax.swing.JFrame newRuleset;
    private javax.swing.JFrame newRulesetColumns;
    private java.awt.Label newRulesetLabel;
    private javax.swing.JPanel querymanage;
    private java.awt.Button refresh;
    private javax.swing.JPanel request;
    private javax.swing.JPanel rulegenel;
    private javax.swing.JPanel rulemanage;
    private javax.swing.JButton ruleset;
    private java.awt.TextField rulesetName;
    private javax.swing.JLabel rulesetismi;
    // End of variables declaration//GEN-END:variables

    private JFrame newrule;
}

