roledialog.java
来自「TestDataBuilder是一个采用Java编写的」· Java 代码 · 共 1,550 行 · 第 1/4 页
JAVA
1,550 行
throw new ValidataException(txtName,RM.R("label.RoleDialog.error.validation.nameExist"));
}
}
public RoleFactory getCurRoleFactory(){
return this.curRoleFactory;
}
/**
* This method initializes OK
*
* @return com.testDataBuilder.ui.core.JTDButton
*/
private JTDButton getBtnOK() {
if (btnOK == null) {
btnOK = new JTDButton();
btnOK.setBounds(288, 387, 69, 23);
btnOK.setText(RM.R("label.info.btnOK"));
btnOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
RoleDialog.this.saveConfig();
} catch (ValidataException e1) {
JOptionPane.showMessageDialog(RoleDialog.this, e1.getMessage());
if(e1.getControl() instanceof JTextComponent){
JTextComponent txtControl = (JTextComponent)e1.getControl();
txtControl.grabFocus();
txtControl.selectAll();
}
return ;
}
RoleDialog.this.dispose();
}
});
}
return btnOK;
}
/**
* This method initializes cancel
*
* @return com.testDataBuilder.ui.core.JTDButton
*/
private JTDButton getBtnClose() {
if (btnClose == null) {
btnClose = new JTDButton();
btnClose.setBounds(369, 387, 69, 23);
btnClose.setText(RM.R("label.info.btnClose"));
btnClose.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
RoleDialog.this.dispose();
}
});
}
return btnClose;
}
public WorkspaceDataCache getWorkspaceDataCache() {
return workspaceDataCache;
}
public void setConfigDataCatch(WorkspaceDataCache workspaceDataCache) {
this.workspaceDataCache = workspaceDataCache;
}
/**
* This method initializes comboxConnection
*
* @return javax.swing.JComboBox
*/
private ConnectionComboBox getComboxConnection() {
if (comboxConnection == null) {
comboxConnection = new ConnectionComboBox();
comboxConnection.setBounds(98, 7, 213, 24);
List<String> connNames = this.getParent().getTestDataConfig().getAllConnNames();
comboxConnection.setConnNames(connNames);
}
return comboxConnection;
}
/**
* This method initializes btnSelEnum
*
* @return com.testDataBuilder.ui.core.JTDButton
*/
private JTDButton getBtnSelEnum() {
if (btnSelEnum == null) {
btnSelEnum = new JTDButton();
btnSelEnum.setText("...");
btnSelEnum.setBounds(353, 12, 44, 24);
btnSelEnum.setToolTipText(RM.R("label.RoleDialog.info.enum.alt"));
btnSelEnum.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
RoleDialog.this.getEnumFromFile();
}
});
}
return btnSelEnum;
}
protected void getEnumFromFile() {
EnumList tempEnumList = new EnumList(Arrays.asList(new Object[this.getJEnumTable().getData().size()]));
Collections.copy(tempEnumList, this.getJEnumTable().getData());
GetEnumValueFromFileOrDB getEnumValueFromFileOrDB = new GetEnumValueFromFileOrDB(this, tempEnumList);
getEnumValueFromFileOrDB.setModal(true);
getEnumValueFromFileOrDB.setVisible(true);
if(getEnumValueFromFileOrDB.isOK()){
this.getJEnumTable().setData(getEnumValueFromFileOrDB.getEnumList());
}
}
/**
* This method initializes txtNullPercent
*
* @return javax.swing.JTextField
*/
private JTextField getTxtNullPercent() {
if (txtNullPercent == null) {
txtNullPercent = new JTextFieldEx();
txtNullPercent.setBounds(312, 54, 126, 25);
}
return txtNullPercent;
}
/**
* This method initializes jMethodTabbedPane
*
* @return javax.swing.JTabbedPane
*/
private JTabbedPane getJMethodTabbedPane() {
if (jMethodTabbedPane == null) {
jMethodTabbedPane = new JTabbedPane();
jMethodTabbedPane.setBounds(25, 163, 413, 212);
jMethodTabbedPane.addTab(Role.METHOD_INCREMENT + "&" + Role.METHOD_RANDOM, getJIncRandomPanel());
jMethodTabbedPane.addTab(Role.METHOD_ENUM, getJEnumPanel());
jMethodTabbedPane.addTab(Role.METHOD_SQL_QUERY, getJSQLQueryPanel());
jMethodTabbedPane.addTab(Role.METHOD_JAVA, null, getJJavaSourcePanel(), null);
}
return jMethodTabbedPane;
}
/**
* This method initializes jIncRandomPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJIncRandomPanel() {
if (jIncRandomPanel == null) {
jIncRandomPanel = new JPanel();
jIncRandomPanel.setLayout(null);
jIncRandomPanel.add(labMin, null);
jIncRandomPanel.add(getTxtMin(), null);
jIncRandomPanel.add(labMax, null);
jIncRandomPanel.add(getTxtMax(), null);
}
return jIncRandomPanel;
}
/**
* This method initializes jEnumPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJEnumPanel() {
if (jEnumPanel == null) {
jEnumPanel = new JPanel();
jEnumPanel.setLayout(null);
jEnumPanel.add(getJEnumlPane(), null);
jEnumPanel.add(getBtnAddEnum(), null);
jEnumPanel.add(getBtnDelEnum(), null);
jEnumPanel.add(getBtnSelEnum(), null);
}
return jEnumPanel;
}
/**
* This method initializes jSQLQueryPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJSQLQueryPanel() {
if (jSQLQueryPanel == null) {
jSQLQueryPanel = new JPanel();
jSQLQueryPanel.setLayout(null);
jSQLQueryPanel.add(jLabel7, null);
jSQLQueryPanel.add(getComboxConnection(), null);
jSQLQueryPanel.add(getBtnShowSQLQueryDialog(), null);
jSQLQueryPanel.add(getJSQLPane(), null);
}
return jSQLQueryPanel;
}
public void genToPreview(){
TestDataConfig testDataConfig = WorkspaceDataCache.getInstance().getTestDataConfig();
if(testDataConfig != null){
TableConfig tableConfig = this.getCurRoleFactory().getTableConfig();
if(tableConfig != null){
new Thread(new ProgressRunner(this, testDataConfig, tableConfig)).start();
}
}else{
JOptionPane.showMessageDialog(this, "出错了..testDataBuilder为null");
}
}
private JPanel getJJavaSourcePanel() {
if(jJavaSourcePanel == null) {
jJavaSourcePanel = new JPanel();
jJavaSourcePanel.setLayout(null);
jJavaSourcePanel.setPreferredSize(new java.awt.Dimension(372, 173));
jJavaSourcePanel.add(getTxtJavaSource());
jJavaSourcePanel.add(getJLabel9());
jJavaSourcePanel.add(getTxtReturnFields());
jJavaSourcePanel.add(getBtnEditInNewWindow());
jJavaSourcePanel.add(getCbxReturnType());
jJavaSourcePanel.add(getJLabel10());
}
return jJavaSourcePanel;
}
private JEditTextArea getTxtJavaSource() {
if(txtJavaSource == null) {
txtJavaSource = new JEditTextArea();
txtJavaSource.setTokenMarker(new JavaTokenMarker());
txtJavaSource.setBounds(12, 63, 384, 110);
}
return txtJavaSource;
}
private JLabel getJLabel9() {
if(jLabel9 == null) {
jLabel9 = new JLabel();
jLabel9.setText(RM.R("label.RoleDialog.label.returnFields"));
jLabel9.setBounds(12, 34, 81, 22);
}
return jLabel9;
}
private JTextField getTxtReturnFields() {
if(txtReturnFields == null) {
txtReturnFields = new JTextField();
txtReturnFields.setBounds(120, 35, 276, 22);
txtReturnFields.setEnabled(false);
}
return txtReturnFields;
}
private JButton getBtnEditInNewWindow() {
if(btnEditInNewWindow == null) {
btnEditInNewWindow = new JButton();
btnEditInNewWindow.setText("...");
btnEditInNewWindow.setToolTipText(RM.R("label.RoleDialog.label.btnEditJavaInNewWindow"));
btnEditInNewWindow.setBounds(289, 7, 107, 22);
btnEditInNewWindow.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
RoleDialog.this.showJavaSourceEditor();
}
});
}
return btnEditInNewWindow;
}
protected void showJavaSourceEditor() {
JavaEditorDialog editorDialog = new JavaEditorDialog(this);
editorDialog.setReturnType(this.getCbxReturnType().getSelectedItem());
editorDialog.setReturnFields(this.getTxtReturnFields().getText());
editorDialog.setJavaCode(this.getTxtJavaSource().getText());
editorDialog.setVisible(true);
if(editorDialog.isOK()){
this.getCbxReturnType().setSelectedItem(editorDialog.getReturnType());
this.getTxtReturnFields().setText(editorDialog.getReturnFields());
this.getTxtJavaSource().setText(editorDialog.getJavaCode());
}
}
private JComboBox getCbxReturnType() {
if(cbxReturnType == null) {
cbxReturnType = new JComboBox();
cbxReturnType.addItem(JavaSource.RETURN_TYPE_SIMPLE_OBJ);
cbxReturnType.addItem(JavaSource.RETURN_TYPE_COMPLEX_OBJ);
cbxReturnType.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
RoleDialog.this.returnTypeBoxStateChanged(e);
}
});
cbxReturnType.setBounds(120, 7, 157, 22);
}
return cbxReturnType;
}
protected void returnTypeBoxStateChanged(ItemEvent e) {
String returnType = (String)(this.getCbxReturnType().getSelectedItem());
if(JavaSource.RETURN_TYPE_SIMPLE_OBJ.equalsIgnoreCase(returnType)){
this.getTxtReturnFields().setEnabled(false);
}else{
this.getTxtReturnFields().setEnabled(true);
}
}
private JLabel getJLabel10() {
if(jLabel10 == null) {
jLabel10 = new JLabel();
jLabel10.setText(RM.R("label.RoleDialog.label.returnType"));
jLabel10.setBounds(12, 7, 81, 22);
}
return jLabel10;
}
} // @jve:decl-index=0:visual-constraint="10,10"
class ProgressRunner implements Runnable{
static Logger logger = Logger.getLogger(ProgressRunner.class);
RoleDialog roleDialog = null;
TestDataConfig testDataConfig = null;
TableConfig tableConfig = null;
public ProgressRunner(RoleDialog roleDialog,TestDataConfig testDataConfig,TableConfig tableConfig){
this.roleDialog = roleDialog;
this.testDataConfig = testDataConfig;
this.tableConfig = tableConfig;
}
public void run() {
Connection defConn = null;
TableConfig tableConfig = null;
try {
defConn = testDataConfig.getDefConnection();
defConn.setAutoCommit(false);
tableConfig = roleDialog.getCurRoleFactory().getTableConfig();
if(tableConfig == null){
return;
}
Insert2Table insert2Table = new Insert2Table(tableConfig, testDataConfig);
insert2Table.setProcessBar(roleDialog.getMsgLine());
insert2Table.insert();
String sql = "select * from " + tableConfig.getTableName();
QueryDialog queryDialog = new QueryDialog(roleDialog);
String defConnName = testDataConfig.getDefDatabaseConfig().getName();
List<String> allConnNames = new ArrayList<String>(1);
allConnNames.add(defConnName);
queryDialog.initConnectionCombox(allConnNames, defConnName);
queryDialog.setSQLString(sql);
queryDialog.setQueryType(Role.METHOD_SQL_QUERY);
queryDialog.setModal(true);
queryDialog.setVisible(true);
}catch(JavaCodeRuntimeException ex){
logger.error("生成预览时出现运行时异常.", ex);
} catch (SQLException ex) {
logger.error("生成预览时出错",ex);
} catch (IOException ex) {
logger.error("生成预览时出现IO异常",ex);
} finally{
roleDialog.getMsgLine().clearText();
if(defConn != null){
try {
defConn.rollback();
} catch (SQLException ex) {
logger.error("生成预览回滚时出错",ex);
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?