优化模板选择界面

This commit is contained in:
makejava 2021-08-16 17:09:30 +08:00
parent 9d63071d3e
commit 8deb87db46
3 changed files with 192 additions and 148 deletions

View File

@ -8,7 +8,7 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<grid id="e3588" layout-manager="GridLayoutManager" row-count="9" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="e3588" layout-manager="GridLayoutManager" row-count="7" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <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"/> <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"/>
@ -18,13 +18,13 @@
<children> <children>
<component id="76436" class="javax.swing.JComboBox" binding="moduleComboBox"> <component id="76436" class="javax.swing.JComboBox" binding="moduleComboBox">
<constraints> <constraints>
<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"/> <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> </constraints>
<properties/> <properties/>
</component> </component>
<component id="2dff5" class="javax.swing.JLabel"> <component id="2dff5" class="javax.swing.JLabel">
<constraints> <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="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> </constraints>
<properties> <properties>
<labelFor value="158fc"/> <labelFor value="158fc"/>
@ -33,7 +33,7 @@
</component> </component>
<component id="158fc" class="javax.swing.JTextField" binding="packageField"> <component id="158fc" class="javax.swing.JTextField" binding="packageField">
<constraints> <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="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">
<preferred-size width="150" height="-1"/> <preferred-size width="150" height="-1"/>
</grid> </grid>
</constraints> </constraints>
@ -41,7 +41,7 @@
</component> </component>
<component id="d7b53" class="javax.swing.JLabel"> <component id="d7b53" class="javax.swing.JLabel">
<constraints> <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="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> </constraints>
<properties> <properties>
<labelFor value="ab063"/> <labelFor value="ab063"/>
@ -50,7 +50,7 @@
</component> </component>
<component id="ab063" class="javax.swing.JTextField" binding="pathField"> <component id="ab063" class="javax.swing.JTextField" binding="pathField">
<constraints> <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="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"/> <preferred-size width="150" height="-1"/>
</grid> </grid>
</constraints> </constraints>
@ -58,7 +58,7 @@
</component> </component>
<component id="7467f" class="javax.swing.JButton" binding="packageChooseButton"> <component id="7467f" class="javax.swing.JButton" binding="packageChooseButton">
<constraints> <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="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"/>
</constraints> </constraints>
<properties> <properties>
<text resource-bundle="string" key="label.choose"/> <text resource-bundle="string" key="label.choose"/>
@ -66,16 +66,15 @@
</component> </component>
<component id="fba1b" class="javax.swing.JButton" binding="pathChooseButton"> <component id="fba1b" class="javax.swing.JButton" binding="pathChooseButton">
<constraints> <constraints>
<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"/> <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> </constraints>
<properties> <properties>
<text resource-bundle="string" key="label.choose"/> <text resource-bundle="string" key="label.choose"/>
</properties> </properties>
</component> </component>
<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"> <grid id="7831c" binding="templatePanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<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"/> <grid row="4" column="1" row-span="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties/> <properties/>
<border type="none"/> <border type="none"/>
@ -83,44 +82,20 @@
</grid> </grid>
<component id="91ae2" class="javax.swing.JLabel"> <component id="91ae2" class="javax.swing.JLabel">
<constraints> <constraints>
<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"/> <grid row="4" column="0" row-span="3" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<text resource-bundle="string" key="label.template"/> <text resource-bundle="string" key="label.template"/>
</properties> </properties>
</component> </component>
<component id="9a8d1" class="javax.swing.JCheckBox" binding="allCheckBox" default-binding="true">
<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"/>
</constraints>
<properties>
<text resource-bundle="string" key="label.all"/>
</properties>
</component>
<vspacer id="98aa7"> <vspacer id="98aa7">
<constraints> <constraints>
<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"/> <grid row="6" 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> </constraints>
</vspacer> </vspacer>
<component id="5e5a1" class="javax.swing.JCheckBox" binding="unifiedConfig">
<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"/>
</constraints>
<properties>
<text resource-bundle="string" key="label.unified.config"/>
</properties>
</component>
<component id="af94e" class="javax.swing.JCheckBox" binding="titleConfig">
<constraints>
<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="禁止提示"/>
</properties>
</component>
<component id="caddc" class="javax.swing.JLabel"> <component id="caddc" class="javax.swing.JLabel">
<constraints> <constraints>
<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"/> <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> </constraints>
<properties> <properties>
<labelFor value="81a34"/> <labelFor value="81a34"/>
@ -129,35 +104,36 @@
</component> </component>
<component id="81a34" class="javax.swing.JTextField" binding="preField"> <component id="81a34" class="javax.swing.JTextField" binding="preField">
<constraints> <constraints>
<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"> <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"/> <preferred-size width="150" height="-1"/>
</grid> </grid>
</constraints> </constraints>
<properties/> <properties/>
</component> </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"> <component id="a9ca" class="javax.swing.JLabel">
<constraints> <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="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> </constraints>
<properties> <properties>
<labelFor value="76436"/> <labelFor value="76436"/>
<text resource-bundle="string" key="label.module"/> <text resource-bundle="string" key="label.module"/>
</properties> </properties>
</component> </component>
<component id="2c7fc" class="javax.swing.JComboBox" binding="groupComboBox"> <component id="5e5a1" class="javax.swing.JCheckBox" binding="unifiedConfig">
<constraints> <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="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"/>
</constraints> </constraints>
<properties/> <properties>
<text resource-bundle="string" key="label.unified.config"/>
</properties>
</component>
<component id="af94e" class="javax.swing.JCheckBox" binding="titleConfig">
<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"/>
</constraints>
<properties>
<text value="禁止提示"/>
</properties>
</component> </component>
</children> </children>
</grid> </grid>

