📄 getenumvaluefromfileordb.java
字号:
package com.testDataBuilder.ui.role;
import com.testDataBuilder.core.role.EnumList;
import com.testDataBuilder.core.role.EnumObj;
import com.testDataBuilder.resources.RM;
import com.testDataBuilder.ui.core.CenterDialog;
import com.testDataBuilder.ui.help.Helper;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.HeadlessException;
import javax.swing.JPanel;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.border.EtchedBorder;
import javax.swing.filechooser.FileFilter;
import javax.swing.ButtonGroup;
import com.testDataBuilder.ui.core.JTDButton;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.GridBagLayout;
import java.io.File;
import java.io.IOException;
import javax.swing.JRadioButton;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
public class GetEnumValueFromFileOrDB extends CenterDialog {
private JPanel jContentPane = null;
private JPanel innerPanel = null;
private JTDButton btnSelFromFile = null;
private JScrollPane jEnumScrollPane = null;
private JEnumTable jEnumTable = null;
private JTabbedPane jTabbedPane = null;
private JPanel jFromFilePanel = null;
private JPanel jFromDBPanel = null;
private JTDButton btnOK = null;
private JTDButton btnOK1 = null;
private JTDButton btnOK2 = null;
private JTDButton btnCancel = null;
private JTDButton btnFromDB = null;
private EnumList enumList = null;
private JTDButton btnClearAll = null;
private JPanel jInnerPanel1 = null;
private JPanel innerPanel2 = null;
private JLabel jLabel = null;
private JTextField txtFilePath = null;
private JTDButton btnSelFile = null;
private JRadioButton radioLineFeed = null;
private JRadioButton radioComma = null;
private JRadioButton radioSemicolon = null;
private JRadioButton radioOther = null;
private ButtonGroup radioGroup = null; // @jve:decl-index=0:
private JTextField txtOther = null;
/**
* This method initializes
*
*/
public GetEnumValueFromFileOrDB() {
super();
initialize();
}
public GetEnumValueFromFileOrDB(Dialog arg0, EnumList enumList) throws HeadlessException {
super(arg0);
this.enumList = enumList;
initialize();
}
/**
* This method initializes this
*
*/
private void initialize() {
this.setSize(new Dimension(444, 354));
this.setResizable(false);
this.setContentPane(getJTabbedPane());
this.setTitle(RM.R("label.GetEnumValueFromFileOrDB.title")); //$NON-NLS-1$
this.center();
Helper.getInstance().enableHelpKey(this.getRootPane(), "detail.role.userRole.getEnumValueFromFileOrSQL"); //$NON-NLS-1$
}
/**
* 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(getBtnCancel(), null);
jContentPane.add(getBtnOK(), null);
}
return jContentPane;
}
/**
* This method initializes innerPanel
*
* @return javax.swing.JPanel
*/
private JPanel getInnerPanel() {
if (innerPanel == null) {
innerPanel = new JPanel();
innerPanel.setLayout(null);
innerPanel.setBounds(new Rectangle(12, 12, 408, 248));
innerPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
innerPanel.add(getBtnSelFromFile(), null);
innerPanel.add(getJEnumScrollPane(), null);
innerPanel.add(getBtnFromDB(), null);
innerPanel.add(getBtnClearAll(), null);
}
return innerPanel;
}
/**
* This method initializes btnSelFromFile
*
* @return com.testDataBuilder.ui.core.JTDButton
*/
private JTDButton getBtnSelFromFile() {
if (btnSelFromFile == null) {
btnSelFromFile = new JTDButton();
btnSelFromFile.setBounds(new Rectangle(313, 15, 78, 22));
btnSelFromFile.setText(RM.R("label.GetEnumValueFromFileOrDB.fromFile")); //$NON-NLS-1$
btnSelFromFile.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
GetEnumValueFromFileOrDB.this.showFromFilePanel();
}
});
}
return btnSelFromFile;
}
protected void showFromFilePanel() {
this.getJTabbedPane().setSelectedIndex(1);
}
/**
* This method initializes jEnumScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJEnumScrollPane() {
if (jEnumScrollPane == null) {
jEnumScrollPane = new JScrollPane();
jEnumScrollPane.setBounds(new Rectangle(16, 16, 286, 210));
jEnumScrollPane.setViewportView(getJEnumTable());
}
return jEnumScrollPane;
}
/**
* This method initializes jEnumTable
*
* @return com.testDataBuilder.ui.role.JEnumTable
*/
private JEnumTable getJEnumTable() {
if (jEnumTable == null) {
jEnumTable = new JEnumTable();
jEnumTable.setData(this.enumList);
}
return jEnumTable;
}
/**
* This method initializes jTabbedPane1
*
* @return javax.swing.JTabbedPane
*/
private JTabbedPane getJTabbedPane() {
if (jTabbedPane == null) {
jTabbedPane = new JTabbedPane();
jTabbedPane.addTab(RM.R("label.GetEnumValueFromFileOrDB.enumValue"), null, getJContentPane(), null); //$NON-NLS-1$
jTabbedPane.addTab(RM.R("label.GetEnumValueFromFileOrDB.fromFile"), null, getJFromFilePanel(), null); //$NON-NLS-1$
jTabbedPane.addTab(RM.R("label.GetEnumValueFromFileOrDB.fromDB"), null, getJFromDBPanel(), null); //$NON-NLS-1$
}
return jTabbedPane;
}
/**
* This method initializes jFromFilePanel
*
* @return javax.swing.JPanel
*/
private JPanel getJFromFilePanel() {
if (jFromFilePanel == null) {
jFromFilePanel = new JPanel();
jFromFilePanel.setLayout(null);
jFromFilePanel.add(getJInnerPanel1(), null);
jFromFilePanel.add(getBtnOK1(), null);
}
return jFromFilePanel;
}
/**
* This method initializes jFromDBPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJFromDBPanel() {
if (jFromDBPanel == null) {
jFromDBPanel = new JPanel();
jFromDBPanel.setLayout(null);
jFromDBPanel.add(getInnerPanel2(), null);
jFromDBPanel.add(getBtnOK2(), null);
}
return jFromDBPanel;
}
/**
* This method initializes btnOK
*
* @return com.testDataBuilder.ui.core.JTDButton
*/
private JTDButton getBtnOK() {
if (btnOK == null) {
btnOK = new JTDButton();
btnOK.setBounds(new Rectangle(279, 269, 65, 20));
btnOK.setText(RM.R("label.info.btnOK")); //$NON-NLS-1$
btnOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
GetEnumValueFromFileOrDB.this.onOK();
}
});
}
return btnOK;
}
/**
* This method initializes btnOK
*
* @return com.testDataBuilder.ui.core.JTDButton
*/
private JTDButton getBtnOK1() {
if (btnOK1 == null) {
btnOK1 = new JTDButton();
btnOK1.setText(RM.R("label.info.btnOK")); //$NON-NLS-1$
btnOK1.setBounds(new Rectangle(354, 269, 65, 20));
btnOK1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
GetEnumValueFromFileOrDB.this.getEnumFromFile();
}
});
}
return btnOK1;
}
protected void getEnumFromFile() {
String filePath = this.getTxtFilePath().getText();
if(StringUtils.isEmpty(filePath)){
JOptionPane.showMessageDialog(this, RM.R("label.GetEnumValueFromFileOrDB.selFileAlter")); //$NON-NLS-1$
this.getTxtFilePath().grabFocus();
return;
}
String sep = this.getSep();
if(sep == null || sep.equals("")){ //$NON-NLS-1$
JOptionPane.showMessageDialog(this, RM.R("label.GetEnumValueFromFileOrDB.inputSeparatorAlter")); //$NON-NLS-1$
this.getTxtOther().grabFocus();
return;
}
String content = ""; //$NON-NLS-1$
try {
content = FileUtils.readFileToString(new File(filePath));
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "读取文件[" + filePath + "]失败。" + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
String[] items = content.split(sep);
for(String item: items){
item = item.trim();
if(StringUtils.isNotEmpty(item)){
this.getEnumList().add(new EnumObj(item,1));
}
}
this.getJTabbedPane().setSelectedIndex(0);
this.getJEnumTable().updateUI();
}
/**
* This method initializes btnOK
*
* @return com.testDataBuilder.ui.core.JTDButton
*/
private JTDButton getBtnOK2() {
if (btnOK2 == null) {
btnOK2 = new JTDButton();
btnOK2.setText(RM.R("label.info.btnOK")); //$NON-NLS-1$
btnOK2.setBounds(new Rectangle(354, 269, 65, 20));
btnOK2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
}
});
}
return btnOK2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -