初步尝试添加项目级Settings,替换原来的.idea目录自行维护配置文件。

This commit is contained in:
makejava 2021-08-14 18:11:03 +08:00
parent 38acd0cf46
commit 566e4830d8
8 changed files with 270 additions and 7 deletions

View File

@ -0,0 +1,36 @@
package com.sjhy.plugin.dto;
import lombok.Data;
import java.util.Map;
/**
* 列信息传输对象
*
* @author makejava
* @version 1.0.0
* @date 2021/08/14 17:29
*/
@Data
public class ColumnInfoDTO {
/**
* 名称
*/
private String name;
/**
* 注释
*/
private String comment;
/**
* 全类型
*/
private String type;
/**
* 标记是否为自定义附加列
*/
private Boolean custom;
/**
* 扩展数据
*/
private Map<String, Object> ext;
}

View File

@ -0,0 +1,48 @@
package com.sjhy.plugin.dto;
import lombok.Data;
import java.util.List;
/**
* 表格信息传输对象
*
* @author makejava
* @version 1.0.0
* @date 2021/08/14 17:28
*/
@Data
public class TableInfoDTO {
/**
* 表名首字母大写
*/
private String name;
/**
* 表名前缀
*/
private String preName;
/**
* 注释
*/
private String comment;
/**
* 模板组名称
*/
private String templateGroupName;
/**
* 所有列
*/
private List<ColumnInfoDTO> fullColumn;
/**
* 保存的包名称
*/
private String savePackageName;
/**
* 保存路径
*/
private String savePath;
/**
* 保存的model名称
*/
private String saveModelName;
}

View File

@ -0,0 +1,89 @@
package com.sjhy.plugin.dto;
import com.intellij.database.model.DasNamespace;
import com.intellij.database.psi.DbElement;
import com.intellij.database.psi.DbTable;
import com.sjhy.plugin.entity.TableInfo;
import lombok.Data;
import java.util.HashMap;
import java.util.Map;
/**
* 表格信息设置传输对象
*
* @author makejava
* @version 1.0.0
* @date 2021/08/14 17:40
*/
@Data
public class TableInfoSettingsDTO {
private Map<String, TableInfoDTO> tableInfoMap;
public TableInfoSettingsDTO() {
this.tableInfoMap = new HashMap<>(16);
}
private String generateKey(DbTable dbTable) {
// 递归添加3层名称作为key第一层为表名第二层为名命空间名称第三层为数据库名
StringBuilder builder = new StringBuilder();
DbElement element = dbTable;
for (int i = 0; i < 3; i++) {
String name = element.getName();
if (builder.length() > 0) {
// 添加分割符
builder.insert(0, ".");
}
builder.insert(0, name);
element = element.getParent();
if (element == null) {
break;
}
// 未必所有的数据库都是存在三层例如MySQL就只有两层如果上次层不是Namespace则不再继续获取
if (!(element instanceof DasNamespace)) {
break;
}
}
return builder.toString();
}
/**
* 读取表信息
*
* @param dbTable 原始表对象
* @return 储存的表信息
*/
public TableInfo readTableInfo(DbTable dbTable) {
if (dbTable == null) {
return null;
}
String key = generateKey(dbTable);
TableInfoDTO dto = this.tableInfoMap.get(key);
if (dto == null) {
dto = new TableInfoDTO();
dto.setName(dbTable.getName());
dto.setComment(dbTable.getComment());
dto.setPreName("");
dto.setSaveModelName("");
dto.setSavePath("");
dto.setTemplateGroupName("");
this.tableInfoMap.put(key, dto);
}
return null;
}
/**
* 保存表信息
*
* @param tableInfo 表信息
*/
public void saveTableInfo(TableInfo tableInfo) {
if (tableInfo == null) {
return;
}
DbTable dbTable = tableInfo.getObj();
if (dbTable == null) {
return;
}
}
}

View File

