⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generatedatadialog.java

📁 TestDataBuilder是一个采用Java编写的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.testDataBuilder.ui.role;

import com.testDataBuilder.config.preference.IPreference;
import com.testDataBuilder.core.GenerateAndInsertData;
import com.testDataBuilder.core.IProcess;
import com.testDataBuilder.core.SQLRecorder;
import com.testDataBuilder.resources.RM;
import com.testDataBuilder.ui.core.CenterDialog;
import com.testDataBuilder.ui.core.ProgressPanel;
import com.testDataBuilder.config.WorkspaceDataCache;
import com.testDataBuilder.exception.JavaCodeRuntimeException;
import com.testDataBuilder.ui.database.JSQLFileChooser;
import com.testDataBuilder.ui.help.Helper;
import com.testDataBuilder.ui.main.MainFrame;
import com.testDataBuilder.ui.main.OpenWorkspaceUtil;
import com.testDataBuilder.util.Global;
import com.testDataBuilder.util.TimeUtils;
import java.awt.Dimension;
import javax.swing.JPanel;
import java.awt.Rectangle;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import com.testDataBuilder.ui.core.JTDButton;
import javax.swing.JTextField;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.border.EtchedBorder;
import javax.swing.JCheckBox;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import java.awt.Color;
import javax.swing.JTabbedPane;
import javax.swing.JScrollPane;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class GenerateDataDialog extends CenterDialog implements IProcess{

    static Logger logger = Logger.getLogger(GenerateDataDialog.class);
    
    private JPanel jContentPane = null;
    private ProgressPanel innerPanel = null;
    private JTDButton btnBegin = null;
    private JTDButton btnRunInBackground = null;
    private JTDButton btnGenPreferences = null;
    private JPanel recordFilePanel = null;
    private JCheckBox cbxGenerateSQLFile = null;
    private JTDButton btnOpenScriptDir;
    private JTextField txtSQLFilePath = null;
    private JTDButton btnSelSQLFile = null;
    
    public static final String BTN_BEING_BEING = RM.R("label.GenerateDataDialog.btnStart"); //$NON-NLS-1$
    public static final String BTN_BEING_STOP = RM.R("label.GenerateDataDialog.btnStop"); //$NON-NLS-1$
    
    private IPreference p = Global.getInstance().P;
    private WorkspaceDataCache workspaceDataCache = null;
    
    int minHeight = 165;
    int maxHeight = minHeight;
    @Override
    public MainFrame getParent(){
        return (MainFrame) super.getParent();
    }
    /**
     * This method initializes 
     * 
     */
    public GenerateDataDialog() {
        super();
        initialize();
        this.setDefaultCloseOperation(GenerateDataDialog.DO_NOTHING_ON_CLOSE); 
        this.center();
    }

    public GenerateDataDialog(MainFrame parent, final WorkspaceDataCache workspaceDataCache ) {
        super(parent);
        this.workspaceDataCache = workspaceDataCache;
        initialize();
        this.center();
    }

    
    /**
     * This method initializes this
     * 
     */
    private void initialize() {
        this.setSize(new Dimension(490, 432));
        this.setResizable(false);
        this.setTitle(RM.R("label.GenerateDataDialog.title")); //$NON-NLS-1$
        this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);   
        maxHeight = this.getHeight();
        this.setContentPane(getJContentPane());
        this.initOptionPanel();
        Helper.getInstance().enableHelpKey(this.getRootPane(), "detail.role.generateData"); //$NON-NLS-1$
    }

