📄 roledialog.java
字号:
txtMin.setBounds(153, 54, 106, 25);
}
return txtMin;
}
/**
* This method initializes txtMax
*
* @return javax.swing.JTextField
*/
private JTextField getTxtMax() {
if (txtMax == null) {
txtMax = new JTextFieldEx();
txtMax.setBounds(153, 90, 106, 25);
}
return txtMax;
}
/**
* This method initializes jEnumlPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJEnumlPane() {
if (jEnumlPane == null) {
jEnumlPane = new JScrollPane();
jEnumlPane.setBounds(12, 12, 323, 161);
jEnumlPane.setViewportView(getJEnumTable());
}
return jEnumlPane;
}
/**
* This method initializes jEnumList
*
* @return javax.swing.JList
*/
private JEnumTable getJEnumTable() {
if (jEnumTable == null) {
jEnumTable = new JEnumTable();
jEnumTable.setFont(new Font("Dialog", Font.BOLD, 14));
jEnumTable.setToolTipText(RM.R("label.RoleDialog.enumTable.alt"));
jEnumTable.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e) {
if(e.getClickCount() == 2){
RoleDialog.this.editCurEnum();
}
}
});
}
return jEnumTable;
}
/**
* This method initializes txtPrefix
*
* @return javax.swing.JTextField
*/
private JTextField getTxtPrefix() {
if (txtPrefix == null) {
txtPrefix = new JTextFieldEx();
txtPrefix.setBounds(99, 87, 120, 27);
}
return txtPrefix;
}
/**
* This method initializes txtSuffix
*
* @return javax.swing.JTextField
*/
private JTextField getTxtSuffix() {
if (txtSuffix == null) {
txtSuffix = new JTextFieldEx();
txtSuffix.setBounds(312, 88, 126, 25);
}
return txtSuffix;
}
/**
* This method initializes btnAddEnum
*
* @return com.testDataBuilder.ui.core.JTDButton
*/
private JTDButton getBtnAddEnum() {
if (btnAddEnum == null) {
btnAddEnum = new JTDButton();
btnAddEnum.setFont(new Font("Dialog", Font.BOLD, 14));
btnAddEnum.setBounds(353, 47, 44, 24);
btnAddEnum.setText("+");
btnAddEnum.setToolTipText(RM.R("label.RoleDialog.info.addEnum.alt"));
btnAddEnum.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
RoleDialog.this.addEnum();
}
});
}
return btnAddEnum;
}
protected void addEnum() {
addOrEditEnum(null);
}
protected void editCurEnum(){
EnumObj enumObj = this.getJEnumTable().getSelEnumObj();
addOrEditEnum(enumObj);
}
protected void addOrEditEnum(EnumObj enumObj){
EnumObj tempEnumObj = null;
if(enumObj != null){
tempEnumObj = new EnumObj(enumObj);
}
EnumValueDialog enumValueDialog = new EnumValueDialog(this, tempEnumObj, this.getCbxType().getSelectedClass());
enumValueDialog.setModal(true);
enumValueDialog.setVisible(true);
if(enumValueDialog.isOK()){
tempEnumObj = enumValueDialog.getEnumObj();
//表示添加�?
if(enumObj == null){
if(this.getJEnumTable().getData().contains(tempEnumObj)){
String info = String.format(RM.R("label.RoleDialog.error.enumNameExist"), tempEnumObj.toString());
JOptionPane.showMessageDialog(this, info ,"警告", JOptionPane.WARNING_MESSAGE);
}else{
this.getJEnumTable().getData().add(tempEnumObj);
this.getJEnumTable().updateUI();
}
}else /*修改一个EnumValue*/{
enumObj.setValue(tempEnumObj.getValue());
enumObj.setPercent(tempEnumObj.getPercent());
}
}
}
/**
* This method initializes btnDelEnum
*
* @return com.testDataBuilder.ui.core.JTDButton
*/
private JTDButton getBtnDelEnum() {
if (btnDelEnum == null) {
btnDelEnum = new JTDButton();
btnDelEnum.setFont(new Font("Dialog", Font.BOLD, 18));
btnDelEnum.setBounds(353, 82, 44, 24);
btnDelEnum.setText("-");
btnDelEnum.setToolTipText(RM.R("label.RoleDialog.info.delEnum.alt"));
btnDelEnum.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
RoleDialog.this.delEnum();
}
});
}
return btnDelEnum;
}
protected void delEnum() {
int selRow = this.getJEnumTable().getSelectedRow();
if(selRow == -1 || selRow >= this.getJEnumTable().getData().size()){
JOptionPane.showMessageDialog(this, RM.R("label.RoleDialog.error.noRowIsSelect"));
}else{
int returnV = JOptionPane.showConfirmDialog(this, RM.R("label.RoleDialog.info.confirmDeleteEnum"),
"enum", JOptionPane.OK_CANCEL_OPTION);
if(returnV == JOptionPane.OK_OPTION){
this.getJEnumTable().deleteCurrentItem();
}
}
}
/**
* This method initializes jSQLPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJSQLPane() {
if (jSQLPane == null) {
jSQLPane = new JScrollPane();
jSQLPane.setFont(new Font("Dialog", Font.PLAIN, 14));
jSQLPane.setBounds(13, 42, 383, 131);
jSQLPane.setViewportView(getTxtSQL());
}
return jSQLPane;
}
/**
* This method initializes txtSQL
*
* @return javax.swing.JTextArea
*/
private JEditTextArea getTxtSQL() {
if (txtSQL == null) {
txtSQL = new JEditTextArea();
txtSQL.setTokenMarker(new TSQLTokenMarker());
txtSQL.setToolTipText(RM.R("label.RoleDialog.info.txtSQl.alt"));
txtSQL.setPreferredSize(new java.awt.Dimension(344, 109));
}
return txtSQL;
}
/**
* This method initializes btnSQL
*
* @return com.testDataBuilder.ui.core.JTDButton
*/
private JTDButton getBtnShowSQLQueryDialog() {
if (btnShowSQLQueryDialog == null) {
btnShowSQLQueryDialog = new JTDButton();
btnShowSQLQueryDialog.setText("...");
btnShowSQLQueryDialog.setBounds(347, 7, 49, 24);
btnShowSQLQueryDialog.setOpaque(false);
btnShowSQLQueryDialog.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
RoleDialog.this.showEditSqlDialog();
}
});
}
return btnShowSQLQueryDialog;
}
protected void showEditSqlDialog() {
QueryDialog sqlEditDialog = new QueryDialog(this);
List<String> allConnNames = this.getParent().getTestDataConfig().getAllConnNames();
sqlEditDialog.initConnectionCombox(allConnNames, this.getComboxConnection().getSelectedItem());
sqlEditDialog.setSQLString(this.getTxtSQL().getText().trim());
sqlEditDialog.setQueryType((String)this.getCbxMethod().getSelectedItem());
sqlEditDialog.setModal(true);
sqlEditDialog.setVisible(true);
if(sqlEditDialog.isOK()){
this.getComboxConnection().setSelectedItem(sqlEditDialog.getSelConnName());
this.getTxtSQL().setText(sqlEditDialog.getSQLString());
}
}
/**
* This method initializes btnSave
*
* @return com.testDataBuilder.ui.core.JTDButton
*/
private JTDButton getBtnSave() {
if (btnSave == null) {
btnSave = new JTDButton();
btnSave.setBounds(202, 387, 69, 23);
btnSave.setText(RM.R("label.info.btnSave"));
btnSave.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,
RM.R("label.RoleDialog.error.saveError") + e1.getMessage());
e1.getControl().grabFocus();
if(e1.getControl() instanceof JTextComponent){
JTextComponent txtControl = (JTextComponent)e1.getControl();
txtControl.selectAll();
}
}
}
});
}
return btnSave;
}
protected void saveConfig() throws ValidataException {
if (this.curRole == null) {
return;
}
// 验证�?
validateControlValue();
String oldName = this.curRole.getName();
this.dataExchange(this.curRole, false);
try {
getCurRoleFactory().saveOrUpdateToFile(this.curRole, oldName);
this.getRoleTree().updateUI();
//同步更新TableConfig中的引用 �?
String newName = this.curRole.getName();
if(!oldName.equals(newName)){
TableConfig tableConfig = this.getCurRoleFactory().getTableConfig();
if(tableConfig != null){
tableConfig.updateAllRefs(oldName, newName);
tableConfig.saveConfig();
}else{
System.out.println("isGlobal..");
}
}
} catch (Exception e) {
logger.error("RoleFrame", e);
JOptionPane.showMessageDialog(this, RM.R("label.RoleDialog.error.saveConfigError") + e.getMessage());
return ;
}
}
private void validateControlValue()throws ValidataException{
String name = this.txtName.getText();
if (StringUtils.isEmpty(name)) {
throw new ValidataException(txtName,
RM.R("label.RoleDialog.error.validation.nameIsNull"));
}
Class type = this.getCbxType().getSelectedClass();
String strNullPercent = this.txtNullPercent.getText().trim();
if(StringUtils.isNotEmpty(strNullPercent)){
try{
float v = Float.valueOf(strNullPercent).floatValue();
if(v < 0 || v > 1){
throw new ValidataException(txtNullPercent,
RM.R("label.RoleDialog.error.validation.percentValueInvalid"));
}
}catch (Exception ex){
throw new ValidataException(txtNullPercent,
RM.R("label.RoleDialog.error.validation.percentValueInvalid"));
}
}
String method = (String) this.getCbxMethod().getSelectedItem();
if(Role.METHOD_INCREMENT.equalsIgnoreCase(method)
||Role.METHOD_RANDOM.equalsIgnoreCase(method)){
if(type.equals(JavaTypes.OBJECT)){
throw new ValidataException(this.cbxType, RM.R("label.RoleDialog.error.validation.methodTypeNotMatch"));
}
String strMin = this.txtMin.getText().trim();
String strMax = this.txtMax.getText().trim();
if (StringUtils.isNotEmpty(strMin)) {
try {
JavaTypes.getInstance().valueOf(type, strMin);
} catch (Exception ex) {
throw new ValidataException(txtMin, ex.getMessage());
}
}
if (StringUtils.isNotEmpty(strMax)) {
try {
JavaTypes.getInstance().valueOf(type, strMax);
} catch (Exception e) {
throw new ValidataException(txtMax, e.getMessage());
}
}
}else if(Role.METHOD_ENUM.equalsIgnoreCase(method)){
if(this.getJEnumTable().getData() == null || this.getJEnumTable().getData().isEmpty()){
throw new ValidataException(this.getJEnumTable(),
RM.R("label.RoleDialog.error.validation.enumValueIsNull"));
}
}else if(Role.METHOD_SQL_QUERY.equalsIgnoreCase(method)){
String sql = this.getTxtSQL().getText();
if(StringUtils.isEmpty(sql)){
throw new ValidataException(this.txtSQL,
RM.R("label.RoleDialog.error.validation.sqlIsNull"));
}
}else if(Role.METHOD_JAVA.equals(method)){
String returnType = (String) this.getCbxReturnType().getSelectedItem();
if(JavaSource.RETURN_TYPE_COMPLEX_OBJ.equalsIgnoreCase(returnType)){
String returnFields = this.getTxtReturnFields().getText();
if(StringUtils.isEmpty(returnFields)){
throw new ValidataException(this.txtReturnFields,
RM.R("label.RoleDialog.error.validation.returnFieldsIsNull"));
}
}
String javaSource = this.getTxtJavaSource().getText();
if(StringUtils.isEmpty(javaSource)){
throw new ValidataException(this.txtJavaSource,
RM.R("label.RoleDialog.error.validation.javaSourceIsNull"));
} else {
if (this.curRole.getJavaSource() == null || !StringUtil .equals(javaSource,
this.curRole.getJavaSource().getJavaCode())) {
DynamicCompiler dynamicCompiler = new DynamicCompiler();
try {
dynamicCompiler.validateJavaSource(javaSource);
} catch (BaseException e) {
throw new CompileException(this.txtJavaSource, e
.getMessage());
}
}
}
}
String oldName = this.curRole.getName();
//表示有重�?
if(!oldName.equals(name) && this.getWorkspaceDataCache()
.getRole(this.curRoleFactory.toString(), name) != null){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -