优化大量代码,修复关闭项目时编辑框未释放导致报错问题。

This commit is contained in:
makejava 2018-07-18 16:26:12 +08:00
parent 6f2e067292
commit 4ecec56a12
16 changed files with 422 additions and 448 deletions

View File

@ -1,35 +1,20 @@
package com.sjhy.plugin.comm;
import com.sjhy.plugin.entity.TypeMapperGroup;
import com.sjhy.plugin.service.ConfigService;
import com.sjhy.plugin.service.impl.ConfigServiceImpl;
import com.sjhy.plugin.tool.ConfigInfo;
public abstract class ServiceComm {
protected ConfigService getConfigService() {
try {
return ConfigService.getInstance();
} catch (Exception e) {
e.printStackTrace();
return new ConfigServiceImpl();
}
protected ConfigInfo getConfigInfo() {
return ConfigInfo.getInstance();
}
protected TypeMapperGroup getCurrMapper() {
ConfigService configService = getConfigService();
return configService.getTypeMapperGroupMap().get(configService.getCurrTemplateGroupName());
ConfigInfo configInfo = getConfigInfo();
return configInfo.getTypeMapperGroupMap().get(configInfo.getCurrTemplateGroupName());
}
protected void setCurrMapper(TypeMapperGroup typeMapper) {
ConfigService configService = getConfigService();
configService.getTypeMapperGroupMap().put(configService.getCurrTypeMapperGroupName(), typeMapper);
ConfigInfo configInfo = getConfigInfo();
configInfo.getTypeMapperGroupMap().put(configInfo.getCurrTypeMapperGroupName(), typeMapper);
}
// protected Map<String, String> getCurrTemplate() {
// ConfigService configService = getConfigService();
// return configService.getTemplateGroup().get(configService.getCurrTemplateGroupName());
// }
//
// protected void setCurrTemplate(Map<String, String> template) {
// ConfigService configService = getConfigService();
// configService.getTemplateGroup().put(configService.getCurrTemplateGroupName(), template);
// }
}

View File

@ -12,8 +12,17 @@ import lombok.Data;
*/
@Data
public class ColumnConfig extends CommClone<ColumnConfig> {
/**
* 标题
*/
private String title;
/**
* 类型
*/
private ColumnConfigType type;
/**
* 可选值逗号分割
*/
private String selectValue;
public ColumnConfig(String title, ColumnConfigType type) {

View File

@ -1,64 +0,0 @@
package com.sjhy.plugin.service;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.sjhy.plugin.entity.ColumnConfigGroup;
import com.sjhy.plugin.entity.TemplateGroup;
import com.sjhy.plugin.entity.TypeMapperGroup;
import java.util.Map;
/**
* 配置服务接口
*
* @author makejava
* @version 1.0.0
* @since 2018/07/17 13:10
*/
public interface ConfigService extends PersistentStateComponent<ConfigService> {
/**
* 默认名称
*/
String DEFAULT_NAME = "Default";
/**
* 获取单例实例对象
*
* @return 实例对象
*/
static ConfigService getInstance() {
return ServiceManager.getService(ConfigService.class);
}
String getCurrTypeMapperGroupName();
void setCurrTypeMapperGroupName(String currTypeMapperGroupName);
Map<String, TypeMapperGroup> getTypeMapperGroupMap();
String getCurrTemplateGroupName();
void setCurrTemplateGroupName(String currTemplateGroupName);
String getEncode();
void setEncode(String encode);
String getAuthor();
void setAuthor(String author);
void setTypeMapperGroupMap(Map<String, TypeMapperGroup> typeMapperGroupMap);
Map<String, TemplateGroup> getTemplateGroupMap();
void setTemplateGroupMap(Map<String, TemplateGroup> templateGroupMap);
Map<String, ColumnConfigGroup> getColumnConfigGroupMap();
void setColumnConfigGroupMap(Map<String, ColumnConfigGroup> columnConfigGroupMap);
String getCurrColumnConfigGroupName();
void setCurrColumnConfigGroupName(String currColumnConfigGroupName);
}

View File

@ -1,218 +0,0 @@
package com.sjhy.plugin.service.impl;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.sjhy.plugin.entity.*;
import com.sjhy.plugin.service.ConfigService;
import com.sjhy.plugin.tool.FileUtils;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* 配置服务实现类
*
* @author makejava
* @version 1.0.0
* @since 2018/07/17 13:10
*/
@State(name = "EasyCodeSetting", storages = @Storage("$APP_CONFIG$/EasyCode-settings.xml"))
public class ConfigServiceImpl implements ConfigService {
//当前类型映射组名
private String currTypeMapperGroupName;
//类型映射组
private Map<String, TypeMapperGroup> typeMapperGroupMap;
//当前模板组名
private String currTemplateGroupName;
//模板组
private Map<String, TemplateGroup> templateGroupMap;
//当前配置表组名
private String currColumnConfigGroupName;
//配置表组
private Map<String, ColumnConfigGroup> columnConfigGroupMap;
//默认编码
private String encode;
//作者
private String author;
public ConfigServiceImpl() {
initDefault();
}
@Nullable
@Override
public ConfigService getState() {
return this;
}
@Override
public void loadState(ConfigService configService) {
if (configService==null || configService.getTemplateGroupMap()==null || configService.getTypeMapperGroupMap()==null || configService.getColumnConfigGroupMap()==null) {
return;
}
//重点没有数据时不要序列化
if (configService.getTypeMapperGroupMap().isEmpty()) {
return;
}
if (configService.getTemplateGroupMap().isEmpty()) {
return;
}
if (configService.getColumnConfigGroupMap().isEmpty()) {
return;
}
//加载配置信息
XmlSerializerUtil.copyBean(configService, this);
}
/**
* 初始化默认设置
*/
private void initDefault() {
if (this.encode==null) {
this.encode = "UTF-8";
}
if (this.author==null) {
this.author = "Mr.Wang";
}
if (this.currTemplateGroupName==null) {
this.currTemplateGroupName = DEFAULT_NAME;
}
if (this.currTypeMapperGroupName==null) {
this.currTypeMapperGroupName = DEFAULT_NAME;
}
if (this.currColumnConfigGroupName==null) {
this.currColumnConfigGroupName = DEFAULT_NAME;
}
//配置默认模板
if (this.templateGroupMap==null) {
this.templateGroupMap = new LinkedHashMap<>();
}
TemplateGroup templateGroup = new TemplateGroup();
List<Template> templateList = new ArrayList<>();
templateList.add(new Template("entity", loadTemplate("entity")));
templateList.add(new Template("dao", loadTemplate("dao")));
templateGroup.setName(DEFAULT_NAME);
templateGroup.setElementList(templateList);
this.templateGroupMap.put(DEFAULT_NAME, templateGroup);
//配置默认类型映射
if (this.typeMapperGroupMap==null) {
this.typeMapperGroupMap = new LinkedHashMap<>();
}
TypeMapperGroup typeMapperGroup = new TypeMapperGroup();
List<TypeMapper> typeMapperList = new ArrayList<>();
typeMapperList.add(new TypeMapper("varchar(\\(\\d+\\))?", "java.lang.String"));
typeMapperList.add(new TypeMapper("decimal(\\(\\d+\\))?", "java.lang.Double"));
typeMapperList.add(new TypeMapper("integer", "java.lang.Integer"));
typeMapperList.add(new TypeMapper("int4", "java.lang.Integer"));
typeMapperList.add(new TypeMapper("int8", "java.lang.Long"));
typeMapperList.add(new TypeMapper("bigint", "java.lang.Long"));
typeMapperList.add(new TypeMapper("datetime", "java.util.Date"));
typeMapperList.add(new TypeMapper("timestamp", "java.util.Date"));
typeMapperList.add(new TypeMapper("boolean", "java.lang.Boolean"));
typeMapperGroup.setName(DEFAULT_NAME);
typeMapperGroup.setElementList(typeMapperList);
typeMapperGroupMap.put(DEFAULT_NAME, typeMapperGroup);
//初始化表配置
if (this.columnConfigGroupMap==null) {
this.columnConfigGroupMap = new LinkedHashMap<>();
}
ColumnConfigGroup columnConfigGroup = new ColumnConfigGroup();
List<ColumnConfig> columnConfigList = new ArrayList<>();
columnConfigList.add(new ColumnConfig("disable", ColumnConfigType.BOOLEAN));
columnConfigGroup.setName(DEFAULT_NAME);
columnConfigGroup.setElementList(columnConfigList);
columnConfigGroupMap.put(DEFAULT_NAME, columnConfigGroup);
}
private String loadTemplate(String name) {
return FileUtils.getInstance().read(getClass().getResourceAsStream("/template/"+name+".vm")).replaceAll("\r", "");
}
//GET SET
@Override
public String getCurrTypeMapperGroupName() {
return currTypeMapperGroupName;
}
@Override
public void setCurrTypeMapperGroupName(String currTypeMapperGroupName) {
this.currTypeMapperGroupName = currTypeMapperGroupName;
}
@Override
public Map<String, TypeMapperGroup> getTypeMapperGroupMap() {
return typeMapperGroupMap;
}
@Override
public String getCurrTemplateGroupName() {
return currTemplateGroupName;
}
@Override
public void setCurrTemplateGroupName(String currTemplateGroupName) {
this.currTemplateGroupName = currTemplateGroupName;
}
@Override
public String getEncode() {
return encode;
}
@Override
public void setEncode(String encode) {
this.encode = encode;
}
@Override
public String getAuthor() {
return author;
}
@Override
public void setAuthor(String author) {
this.author = author;
}
@Override
public void setTypeMapperGroupMap(Map<String, TypeMapperGroup> typeMapperGroupMap) {
this.typeMapperGroupMap = typeMapperGroupMap;
}
@Override
public Map<String, TemplateGroup> getTemplateGroupMap() {
return templateGroupMap;
}
@Override
public void setTemplateGroupMap(Map<String, TemplateGroup> templateGroupMap) {
this.templateGroupMap = templateGroupMap;
}
@Override
public Map<String, ColumnConfigGroup> getColumnConfigGroupMap() {
return columnConfigGroupMap;
}
@Override
public void setColumnConfigGroupMap(Map<String, ColumnConfigGroup> columnConfigGroupMap) {
this.columnConfigGroupMap = columnConfigGroupMap;
}
@Override
public String getCurrColumnConfigGroupName() {
return currColumnConfigGroupName;
}
@Override
public void setCurrColumnConfigGroupName(String currColumnConfigGroupName) {
this.currColumnConfigGroupName = currColumnConfigGroupName;
}
}

View File

@ -0,0 +1,158 @@
package com.sjhy.plugin.tool;
import com.intellij.openapi.components.*;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.intellij.util.xmlb.annotations.Transient;
import com.sjhy.plugin.entity.*;
import lombok.Data;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* 全局配置信息
*
* @author makejava
* @version 1.0.0
* @since 2018/07/18 09:33
*/
@Data
@State(name = "EasyCodeSetting", storages = @Storage("easy-code-setting.xml"))
public class ConfigInfo implements PersistentStateComponent<ConfigInfo> {
/**
* 默认名称
*/
@Transient
public static final String DEFAULT_NAME = "Default";
private String version;
/**
* 当前类型映射组名
*/
private String currTypeMapperGroupName;
/**
* 类型映射组
*/
private Map<String, TypeMapperGroup> typeMapperGroupMap;
/**
* 当前模板组名
*/
private String currTemplateGroupName;
/**
* 模板组
*/
private Map<String, TemplateGroup> templateGroupMap;
/**
* 当前配置表组名
*/
private String currColumnConfigGroupName;
/**
* 配置表组
*/
private Map<String, ColumnConfigGroup> columnConfigGroupMap;
/**
* 默认编码
*/
private String encode;
/**
* 作者
*/
private String author;
/**
* 获取单例实例对象
*
* @return 实例对象
*/
public static ConfigInfo getInstance() {
return ServiceManager.getService(ConfigInfo.class);
}
/**
* 默认构造方法
*/
@SuppressWarnings("unused")
public ConfigInfo() {
initDefault();
}
/**
* 初始化默认设置
*/
private void initDefault() {
// 默认编码
this.encode = "UTF-8";
// 作者名称
this.author = "makejava";
// 当前各项分组名称
this.currTemplateGroupName = DEFAULT_NAME;
this.currTypeMapperGroupName = DEFAULT_NAME;
this.currColumnConfigGroupName = DEFAULT_NAME;
//配置默认模板
if (this.templateGroupMap==null) {
this.templateGroupMap = new LinkedHashMap<>();
}
TemplateGroup templateGroup = new TemplateGroup();
List<Template> templateList = new ArrayList<>();
templateList.add(new Template("entity", loadTemplate("entity")));
templateList.add(new Template("dao", loadTemplate("dao")));
templateGroup.setName(DEFAULT_NAME);
templateGroup.setElementList(templateList);
this.templateGroupMap.put(DEFAULT_NAME, templateGroup);
//配置默认类型映射
if (this.typeMapperGroupMap==null) {
this.typeMapperGroupMap = new LinkedHashMap<>();
}
TypeMapperGroup typeMapperGroup = new TypeMapperGroup();
List<TypeMapper> typeMapperList = new ArrayList<>();
typeMapperList.add(new TypeMapper("varchar(\\(\\d+\\))?", "java.lang.String"));
typeMapperList.add(new TypeMapper("decimal(\\(\\d+\\))?", "java.lang.Double"));
typeMapperList.add(new TypeMapper("integer", "java.lang.Integer"));
typeMapperList.add(new TypeMapper("int4", "java.lang.Integer"));
typeMapperList.add(new TypeMapper("int8", "java.lang.Long"));
typeMapperList.add(new TypeMapper("bigint", "java.lang.Long"));
typeMapperList.add(new TypeMapper("datetime", "java.util.Date"));
typeMapperList.add(new TypeMapper("timestamp", "java.util.Date"));
typeMapperList.add(new TypeMapper("boolean", "java.lang.Boolean"));
typeMapperGroup.setName(DEFAULT_NAME);
typeMapperGroup.setElementList(typeMapperList);
typeMapperGroupMap.put(DEFAULT_NAME, typeMapperGroup);
//初始化表配置
if (this.columnConfigGroupMap==null) {
this.columnConfigGroupMap = new LinkedHashMap<>();
}
ColumnConfigGroup columnConfigGroup = new ColumnConfigGroup();
List<ColumnConfig> columnConfigList = new ArrayList<>();
columnConfigList.add(new ColumnConfig("disable", ColumnConfigType.BOOLEAN));
columnConfigList.add(new ColumnConfig("type", ColumnConfigType.SELECT, "ENUM,SELECT,RADIO,CHECKBOX"));
columnConfigGroup.setName(DEFAULT_NAME);
columnConfigGroup.setElementList(columnConfigList);
columnConfigGroupMap.put(DEFAULT_NAME, columnConfigGroup);
}
/**
* 加载模板文件
* @param name 模板名称
* @return 模板文件内容
*/
private static String loadTemplate(String name) {
return FileUtils.getInstance().read(ConfigInfo.class.getResourceAsStream("/template/"+name+".vm")).replaceAll("\r", "");
}
@Nullable
@Override
public ConfigInfo getState() {
return this;
}
@Override
public void loadState(@NotNull ConfigInfo configInfo) {
XmlSerializerUtil.copyBean(configInfo, this);
}
}

View File

@ -5,7 +5,6 @@ import com.intellij.openapi.vfs.VirtualFileManager;
import com.sjhy.plugin.entity.Callback;
import com.sjhy.plugin.entity.TableInfo;
import com.sjhy.plugin.entity.Template;
import com.sjhy.plugin.service.ConfigService;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
@ -21,10 +20,12 @@ public class VelocityUtils {
private static class Instance {
private static final VelocityUtils ME = new VelocityUtils();
}
public static VelocityUtils getInstance() {
return Instance.ME;
}
private VelocityUtils(){
private VelocityUtils() {
velocityEngine = new VelocityEngine();
}
@ -34,9 +35,9 @@ public class VelocityUtils {
private NameUtils nameUtils = NameUtils.getInstance();
private FileUtils fileUtils = FileUtils.getInstance();
private String generate(String template, Map<String,Object> map, String encode) {
private String generate(String template, Map<String, Object> map, String encode) {
VelocityContext velocityContext = new VelocityContext();
if (map==null) {
if (map == null) {
map = new HashMap<>();
}
map.forEach(velocityContext::put);
@ -49,10 +50,10 @@ public class VelocityUtils {
//设置全局参数
private Map<String, Object> handlerMap() {
ConfigService configService = ConfigService.getInstance();
Map<String, Object> map = new HashMap<>();
String encode = configService.getEncode();
String author = configService.getAuthor();
ConfigInfo configInfo = ConfigInfo.getInstance();
Map<String, Object> map = new HashMap<>(10);
String encode = configInfo.getEncode();
String author = configInfo.getAuthor();
List<TableInfo> tableInfoList = tableInfoUtils.handler(cacheDataUtils.getDbTableList());
Module selectModule = cacheDataUtils.getSelectModule();
@ -65,7 +66,7 @@ public class VelocityUtils {
map.put("tool", nameUtils);
//设置的包名
map.put("packageName", cacheDataUtils.getPackageName());
if (selectModule!=null){
if (selectModule != null) {
//module路径
//noinspection ConstantConditions
map.put("modulePath", selectModule.getModuleFile().getParent().getPath());
@ -78,15 +79,15 @@ public class VelocityUtils {
File path = new File(savePath);
if (!new File(savePath).exists()) {
int result = JOptionPane.showConfirmDialog(null, "Save Path Is Not Exists, Confirm Create?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
if(result==0){
if(!path.mkdirs()){
if (result == 0) {
if (!path.mkdirs()) {
return false;
}
}else{
} else {
return false;
}
}
if (path.isFile()){
if (path.isFile()) {
JOptionPane.showMessageDialog(null, "Error,Save Path Is File!");
return false;
}
@ -96,15 +97,15 @@ public class VelocityUtils {
//创建或覆盖文件
private boolean coverFile(File file) {
if (file.exists()) {
if (file.isDirectory()){
if (file.isDirectory()) {
JOptionPane.showMessageDialog(null, "Error,Save File Is Path!");
return false;
}
int result = JOptionPane.showConfirmDialog(null, "File "+file.getName()+" Exists, Confirm Continue?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
int result = JOptionPane.showConfirmDialog(null, "File " + file.getName() + " Exists, Confirm Continue?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
return result == 0;
}else{
} else {
try {
if(!file.createNewFile()){
if (!file.createNewFile()) {
return false;
}
} catch (IOException e) {
@ -116,13 +117,13 @@ public class VelocityUtils {
public void handler() {
AtomicReference<String> savePath = new AtomicReference<>(cacheDataUtils.getSavePath());
if (!createPath(savePath.get())){
if (!createPath(savePath.get())) {
return;
}
List<TableInfo> tableInfoList = tableInfoUtils.handler(cacheDataUtils.getDbTableList());
List<Template> templateList = cacheDataUtils.getSelectTemplate();
ConfigService configService = ConfigService.getInstance();
String encode = configService.getEncode();
ConfigInfo configInfo = ConfigInfo.getInstance();
String encode = configInfo.getEncode();
Map<String, Object> map = handlerMap();
tableInfoList.forEach(tableInfo -> {
@ -137,18 +138,18 @@ public class VelocityUtils {
//保存路径
String callbackSavePath = callback.getSavePath();
//是否使用保存路径
if (callbackSavePath!=null && callbackSavePath.trim().length()>0){
if (!createPath(callbackSavePath)){
if (callbackSavePath != null && callbackSavePath.trim().length() > 0) {
if (!createPath(callbackSavePath)) {
return;
}
savePath.set(callbackSavePath);
}
if (fileName==null) {
fileName = tableInfo.getName()+"Default.java";
if (fileName == null) {
fileName = tableInfo.getName() + "Default.java";
}
File file = new File(new File(savePath.get()), fileName);
//覆盖或创建文件
if (!coverFile(file)){
if (!coverFile(file)) {
return;
}
fileUtils.write(file, content);
@ -162,7 +163,7 @@ public class VelocityUtils {
private Set<String> getImportList(TableInfo tableInfo) {
Set<String> result = new TreeSet<>();
tableInfo.getFullColumn().forEach(columnInfo -> {
if (!columnInfo.getType().startsWith("java.lang")){
if (!columnInfo.getType().startsWith("java.lang")) {
result.add(columnInfo.getType());
}
});

View File

@ -3,7 +3,7 @@ package com.sjhy.plugin.ui;
import com.intellij.openapi.ui.VerticalFlowLayout;
import com.sjhy.plugin.comm.CommClone;
import com.sjhy.plugin.entity.AbstractGroup;
import com.sjhy.plugin.service.ConfigService;
import com.sjhy.plugin.tool.ConfigInfo;
import javax.swing.*;
import java.awt.*;
@ -12,7 +12,7 @@ import java.util.Map;
import java.util.Set;
@SuppressWarnings("unused")
public abstract class AbstractGroupPanel<T extends AbstractGroup<T,E>, E extends CommClone> {
public abstract class AbstractGroupPanel<T extends AbstractGroup<T, E>, E extends CommClone> {
private JPanel mainPanel;
private JComboBox groupComboBox;
private JButton copyGroupButton;
@ -68,7 +68,7 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T,E>, E extends
private void initItem(List<E> itemList) {
initFlag = false;
itemGroupPanel.removeAll();
if (itemList.isEmpty()){
if (itemList.isEmpty()) {
itemGroupPanel.updateUI();
initFlag = true;
return;
@ -83,7 +83,7 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T,E>, E extends
return;
}
String itemName = button.getText();
for (int i=0; i < itemList.size(); i++) {
for (int i = 0; i < itemList.size(); i++) {
E element = itemList.get(i);
if (itemName.equals(getItemName(element))) {
selectItemIndex = i;
@ -104,11 +104,11 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T,E>, E extends
private void initEvent() {
//切换分组事件
groupComboBox.addActionListener(e -> {
if (!initFlag){
if (!initFlag) {
return;
}
String groupName = (String) groupComboBox.getSelectedItem();
if (groupName==null) {
if (groupName == null) {
return;
}
if (currGroupName.equals(groupName)) {
@ -121,15 +121,15 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T,E>, E extends
if (!initFlag) {
return;
}
String value = JOptionPane.showInputDialog(null, "Input Group Name:", currGroupName+" Copy");
if (value==null) {
String value = JOptionPane.showInputDialog(null, "Input Group Name:", currGroupName + " Copy");
if (value == null) {
return;
}
if (value.trim().length()==0){
if (value.trim().length() == 0) {
JOptionPane.showMessageDialog(null, "Group Name Can't Is Empty!");
return;
}
if (group.containsKey(value)){
if (group.containsKey(value)) {
JOptionPane.showMessageDialog(null, "Group Name Already exist!");
return;
}
@ -144,14 +144,14 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T,E>, E extends
if (!initFlag) {
return;
}
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Group "+currGroupName+"?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
if (result==0){
if(ConfigService.DEFAULT_NAME.equals(currGroupName)){
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Group " + currGroupName + "?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
if (result == 0) {
if (ConfigInfo.DEFAULT_NAME.equals(currGroupName)) {
JOptionPane.showMessageDialog(null, "Can't Delete Default Group!");
return;
}
group.remove(currGroupName);
init(group, ConfigService.DEFAULT_NAME);
init(group, ConfigInfo.DEFAULT_NAME);
}
});
//添加元素事件
@ -160,22 +160,22 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T,E>, E extends
return;
}
String value = JOptionPane.showInputDialog(null, "Input Item Name:", "Demo");
if (value==null) {
if (value == null) {
return;
}
if (value.trim().length()==0){
if (value.trim().length() == 0) {
JOptionPane.showMessageDialog(null, "Item Name Can't Is Empty!");
return;
}
List<E> itemList = group.get(currGroupName).getElementList();
for (E item : itemList) {
if (getItemName(item).equals(value)){
if (getItemName(item).equals(value)) {
JOptionPane.showMessageDialog(null, "Item Name Already exist!");
return;
}
}
itemList.add(createItem(value));
selectItemIndex = itemList.size()-1;
selectItemIndex = itemList.size() - 1;
initItem(itemList);
});
//删除元素
@ -188,11 +188,11 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T,E>, E extends
return;
}
String itemName = getItemName(itemList.get(selectItemIndex));
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Item "+itemName+"?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
if (result==0) {
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Item " + itemName + "?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
if (result == 0) {
itemList.remove(selectItemIndex);
if (selectItemIndex>=itemList.size()) {
selectItemIndex = itemList.size()-1;
if (selectItemIndex >= itemList.size()) {
selectItemIndex = itemList.size() - 1;
}
initItem(itemList);
}
@ -208,11 +208,11 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T,E>, E extends
}
E item = itemList.get(selectItemIndex);
String itemName = getItemName(item);
String value = JOptionPane.showInputDialog(null, "Input Item Name:", itemName+" Copy");
if (value==null) {
String value = JOptionPane.showInputDialog(null, "Input Item Name:", itemName + " Copy");
if (value == null) {
return;
}
if (value.trim().length()==0){
if (value.trim().length() == 0) {
JOptionPane.showMessageDialog(null, "Item Name Can't Is Empty!");
return;
}
@ -220,7 +220,7 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T,E>, E extends
item = (E) item.clone();
setItemName(item, value);
itemList.add(item);
selectItemIndex = itemList.size()-1;
selectItemIndex = itemList.size() - 1;
initItem(itemList);
});
}

View File

@ -5,14 +5,21 @@ import com.intellij.util.ui.ComboBoxCellEditor;
import com.sjhy.plugin.comm.CommClone;
import com.sjhy.plugin.entity.AbstractGroup;
import com.sjhy.plugin.entity.ColumnConfig;
import com.sjhy.plugin.service.ConfigService;
import com.sjhy.plugin.tool.ConfigInfo;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import java.util.*;
public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T,E>, E extends CommClone> {
/**
* 抽象的表分组面板
*
* @author makejava
* @version 1.0.0
* @since 2018/07/17 13:10
*/
public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T, E>, E extends CommClone> {
private JPanel mainPanel;
private JComboBox groupComboBox;
private JTable table;
@ -25,7 +32,7 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T,E>, E ex
private DefaultTableModel tableModel;
protected Map<String,T> group;
protected Map<String, T> group;
protected String currGroupName;
private boolean initFlag;
@ -36,11 +43,13 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T,E>, E ex
initEvent();
}
protected AbstractGroup<T,E> getCurrGroup() {
protected AbstractGroup<T, E> getCurrGroup() {
return this.group.get(this.currGroupName);
}
//刷新类类型配置
/**
* 刷新类类型配置
*/
private void refreshEditorType() {
for (ColumnConfig column : columnConfigInfo) {
TableColumn tableColumn = table.getColumn(column.getTitle());
@ -58,6 +67,8 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T,E>, E ex
case BOOLEAN:
tableColumn.setCellEditor(new BooleanTableCellEditor());
break;
default:
break;
}
}
}
@ -87,11 +98,11 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T,E>, E ex
private void initEvent() {
//切换分组事件
groupComboBox.addActionListener(e -> {
if (!initFlag){
if (!initFlag) {
return;
}
String groupName = (String) groupComboBox.getSelectedItem();
if (groupName==null) {
if (groupName == null) {
return;
}
if (currGroupName.equals(groupName)) {
@ -104,15 +115,15 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T,E>, E ex
if (!initFlag) {
return;
}
String value = JOptionPane.showInputDialog(null, "Input Group Name:", currGroupName+" Copy");
if (value==null) {
String value = JOptionPane.showInputDialog(null, "Input Group Name:", currGroupName + " Copy");
if (value == null) {
return;
}
if (value.trim().length()==0){
if (value.trim().length() == 0) {
JOptionPane.showMessageDialog(null, "Group Name Can't Is Empty!");
return;
}
if (group.containsKey(value)){
if (group.containsKey(value)) {
JOptionPane.showMessageDialog(null, "Group Name Already exist!");
return;
}
@ -127,14 +138,14 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T,E>, E ex
if (!initFlag) {
return;
}
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Group "+currGroupName+"?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
if (result==0){
if(ConfigService.DEFAULT_NAME.equals(currGroupName)){
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Group " + currGroupName + "?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
if (result == 0) {
if (ConfigInfo.DEFAULT_NAME.equals(currGroupName)) {
JOptionPane.showMessageDialog(null, "Can't Delete Default Group!");
return;
}
group.remove(currGroupName);
init(group, ConfigService.DEFAULT_NAME);
init(group, ConfigInfo.DEFAULT_NAME);
}
});
//添加元素事件
@ -143,16 +154,16 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T,E>, E ex
return;
}
String value = JOptionPane.showInputDialog(null, "Input Item Name:", "Demo");
if (value==null) {
if (value == null) {
return;
}
if (value.trim().length()==0){
if (value.trim().length() == 0) {
JOptionPane.showMessageDialog(null, "Item Name Can't Is Empty!");
return;
}
List<E> itemList = group.get(currGroupName).getElementList();
for (E item : itemList) {
if (getItemName(item).equals(value)){
if (getItemName(item).equals(value)) {
JOptionPane.showMessageDialog(null, "Item Name Already exist!");
return;
}
@ -170,9 +181,9 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T,E>, E ex
return;
}
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Selected Item?", "Title Info", JOptionPane.OK_CANCEL_OPTION);
if (result==0) {
if (result == 0) {
int[] rows = table.getSelectedRows();
for (int i = rows.length-1; i>=0; i--) {
for (int i = rows.length - 1; i >= 0; i--) {
tableModel.removeRow(rows[i]);
getCurrGroup().getElementList().remove(rows[i]);
}
@ -190,7 +201,7 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T,E>, E ex
//用于数据回绑定
protected void refresh() {
if (tableModel==null){
if (tableModel == null) {
return;
}
Vector vector = tableModel.getDataVector();
@ -201,11 +212,11 @@ public abstract class AbstractTableGroupPanel<T extends AbstractGroup<T,E>, E ex
Object[] itemArr = new Object[item.size()];
int i = 0;
for (Object obj2 : item) {
if (obj2!=null && obj2 instanceof String) {
if (obj2 != null && obj2 instanceof String) {
String str = (String) obj2;
str = str.trim();
obj2 = str;
if (str.isEmpty()){
if (str.isEmpty()) {
obj2 = null;
}
}

View File

@ -3,14 +3,16 @@ package com.sjhy.plugin.ui;
import com.intellij.ui.BooleanTableCellEditor;
import com.intellij.util.ui.ComboBoxCellEditor;
import com.sjhy.plugin.entity.*;
import com.sjhy.plugin.service.ConfigService;
import com.sjhy.plugin.tool.CacheDataUtils;
import com.sjhy.plugin.tool.ConfigInfo;
import com.sjhy.plugin.tool.TableInfoUtils;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import java.awt.event.*;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.*;
public class ConfigTableDialog extends JDialog {
@ -71,8 +73,8 @@ public class ConfigTableDialog extends JDialog {
private void init() {
initFlag = false;
ConfigService configService = ConfigService.getInstance();
ColumnConfigGroup columnConfigGroup = configService.getColumnConfigGroupMap().get(configService.getCurrColumnConfigGroupName());
ConfigInfo configInfo = ConfigInfo.getInstance();
ColumnConfigGroup columnConfigGroup = configInfo.getColumnConfigGroupMap().get(configInfo.getCurrColumnConfigGroupName());
columnConfigList = getInitColumn(columnConfigGroup.getElementList());
//绑定数据
tableInfo = tableInfoUtils.handler(Collections.singletonList(cacheDataUtils.getSelectDbTable())).get(0);

View File

@ -11,24 +11,44 @@ import com.sjhy.plugin.entity.Template;
import javax.swing.*;
import java.awt.*;
/**
* 模板编辑框面板
*
* @author makejava
* @version 1.0.0
* @since 2018/07/18 09:33
*/
public class EditTemplatePanel {
private JPanel mainPanel;
private JPanel editPanel;
private Template template;
private Editor editor;
/**
* 编辑框支持的文件类型
*/
private final static FileType FILE_TYPE = FileTypeManager.getInstance().getFileTypeByExtension("vm");
/**
* 编辑框大小样式配置
*/
private final static GridConstraints GRID_CONSTRAINTS = new GridConstraints(0, 0, 1, 1,
GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED,
null, new Dimension(600, 400), null,
0, true);
/**
* 默认构造方法
* @param template
*/
EditTemplatePanel(Template template) {
this.template = template;
init();
}
/**
* 初始化编辑框
*/
private void init() {
//初始化系统编辑器
EditorFactory factory = EditorFactory.getInstance();
@ -38,11 +58,27 @@ public class EditTemplatePanel {
editPanel.add(editor.getComponent(), GRID_CONSTRAINTS);
}
/**
* 刷新编辑可内容
*/
public void refresh() {
this.template.setCode(editor.getDocument().getText());
}
/**
* 获取主面板
* @return 主面板
*/
public JPanel getMainPanel() {
return mainPanel;
}
/**
* 释放掉编辑框防止内存占用
*/
public void disposeEditor() {
if (editor!=null && !editor.isDisposed()) {
EditorFactory.getInstance().releaseEditor(editor);
}
}
}

View File

@ -2,7 +2,7 @@ package com.sjhy.plugin.ui;
import com.intellij.openapi.options.Configurable;
import com.sjhy.plugin.comm.ServiceComm;
import com.sjhy.plugin.service.ConfigService;
import com.sjhy.plugin.tool.ConfigInfo;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -10,17 +10,25 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
public class MainSetting extends ServiceComm implements Configurable, Configurable.Composite {
//主面板
/**
* 主面板
*/
private JPanel mainPanel;
//编码选择下拉框
/**
* 编码选择下拉框
*/
private JComboBox encodeComboBox;
//作者编辑框
/**
* 作者编辑框
*/
private JTextField authorTextField;
//全局配置服务
private ConfigService configService;
/**
* 全局配置服务
*/
private ConfigInfo configInfo;
public MainSetting(ConfigService configService) {
this.configService = configService;
public MainSetting(ConfigInfo configInfo) {
this.configInfo = configInfo;
init();
}
@ -29,8 +37,8 @@ public class MainSetting extends ServiceComm implements Configurable, Configurab
*/
private void init() {
//初始化数据
authorTextField.setText(configService.getAuthor());
encodeComboBox.setSelectedItem(configService.getEncode());
authorTextField.setText(configInfo.getAuthor());
encodeComboBox.setSelectedItem(configInfo.getEncode());
}
@Nls
@ -41,13 +49,14 @@ public class MainSetting extends ServiceComm implements Configurable, Configurab
/**
* 更多配置
*
* @return 配置选项
*/
@NotNull
@Override
public Configurable[] getConfigurables() {
Configurable[] result = new Configurable[3];
result[0] = new TypeMapperSetting(configService);
result[0] = new TypeMapperSetting(configInfo);
result[1] = new TemplateSettingPanel();
result[2] = new TableSettingPanel();
return result;
@ -61,14 +70,14 @@ public class MainSetting extends ServiceComm implements Configurable, Configurab
@Override
public boolean isModified() {
return !configService.getEncode().equals(encodeComboBox.getSelectedItem()) || !configService.getAuthor().equals(authorTextField.getText());
return !configInfo.getEncode().equals(encodeComboBox.getSelectedItem()) || !configInfo.getAuthor().equals(authorTextField.getText());
}
@Override
public void apply() {
//保存数据
configService.setAuthor(authorTextField.getText());
configService.setEncode((String) encodeComboBox.getSelectedItem());
configInfo.setAuthor(authorTextField.getText());
configInfo.setEncode((String) encodeComboBox.getSelectedItem());
}
@Override

View File

@ -8,13 +8,15 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiPackage;
import com.sjhy.plugin.entity.Template;
import com.sjhy.plugin.entity.TemplateGroup;
import com.sjhy.plugin.service.ConfigService;
import com.sjhy.plugin.tool.CacheDataUtils;
import com.sjhy.plugin.tool.ConfigInfo;
import com.sjhy.plugin.tool.VelocityUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@ -43,8 +45,8 @@ public class SelectSavePath extends JDialog {
private TemplateGroup templateGroup;
public SelectSavePath() {
ConfigService configService = ConfigService.getInstance();
this.templateGroup = configService.getTemplateGroupMap().get(configService.getCurrTemplateGroupName());
ConfigInfo configInfo = ConfigInfo.getInstance();
this.templateGroup = configInfo.getTemplateGroupMap().get(configInfo.getCurrTemplateGroupName());
init();
setContentPane(contentPane);
setModal(true);
@ -70,12 +72,12 @@ public class SelectSavePath extends JDialog {
private List<Template> getSelectTemplate() {
List<String> selectTemplateNameList = new ArrayList<>();
checkBoxList.forEach(jCheckBox -> {
if(jCheckBox.isSelected()){
if (jCheckBox.isSelected()) {
selectTemplateNameList.add(jCheckBox.getText());
}
});
List<Template> selectTemplateList = new ArrayList<>();
if (selectTemplateNameList.isEmpty()){
if (selectTemplateNameList.isEmpty()) {
return selectTemplateList;
}
templateGroup.getElementList().forEach(template -> {
@ -93,7 +95,7 @@ public class SelectSavePath extends JDialog {
return;
}
String savePath = pathField.getText();
if (savePath.isEmpty()){
if (savePath.isEmpty()) {
JOptionPane.showMessageDialog(null, "Can't Select Save Path!");
return;
}
@ -132,7 +134,7 @@ public class SelectSavePath extends JDialog {
PackageChooserDialog dialog = new PackageChooserDialog("Package Chooser", cacheDataUtils.getProject());
dialog.show();
PsiPackage psiPackage = dialog.getSelectedPackage();
if (psiPackage!=null) {
if (psiPackage != null) {
packageField.setText(psiPackage.getQualifiedName());
}
refreshPath();
@ -144,7 +146,7 @@ public class SelectSavePath extends JDialog {
//选择路径
pathChooseButton.addActionListener(e -> {
@SuppressWarnings("ConstantConditions") VirtualFile virtualFile = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(), cacheDataUtils.getProject(), getSelectModule().getModuleFile().getParent());
if (virtualFile!=null) {
if (virtualFile != null) {
pathField.setText(virtualFile.getPath());
}
});
@ -153,7 +155,7 @@ public class SelectSavePath extends JDialog {
private Module getSelectModule() {
String name = (String) moduleComboBox.getSelectedItem();
for (Module module : cacheDataUtils.getModules()) {
if(module.getName().equals(name)){
if (module.getName().equals(name)) {
return module;
}
}
@ -164,12 +166,12 @@ public class SelectSavePath extends JDialog {
private String getBasePath() {
Module module = getSelectModule();
String baseDir = module.getModuleFile().getParent().getPath();
File file = new File(baseDir+"/src/main/java");
if (file.exists()){
File file = new File(baseDir + "/src/main/java");
if (file.exists()) {
return file.getAbsolutePath();
}
file = new File(baseDir+"/src");
if (file.exists()){
file = new File(baseDir + "/src");
if (file.exists()) {
return file.getAbsolutePath();
}
return baseDir;
@ -178,7 +180,7 @@ public class SelectSavePath extends JDialog {
private void refreshPath() {
String packageName = packageField.getText();
String path = getBasePath();
if (!packageName.isEmpty()){
if (!packageName.isEmpty()) {
path += "\\" + packageName.replaceAll("\\.", "\\\\");
}
pathField.setText(path);

View File

@ -4,18 +4,19 @@ import com.intellij.openapi.options.Configurable;
import com.sjhy.plugin.entity.ColumnConfig;
import com.sjhy.plugin.entity.ColumnConfigGroup;
import com.sjhy.plugin.entity.ColumnConfigType;
import com.sjhy.plugin.service.ConfigService;
import com.sjhy.plugin.tool.CloneUtils;
import com.sjhy.plugin.tool.ConfigInfo;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
public class TableSettingPanel extends AbstractTableGroupPanel<ColumnConfigGroup, ColumnConfig> implements Configurable {
private ConfigService configService = ConfigService.getInstance();
private ConfigInfo configInfo = ConfigInfo.getInstance();
private CloneUtils cloneUtils = CloneUtils.getInstance();
TableSettingPanel() {
super(CloneUtils.getInstance().cloneMap(ConfigService.getInstance().getColumnConfigGroupMap()), ConfigService.getInstance().getCurrColumnConfigGroupName());
super(CloneUtils.getInstance().cloneMap(ConfigInfo.getInstance().getColumnConfigGroupMap()), ConfigInfo.getInstance().getCurrColumnConfigGroupName());
}
@Override
@ -62,17 +63,17 @@ public class TableSettingPanel extends AbstractTableGroupPanel<ColumnConfigGroup
@Override
public boolean isModified() {
refresh();
return !configService.getColumnConfigGroupMap().equals(group) || !configService.getCurrColumnConfigGroupName().equals(currGroupName);
return !configInfo.getColumnConfigGroupMap().equals(group) || !configInfo.getCurrColumnConfigGroupName().equals(currGroupName);
}
@Override
public void apply() {
configService.setColumnConfigGroupMap(group);
configService.setCurrColumnConfigGroupName(currGroupName);
configInfo.setColumnConfigGroupMap(group);
configInfo.setCurrColumnConfigGroupName(currGroupName);
}
@Override
public void reset() {
init(cloneUtils.cloneMap(configService.getColumnConfigGroupMap()), configService.getCurrColumnConfigGroupName());
init(cloneUtils.cloneMap(configInfo.getColumnConfigGroupMap()), configInfo.getCurrColumnConfigGroupName());
}
}

View File

@ -3,23 +3,51 @@ package com.sjhy.plugin.ui;
import com.intellij.openapi.options.Configurable;
import com.sjhy.plugin.entity.Template;
import com.sjhy.plugin.entity.TemplateGroup;
import com.sjhy.plugin.service.ConfigService;
import com.sjhy.plugin.tool.CloneUtils;
import com.sjhy.plugin.tool.ConfigInfo;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* 模板编辑主面板
*
* @author makejava
* @version 1.0.0
* @since 2018/07/18 09:33
*/
public class TemplateSettingPanel extends AbstractGroupPanel<TemplateGroup, Template> implements Configurable {
private ConfigService configService = ConfigService.getInstance();
/**
* 配置信息
*/
private ConfigInfo configInfo = ConfigInfo.getInstance();
/**
* 对象克隆工具
*/
private CloneUtils cloneUtils = CloneUtils.getInstance();
/**
* 编辑框面板
*/
private EditTemplatePanel editTemplatePanel;
/**
* 默认构造方法
*/
TemplateSettingPanel() {
super(CloneUtils.getInstance().cloneMap(ConfigService.getInstance().getTemplateGroupMap()), ConfigService.getInstance().getCurrTemplateGroupName());
super(CloneUtils.getInstance().cloneMap(ConfigInfo.getInstance().getTemplateGroupMap()), ConfigInfo.getInstance().getCurrTemplateGroupName());
}
/**
* 切换模板编辑时
* @param itemPanel 面板对象
* @param item 模板对象
*/
@Override
protected void initItemPanel(JPanel itemPanel, Template item) {
if (editTemplatePanel!=null) {
editTemplatePanel.disposeEditor();
}
itemPanel.removeAll();
editTemplatePanel = new EditTemplatePanel(item);
itemPanel.add(editTemplatePanel.getMainPanel());
@ -56,17 +84,31 @@ public class TemplateSettingPanel extends AbstractGroupPanel<TemplateGroup, Temp
@Override
public boolean isModified() {
editTemplatePanel.refresh();
return !configService.getTemplateGroupMap().equals(group) || !configService.getCurrTemplateGroupName().equals(currGroupName);
return !configInfo.getTemplateGroupMap().equals(group) || !configInfo.getCurrTemplateGroupName().equals(currGroupName);
}
/**
* 保存方法
*/
@Override
public void apply() {
configService.setTemplateGroupMap(group);
configService.setCurrTemplateGroupName(currGroupName);
configInfo.setTemplateGroupMap(group);
configInfo.setCurrTemplateGroupName(currGroupName);
}
/**
* 重置方法
*/
@Override
public void reset() {
init(cloneUtils.cloneMap(configService.getTemplateGroupMap()), configService.getCurrTemplateGroupName());
init(cloneUtils.cloneMap(configInfo.getTemplateGroupMap()), configInfo.getCurrTemplateGroupName());
}
/**
* 关闭回调方法
*/
@Override
public void disposeUIResources() {
editTemplatePanel.disposeEditor();
}
}

View File

@ -4,7 +4,7 @@ import com.intellij.openapi.options.Configurable;
import com.sjhy.plugin.entity.TypeMapper;
import com.sjhy.plugin.entity.TypeMapperGroup;
import com.sjhy.plugin.entity.TypeMapperModel;
import com.sjhy.plugin.service.ConfigService;
import com.sjhy.plugin.tool.ConfigInfo;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;
@ -38,29 +38,29 @@ public class TypeMapperSetting implements Configurable {
//类型映射分组集合
private Map<String, TypeMapperGroup> typeMapperGroupMap;
//全局配置服务
private ConfigService configService;
private ConfigInfo configInfo;
TypeMapperSetting(ConfigService configService) {
this.configService = configService;
TypeMapperSetting(ConfigInfo configInfo) {
this.configInfo = configInfo;
//添加类型
addButton.addActionListener(e -> typeMapperModel.addRow(new TypeMapper("demoColumn", "java.lang.Object")));
//移除类型
removeButton.addActionListener(e -> {
int[] selectRows = typeMapperTable.getSelectedRows();
for (int i = selectRows.length-1; i>=0; i--){
for (int i = selectRows.length - 1; i >= 0; i--) {
typeMapperModel.removeRow(selectRows[i]);
}
});
//切换分组
typeMapperComboBox.addActionListener(e -> {
if (!init){
if (!init) {
return;
}
String value = (String) typeMapperComboBox.getSelectedItem();
if (value==null) {
if (value == null) {
return;
}
if (currGroupName.equals(value)) {
@ -72,15 +72,15 @@ public class TypeMapperSetting implements Configurable {
//复制分组按钮
typeMapperCopyButton.addActionListener(e -> {
String value = JOptionPane.showInputDialog(null, "Input Group Name:", currGroupName+" Copy");
if (value==null) {
String value = JOptionPane.showInputDialog(null, "Input Group Name:", currGroupName + " Copy");
if (value == null) {
return;
}
if (value.trim().length()==0){
if (value.trim().length() == 0) {
JOptionPane.showMessageDialog(null, "Group Name Can't Is Empty!");
return;
}
if (typeMapperGroupMap.containsKey(value)){
if (typeMapperGroupMap.containsKey(value)) {
JOptionPane.showMessageDialog(null, "Group Name Already exist!");
return;
}
@ -93,14 +93,14 @@ public class TypeMapperSetting implements Configurable {
//删除分组
deleteButton.addActionListener(e -> {
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Group "+typeMapperComboBox.getSelectedItem()+"?", "温馨提示", JOptionPane.OK_CANCEL_OPTION);
if (result==0){
if(ConfigService.DEFAULT_NAME.equals(currGroupName)){
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Group " + typeMapperComboBox.getSelectedItem() + "?", "温馨提示", JOptionPane.OK_CANCEL_OPTION);
if (result == 0) {
if (ConfigInfo.DEFAULT_NAME.equals(currGroupName)) {
JOptionPane.showMessageDialog(null, "Can't Delete Default Group!");
return;
}
typeMapperGroupMap.remove(currGroupName);
currGroupName = ConfigService.DEFAULT_NAME;
currGroupName = ConfigInfo.DEFAULT_NAME;
refresh();
}
});
@ -115,10 +115,10 @@ public class TypeMapperSetting implements Configurable {
private void init() {
//复制数据
this.typeMapperGroupMap = new LinkedHashMap<>();
for (Map.Entry<String, TypeMapperGroup> entry : configService.getTypeMapperGroupMap().entrySet()) {
for (Map.Entry<String, TypeMapperGroup> entry : configInfo.getTypeMapperGroupMap().entrySet()) {
this.typeMapperGroupMap.put(entry.getKey(), entry.getValue().clone());
}
this.currGroupName = configService.getCurrTypeMapperGroupName();
this.currGroupName = configInfo.getCurrTypeMapperGroupName();
//初始化表格
this.typeMapperModel = new TypeMapperModel();
@ -154,13 +154,13 @@ public class TypeMapperSetting implements Configurable {
@Override
public boolean isModified() {
return !typeMapperGroupMap.equals(configService.getTypeMapperGroupMap()) || !currGroupName.equals(configService.getCurrTypeMapperGroupName());
return !typeMapperGroupMap.equals(configInfo.getTypeMapperGroupMap()) || !currGroupName.equals(configInfo.getCurrTypeMapperGroupName());
}
@Override
public void apply() {
configService.setCurrTypeMapperGroupName(currGroupName);
configService.setTypeMapperGroupMap(typeMapperGroupMap);
configInfo.setCurrTypeMapperGroupName(currGroupName);
configInfo.setTypeMapperGroupMap(typeMapperGroupMap);
}
@Override

View File

@ -32,7 +32,7 @@
<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
<applicationService serviceInterface="com.sjhy.plugin.service.ConfigService" serviceImplementation="com.sjhy.plugin.service.impl.ConfigServiceImpl"/>
<applicationService serviceImplementation="com.sjhy.plugin.tool.ConfigInfo"/>
<applicationConfigurable dynamic="true" instance="com.sjhy.plugin.ui.MainSetting"/>
</extensions>