@ -0,0 +1,40 @@
package com.sjhy.plugin.service;
import com.intellij.database.psi.DbTable;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.sjhy.plugin.dto.TableInfoSettingsDTO;
import com.sjhy.plugin.entity.TableInfo;
import com.sjhy.plugin.service.impl.TableInfoSettingsServiceImpl;
import com.sjhy.plugin.tool.ProjectUtils;
/**
* @author makejava
* @version 1.0.0
* @date 2021/08/14 15:16
*/
public interface TableInfoSettingsService extends PersistentStateComponent<TableInfoSettingsDTO> {
/**
* 获取实例
*
* @return {@link SettingsStorageService}
*/
static TableInfoSettingsService getInstance() {
return ServiceManager.getService(ProjectUtils.getCurrProject(), TableInfoSettingsServiceImpl.class);
}
/**
* 获取表格信息
*
* @param dbTable 数据库表
* @return {@link TableInfo}
*/
TableInfo getTableInfo(DbTable dbTable);
/**
* 保存表信息
*
* @param tableInfo 表信息
*/
void saveTableInfo(TableInfo tableInfo);
}

View File

@ -15,7 +15,6 @@ import org.jetbrains.annotations.Nullable;
* @version 1.0.0
* @date 2021/08/07 11:32
*/
@Data
@State(name = "EasyCodeSetting", storages = @Storage("easy-code-setting.xml"))
public class SettingsStorageServiceImpl implements SettingsStorageService {

View File

@ -0,0 +1,55 @@
package com.sjhy.plugin.service.impl;
import com.intellij.database.psi.DbTable;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.sjhy.plugin.dto.TableInfoSettingsDTO;
import com.sjhy.plugin.entity.TableInfo;
import com.sjhy.plugin.service.TableInfoSettingsService;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
/**
* @author makejava
* @version 1.0.0
* @date 2021/08/14 15:20
*/
@State(name = "EasyCodeTableSetting", storages = @Storage("easyCodeTableSetting.xml"))
public class TableInfoSettingsServiceImpl implements TableInfoSettingsService {
private TableInfoSettingsDTO tableInfoSettings = new TableInfoSettingsDTO();
@Nullable
@Override
public TableInfoSettingsDTO getState() {
return tableInfoSettings;
}
@Override
public void loadState(@NotNull TableInfoSettingsDTO state) {
this.tableInfoSettings = state;
}
/**
* 获取表格信息
*
* @param dbTable 数据库表
* @return {@link TableInfo}
*/
@Override
public TableInfo getTableInfo(DbTable dbTable) {
return Objects.requireNonNull(getState()).readTableInfo(dbTable);
}
/**
* 保存表信息
*
* @param tableInfo 表信息
*/
@Override
public void saveTableInfo(TableInfo tableInfo) {
Objects.requireNonNull(getState()).saveTableInfo(tableInfo);
}
}

View File

@ -238,13 +238,12 @@
<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
<!--实例化配置信息服务-->
<applicationService serviceImplementation="com.sjhy.plugin.config.Settings"/>
<applicationService serviceImplementation="com.sjhy.plugin.service.impl.SettingsStorageServiceImpl"/>
<!--项目服务-->
<projectService serviceImplementation="com.sjhy.plugin.service.impl.TableInfoSettingsServiceImpl"/>
<projectService serviceInterface="com.sjhy.plugin.service.TableInfoService" serviceImplementation="com.sjhy.plugin.service.impl.TableInfoServiceImpl"/>
<projectService serviceInterface="com.sjhy.plugin.service.CodeGenerateService" serviceImplementation="com.sjhy.plugin.service.impl.CodeGenerateServiceImpl"/>
<!--系统设置面板-->
<!--<applicationConfigurable dynamic="true" instance="com.sjhy.plugin.ui.MainSetting"/>-->
<applicationConfigurable dynamic="true" instance="com.sjhy.plugin.ui.MainSettingForm"/>
</extensions>

View File

@ -1,5 +1,4 @@
button.reset=\u91CD\u7F6E\u9ED8\u8BA4\u8BBE\u7F6E
button.type.mapper.copy.group=Copy Group
label.all=&All
label.version=&\u5F53\u524D\u7248\u672C\uFF1A
label.author.name=&\u4F5C\u8005\u540D\u79F0\uFF1A
@ -12,6 +11,4 @@ label.package=&Package:
label.path=&Path:
label.removePre=&RemovePre:
label.template=Template:
label.template.group=&\u6A21\u677F\u7EC4\uFF1A
label.type.mapper=&\u7C7B\u578B\u6620\u5C04\u7EC4\uFF1A
label.unified.config=\u7EDF\u4E00\u914D\u7F6E
label.unified.config=\u7EDF\u4E00\u914D\u7F6E