1 Star 0 Fork 131

富士山下/codeMan

forked from 小螺旋丸/codeMan 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
TablesQuery.java 43.21 KB
一键复制 编辑 原始数据 按行查看 历史
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
package codeMaker;
import java.awt.Color;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import constant.ChildWindowConstant;
import constant.CodeConstant;
import constant.CompareComboBox;
import constant.FiledComment;
import constant.Filed_cn;
import constant.Filed_eng;
import constant.OrderComboBox;
import constant.RelationJcombox;
import constant.ServiceTypeComboBox;
import constant.Table1;
import constant.Table1Fileds;
import constant.Table2;
import constant.Table2Fileds;
import entity.Parameters;
import entity.TableConditionModel;
import entity.TableFiledModel;
import entity.TableRelationModel;
import entity.TablesQueryModel;
public class TablesQuery {
private static String currentDataBaseName;
private static String currentDataBaseUrl;
private JFrame frame;
private JTextField currentModelName;
private JTextField currentModelName_cn;
public JFrame getFrame() {
return frame;
}
public void setFrame(JFrame frame) {
this.frame = frame;
}
/**
* Launch the application.
*/
public static void main(final Parameters parameters) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
if (currentDataBaseName == null || currentDataBaseUrl == null) {
// 记录当前数据库的名称和url
currentDataBaseName = parameters.getDataBaseNameVal();
currentDataBaseUrl = parameters.getDataBaseUrl();
} else {
// 如果数据库不一致,清空map
if (!currentDataBaseName.equals(parameters.getDataBaseNameVal())
|| !currentDataBaseUrl.equals(parameters.getDataBaseUrl())) {
ChildWindowConstant.tablesQueryMap.clear();
ChildWindowConstant.tablesQueryEndAndCnMap.clear();
// 记录当前数据库的名称和url
currentDataBaseName = parameters.getDataBaseNameVal();
currentDataBaseUrl = parameters.getDataBaseUrl();
}
}
TablesQuery window = new TablesQuery(parameters);
ChildWindowConstant.tablesQuery = window;
window.frame.setVisible(true);
JOptionPane.showMessageDialog(window.frame,
"表1字段、表2字段:多个字段使用 & 隔开,字段个数保持一致" + CodeConstant.NEW_LINE + "类型描述:" + CodeConstant.NEW_LINE
+ " 布尔示例:是#否 其中是和否填写数据库中用来表示是和否的值" + CodeConstant.NEW_LINE
+ " 状态码示例:状态名称&状态值#状态名称&状态值(填写状态名称和状态值便于前台生成样式)" + CodeConstant.NEW_LINE
+ " 其他类型将根据类型生成对应的样式,无需描述" + CodeConstant.NEW_LINE + "注意:关联表信息配置完点击确定才会生效!!!",
"提示", JOptionPane.INFORMATION_MESSAGE);
} catch (Exception e) {
}
}
});
}
/**
* test
*
* @param parameters
*/
/*
* public static void main(String[] args) { EventQueue.invokeLater(new
* Runnable() { public void run() { try {
*
* TablesQuery window = new TablesQuery(); ChildWindowConstant.tablesQuery =
* window; window.frame.setVisible(true);
*
* } catch (Exception e) {
*
* } } }); }
*/
/**
* Create the application.
*/
public TablesQuery(Parameters parameters) {
initialize(parameters);
}
/**
* Initialize the contents of the frame.
*/
private void initialize(Parameters parameters) {
frame = new JFrame();
frame.setResizable(true);
frame.setIconImage(Toolkit.getDefaultToolkit().getImage(TablesQuery.class
.getResource("/org/pushingpixels/substance/internal/contrib/randelshofer/quaqua/images/palette.png")));
frame.setTitle("多表查询配置");
frame.setBounds(100, 100, 1761, 759);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JScrollPane addTableScrollPane = new JScrollPane();
JScrollPane queryScrollPane = new JScrollPane();
JButton addTable = new JButton("添加关联表信息");
JButton addQuery = new JButton("添加查询字段");
JLabel label = new JLabel("当前模块英文名称");
currentModelName = new JTextField();
currentModelName.setColumns(10);
JButton confirm = new JButton("确定");
JLabel label_1 = new JLabel("查看已配置模块");
JButton addCondition = new JButton("添加条件字段");
addQuery.setEnabled(false);
addCondition.setEnabled(false);
JScrollPane conditionScrollPane = new JScrollPane();
JButton restart = new JButton("清空重配");
JComboBox<String> tableConfigExit = new JComboBox<String>();
String[] modelArr = ChildWindowConstant.tablesQueryMap.keySet().toArray(new String[] {});
tableConfigExit.setModel(new DefaultComboBoxModel<>(new String[] { "--请选择--" }));
for (String model : modelArr) {
tableConfigExit.addItem(model);
}
JButton confirmRelTable = new JButton("确定");
JLabel label_3 = new JLabel("——————》");
JLabel cnLable = new JLabel("中文名称");
currentModelName_cn = new JTextField();
currentModelName_cn.setColumns(10);
JLabel label_4 = new JLabel("*");
label_4.setForeground(Color.RED);
JButton button = new JButton("配置说明");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(frame,
"表1字段、表2字段:多个字段使用 & 隔开,字段个数保持一致" + CodeConstant.NEW_LINE + "类型描述:" + CodeConstant.NEW_LINE
+ " 布尔示例:是#否 其中是和否填写数据库中用来表示是和否的值" + CodeConstant.NEW_LINE
+ " 状态码示例:状态名称&状态值#状态名称&状态值(填写状态名称和状态值便于前台生成样式)" + CodeConstant.NEW_LINE
+ " 其他类型将根据类型生成对应的样式,无需描述" + CodeConstant.NEW_LINE + "注意:关联表信息配置完点击确定才会生效!!!",
"提示", JOptionPane.INFORMATION_MESSAGE);
}
});
JLabel label_2 = new JLabel("*");
label_2.setForeground(Color.RED);
GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout
.createSequentialGroup().addGap(25).addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(
groupLayout.createSequentialGroup()
.addComponent(conditionScrollPane, GroupLayout.DEFAULT_SIZE, 1716,
Short.MAX_VALUE)
.addContainerGap())
.addGroup(groupLayout.createSequentialGroup().addGroup(groupLayout
.createParallelGroup(Alignment.LEADING).addComponent(addCondition)
.addComponent(addQuery).addComponent(addTable)
.addGroup(groupLayout.createSequentialGroup().addComponent(label)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(currentModelName, GroupLayout.PREFERRED_SIZE, 141,
GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED).addComponent(label_2).addGap(26)
.addComponent(cnLable).addPreferredGap(ComponentPlacement.RELATED)
.addComponent(currentModelName_cn, GroupLayout.PREFERRED_SIZE, 148,
GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED).addComponent(label_4).addGap(26)
.addComponent(label_1).addPreferredGap(ComponentPlacement.RELATED)
.addComponent(tableConfigExit, GroupLayout.PREFERRED_SIZE, 182,
GroupLayout.PREFERRED_SIZE))
.addGroup(groupLayout.createSequentialGroup().addGroup(groupLayout
.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup().addComponent(button).addGap(18)
.addComponent(restart).addGap(18).addComponent(confirm))
.addGroup(groupLayout.createSequentialGroup()
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(addTableScrollPane, GroupLayout.DEFAULT_SIZE, 1512,
Short.MAX_VALUE))
.addComponent(queryScrollPane, GroupLayout.DEFAULT_SIZE, 1512, Short.MAX_VALUE))
.addPreferredGap(ComponentPlacement.UNRELATED).addComponent(label_3)
.addPreferredGap(ComponentPlacement.RELATED).addComponent(confirmRelTable)))
.addContainerGap(30, GroupLayout.PREFERRED_SIZE)))));
groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout
.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup().addContainerGap(204, Short.MAX_VALUE)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(label_3)
.addComponent(confirmRelTable))
.addGap(266))
.addGroup(groupLayout.createSequentialGroup().addGap(30)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(label)
.addComponent(currentModelName, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(currentModelName_cn, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(label_4).addComponent(label_1)
.addComponent(tableConfigExit, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(label_2).addComponent(cnLable))
.addGap(18).addComponent(addTable).addPreferredGap(ComponentPlacement.RELATED)
.addComponent(addTableScrollPane, GroupLayout.PREFERRED_SIZE, 138,
GroupLayout.PREFERRED_SIZE)
.addGap(22).addComponent(addQuery).addPreferredGap(ComponentPlacement.RELATED)
.addComponent(queryScrollPane, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)))
.addGap(18).addComponent(addCondition).addPreferredGap(ComponentPlacement.RELATED)
.addComponent(conditionScrollPane, GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(confirm)
.addComponent(restart).addComponent(button))
.addGap(30)));
JPanel conditionPanel = new JPanel();
conditionScrollPane.setViewportView(conditionPanel);
JPanel querysPanel = new JPanel();
queryScrollPane.setViewportView(querysPanel);
JPanel tablesPanel = new JPanel();
addTableScrollPane.setViewportView(tablesPanel);
tablesPanel.setLayout(new GridLayout(0, 5, 5, 5));
querysPanel.setLayout(new GridLayout(0, 6, 5, 5));
conditionPanel.setLayout(new GridLayout(0, 8, 5, 5));
String[] tablesArr = new String[] { "关联关系", "表1", "表2", "表1字段", "表2字段" };
String[] querysArr = new String[] { "表名", "字段", "中文名称", "字段类型", "类型描述", "是否可排序" };
String[] conditionsArr = new String[] { "关联关系", "表名", "字段", "中文名称", "字段类型", "类型描述", "比较关系", "固定值" };
List<TableRelationModel> tableRelationModelLists = new ArrayList<TableRelationModel>();
Map<String, String> tableMap = new HashMap<>();
addTable.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addQuery.setEnabled(false);
addCondition.setEnabled(false);
if (tablesPanel.getComponentCount() == 0) {
for (String tableStr : tablesArr) {
JLabel label = new JLabel(tableStr);
tablesPanel.add(label);
}
addTableMethod(tablesPanel);
((Table2) tablesPanel.getComponent(7)).setEnabled(false);
((Table1Fileds) tablesPanel.getComponent(8)).setEnabled(false);
((Table1Fileds) tablesPanel.getComponent(8)).setText("/");
((Table2Fileds) tablesPanel.getComponent(9)).setEnabled(false);
((Table2Fileds) tablesPanel.getComponent(9)).setText("/");
} else {
addTableMethod(tablesPanel);
}
frame.validate();
frame.repaint();
}
private void addTableMethod(JPanel tablesPanel) {
List<String> table2List = new ArrayList<>();
if (tablesPanel.getComponentCount() >= 5) {
Component[] components = tablesPanel.getComponents();
for (int i = 5; i < components.length; i++) {
if ("Table1".equals(components[i].getClass().getSimpleName())) {
Table1 table1 = (Table1) components[i];
if ("".equals(table1.getText())) {
JOptionPane.showMessageDialog(frame, "请先把当前内容填写完毕再增加关联表信息!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
table2List.add(table1.getText());
}
else if ("Table1Fileds".equals(components[i].getClass().getSimpleName())) {
Table1Fileds table1Fileds = (Table1Fileds) components[i];
if ("".equals(table1Fileds.getText())) {
JOptionPane.showMessageDialog(frame, "请先把当前内容填写完毕再增加关联表信息!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
}
else if ("Table2Fileds".equals(components[i].getClass().getSimpleName())) {
Table2Fileds table2Fileds = (Table2Fileds) components[i];
if ("".equals(table2Fileds.getText())) {
JOptionPane.showMessageDialog(frame, "请先把当前内容填写完毕再增加关联表信息!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
}
}
}
JComboBox<String> relationComBox = null;
// 如果是第一次添加
if (tablesPanel.getComponentCount() == 5) {
// 关联关系
relationComBox = new JComboBox<>(new String[] { "from" });
} else {
// 关联关系
relationComBox = new JComboBox<>(new String[] { "left join", "join", "right join" });
}
// 关联表
Table1 table1 = new Table1();
// 关联字段
Table2 table2 = new Table2();
if (tablesPanel.getComponentCount() >= 10) {
table2.setModel(new DefaultComboBoxModel<>(table2List.toArray(new String[] {})));
}
Table1Fileds table1Fileds = new Table1Fileds();
Table2Fileds table2Fileds = new Table2Fileds();
tablesPanel.add(relationComBox);
tablesPanel.add(table1);
tablesPanel.add(table2);
tablesPanel.add(table1Fileds);
tablesPanel.add(table2Fileds);
}
});
addQuery.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!canAddQuery(querysPanel)) {
return;
}
if (querysPanel.getComponentCount() == 0) {
for (String queryStr : querysArr) {
JLabel label = new JLabel(queryStr);
querysPanel.add(label);
}
addQueryMethod(querysPanel);
} else {
addQueryMethod(querysPanel);
}
frame.validate();
frame.repaint();
}
private boolean canAddQuery(JPanel querysPanel) {
if (querysPanel.getComponentCount() >= 10) {
Component[] components = querysPanel.getComponents();
for (int i = 6; i < components.length; i++) {
if ("Filed_eng".equals(components[i].getClass().getSimpleName())) {
Filed_eng filed_eng = (Filed_eng) components[i];
if ("".equals(filed_eng.getText())) {
JOptionPane.showMessageDialog(frame, "请先把当前内容填写完毕再增加查询字段信息!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return false;
}
}
else if ("Filed_cn".equals(components[i].getClass().getSimpleName())) {
Filed_cn filed_cn = (Filed_cn) components[i];
if ("".equals(filed_cn.getText())) {
JOptionPane.showMessageDialog(frame, "请先把当前内容填写完毕再增加查询字段信息!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return false;
}
}
else if ("ServiceTypeComboBox".equals(components[i].getClass().getSimpleName())) {
@SuppressWarnings("unchecked")
ServiceTypeComboBox<String> serviceTypeComboBox = (ServiceTypeComboBox<String>) components[i];
if ("布尔".equals(serviceTypeComboBox.getSelectedItem())
|| "状态码".equals(serviceTypeComboBox.getSelectedItem())) {
FiledComment filedComment = (FiledComment) components[i + 1];
if ("".equals(filedComment.getText())) {
JOptionPane.showMessageDialog(frame, "布尔或状态码的类型描述不能为空!!详细请见配置说明!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return false;
}
}
}
}
}
return true;
}
private void addQueryMethod(JPanel querysPanel) {
Set<String> tables = tableMap.keySet();
String[] tableArr = tables.toArray(new String[] {});
// 表名
JComboBox<String> tableName = new JComboBox<>(tableArr);
// 字段
JTextField tableFiled = new Filed_eng();
// 中文名称
JTextField tableFiled_cn = new Filed_cn();
// 字段类型
JComboBox<String> filedType = new ServiceTypeComboBox<>();
String[] typeList = new String[] { "字符串", "数字", "布尔", "状态码", "日期", "文字域" };
filedType.setModel(new DefaultComboBoxModel<String>(typeList));
// 类型描述
JTextField filedComment = new FiledComment();
// 是否可排序
JComboBox<String> comboBox = new OrderComboBox<String>();
comboBox.setModel(new DefaultComboBoxModel<String>(new String[] { "否", "是" }));
querysPanel.add(tableName);
querysPanel.add(tableFiled);
querysPanel.add(tableFiled_cn);
querysPanel.add(filedType);
querysPanel.add(filedComment);
querysPanel.add(comboBox);
}
});
addCondition.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!canAddCondition(conditionPanel)) {
return;
}
if (conditionPanel.getComponentCount() == 0) {
for (String conditionArr : conditionsArr) {
JLabel label = new JLabel(conditionArr);
conditionPanel.add(label);
}
addConditionMethod(conditionPanel);
conditionPanel.getComponent(8).setVisible(false);
} else {
addConditionMethod(conditionPanel);
}
frame.validate();
frame.repaint();
}
private boolean canAddCondition(JPanel conditionPanel) {
if (conditionPanel.getComponentCount() >= 16) {
Component[] components = conditionPanel.getComponents();
for (int i = 8; i < components.length; i++) {
if ("Filed_eng".equals(components[i].getClass().getSimpleName())) {
Filed_eng filed_eng = (Filed_eng) components[i];
if ("".equals(filed_eng.getText())) {
JOptionPane.showMessageDialog(frame, "请先把当前内容填写完毕再增加查询字段信息!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return false;
}
}
else if ("Filed_cn".equals(components[i].getClass().getSimpleName())) {
Filed_cn filed_cn = (Filed_cn) components[i];
if ("".equals(filed_cn.getText())) {
JOptionPane.showMessageDialog(frame, "请先把当前内容填写完毕再增加查询字段信息!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return false;
}
}
else if ("ServiceTypeComboBox".equals(components[i].getClass().getSimpleName())) {
@SuppressWarnings("unchecked")
ServiceTypeComboBox<String> serviceTypeComboBox = (ServiceTypeComboBox<String>) components[i];
if ("布尔".equals(serviceTypeComboBox.getSelectedItem())
|| "状态码".equals(serviceTypeComboBox.getSelectedItem())) {
FiledComment filedComment = (FiledComment) components[i + 1];
if ("".equals(filedComment.getText())) {
JOptionPane.showMessageDialog(frame, "布尔或状态码的类型描述不能为空!!详细请见配置说明!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return false;
}
}
}
}
}
return true;
}
private void addConditionMethod(JPanel conditionsPanel) {
// 关联关系
JComboBox<String> relationComBox = new RelationJcombox<>();
relationComBox.setModel(new DefaultComboBoxModel<>(new String[] { "and", "or" }));
// 表名
Set<String> tables = tableMap.keySet();
String[] tableArr = tables.toArray(new String[] {});
JComboBox<String> tableName = new JComboBox<>(tableArr);
// 字段
JTextField tableFiled = new Filed_eng();
// 中文名称
JTextField tableFiled_cn = new Filed_cn();
// 字段类型
JComboBox<String> filedType = new ServiceTypeComboBox<>();
String[] typeList = new String[] { "字符串", "数字", "布尔", "状态码", "日期", "文字域" };
filedType.setModel(new DefaultComboBoxModel<String>(typeList));
FiledComment filedComment = new FiledComment();
// 比较关系
JComboBox<String> compareRelation = new CompareComboBox<>();
compareRelation.setModel(
new DefaultComboBoxModel<>(new String[] { "=", "like", ">=", "<=", "!=", ">= && <=" }));
// 固定值
JTextField unchangeValue = new JTextField();
conditionsPanel.add(relationComBox);
conditionsPanel.add(tableName);
conditionsPanel.add(tableFiled);
conditionsPanel.add(tableFiled_cn);
conditionsPanel.add(filedType);
conditionsPanel.add(filedComment);
conditionsPanel.add(compareRelation);
conditionsPanel.add(unchangeValue);
}
});
restart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tablesPanel.removeAll();
querysPanel.removeAll();
conditionPanel.removeAll();
frame.validate();
frame.repaint();
}
});
confirm.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String modelName = currentModelName.getText();
String modelNameCn = currentModelName_cn.getText();
if ("".equals(modelName) || "".equals(modelNameCn)) {
JOptionPane.showMessageDialog(frame, "中文和英文模块名称不可以为空!请填写!", "错误", JOptionPane.ERROR_MESSAGE);
return;
}
if (!checkRelTable(tablesPanel, tableRelationModelLists, tableMap)) {
return;
}
String selectTableSql = "";
String unsualFix = "";
if ("mysql".equals(parameters.getDataBaseTypeVal())) {
unsualFix = "`";
} else if ("oracle".equals(parameters.getDataBaseTypeVal())) {
unsualFix = "\"";
}
for (int i = 0; i < tableRelationModelLists.size(); i++) {
TableRelationModel tableRelationModel = tableRelationModelLists.get(i);
// 如果是第一个
String anotherTableName = tableRelationModel.getAnotherTableName();
String table2Text = tableRelationModel.getTable2_text();
if (i == 0) {
selectTableSql += " " + tableRelationModel.getRelation() + " " + unsualFix
+ tableRelationModel.getTable1_text() + unsualFix + " " + anotherTableName + " ";
continue;
}
selectTableSql += " " + tableRelationModel.getRelation() + " " + unsualFix
+ tableRelationModel.getTable1_text() + unsualFix + " " + anotherTableName + " ON ";
String table1Fileds = tableRelationModel.getTable1Fileds_text();
String table2Fileds = tableRelationModel.getTable2Fileds_text();
String[] table1FiledsArr = table1Fileds.split("&");
String[] table2FiledsArr = table2Fileds.split("&");
if (table1FiledsArr.length != table2FiledsArr.length) {
JOptionPane.showMessageDialog(frame, "关联表配置中第 " + (i + 1) + " 行表1和表2的关联字段的个数不相等,请检查后重新配置!",
"错误", JOptionPane.ERROR_MESSAGE);
return;
}
for (int j = 0; j < table1FiledsArr.length; j++) {
if (j == table1FiledsArr.length - 1) {
selectTableSql += anotherTableName + "." + table1FiledsArr[j] + " = "
+ tableMap.get(table2Text) + "." + table2FiledsArr[j];
break;
}
selectTableSql += anotherTableName + "." + table1FiledsArr[j] + " = " + tableMap.get(table2Text)
+ "." + table2FiledsArr[j] + " and ";
}
}
System.out.println(selectTableSql);
Component[] queryComponents = querysPanel.getComponents();
List<TableFiledModel> tableFiledModels = new ArrayList<>();
// 查询panel的信息
for (int i = 6; i < queryComponents.length; i++) {
if ("JComboBox".equals(queryComponents[i].getClass().getSimpleName())) {
@SuppressWarnings("unchecked")
JComboBox<String> comboBox = (JComboBox<String>) queryComponents[i];
TableFiledModel filedModel = new TableFiledModel();
filedModel.setComboBox(comboBox);
filedModel.setTableName((String) comboBox.getSelectedItem());
filedModel.setAnotherTableName(tableMap.get((String) comboBox.getSelectedItem()));
tableFiledModels.add(filedModel);
}
else if ("Filed_eng".equals(queryComponents[i].getClass().getSimpleName())) {
Filed_eng filed_eng = (Filed_eng) queryComponents[i];
String engFiled = filed_eng.getText();
if ("".equals(engFiled)) {
JOptionPane.showMessageDialog(frame, "添加查询字段中的字段列不能为空!请填写!!", "错误",
JOptionPane.ERROR_MESSAGE);
return;
}
TableFiledModel tableFiledModel = tableFiledModels.get(tableFiledModels.size() - 1);
tableFiledModel.setFiled_eng(filed_eng);
tableFiledModel.setFiledText_eng(engFiled);
tableFiledModel.setAnotherFiledName(tableFiledModel.getAnotherTableName() + "_" + engFiled);
}
else if ("Filed_cn".equals(queryComponents[i].getClass().getSimpleName())) {
Filed_cn filed_cn = (Filed_cn) queryComponents[i];
String cnFiled = filed_cn.getText();
if ("".equals(cnFiled)) {
JOptionPane.showMessageDialog(frame, "添加查询字段中的中文名称列不能为空!请填写!!", "错误",
JOptionPane.ERROR_MESSAGE);
return;
}
tableFiledModels.get(tableFiledModels.size() - 1).setFiled_cn(filed_cn);
tableFiledModels.get(tableFiledModels.size() - 1).setFiledText_cn(cnFiled);
}
else if ("ServiceTypeComboBox".equals(queryComponents[i].getClass().getSimpleName())) {
@SuppressWarnings("unchecked")
ServiceTypeComboBox<String> serviceTypeComboBox = (ServiceTypeComboBox<String>) queryComponents[i];
String filedType = (String) serviceTypeComboBox.getSelectedItem();
tableFiledModels.get(tableFiledModels.size() - 1).setServiceTypeComboBox(serviceTypeComboBox);
tableFiledModels.get(tableFiledModels.size() - 1).setFiledType(filedType);
}
else if ("FiledComment".equals(queryComponents[i].getClass().getSimpleName())) {
FiledComment filedComment = (FiledComment) queryComponents[i];
String comment = filedComment.getText();
String[] serviceArr = comment.split("#");
TableFiledModel tableFiledModel = tableFiledModels.get(tableFiledModels.size() - 1);
tableFiledModel.setTextFiled(filedComment);
tableFiledModel.setFiledCommentStr(comment);
String filedType = tableFiledModel.getFiledType();
Map<String, Object> map = new HashMap<>();
if ("布尔".equals(filedType)) {
try {
map.put("是", serviceArr[0]);
map.put("否", serviceArr[1]);
tableFiledModel.setFiledComment(map);
} catch (Exception e1) {
JOptionPane.showMessageDialog(frame, "布尔值的类型描述填写有误,请检查重写!", "错误",
JOptionPane.ERROR_MESSAGE);
return;
}
}
if ("状态码".equals(filedType)) {
try {
for (String serviece : serviceArr) {
String[] arr = serviece.split("&");
map.put(arr[0], arr[1]);
}
tableFiledModel.setFiledComment(map);
} catch (Exception e1) {
JOptionPane.showMessageDialog(frame, "状态码的类型描述填写有误,请检查重写!", "错误",
JOptionPane.ERROR_MESSAGE);
return;
}
}
}
else if ("OrderComboBox".equals(queryComponents[i].getClass().getSimpleName())) {
@SuppressWarnings("unchecked")
OrderComboBox<String> orderComboBox = (OrderComboBox<String>) queryComponents[i];
String canSort = (String) orderComboBox.getSelectedItem();
tableFiledModels.get(tableFiledModels.size() - 1).setOrderComboBox(orderComboBox);
tableFiledModels.get(tableFiledModels.size() - 1).setCanSort(canSort);
}
}
if (tableFiledModels.size() == 0) {
JOptionPane.showMessageDialog(frame, "请配置查询字段信息!", "错误", JOptionPane.ERROR_MESSAGE);
return;
}
Component[] conditionComponents = conditionPanel.getComponents();
List<TableConditionModel> tableConditionModels = new ArrayList<>();
// 查询panel的信息
for (int i = 6; i < conditionComponents.length; i++) {
if ("RelationJcombox".equals(conditionComponents[i].getClass().getSimpleName())) {
@SuppressWarnings("unchecked")
RelationJcombox<String> comboBox = (RelationJcombox<String>) conditionComponents[i];
TableConditionModel conditionModel = new TableConditionModel();
conditionModel.setRelationJcombox(comboBox);
conditionModel.setRelation((String) comboBox.getSelectedItem());
tableConditionModels.add(conditionModel);
}
else if ("JComboBox".equals(conditionComponents[i].getClass().getSimpleName())) {
@SuppressWarnings("unchecked")
JComboBox<String> comboBox = (JComboBox<String>) conditionComponents[i];
tableConditionModels.get(tableConditionModels.size() - 1).setComboBox(comboBox);
// 设置表名
tableConditionModels.get(tableConditionModels.size() - 1)
.setTableName((String) comboBox.getSelectedItem());
// 设置表别名
tableConditionModels.get(tableConditionModels.size() - 1)
.setAnotherTableName(tableMap.get((String) comboBox.getSelectedItem()));
}
else if ("Filed_eng".equals(conditionComponents[i].getClass().getSimpleName())) {
Filed_eng filed_eng = (Filed_eng) conditionComponents[i];
String engFiled = filed_eng.getText();
if ("".equals(engFiled)) {
JOptionPane.showMessageDialog(frame, "添加条件字段中的字段列不能为空!请填写!!", "错误",
JOptionPane.ERROR_MESSAGE);
return;
}
tableConditionModels.get(tableConditionModels.size() - 1).setFiled_eng_textFiled(filed_eng);
tableConditionModels.get(tableConditionModels.size() - 1).setFiled_eng(engFiled);
}
else if ("Filed_cn".equals(conditionComponents[i].getClass().getSimpleName())) {
Filed_cn filed_cn = (Filed_cn) conditionComponents[i];
String cnFiled = filed_cn.getText();
if ("".equals(cnFiled)) {
JOptionPane.showMessageDialog(frame, "添加条件字段中的中文名称列不能为空!请填写!!", "错误",
JOptionPane.ERROR_MESSAGE);
return;
}
tableConditionModels.get(tableConditionModels.size() - 1).setFiled_cn_textFiled(filed_cn);
tableConditionModels.get(tableConditionModels.size() - 1).setFiled_cn(cnFiled);
}
else if ("ServiceTypeComboBox".equals(conditionComponents[i].getClass().getSimpleName())) {
@SuppressWarnings("unchecked")
ServiceTypeComboBox<String> serviceTypeComboBox = (ServiceTypeComboBox<String>) conditionComponents[i];
String filedType = (String) serviceTypeComboBox.getSelectedItem();
tableConditionModels.get(tableConditionModels.size() - 1)
.setServiceTypeComboBox(serviceTypeComboBox);
tableConditionModels.get(tableConditionModels.size() - 1).setServiceType(filedType);
}
else if ("FiledComment".equals(conditionComponents[i].getClass().getSimpleName())) {
FiledComment filedComment = (FiledComment) conditionComponents[i];
String comment = filedComment.getText();
String[] serviceArr = comment.split("#");
TableConditionModel tableConditionModel = tableConditionModels
.get(tableConditionModels.size() - 1);
tableConditionModel.setFiledComment(filedComment);
String filedType = tableConditionModel.getServiceType();
Map<String, Object> map = new HashMap<>();
if ("布尔".equals(filedType)) {
try {
map.put("是", serviceArr[0]);
map.put("否", serviceArr[1]);
tableConditionModel.setServiceText(map);
} catch (Exception e1) {
JOptionPane.showMessageDialog(frame, "布尔值的类型描述填写有误,请检查重写!", "错误",
JOptionPane.ERROR_MESSAGE);
return;
}
}
if ("状态码".equals(filedType)) {
try {
for (String serviece : serviceArr) {
String[] arr = serviece.split("&");
map.put(arr[0], arr[1]);
}
tableConditionModel.setServiceText(map);
} catch (Exception e1) {
JOptionPane.showMessageDialog(frame, "状态码的类型描述填写有误,请检查重写!", "错误",
JOptionPane.ERROR_MESSAGE);
return;
}
}
}
else if ("CompareComboBox".equals(conditionComponents[i].getClass().getSimpleName())) {
@SuppressWarnings("unchecked")
CompareComboBox<String> compareComboBox = (CompareComboBox<String>) conditionComponents[i];
String compareText = (String) compareComboBox.getSelectedItem();
tableConditionModels.get(tableConditionModels.size() - 1).setCompareComboBox(compareComboBox);
tableConditionModels.get(tableConditionModels.size() - 1).setCompareText(compareText);
}
else if ("JTextField".equals(conditionComponents[i].getClass().getSimpleName())) {
JTextField textField = (JTextField) conditionComponents[i];
String unchangeValue = textField.getText();
tableConditionModels.get(tableConditionModels.size() - 1).setTextFiled(textField);
tableConditionModels.get(tableConditionModels.size() - 1).setUnchangeValue(unchangeValue);
}
}
if (tableConditionModels.size() == 0) {
JOptionPane.showMessageDialog(frame, "请配置条件字段信息!", "错误", JOptionPane.ERROR_MESSAGE);
return;
}
TablesQueryModel tablesQueryModel = new TablesQueryModel();
// 储存多表查询的信息配置
tablesQueryModel.setFormSql(selectTableSql);
List<TableRelationModel> realTableRelationModelLists = new ArrayList<>();
realTableRelationModelLists.addAll(tableRelationModelLists);
tablesQueryModel.setTableRelationModelLists(realTableRelationModelLists);
tablesQueryModel.setTableFiledModels(tableFiledModels);
tablesQueryModel.setTableConditionModels(tableConditionModels);
if (ChildWindowConstant.tablesQueryMap.containsKey(modelName)) {
int getCodeConfirmDialog = JOptionPane.showConfirmDialog(frame,
"当前模块名称‘" + modelName + "’已存在,确认覆盖?", "提示", JOptionPane.YES_NO_OPTION);
if (getCodeConfirmDialog != 0) {
return;
}
}
ChildWindowConstant.tablesQueryMap.put(modelName, tablesQueryModel);
ChildWindowConstant.tablesQueryEndAndCnMap.put(modelName, modelNameCn);
JOptionPane.showMessageDialog(frame, "当前模块配置成功!", "提示", JOptionPane.INFORMATION_MESSAGE);
String[] modelArr = ChildWindowConstant.tablesQueryMap.keySet().toArray(new String[] {});
tableConfigExit.setModel(new DefaultComboBoxModel<>(new String[] { "--请选择--" }));
for (String model : modelArr) {
tableConfigExit.addItem(model);
}
currentModelName.setText("");
currentModelName_cn.setText("");
tablesPanel.removeAll();
querysPanel.removeAll();
conditionPanel.removeAll();
addQuery.setEnabled(false);
addCondition.setEnabled(false);
frame.validate();
frame.repaint();
}
});
confirmRelTable.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!checkRelTable(tablesPanel, tableRelationModelLists, tableMap)) {
return;
}
addQuery.setEnabled(true);
addCondition.setEnabled(true);
Component[] queryComponents = querysPanel.getComponents();
for (int i = 6; i < queryComponents.length; i++) {
if ("JComboBox".equals(queryComponents[i].getClass().getSimpleName())) {
@SuppressWarnings("unchecked")
JComboBox<String> comboBox = (JComboBox<String>) queryComponents[i];
Set<String> tables = tableMap.keySet();
comboBox.removeAllItems();
for (String table : tables) {
comboBox.addItem(table);
}
}
}
Component[] conditionComponents = conditionPanel.getComponents();
for (int i = 8; i < conditionComponents.length; i++) {
if ("JComboBox".equals(conditionComponents[i].getClass().getSimpleName())) {
@SuppressWarnings("unchecked")
JComboBox<String> comboBox = (JComboBox<String>) conditionComponents[i];
Set<String> tables = tableMap.keySet();
comboBox.removeAllItems();
for (String table : tables) {
comboBox.addItem(table);
}
}
}
frame.validate();
frame.repaint();
}
});
tableConfigExit.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() != 1) {
return;
}
// 选取的当前模块
String currentModel = tableConfigExit.getSelectedItem().toString();
if ("--请选择--".equals(currentModel)) {
tablesPanel.removeAll();
querysPanel.removeAll();
conditionPanel.removeAll();
currentModelName.setText("");
currentModelName_cn.setText("");
frame.validate();
frame.repaint();
return;
}
currentModelName.setText(currentModel);
String currentCnModelName = ChildWindowConstant.tablesQueryEndAndCnMap.get(currentModel);
currentModelName_cn.setText(currentCnModelName);
TablesQueryModel tablesQueryModel = ChildWindowConstant.tablesQueryMap.get(currentModel);
List<TableRelationModel> tableRelations = tablesQueryModel.getTableRelationModelLists();
List<TableFiledModel> tableFileds = tablesQueryModel.getTableFiledModels();
List<TableConditionModel> tableConditions = tablesQueryModel.getTableConditionModels();
// 移除三个panel所有的组件
tablesPanel.removeAll();
querysPanel.removeAll();
conditionPanel.removeAll();
// 加入表头和内容
for (String tableStr : tablesArr) {
JLabel label = new JLabel(tableStr);
tablesPanel.add(label);
}
for (TableRelationModel tableRelation : tableRelations) {
tablesPanel.add(tableRelation.getComboBox());
tablesPanel.add(tableRelation.getTable1());
tablesPanel.add(tableRelation.getTable2());
tablesPanel.add(tableRelation.getTable1Fileds());
tablesPanel.add(tableRelation.getTable2Fileds());
}
for (String queryStr : querysArr) {
JLabel label = new JLabel(queryStr);
querysPanel.add(label);
}
for (TableFiledModel tableFiled : tableFileds) {
querysPanel.add(tableFiled.getComboBox());
querysPanel.add(tableFiled.getFiled_eng());
querysPanel.add(tableFiled.getFiled_cn());
querysPanel.add(tableFiled.getServiceTypeComboBox());
querysPanel.add(tableFiled.getTextFiled());
querysPanel.add(tableFiled.getOrderComboBox());
}
for (String conditionStr : conditionsArr) {
JLabel label = new JLabel(conditionStr);
conditionPanel.add(label);
}
for (TableConditionModel tableCondition : tableConditions) {
conditionPanel.add(tableCondition.getRelationJcombox());
conditionPanel.add(tableCondition.getComboBox());
conditionPanel.add(tableCondition.getFiled_eng_textFiled());
conditionPanel.add(tableCondition.getFiled_cn_textFiled());
conditionPanel.add(tableCondition.getServiceTypeComboBox());
conditionPanel.add(tableCondition.getFiledComment());
conditionPanel.add(tableCondition.getCompareComboBox());
conditionPanel.add(tableCondition.getTextFiled());
}
frame.validate();
frame.repaint();
}
});
frame.getContentPane().setLayout(groupLayout);
}
private boolean checkRelTable(JPanel tablesPanel, List<TableRelationModel> tableRelationModelLists,
Map<String, String> tableMap) {
// 清空集合
tableRelationModelLists.clear();
tableMap.clear();
Component[] tableComponents = tablesPanel.getComponents();
// 读取关联表的配置信息
for (int i = 4; i < tableComponents.length; i++) {
if ("JComboBox".equals(tableComponents[i].getClass().getSimpleName())) {
@SuppressWarnings("unchecked")
JComboBox<String> comboBox = (JComboBox<String>) tableComponents[i];
TableRelationModel tableRelationModel = new TableRelationModel();
tableRelationModel.setComboBox(comboBox);
tableRelationModel.setRelation((String) comboBox.getSelectedItem());
tableRelationModelLists.add(tableRelationModel);
}
else if ("Table1".equals(tableComponents[i].getClass().getSimpleName())) {
Table1 table1 = (Table1) tableComponents[i];
tableRelationModelLists.get(tableRelationModelLists.size() - 1).setTable1(table1);
tableRelationModelLists.get(tableRelationModelLists.size() - 1).setTable1_text(table1.getText());
// 表别名
tableRelationModelLists.get(tableRelationModelLists.size() - 1)
.setAnotherTableName("T" + (tableRelationModelLists.size() - 1));
}
else if ("Table2".equals(tableComponents[i].getClass().getSimpleName())) {
Table2 table2 = (Table2) tableComponents[i];
tableRelationModelLists.get(tableRelationModelLists.size() - 1).setTable2(table2);
tableRelationModelLists.get(tableRelationModelLists.size() - 1)
.setTable2_text((String) table2.getSelectedItem());
}
else if ("Table1Fileds".equals(tableComponents[i].getClass().getSimpleName())) {
Table1Fileds table1Fileds = (Table1Fileds) tableComponents[i];
tableRelationModelLists.get(tableRelationModelLists.size() - 1).setTable1Fileds(table1Fileds);
tableRelationModelLists.get(tableRelationModelLists.size() - 1)
.setTable1Fileds_text(table1Fileds.getText());
}
else if ("Table2Fileds".equals(tableComponents[i].getClass().getSimpleName())) {
Table2Fileds table2Fileds = (Table2Fileds) tableComponents[i];
tableRelationModelLists.get(tableRelationModelLists.size() - 1).setTable2Fileds(table2Fileds);
tableRelationModelLists.get(tableRelationModelLists.size() - 1)
.setTable2Fileds_text(table2Fileds.getText());
}
}
// 如果集合大小为0,说明没配
if (tableRelationModelLists.size() == 0) {
JOptionPane.showMessageDialog(frame, "请先配置关联表信息!!!", "提示", JOptionPane.INFORMATION_MESSAGE);
return false;
}
// 检查关联表配置有没有字段为空
for (int i = 0; i < tableRelationModelLists.size(); i++) {
TableRelationModel tableRelationModel = tableRelationModelLists.get(i);
if ("".equals(tableRelationModel.getTable1_text()) || "".equals(tableRelationModel.getTable1Fileds_text())
|| "".equals(tableRelationModel.getTable2Fileds_text())) {
JOptionPane.showMessageDialog(frame, "表1,表1字段,表2字段不能为空!!请填写!!", "错误", JOptionPane.ERROR_MESSAGE);
return false;
}
// 动态表名称使用
tableMap.put(tableRelationModel.getTable1_text(), tableRelationModel.getAnotherTableName());
}
return true;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/seelo/codeMan.git
git@gitee.com:seelo/codeMan.git
seelo
codeMan
codeMan
master

搜索帮助