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

📄 roledialog.java

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

import java.awt.Component;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JSplitPane;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.WindowConstants;
import com.testDataBuilder.ui.core.JTDButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JComboBox;

import com.testDataBuilder.config.TableConfig;
import com.testDataBuilder.config.TestDataConfig;
import com.testDataBuilder.core.Insert2Table;
import com.testDataBuilder.core.baseType.JavaTypes;
import com.testDataBuilder.core.role.JavaRole;
import com.testDataBuilder.core.role.JavaSource;
import com.testDataBuilder.core.role.RoleFactory;
import com.testDataBuilder.core.role.Role;
import com.testDataBuilder.core.role.EnumList;
import com.testDataBuilder.core.role.EnumObj;
import com.testDataBuilder.exception.BaseException;
import com.testDataBuilder.exception.CompileException;
import com.testDataBuilder.exception.JavaCodeRuntimeException;
import com.testDataBuilder.exception.ValidataException;
import com.testDataBuilder.resources.RM;
import com.testDataBuilder.ui.core.CenterDialog;
import com.testDataBuilder.ui.core.JTextFieldEx;
import com.testDataBuilder.ui.core.ProgressLable;
import com.testDataBuilder.config.WorkspaceDataCache;
import com.testDataBuilder.dynamicCompile.DynamicCompiler;
import com.testDataBuilder.ui.help.Helper;
import com.testDataBuilder.ui.main.MainFrame;
import com.testDataBuilder.ui.main.queryConsole.ConnectionComboBox;
import com.testDataBuilder.ui.main.queryConsole.JEditTextArea;
import com.testDataBuilder.ui.main.queryConsole.QueryDialog;
import com.testDataBuilder.ui.preference.PreferenceDialog;
import com.testDataBuilder.util.Global;
import com.testDataBuilder.util.StringUtil;

import java.awt.Font;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.swing.JButton;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.text.JTextComponent;
import javax.swing.tree.TreePath;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.syntax.jedit.tokenmarker.JavaTokenMarker;
import org.syntax.jedit.tokenmarker.TSQLTokenMarker;
import javax.swing.JTabbedPane;


/**
* 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 RoleDialog extends CenterDialog{

    static Logger logger = Logger.getLogger(PreferenceDialog.class);
    
	private static final long serialVersionUID = 1L;
	private JSplitPane jSplitPane = null;	
	private JPanel jContentPane = null;	
	private JRoleToolBar jToolBar = null;
	private JScrollPane leftPane = null;
	private JPanel rightPanel = null;
	private JRoleTree roleTree = null;
	private JLabel jLabel = null;
	private JTextField txtName = null;
	private JLabel jLabel10;
	private JComboBox cbxReturnType;
	private JLabel jLabel1 = null;
	private JavaTypeComboBox cbxType = null;
	private JLabel jLabel2 = null;
	private JComboBox cbxMethod = null;
	private JLabel labMin = null;
	private JTextField txtMin = null;
	private JLabel labMax = null;
	private JTextField txtMax = null;
	private JLabel jLabel3 = null;
	private JScrollPane jEnumlPane = null;
	private JEnumTable jEnumTable = null;
	private JLabel jLabel4 = null;
	private JTextField txtPrefix = null;
	private JLabel jLabel5 = null;
	private JTextField txtSuffix = null;
	private JTDButton btnAddEnum = null;
	private JTDButton btnDelEnum = null;
	private JLabel jLabel6 = null;
	private JScrollPane jSQLPane = null;
	private JEditTextArea txtSQL = null;
	private JTDButton btnShowSQLQueryDialog = null;
	private JTDButton btnSave = null;
	private JTDButton btnOK = null;
	private JTDButton btnClose = null;	
	private WorkspaceDataCache workspaceDataCache;  //  @jve:decl-index=0:
    Role curRole = null;  //  @jve:decl-index=0:
    RoleFactory curRoleFactory = null;  //  @jve:decl-index=0:
    
    //String curTableName = null;
    protected Object cbxInva;
    private JButton btnEditInNewWindow;
    private JTextField txtReturnFields;
    private JLabel jLabel9;
    private JEditTextArea txtJavaSource;
    private JLabel jLabel7 = null;
    private ConnectionComboBox comboxConnection = null;
    private JTDButton btnSelEnum = null;
    private JLabel jLabel8 = null;
    private JPanel jJavaSourcePanel;
    private JTextField txtNullPercent = null;

    private JTabbedPane jMethodTabbedPane = null;

    private JPanel jIncRandomPanel = null;

    private JPanel jEnumPanel = null;

    private JPanel jSQLQueryPanel = null;
  
    private ProgressLable msgLine = null;
    
    public ProgressLable getMsgLine(){
        if(msgLine == null){
            msgLine = new ProgressLable(" ");             //$NON-NLS-1$
        }
        return msgLine;
    }
    
    /**
	 * This is the default constructor
	 */
	public RoleDialog(JFrame parent, WorkspaceDataCache workspaceDataCache) {
		super(parent);
		this.workspaceDataCache = workspaceDataCache;		
		initialize();
		center();
		initControl();
		
	}

    
    public MainFrame getParent(){
        return (MainFrame)super.getParent();
    }
    
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(650, 500);
		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.setJMenuBar(new JRoleMenuBar(this));
		this.setContentPane(getJContentPane());
		this.setTitle(RM.R("label.RoleDialog.title"));
        this.enableControl(false);
        Helper.getInstance().enableHelpKey(this.getRootPane(), "detail.role.userRole");
	}
    
    @Override
    public JRoleMenuBar getJMenuBar() {
        return (JRoleMenuBar)super.getJMenuBar();
    }
    
	/**
	 * 根据配置文件初始化控�?
	 * <p><code>initControl</code></p>
	 * @author LiuXiaojie 2007-7-7
	 */
	private void initControl() {
        this.getRoleTree().setData(this.workspaceDataCache);
	}

//    public void refreshData(){
//    	this.getRoleTree().clear();
//    	this.getRoleTree().setData(this.workspaceDataCache);
//    }

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
//            jContentPane.add(getJToolBar(), BorderLayout.NORTH);
			jContentPane.add(getJSplitPane(), BorderLayout.CENTER);
			jContentPane.add(getMsgLine(),BorderLayout.SOUTH);
		}
		return jContentPane;
	}
	
	/**
	 * This method initializes jToolBar	
	 * 	
	 * @return javax.swing.JToolBar	
	 */
	private JRoleToolBar getJToolBar() {
		if (jToolBar == null) {
			jToolBar = new JRoleToolBar(this);
		}
		return jToolBar;
	}
	
	
	protected void showTablePopupMenu(Component invoker, int x, int y) {
		JPopupMenu pupupMenu = this.getJMenuBar().getTablePopupMenu();
		pupupMenu.show(invoker, x, y);
	}

    
	protected void deleteSelRole() {
        if(curRole != null){
            try {
                int result = JOptionPane.showConfirmDialog(this, RM.R("label.RoleDialog.info.confirm.delete"));
                if(result == JOptionPane.OK_OPTION){
                    this.getCurRoleFactory().deleteItem(curRole);
                    this.getRoleTree().updateUI();
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, RM.R("label.RoleDialog.error.delete") + e.getMessage());
            } 
        }
    
    }


    protected void deleteAll() {
		int result = JOptionPane.showConfirmDialog(this, RM.R("label.RoleDialog.info.confirm.deleteAll"));
		if(result == JOptionPane.OK_OPTION){
			try {
				this.getCurRoleFactory().deleteAll();
				this.getRoleTree().updateUI();
			} catch (Exception e1) {
				logger.error("deleteAll", e1);
				JOptionPane.showMessageDialog(this, RM.R("label.RoleDialog.error.deleteAll") + e1.getMessage());
			} 
		}
	}

    public Role addRole(ActionEvent e){
        if(!this.getRoleTree().isSelectionEmpty()){
            Role role = this.getCurRoleFactory().addDefaultRole();
            this.getRoleTree().updateUI();
            this.getTxtName().grabFocus();
            int index[] = this.getRoleTree().getSelectionRows();
            if(index.length == 1){
                int selRow = index[0] + this.getCurRoleFactory().getRoles().size();
                this.getRoleTree().setSelectionRow(selRow);   
            }else{
                System.out.println("error sel much rows。[" + index.length);
            }
            return role;
        }
        return null;
    }

	/**
	 * This method initializes jSplitPane	
	 * 	
	 * @return javax.swing.JSplitPane	
	 */
	private JSplitPane getJSplitPane() {
		if (jSplitPane == null) {
			jSplitPane = new JSplitPane();
			jSplitPane.setDividerSize(3);
			jSplitPane.setLeftComponent(getLeftPane());
			jSplitPane.setRightComponent(getRightPanel());
			jSplitPane.setDividerLocation(180);
			jSplitPane.setResizeWeight(0.4);   
			//jSplitPane.setPreferredSize(new java.awt.Dimension(606, 490));

		}
		return jSplitPane;
	}

	/**
	 * This method initializes leftPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getLeftPane() {
		if (leftPane == null) {
			leftPane = new JScrollPane();
			leftPane.setViewportView(getRoleTree());
		}
		return leftPane;
	}

	/**
	 * This method initializes rightPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getRightPanel() {
		if (rightPanel == null) {
			jLabel8 = new JLabel();
			jLabel8.setBounds(237, 54, 69, 23);
			jLabel8.setText(RM.R("label.RoleDialog.label.nullPercent"));
			jLabel7 = new JLabel();
			jLabel7.setText(RM.R("label.RoleDialog.label.useConnection"));
			jLabel7.setBounds(11, 7, 75, 24);
			jLabel6 = new JLabel();
			jLabel6.setText(RM.R("label.RoleDialog.label.sqlQuery"));
			jLabel6.setBounds(new Rectangle(670, 222, 60, 19));
			jLabel5 = new JLabel();
			jLabel5.setBounds(237, 87, 67, 25);
			jLabel5.setText(RM.R("label.RoleDialog.label.suffix"));
			jLabel4 = new JLabel();
			jLabel4.setBounds(23, 87, 64, 25);
			jLabel4.setText(RM.R("label.RoleDialog.label.prefix"));
			jLabel3 = new JLabel();
			jLabel3.setBounds(new Rectangle(673, 172, 60, 22));
			jLabel3.setText(RM.R("label.RoleDialog.label.enumValue"));
			labMax = new JLabel();
			labMax.setText(RM.R("label.RoleDialog.label.maxLength"));
			labMax.setBounds(67, 88, 69, 25);
			labMin = new JLabel();
			labMin.setText(RM.R("label.RoleDialog.label.minLength"));
			labMin.setBounds(68, 54, 69, 25);
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(24, 124, 63, 25));
			jLabel2.setText(RM.R("label.RoleDialog.label.generateMethod"));
			jLabel1 = new JLabel();
			jLabel1.setBounds(23, 55, 69, 23);
			jLabel1.setText(RM.R("label.RoleDialog.label.javaType"));
			jLabel = new JLabel();
			jLabel.setBounds(23, 16, 69, 25);
			jLabel.setText(RM.R("label.RoleDialog.label.genName"));
			rightPanel = new JPanel();
			rightPanel.setLayout(null);
			rightPanel.setPreferredSize(new java.awt.Dimension(437, 442));
            rightPanel.add(jLabel, null);
			rightPanel.add(getTxtName(), null);
			rightPanel.add(jLabel1, null);
			rightPanel.add(getCbxType(), null);
			rightPanel.add(jLabel2, null);
			rightPanel.add(getCbxMethod(), null);
			rightPanel.add(jLabel3, null);
			rightPanel.add(jLabel4, null);
			rightPanel.add(getTxtPrefix(), null);
			rightPanel.add(jLabel5, null);
			rightPanel.add(getTxtSuffix(), null);
			rightPanel.add(getBtnSave(), null);
			rightPanel.add(getBtnOK(), null);
			rightPanel.add(getBtnClose(), null);
            rightPanel.add(jLabel8, null);
            rightPanel.add(getTxtNullPercent(), null);
            rightPanel.add(getJMethodTabbedPane(), null);
            rightPanel.add(jLabel6, null);
		}
		return rightPanel;
	}

⌨️ 快捷键说明

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