//    public boolean confirmCloseWindow(){
//        boolean isClose = true;
//        if(generateAndInsertData != null){
//            int result = JOptionPane.showConfirmDialog(this, 
//                            RM.R("label.GenerateDataDialog.4"),RM.R("label.GenerateDataDialog.5"), JOptionPane.OK_CANCEL_OPTION); //$NON-NLS-1$ //$NON-NLS-2$
//            if(result == JOptionPane.OK_OPTION){
//                beginOrStopInsert();
//            }else{
//                isClose = false;
//            }
//            
//        }
//        return isClose;
//    }
    
    private void initOptionPanel(){
        this.getCbxGenerateSQLFile().setSelected(p.getGenerateSQLFile());
        this.getJTableTable().setData(this.workspaceDataCache.getTableConfigs());
    }
    
    /**
     * This method initializes jContentPane	
     * 	
     * @return javax.swing.JPanel	
     */
    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(null);
            jContentPane.add(getInnerPanel(), null);
            jContentPane.add(getJOptionTabbedPane(), null);
        }
        return jContentPane;
    }

    /**
     * This method initializes innerPanel	
     * 	
     * @return javax.swing.JPanel	
     */
    private ProgressPanel getInnerPanel() {
        if (innerPanel == null) {
            innerPanel = new ProgressPanel();
            innerPanel.setLayout(null);
            innerPanel.setBounds(14, 13, 452, 112);
            innerPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
            innerPanel.add(getBtnBegin());
            innerPanel.add(getBtnGenPreferences());
            innerPanel.add(getBtnRunInBackground());
            innerPanel.add(getBtnClose());
        }
        return innerPanel;
    }

    /**
     * This method initializes btnBegin	
     * 	
     * @return com.testDataBuilder.ui.core.JTDButton	
     */
    private JTDButton getBtnBegin() {
        if (btnBegin == null) {
            btnBegin = new JTDButton();
            btnBegin.setBounds(256, 74, 78, 24);
            btnBegin.setText(BTN_BEING_BEING); //$NON-NLS-1$
            btnBegin.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
//                    try{
                        GenerateDataDialog.this.beginOrStopInsert();
//                    }catch(IOException ex){
//                        JOptionPane.showMessageDialog(GenerateDataDialog.this, "创建SQL文件时出错," + ex.getMessage());
//                    }
                }
            });
        }
        return btnBegin;
    }

    private SQLRecorder sqlRecorder = null;
    
    protected void beginOrStopInsert() {
        if(this.generateAndInsertData == null){
            this.getBtnBegin().setText(BTN_BEING_STOP);
            this.getBtnClose().setEnabled(false);
            generateAndInsertData = new GenerateAndInsertData();
            generateAndInsertData.setProcessBar(this);
            if(this.getCbxGenerateSQLFile().isSelected()){
                File sqlFile = new File(this.getTxtSQLFilePath().getText().trim());
                sqlRecorder = new SQLRecorder(sqlFile);
                generateAndInsertData.setSqlRecorder(sqlRecorder);
            }
            GenearterExecutor executor = new GenearterExecutor(generateAndInsertData, this, workspaceDataCache);
            new Thread(executor).start();
        }else{
            int result = JOptionPane.showConfirmDialog(this, RM.R("label.GenerateDataDialog.confirmStop"));
            if(result == JOptionPane.OK_OPTION){
                this.getBtnBegin().setText(BTN_BEING_BEING);
                this.getBtnClose().setEnabled(true);
                generateAndInsertData.setBread(true);
                generateAndInsertData = null;
            }
        }
        
        
    }
    /**
     * This method initializes btnCancel	
     * 	
     * @return com.testDataBuilder.ui.core.JTDButton	
     */
    private JTDButton getBtnRunInBackground() {
        if (btnRunInBackground == null) {
            btnRunInBackground = new JTDButton();
            btnRunInBackground.setBounds(47, 74, 93, 24);
            btnRunInBackground.setText(RM.R("label.GenerateDataDialog.btnRunInBack")); //$NON-NLS-1$
            btnRunInBackground.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    GenerateDataDialog.this.runInBackground();
                }
            });
        }
        return btnRunInBackground;
    }

    private boolean isRunInBackground = false;
    
    public boolean isRunInBackground(){
        return isRunInBackground;
    }
    
    public void setIsRunInBackground(boolean isRunInBackground){
        this.isRunInBackground = isRunInBackground;
    }
    
    protected void runInBackground() {
        this.setVisible(false);
        this.isRunInBackground = true;
    }
    
    /**
     * This method initializes btnGenPreferences	
     * 	
     * @return com.testDataBuilder.ui.core.JTDButton	
     */
    private JTDButton getBtnGenPreferences() {
        if (btnGenPreferences == null) {
            btnGenPreferences = new JTDButton();
            btnGenPreferences.setBounds(159, 74, 78, 24);
            btnGenPreferences.setText(RM.R("label.GenerateDataDialog.btnOption")); //$NON-NLS-1$
            btnGenPreferences.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                     GenerateDataDialog.this.showOrHidePreference();
                }
            });
        }
        return btnGenPreferences;
    }

    protected void showOrHidePreference() {
        if(this.getHeight() == this.minHeight){
            this.setSize(this.getWidth(), this.maxHeight);

⌨️ 快捷键说明

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