View File

@ -14,22 +14,23 @@ import com.sjhy.plugin.dict.GlobalDict;
import com.sjhy.plugin.dto.SettingsStorageDTO; import com.sjhy.plugin.dto.SettingsStorageDTO;
import com.sjhy.plugin.entity.TableInfo; import com.sjhy.plugin.entity.TableInfo;
import com.sjhy.plugin.entity.Template; import com.sjhy.plugin.entity.Template;
import com.sjhy.plugin.entity.TemplateGroup;
import com.sjhy.plugin.service.CodeGenerateService; import com.sjhy.plugin.service.CodeGenerateService;
import com.sjhy.plugin.service.SettingsStorageService; import com.sjhy.plugin.service.SettingsStorageService;
import com.sjhy.plugin.service.TableInfoService; import com.sjhy.plugin.service.TableInfoService;
import com.sjhy.plugin.tool.*; import com.sjhy.plugin.tool.CacheDataUtils;
import com.sjhy.plugin.tool.ModuleUtils;
import com.sjhy.plugin.tool.ProjectUtils;
import com.sjhy.plugin.tool.StringUtils;
import com.sjhy.plugin.ui.component.TemplateSelectComponent;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter; import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -69,10 +70,6 @@ public class SelectSavePath extends DialogWrapper {
* 路径选择按钮 * 路径选择按钮
*/ */
private JButton pathChooseButton; private JButton pathChooseButton;
/**
* 模板全选框
*/
private JCheckBox allCheckBox;
/** /**
* 模板面板 * 模板面板
*/ */
@ -85,22 +82,10 @@ public class SelectSavePath extends DialogWrapper {
* 禁止提示复选框 * 禁止提示复选框
*/ */
private JCheckBox titleConfig; private JCheckBox titleConfig;
/**
* 分组选择框
*/
private JComboBox<String> groupComboBox;
/**
* 所有模板复选框
*/
private List<JCheckBox> checkBoxList = new ArrayList<>();
/** /**
* 数据缓存工具类 * 数据缓存工具类
*/ */
private CacheDataUtils cacheDataUtils = CacheDataUtils.getInstance(); private CacheDataUtils cacheDataUtils = CacheDataUtils.getInstance();
/**
* 模板组对象
*/
private TemplateGroup templateGroup;
/** /**
* 表信息服务 * 表信息服务
*/ */
@ -123,6 +108,11 @@ public class SelectSavePath extends DialogWrapper {
*/ */
private boolean entityMode; private boolean entityMode;
/**
* 模板选择组件
*/
private TemplateSelectComponent templateSelectComponent;
/** /**
* 构造方法 * 构造方法
*/ */
@ -146,7 +136,6 @@ public class SelectSavePath extends DialogWrapper {
this.project = project; this.project = project;
this.tableInfoService = TableInfoService.getInstance(project); this.tableInfoService = TableInfoService.getInstance(project);
this.codeGenerateService = CodeGenerateService.getInstance(project); this.codeGenerateService = CodeGenerateService.getInstance(project);
this.templateGroup = CurrGroupUtils.getCurrTemplateGroup();
// 初始化module存在资源路径的排前面 // 初始化module存在资源路径的排前面
this.moduleList = new LinkedList<>(); this.moduleList = new LinkedList<>();
for (Module module : ModuleManager.getInstance(project).getModules()) { for (Module module : ModuleManager.getInstance(project).getModules()) {
@ -157,48 +146,32 @@ public class SelectSavePath extends DialogWrapper {
this.moduleList.add(module); this.moduleList.add(module);
} }
} }
initPanel(); this.initPanel();
this.refreshData();
this.initEvent();
init(); init();
setTitle(GlobalDict.TITLE_INFO); setTitle(GlobalDict.TITLE_INFO);
} }
private void initEvent() {
}
private void refreshData() {
}
@Override @Override
protected void doOKAction() { protected void doOKAction() {
onOK(); onOK();
super.doOKAction(); super.doOKAction();
} }
/**
* 获取已经选中的模板
*
* @return 模板对象集合
*/
private List<Template> getSelectTemplate() {
// 获取到已选择的复选框
List<String> selectTemplateNameList = new ArrayList<>();
checkBoxList.forEach(jCheckBox -> {
if (jCheckBox.isSelected()) {
selectTemplateNameList.add(jCheckBox.getText());
}
});
List<Template> selectTemplateList = new ArrayList<>(selectTemplateNameList.size());
if (selectTemplateNameList.isEmpty()) {
return selectTemplateList;
}
// 将复选框转换成对应的模板对象
templateGroup.getElementList().forEach(template -> {
if (selectTemplateNameList.contains(template.getName())) {
selectTemplateList.add(template);
}
});
return selectTemplateList;
}
/** /**
* 确认按钮回调事件 * 确认按钮回调事件
*/ */
private void onOK() { private void onOK() {
List<Template> selectTemplateList = getSelectTemplate(); List<Template> selectTemplateList = templateSelectComponent.getAllSelectedTemplate();
// 如果选择的模板是空的 // 如果选择的模板是空的
if (selectTemplateList.isEmpty()) { if (selectTemplateList.isEmpty()) {
Messages.showWarningDialog("Can't Select Template!", GlobalDict.TITLE_INFO); Messages.showWarningDialog("Can't Select Template!", GlobalDict.TITLE_INFO);
@ -232,7 +205,7 @@ public class SelectSavePath extends DialogWrapper {
tableInfo.setSavePath(savePath); tableInfo.setSavePath(savePath);
tableInfo.setSavePackageName(packageField.getText()); tableInfo.setSavePackageName(packageField.getText());
tableInfo.setPreName(preField.getText()); tableInfo.setPreName(preField.getText());
tableInfo.setTemplateGroupName((String) groupComboBox.getSelectedItem()); tableInfo.setTemplateGroupName(templateSelectComponent.getselectedGroupName());
Module module = getSelectModule(); Module module = getSelectModule();
if (module != null) { if (module != null) {
tableInfo.setSaveModelName(module.getName()); tableInfo.setSaveModelName(module.getName());
@ -240,34 +213,7 @@ public class SelectSavePath extends DialogWrapper {
tableInfoService.save(tableInfo); tableInfoService.save(tableInfo);
// 生成代码 // 生成代码
codeGenerateService.generateByUnifiedConfig(getSelectTemplate(), unifiedConfig.isSelected(), !titleConfig.isSelected(), this.entityMode); codeGenerateService.generateByUnifiedConfig(selectTemplateList, unifiedConfig.isSelected(), !titleConfig.isSelected(), this.entityMode);
}
/**
* 初始化模板组
*/
private void initTemplateGroup() {
//添加模板组
checkBoxList.clear();
templatePanel.removeAll();
templatePanel.repaint();
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);
} }
/** /**
@ -275,7 +221,8 @@ public class SelectSavePath extends DialogWrapper {
*/ */
private void initPanel() { private void initPanel() {
// 初始化模板组 // 初始化模板组
initTemplateGroup(); this.templateSelectComponent = new TemplateSelectComponent();
templatePanel.add(this.templateSelectComponent.getMainPanel(), BorderLayout.CENTER);
//初始化Module选择 //初始化Module选择
for (Module module : this.moduleList) { for (Module module : this.moduleList) {
@ -345,7 +292,7 @@ public class SelectSavePath extends DialogWrapper {
}); });
// 获取选中的表信息鼠标右键的那张表并提示未知类型 // 获取选中的表信息鼠标右键的那张表并提示未知类型
TableInfo tableInfo = null; TableInfo tableInfo;
if(entityMode) { if(entityMode) {
tableInfo = tableInfoService.getTableInfoAndConfigByPsiClass(cacheDataUtils.getSelectPsiClass()); tableInfo = tableInfoService.getTableInfoAndConfigByPsiClass(cacheDataUtils.getSelectPsiClass());
} else { } else {
@ -367,24 +314,9 @@ public class SelectSavePath extends DialogWrapper {
if (!StringUtils.isEmpty(tableInfo.getTemplateGroupName())) { if (!StringUtils.isEmpty(tableInfo.getTemplateGroupName())) {
if (settings.getTemplateGroupMap().containsKey(tableInfo.getTemplateGroupName())) { if (settings.getTemplateGroupMap().containsKey(tableInfo.getTemplateGroupName())) {
groupName = tableInfo.getTemplateGroupName(); groupName = tableInfo.getTemplateGroupName();
this.templateGroup = settings.getTemplateGroupMap().get(groupName);
// 选中的模板组发生变化尝试重新初始化
initTemplateGroup();
} }
} }
for (String key : settings.getTemplateGroupMap().keySet()) { templateSelectComponent.setSelectedGroupName(groupName);
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();
});
String savePath = tableInfo.getSavePath(); String savePath = tableInfo.getSavePath();
if (!StringUtils.isEmpty(savePath)) { if (!StringUtils.isEmpty(savePath)) {
// 判断是否需要拼接项目路径 // 判断是否需要拼接项目路径

View File

@ -0,0 +1,136 @@
package com.sjhy.plugin.ui.component;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.ui.components.JBCheckBox;
import com.sjhy.plugin.entity.Template;
import com.sjhy.plugin.entity.TemplateGroup;
import com.sjhy.plugin.service.SettingsStorageService;
import com.sjhy.plugin.tool.StringUtils;
import lombok.Getter;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 模板选择组件
*
* @author makejava
* @version 1.0.0
* @date 2021/08/16 16:18
*/
public class TemplateSelectComponent {
@Getter
private JPanel mainPanel;
/**
* 分组
*/
private ComboBox<String> groupComboBox;
/**
* 选中所有复选框
*/
private JBCheckBox allCheckbox;
/**
* 所有复选框
*/
private List<JBCheckBox> checkBoxList;
/**
* 模板面板
*/
private JPanel templatePanel;
public TemplateSelectComponent() {
this.init();
}
private void init() {
this.mainPanel = new JPanel(new BorderLayout());
JPanel topPanel = new JPanel(new BorderLayout());
this.groupComboBox = new ComboBox<>();
this.groupComboBox.setSwingPopup(false);
this.groupComboBox.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
String groupName = (String) groupComboBox.getSelectedItem();
if (StringUtils.isEmpty(groupName)) {
return;
}
refreshTemplatePanel(groupName);
}
});
this.allCheckbox = new JBCheckBox("All");
this.allCheckbox.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (checkBoxList == null) {
return;
}
for (JBCheckBox checkBox : checkBoxList) {
checkBox.setSelected(allCheckbox.isSelected());
}
}
});
topPanel.add(this.groupComboBox, BorderLayout.WEST);
topPanel.add(this.allCheckbox, BorderLayout.EAST);
this.mainPanel.add(topPanel, BorderLayout.NORTH);
this.templatePanel = new JPanel(new GridLayout(-1, 2));
this.mainPanel.add(templatePanel, BorderLayout.CENTER);
this.refreshData();
}
private void refreshData() {
this.groupComboBox.removeAllItems();
for (String groupName : SettingsStorageService.getSettingsStorage().getTemplateGroupMap().keySet()) {
this.groupComboBox.addItem(groupName);
}
}
private void refreshTemplatePanel(String groupName) {
this.allCheckbox.setSelected(false);
this.templatePanel.removeAll();
this.checkBoxList = new ArrayList<>();
TemplateGroup templateGroup = SettingsStorageService.getSettingsStorage().getTemplateGroupMap().get(groupName);
for (Template template : templateGroup.getElementList()) {
JBCheckBox checkBox = new JBCheckBox(template.getName());
this.checkBoxList.add(checkBox);
this.templatePanel.add(checkBox);
}
this.mainPanel.updateUI();
}
public String getselectedGroupName() {
return (String) this.groupComboBox.getSelectedItem();
}
public void setSelectedGroupName(String groupName) {
this.groupComboBox.setSelectedItem(groupName);
}
public List<Template> getAllSelectedTemplate() {
String groupName = (String) this.groupComboBox.getSelectedItem();
if (StringUtils.isEmpty(groupName)) {
return Collections.emptyList();
}
TemplateGroup templateGroup = SettingsStorageService.getSettingsStorage().getTemplateGroupMap().get(groupName);
Map<String, Template> map = templateGroup.getElementList().stream().collect(Collectors.toMap(Template::getName, val -> val));
List<Template> result = new ArrayList<>();
for (JBCheckBox checkBox : this.checkBoxList) {
if (checkBox.isSelected()) {
Template template = map.get(checkBox.getText());
if (template != null) {
result.add(template);
}
}
}
return result;
}
}