生成代码时加入模板组选择功能

This commit is contained in:
makejava 2020-06-11 18:41:00 +08:00
parent 415edcdaa3
commit f937aea970
5 changed files with 98 additions and 29 deletions

View File

@ -25,13 +25,17 @@ public class TableInfo {
*/
private String name;
/**
* 表名前缀(首字母大写)
* 表名前缀
*/
private String preName;
/**
* 注释
*/
private String comment;
/**
* 模板组名称
*/
private String templateGroupName;
/**
* 所有列
*/

View File

@ -150,6 +150,8 @@ public class TableInfoServiceImpl implements TableInfoService {
tableInfo.setSavePath(tableInfoConfig.getSavePath());
// 选择的表名前缀
tableInfo.setPreName(tableInfoConfig.getPreName());
// 选择的模板组
tableInfo.setTemplateGroupName(tableInfoConfig.getTemplateGroupName());
// 没有列时不处理
if (CollectionUtil.isEmpty(tableInfoConfig.getFullColumn())) {

View File

@ -3,7 +3,7 @@
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="48" y="54" width="436" height="319"/>
<xy x="48" y="54" width="436" height="336"/>
</constraints>
<properties/>
<border type="none"/>
@ -49,7 +49,7 @@
</grid>
</children>
</grid>
<grid id="e3588" layout-manager="GridLayoutManager" row-count="8" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="e3588" layout-manager="GridLayoutManager" row-count="9" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@ -57,24 +57,15 @@
<properties/>
<border type="none"/>
<children>
<component id="f79bc" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="76436"/>
<text resource-bundle="string" key="label.module"/>
</properties>
</component>
<component id="76436" class="javax.swing.JComboBox" binding="moduleComboBox">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="2dff5" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="158fc"/>
@ -83,7 +74,7 @@
</component>
<component id="158fc" class="javax.swing.JTextField" binding="packageField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
@ -91,7 +82,7 @@
</component>
<component id="d7b53" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="ab063"/>
@ -100,7 +91,7 @@
</component>
<component id="ab063" class="javax.swing.JTextField" binding="pathField">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
@ -108,7 +99,7 @@
</component>
<component id="7467f" class="javax.swing.JButton" binding="packageChooseButton">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="string" key="label.choose"/>
@ -116,7 +107,7 @@
</component>
<component id="fba1b" class="javax.swing.JButton" binding="pathChooseButton">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="string" key="label.choose"/>
@ -125,7 +116,7 @@
<grid id="7831c" binding="templatePanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="4" column="1" row-span="4" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="5" column="1" row-span="4" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@ -133,7 +124,7 @@
</grid>
<component id="91ae2" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="4" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="5" column="0" row-span="4" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="string" key="label.template"/>
@ -141,7 +132,7 @@
</component>
<component id="9a8d1" class="javax.swing.JCheckBox" binding="allCheckBox" default-binding="true">
<constraints>
<grid row="4" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="string" key="label.all"/>
@ -149,12 +140,12 @@
</component>
<vspacer id="98aa7">
<constraints>
<grid row="7" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="8" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="5e5a1" class="javax.swing.JCheckBox" binding="unifiedConfig">
<constraints>
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="6" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="string" key="label.unified.config"/>
@ -162,7 +153,7 @@
</component>
<component id="af94e" class="javax.swing.JCheckBox" binding="titleConfig">
<constraints>
<grid row="6" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="7" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="禁止提示"/>
@ -170,7 +161,7 @@
</component>
<component id="caddc" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="81a34"/>
@ -179,12 +170,36 @@
</component>
<component id="81a34" class="javax.swing.JTextField" binding="preField">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="f79bc" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="76436"/>
<text resource-bundle="string" key="label.group"/>
</properties>
</component>
<component id="a9ca" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="76436"/>
<text resource-bundle="string" key="label.module"/>
</properties>
</component>
<component id="2c7fc" class="javax.swing.JComboBox" binding="groupComboBox">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>

View File

@ -11,6 +11,7 @@ import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
//import com.intellij.psi.PsiPackage;
import com.intellij.util.ExceptionUtil;
import com.sjhy.plugin.config.Settings;
import com.sjhy.plugin.constants.MsgValue;
import com.sjhy.plugin.constants.StrState;
import com.sjhy.plugin.entity.TableInfo;
@ -89,6 +90,10 @@ public class SelectSavePath extends JDialog {
* 禁止提示复选框
*/
private JCheckBox titleConfig;
/**
* 分组选择框
*/
private JComboBox<String> groupComboBox;
/**
* 所有模板复选框
*/
@ -212,6 +217,7 @@ public class SelectSavePath extends JDialog {
tableInfo.setSavePath(savePath);
tableInfo.setSavePackageName(packageField.getText());
tableInfo.setPreName(preField.getText());
tableInfo.setTemplateGroupName((String) groupComboBox.getSelectedItem());
Module module = getSelectModule();
if (module != null) {
tableInfo.setSaveModelName(module.getName());
@ -232,19 +238,36 @@ public class SelectSavePath extends JDialog {
}
/**
* 初始化方法
* 初始化模板组
*/
private void init() {
private void initTemplateGroup() {
//添加模板组
checkBoxList.clear();
templatePanel.removeAll();
templatePanel.setLayout(new GridLayout(6, 2));
templateGroup.getElementList().forEach(template -> {
JCheckBox checkBox = new JCheckBox(template.getName());
checkBoxList.add(checkBox);
templatePanel.add(checkBox);
});
// 移除所有旧事件
ActionListener[] actionListeners = allCheckBox.getActionListeners();
if (actionListeners != null && actionListeners.length > 0) {
for (ActionListener actionListener : actionListeners) {
allCheckBox.removeActionListener(actionListener);
}
}
//添加全选事件
allCheckBox.addActionListener(e -> checkBoxList.forEach(jCheckBox -> jCheckBox.setSelected(allCheckBox.isSelected())));
allCheckBox.setSelected(false);
}
/**
* 初始化方法
*/
private void init() {
// 初始化模板组
initTemplateGroup();
//初始化Module选择
for (Module module : this.moduleList) {
@ -331,6 +354,30 @@ public class SelectSavePath extends JDialog {
if (!StringUtils.isEmpty(tableInfo.getPreName())) {
preField.setText(tableInfo.getPreName());
}
Settings settings = Settings.getInstance();
String groupName = settings.getCurrTemplateGroupName();
if (!StringUtils.isEmpty(tableInfo.getTemplateGroupName())) {
if (settings.getTemplateGroupMap().containsKey(tableInfo.getTemplateGroupName())) {
groupName = tableInfo.getTemplateGroupName();
this.templateGroup = settings.getTemplateGroupMap().get(groupName);
// 选中的模板组发生变化尝试重新初始化
initTemplateGroup();
}
}
for (String key : settings.getTemplateGroupMap().keySet()) {
groupComboBox.addItem(key);
}
groupComboBox.setSelectedItem(groupName);
groupComboBox.addActionListener(e -> {
String selectedItem = (String) groupComboBox.getSelectedItem();
if (this.templateGroup.getName().equals(selectedItem)) {
return;
}
this.templateGroup = settings.getTemplateGroupMap().get(selectedItem);
// 选中的模板组发生变化尝试重新初始化
initTemplateGroup();
this.open();
});
String savePath = tableInfo.getSavePath();
if (!StringUtils.isEmpty(savePath)) {
// 判断是否需要拼接项目路径

View File

@ -5,6 +5,7 @@ label.version=&\u5F53\u524D\u7248\u672C\uFF1A
label.author.name=&\u4F5C\u8005\u540D\u79F0\uFF1A
label.cancel=&Cancel
label.choose=&Choose
label.group=&Group
label.module=&Module:
label.ok=&OK
label.package=&Package: