Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 131

春天的阳光/codeMan

forked from 小螺旋丸/codeMan
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
codeMan
/
src
/
main
/
java
/
codeMaker
/
MakeEntity.java
codeMan
/
src
/
main
/
java
/
codeMaker
/
MakeEntity.java
MakeEntity.java 15.61 KB
Copy Edit Raw Blame History
小螺旋丸 authored 2020年05月11日 23:43 +08:00 . 自定义实体完毕
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
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.List;
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.Filed_cn;
import constant.Filed_eng;
import constant.ServiceTypeComboBox;
import entity.MakeEntityModel;
public class MakeEntity {
private JFrame frame;
private JTextField entityName;
private JTextField entityName_cn;
public JFrame getFrame() {
return frame;
}
public void setFrame(JFrame frame) {
this.frame = frame;
}
/**
* Launch the application.
*/
public static void main() {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MakeEntity window = new MakeEntity();
ChildWindowConstant.makeEntity = window;
window.frame.setVisible(true);
} 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 MakeEntity() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setResizable(true);
frame.setIconImage(Toolkit.getDefaultToolkit().getImage(MakeEntity.class
.getResource("/org/pushingpixels/substance/internal/contrib/randelshofer/quaqua/images/pencil.png")));
frame.setTitle("自定义实体");
frame.setBounds(100, 100, 781, 530);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JScrollPane queryScrollPane = new JScrollPane();
JButton addField = new JButton("添加字段");
JLabel label = new JLabel("英文名称");
entityName = new JTextField();
entityName.setColumns(10);
JLabel lblbean = new JLabel("查看已配置的实体");
JComboBox<String> entityListCombox = new JComboBox<String>();
String[] modelArr = ChildWindowConstant.makeEntityEngAndCn.keySet().toArray(new String[] {});
entityListCombox.setModel(new DefaultComboBoxModel<>(new String[] { "--请选择--" }));
for (String model : modelArr) {
entityListCombox.addItem(model);
}
JLabel cnLable = new JLabel("中文名称");
entityName_cn = new JTextField();
entityName_cn.setColumns(10);
JLabel label_2 = new JLabel("*");
label_2.setForeground(Color.RED);
JButton confirmButton = new JButton("确定");
JButton deleteButton = new JButton("删除");
JButton deleteLastRow = new JButton("删除尾行");
GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.TRAILING).addGroup(groupLayout
.createSequentialGroup().addGap(25)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(entityListCombox, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
.addComponent(lblbean)
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING).addComponent(cnLable)
.addComponent(label))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
.addComponent(entityName_cn, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 106,
Short.MAX_VALUE)
.addComponent(entityName, Alignment.TRAILING))
.addPreferredGap(ComponentPlacement.RELATED).addComponent(label_2)))
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup().addGap(13)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup().addComponent(confirmButton)
.addPreferredGap(ComponentPlacement.RELATED).addComponent(deleteButton))
.addComponent(queryScrollPane, GroupLayout.PREFERRED_SIZE, 514,
GroupLayout.PREFERRED_SIZE)))
.addGroup(groupLayout.createSequentialGroup().addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(addField).addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(deleteLastRow)))
.addGap(45)));
groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup().addGap(31).addGroup(groupLayout
.createParallelGroup(Alignment.TRAILING)
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(label)
.addComponent(entityName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addComponent(label_2))
.addGap(18))
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(addField)
.addComponent(deleteLastRow))
.addPreferredGap(ComponentPlacement.UNRELATED)))
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout
.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(cnLable)
.addComponent(entityName_cn, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18).addComponent(lblbean).addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(entityListCombox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE))
.addComponent(queryScrollPane, GroupLayout.PREFERRED_SIZE, 286,
GroupLayout.PREFERRED_SIZE))
.addGap(18).addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(confirmButton).addComponent(deleteButton))
.addGap(323)));
JPanel querysPanel = new JPanel();
queryScrollPane.setViewportView(querysPanel);
querysPanel.setLayout(new GridLayout(0, 3, 5, 5));
String[] fieldArr = new String[] { "字段名称", "注释", "字段类型" };
deleteLastRow.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 获取容器个数
int componentCount = querysPanel.getComponentCount();
if (componentCount == 0) {
return;
}
// 一行有6个
// 如果是12,全部移除
if (componentCount == 6) {
querysPanel.removeAll();
// 否则,移除最后6个
} else {
querysPanel.remove(componentCount - 1);
querysPanel.remove(componentCount - 2);
querysPanel.remove(componentCount - 3);
}
frame.validate();
frame.repaint();
}
});
addField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!canAddField(querysPanel)) {
return;
}
if (querysPanel.getComponentCount() == 0) {
for (String queryStr : fieldArr) {
JLabel label = new JLabel(queryStr);
querysPanel.add(label);
}
addFieldMethod(querysPanel);
} else {
addFieldMethod(querysPanel);
}
frame.validate();
frame.repaint();
}
private boolean canAddField(JPanel querysPanel) {
if (querysPanel.getComponentCount() >= 6) {
Component[] components = querysPanel.getComponents();
for (int i = 3; 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;
}
}
}
}
return true;
}
private void addFieldMethod(JPanel querysPanel) {
// 字段
JTextField tableFiled = new Filed_eng();
// 中文名称
JTextField tableFiled_cn = new Filed_cn();
// 字段类型
JComboBox<String> filedType = new ServiceTypeComboBox<>();
String[] typeList = new String[] { "String", "Byte", "Short", "Integer", "Float", "Double", "Long",
"Char", "Boolean", "List" };
filedType.setModel(new DefaultComboBoxModel<String>(typeList));
querysPanel.add(tableFiled);
querysPanel.add(tableFiled_cn);
querysPanel.add(filedType);
}
});
// 配置模块下拉框监听
entityListCombox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() != 1) {
return;
}
// 选取的当前模块
String currentEntityName = entityListCombox.getSelectedItem().toString();
if ("--请选择--".equals(currentEntityName)) {
entityName.setText("");
entityName_cn.setText("");
querysPanel.removeAll();
frame.validate();
frame.repaint();
return;
}
entityName.setText(currentEntityName);
String currentEntityName_cn = ChildWindowConstant.makeEntityEngAndCn.get(currentEntityName);
entityName_cn.setText(currentEntityName_cn);
List<MakeEntityModel> makeEntityModels = ChildWindowConstant.makeEntityModelMap.get(currentEntityName);
// 移除panel的组件
querysPanel.removeAll();
// 加入表头和内容
for (String tableStr : fieldArr) {
JLabel label = new JLabel(tableStr);
querysPanel.add(label);
}
for (MakeEntityModel entityModel : makeEntityModels) {
JTextField filed_eng = new Filed_eng();
filed_eng.setText(entityModel.getFiledName_eng());
JTextField filed_cn = new Filed_cn();
filed_cn.setText(entityModel.getFiledName_cn());
// 字段类型
JComboBox<String> filedType = new ServiceTypeComboBox<>();
String[] typeList = new String[] { "String", "Byte", "Short", "Integer", "Float", "Double", "Long",
"Char", "Boolean", "List" };
filedType.setModel(new DefaultComboBoxModel<String>(typeList));
filedType.setSelectedItem(entityModel.getServiceType());
querysPanel.add(filed_eng);
querysPanel.add(filed_cn);
querysPanel.add(filedType);
}
frame.validate();
frame.repaint();
}
});
/**
* 确定设置实体
*/
confirmButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String entityNameStr = entityName.getText();
if ("".equals(entityNameStr)) {
JOptionPane.showMessageDialog(frame, "实体名称不能为空!请填写!!", "错误",
JOptionPane.ERROR_MESSAGE);
return;
}
String entityNameStr_cn = entityName_cn.getText();
entityNameStr_cn = "".equals(entityNameStr_cn) ? entityNameStr : entityNameStr_cn;
if (ChildWindowConstant.makeEntityEngAndCn.containsKey(entityNameStr)) {
int getCodeConfirmDialog = JOptionPane.showConfirmDialog(frame,
"当前实体‘" + entityNameStr + "’已存在,确认覆盖?", "提示", JOptionPane.YES_NO_OPTION);
if (getCodeConfirmDialog != 0) {
return;
}
}
// 内容
Component[] queryComponents = querysPanel.getComponents();
List<MakeEntityModel> makeEntityModels = new ArrayList<>();
for (int i = 3; i < queryComponents.length; i++) {
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;
}
MakeEntityModel makeEntityModel = new MakeEntityModel();
makeEntityModel.setFiledName_eng(engFiled);
makeEntityModels.add(makeEntityModel);
}
else if ("Filed_cn".equals(queryComponents[i].getClass().getSimpleName())) {
Filed_cn filed_cn = (Filed_cn) queryComponents[i];
String filedName_eng = makeEntityModels.get(makeEntityModels.size() - 1).getFiledName_eng();
String cnFiled = "".equals(filed_cn.getText()) ? filedName_eng : filed_cn.getText();
makeEntityModels.get(makeEntityModels.size() - 1).setFiledName_cn(cnFiled);
}
else if ("ServiceTypeComboBox".equals(queryComponents[i].getClass().getSimpleName())) {
@SuppressWarnings("unchecked")
ServiceTypeComboBox<String> serviceTypeComboBox = (ServiceTypeComboBox<String>) queryComponents[i];
String filedType = (String) serviceTypeComboBox.getSelectedItem();
makeEntityModels.get(makeEntityModels.size() - 1).setServiceType(filedType);
}
}
if (makeEntityModels.size() == 0) {
JOptionPane.showMessageDialog(frame, "请配置实体的字段信息!", "错误", JOptionPane.ERROR_MESSAGE);
return;
}
ChildWindowConstant.makeEntityEngAndCn.put(entityNameStr, entityNameStr_cn);
ChildWindowConstant.makeEntityModelMap.put(entityNameStr, makeEntityModels);
JOptionPane.showMessageDialog(frame, "当前实体配置成功!", "提示", JOptionPane.INFORMATION_MESSAGE);
String[] entityNameArr = ChildWindowConstant.makeEntityModelMap.keySet().toArray(new String[] {});
entityListCombox.setModel(new DefaultComboBoxModel<>(new String[] { "--请选择--" }));
for (String entity : entityNameArr) {
entityListCombox.addItem(entity);
}
entityListCombox.setSelectedItem(entityNameStr);
entityName_cn.setText(entityNameStr_cn);
frame.validate();
frame.repaint();
}
});
/**
* 删除当前实体
*/
deleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if ("".equals(entityName.getText())) {
return;
}
int deleteFlg = JOptionPane.showConfirmDialog(frame, "确定删除当前实体‘" + entityName.getText() + "’吗?",
"提示", JOptionPane.YES_NO_OPTION);
if (deleteFlg != 0) {
return;
}
ChildWindowConstant.makeEntityModelMap.remove(entityName.getText());
ChildWindowConstant.makeEntityEngAndCn.remove(entityName.getText());
String[] entityNameArr = ChildWindowConstant.makeEntityModelMap.keySet().toArray(new String[] {});
entityListCombox.setModel(new DefaultComboBoxModel<>(new String[] { "--请选择--" }));
for (String entity : entityNameArr) {
entityListCombox.addItem(entity);
}
entityName.setText("");
entityName_cn.setText("");
querysPanel.removeAll();
frame.validate();
frame.repaint();
JOptionPane.showMessageDialog(frame, "已删除!!", "提示",
JOptionPane.INFORMATION_MESSAGE);
}
});
frame.getContentPane().setLayout(groupLayout);
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

代码生成器源码,可一键生成controller,service,dao,实体类,单表、多表的sql语句,日志处理、事务支持等,同时可以生成dubbo和springCloud脚手架方便开发微服务项目,能在很大程度上提高开发效率,节约开发时间。代码生成完毕后即为一个前台到后台的完整项目。目前后台支持SSM/SpringBoot,数据库支持mysql/postgresql/oracle,前台样式使用BootStrap,js支持jquery/vue,导入eclipse/idea便可运行,可根据需求自由扩展!
No labels
Apache-2.0
Use Apache-2.0
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/spring55/codeMan.git
git@gitee.com:spring55/codeMan.git
spring55
codeMan
codeMan
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /