升级到1.2.7版本,并修复已知BUG

This commit is contained in:
makejava 2022-07-06 15:46:54 +08:00 committed by makejava
parent 66aabeecc4
commit 19a7ddac8f
12 changed files with 130 additions and 62 deletions

View File

@ -15,7 +15,7 @@ public interface GlobalDict {
/**
* 版本号
*/
String VERSION = "1.2.6";
String VERSION = "1.2.7";
/**
* 作者名称
*/

View File

@ -30,7 +30,7 @@ public class ColumnInfoDTO {
this.comment = DocCommentUtils.getComment(field.getDocComment());
this.type = field.getType().getCanonicalText();
this.custom = false;
this.ext = new HashMap<>();
this.ext = "{}";
}
public ColumnInfoDTO(DasColumn column) {
@ -38,7 +38,7 @@ public class ColumnInfoDTO {
this.comment = column.getComment();
this.type = getJavaType(column.getDataType().toString());
this.custom = false;
this.ext = new HashMap<>();
this.ext = "{}";
}
private String getJavaType(String dbType) {
@ -74,7 +74,7 @@ public class ColumnInfoDTO {
*/
private Boolean custom;
/**
* 扩展数据
* 扩展数据(JSON字符串)
*/
private Map<String, Object> ext;
private String ext;
}

View File

@ -70,7 +70,7 @@ public class TableInfoDTO {
}
private static void merge(TableInfoDTO oldData, TableInfoDTO newData) {
if (oldData == null) {
if (oldData == null || CollectionUtil.isEmpty(oldData.getFullColumn())) {
return;
}
if (!StringUtils.isEmpty(oldData.getPreName())) {
@ -88,32 +88,66 @@ public class TableInfoDTO {
if (!StringUtils.isEmpty(oldData.getSaveModelName())) {
newData.saveModelName = oldData.getSaveModelName();
}
if (CollectionUtil.isEmpty(oldData.getFullColumn())) {
return;
List<String> allNewColumnNames = newData.getFullColumn().stream().map(ColumnInfoDTO::getName).collect(Collectors.toList());
// 列出旧的顺序并删除已经不存在的列不包括自定义列
List<ColumnInfoDTO> oldSequenceColumn = oldData.getFullColumn().stream()
.filter(item -> allNewColumnNames.contains(item.getName()) || Boolean.TRUE.equals(item.getCustom()))
.collect(Collectors.toList());
// 尽可能的保留原始顺序(把自定义列按原始位置插入)
Map<String, String> nameMap = new HashMap<>(oldSequenceColumn.size());
for (int i = 0; i < oldSequenceColumn.size(); i++) {
ColumnInfoDTO columnInfo = oldSequenceColumn.get(i);
if (columnInfo.getCustom()) {
// 如果原本是自定义列现在变成了数据库列则忽略调原本的自定义列
if (allNewColumnNames.contains(columnInfo.getName())) {
continue;
}
// 获取当前自定义列的前一个名称
String beforeName = "";
if (i > 0) {
beforeName = oldSequenceColumn.get(i - 1).getName();
}
nameMap.put(beforeName, columnInfo.getName());
}
}
// 补充自定义列
for (ColumnInfoDTO oldColumn : oldData.getFullColumn()) {
if (!oldColumn.getCustom()) {
// 将自定义列按顺序插入到新表中
nameMap.forEach((k, v) -> {
if (StringUtils.isEmpty(k)) {
allNewColumnNames.add(0, v);
} else {
for (int i = 0; i < allNewColumnNames.size(); i++) {
if (allNewColumnNames.get(i).equals(k)) {
allNewColumnNames.add(i + 1, v);
return;
}
}
}
});
// 按顺序依次重写数据
Map<String, ColumnInfoDTO> oldColumnMap = oldData.getFullColumn().stream().collect(Collectors.toMap(ColumnInfoDTO::getName, v -> v));
Map<String, ColumnInfoDTO> newColumnMap = newData.getFullColumn().stream().collect(Collectors.toMap(ColumnInfoDTO::getName, v -> v));
List<ColumnInfoDTO> tmpList = new ArrayList<>();
for (String name : allNewColumnNames) {
ColumnInfoDTO newColumnInfo = newColumnMap.get(name);
if (newColumnInfo == null) {
newColumnInfo = oldColumnMap.get(name);
if (newColumnInfo == null) {
throw new NullPointerException("找不到列信息");
}
tmpList.add(newColumnInfo);
continue;
}
newData.getFullColumn().add(oldColumn);
}
// 保持旧列的顺序
Map<String, ColumnInfoDTO> map = newData.getFullColumn().stream().collect(Collectors.toMap(ColumnInfoDTO::getName, val -> val));
List<ColumnInfoDTO> tmpList = new ArrayList<>();
for (ColumnInfoDTO columnInfo : oldData.getFullColumn()) {
ColumnInfoDTO newColumn = map.get(columnInfo.getName());
if (newColumn != null) {
// ext属性转移
newColumn.setExt(columnInfo.getExt());
tmpList.add(newColumn);
ColumnInfoDTO oldColumnInfo = oldColumnMap.get(name);
if (oldColumnInfo == null) {
tmpList.add(newColumnInfo);
continue;
}
}
// 补充剩余列
for (ColumnInfoDTO columnInfoDTO : newData.getFullColumn()) {
if (!tmpList.contains(columnInfoDTO)) {
tmpList.add(columnInfoDTO);
// 需要进行合并操作
newColumnInfo.setExt(oldColumnInfo.getExt());
if (StringUtils.isEmpty(newColumnInfo.getComment())) {
newColumnInfo.setComment(oldColumnInfo.getComment());
}
tmpList.add(newColumnInfo);
}
// list数据替换
newData.getFullColumn().clear();
@ -187,6 +221,7 @@ public class TableInfoDTO {
return tableInfo;
}
@SuppressWarnings("unchecked")
public TableInfo toTableInfo(DbTable dbTable) {
TableInfo tableInfo = new TableInfo();
tableInfo.setObj(dbTable);
@ -216,7 +251,7 @@ public class TableInfoDTO {
columnInfo.setShortType(split[split.length - 1]);
columnInfo.setComment(dto.getComment());
columnInfo.setCustom(dto.getCustom());
columnInfo.setExt(dto.getExt());
columnInfo.setExt(JSON.parse(dto.getExt(), HashMap.class));
tableInfo.getFullColumn().add(columnInfo);
if (columnInfo.getObj() != null && DasUtil.isPrimary(columnInfo.getObj())) {
tableInfo.getPkColumn().add(columnInfo);
@ -242,7 +277,7 @@ public class TableInfoDTO {
ColumnInfoDTO columnInfoDTO = new ColumnInfoDTO();
columnInfoDTO.setName(columnInfo.getName());
columnInfoDTO.setType(columnInfo.getType());
columnInfoDTO.setExt(columnInfo.getExt());
columnInfoDTO.setExt(JSON.toJson(columnInfo.getExt()));
columnInfoDTO.setCustom(columnInfo.getCustom());
columnInfoDTO.setComment(columnInfo.getComment());
dto.getFullColumn().add(columnInfoDTO);

View File

@ -21,17 +21,6 @@ import java.util.stream.Stream;
*/
public class CellEditorFactory {
/**
* 创建下拉框编辑器
*
* @param editable 可编辑的
* @return {@link TableCellEditor}
*/
public static TableCellEditor createComboBoxEditor(boolean editable, Class<? extends Enum> enumCls) {
Enum[] enumConstants = enumCls.getEnumConstants();
return createComboBoxEditor(editable, Stream.of(enumConstants).map(Enum::name).toArray(value -> new String[enumConstants.length]));
}
/**
* 创建下拉框编辑器
*
@ -42,11 +31,6 @@ public class CellEditorFactory {
public static TableCellEditor createComboBoxEditor(boolean editable, String... items) {
ComboBox<String> comboBox = new ComboBox<>(items);
comboBox.setEditable(editable);
// 配色
if (comboBox.getPopup() != null) {
comboBox.getPopup().getList().setBackground(JBColor.WHITE);
comboBox.getPopup().getList().setForeground(JBColor.GREEN);
}
if (!editable) {
transmitFocusEvent(comboBox);
}

View File

@ -2,6 +2,7 @@ package com.sjhy.plugin.ui;
import com.fasterxml.jackson.core.type.TypeReference;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.ui.ComboBoxTableRenderer;
import com.sjhy.plugin.dict.GlobalDict;
import com.sjhy.plugin.dto.SettingsStorageDTO;
import com.sjhy.plugin.entity.ColumnConfig;
@ -15,11 +16,13 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Stream;
/**
* @author makejava
@ -27,7 +30,7 @@ import java.util.function.Consumer;
* @date 2021/08/10 13:27
*/
public class ColumnConfigSettingForm implements Configurable, BaseSettings {
private JPanel mainPanel;
private final JPanel mainPanel;
/**
* 列配置
*/
@ -51,14 +54,16 @@ public class ColumnConfigSettingForm implements Configurable, BaseSettings {
private void initTable() {
// 第一列类型
TableCellEditor typeEditor = CellEditorFactory.createComboBoxEditor(false, ColumnConfigType.class);
TableComponent.Column<ColumnConfig> typeColumn = new TableComponent.Column<>("type", item -> item.getType().name(), (entity, val) -> entity.setType(ColumnConfigType.valueOf(val)), typeEditor);
String[] columnConfigTypeNames = Stream.of(ColumnConfigType.values()).map(ColumnConfigType::name).toArray(String[]::new);
TableCellEditor typeEditor = CellEditorFactory.createComboBoxEditor(false, columnConfigTypeNames);
TableCellRenderer typeRenderer = new ComboBoxTableRenderer<>(columnConfigTypeNames);
TableComponent.Column<ColumnConfig> typeColumn = new TableComponent.Column<>("type", item -> item.getType().name(), (entity, val) -> entity.setType(ColumnConfigType.valueOf(val)), typeEditor, typeRenderer);
// 第二列标题
TableCellEditor titleEditor = CellEditorFactory.createTextFieldEditor();
TableComponent.Column<ColumnConfig> titleColumn = new TableComponent.Column<>("title", ColumnConfig::getTitle, ColumnConfig::setTitle, titleEditor);
TableComponent.Column<ColumnConfig> titleColumn = new TableComponent.Column<>("title", ColumnConfig::getTitle, ColumnConfig::setTitle, titleEditor, null);
// 第三列选项
TableCellEditor selectValueEditor = CellEditorFactory.createTextFieldEditor();
TableComponent.Column<ColumnConfig> selectValueColumn = new TableComponent.Column<>("selectValue", ColumnConfig::getSelectValue, ColumnConfig::setSelectValue, selectValueEditor);
TableComponent.Column<ColumnConfig> selectValueColumn = new TableComponent.Column<>("selectValue", ColumnConfig::getSelectValue, ColumnConfig::setSelectValue, selectValueEditor, null);
List<TableComponent.Column<ColumnConfig>> columns = Arrays.asList(typeColumn, titleColumn, selectValueColumn);
// 表格初始化

View File

@ -1,6 +1,8 @@
package com.sjhy.plugin.ui;
import com.intellij.openapi.ui.ComboBoxTableRenderer;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.BooleanTableCellRenderer;
import com.intellij.ui.ToolbarDecorator;
import com.intellij.ui.table.JBTable;
import com.sjhy.plugin.dict.GlobalDict;
@ -18,6 +20,8 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.table.TableColumn;
import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
/**
* 表配置窗口
@ -30,7 +34,7 @@ public class ConfigTableDialog extends DialogWrapper {
/**
* 主面板
*/
private JPanel mainPanel;
private final JPanel mainPanel;
/**
* 表信息对象
*/
@ -52,8 +56,10 @@ public class ConfigTableDialog extends DialogWrapper {
// 配置列编辑器
table.getColumn("name").setCellEditor(CellEditorFactory.createTextFieldEditor());
table.getColumn("type").setCellEditor(CellEditorFactory.createComboBoxEditor(true, GlobalDict.DEFAULT_JAVA_TYPE_LIST));
table.getColumn("type").setMinWidth(120);
TableColumn typeColumn = table.getColumn("type");
typeColumn.setCellRenderer(new ComboBoxTableRenderer<>(GlobalDict.DEFAULT_JAVA_TYPE_LIST));
typeColumn.setCellEditor(CellEditorFactory.createComboBoxEditor(true, GlobalDict.DEFAULT_JAVA_TYPE_LIST));
typeColumn.setMinWidth(120);
table.getColumn("comment").setCellEditor(CellEditorFactory.createTextFieldEditor());
// 其他附加列
for (ColumnConfig columnConfig : CurrGroupUtils.getCurrColumnConfigGroup().getElementList()) {
@ -66,10 +72,17 @@ public class ConfigTableDialog extends DialogWrapper {
if (StringUtils.isEmpty(columnConfig.getSelectValue())) {
column.setCellEditor(CellEditorFactory.createTextFieldEditor());
} else {
column.setCellEditor(CellEditorFactory.createComboBoxEditor(false, columnConfig.getSelectValue().split(",")));
String[] split = columnConfig.getSelectValue().split(",");
ArrayList<String> list = new ArrayList<>(Arrays.asList(split));
// 添加一个空值作为默认值
list.add(0, "");
split = list.toArray(new String[0]);
column.setCellRenderer(new ComboBoxTableRenderer<>(split));
column.setCellEditor(CellEditorFactory.createComboBoxEditor(false, split));
}
break;
case BOOLEAN:
column.setCellRenderer(new BooleanTableCellRenderer());
column.setCellEditor(CellEditorFactory.createBooleanEditor());
break;
default:

View File

@ -2,6 +2,7 @@ package com.sjhy.plugin.ui;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.sjhy.plugin.dict.GlobalDict;
import com.sjhy.plugin.dto.SettingsStorageDTO;
import com.sjhy.plugin.service.impl.ClipboardExportImportSettingsServiceImpl;
import com.sjhy.plugin.service.impl.LocalFileExportImportSettingsServiceImpl;
@ -151,7 +152,7 @@ public class MainSettingForm implements Configurable, Configurable.Composite, Ba
*/
@Override
public void loadSettingsStore(SettingsStorageDTO settingsStorage) {
this.versionLabel.setText(settingsStorage.getVersion());
this.versionLabel.setText(GlobalDict.VERSION);
this.authorEditor.setText(settingsStorage.getAuthor());
this.userSecureEditor.setText(settingsStorage.getUserSecure());
if (StringUtils.isEmpty(settingsStorage.getUserSecure())) {

View File

@ -1,6 +1,7 @@
package com.sjhy.plugin.ui;
import com.fasterxml.jackson.core.type.TypeReference;
import com.intellij.openapi.ui.ComboBoxTableRenderer;
import com.sjhy.plugin.dict.GlobalDict;
import com.sjhy.plugin.dto.SettingsStorageDTO;
import com.sjhy.plugin.entity.TypeMapper;
@ -14,11 +15,13 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Stream;
/**
* @author makejava
@ -26,7 +29,7 @@ import java.util.function.Consumer;
* @date 2021/08/07 15:33
*/
public class TypeMapperSettingForm implements BaseSettings {
private JPanel mainPanel;
private final JPanel mainPanel;
/**
* 类型映射配置
*/
@ -50,18 +53,22 @@ public class TypeMapperSettingForm implements BaseSettings {
private void initTable() {
// 第一列仅适用下拉框
TableCellEditor matchTypeEditor = CellEditorFactory.createComboBoxEditor(false, MatchType.class);
String[] matchTypeNames = Stream.of(MatchType.values()).map(MatchType::name).toArray(String[]::new);
TableCellEditor matchTypeEditor = CellEditorFactory.createComboBoxEditor(false, matchTypeNames);
TableCellRenderer matchTypeRenderer = new ComboBoxTableRenderer<>(matchTypeNames);
TableComponent.Column<TypeMapper> matchTypeColumn = new TableComponent.Column<>("matchType",
item -> item.getMatchType() != null ? item.getMatchType().name() : MatchType.REGEX.name(),
(entity, val) -> entity.setMatchType(MatchType.valueOf(val)),
matchTypeEditor
matchTypeEditor,
matchTypeRenderer
);
// 第二列监听输入状态及时修改属性值
TableCellEditor columnTypeEditor = CellEditorFactory.createTextFieldEditor();
TableComponent.Column<TypeMapper> columnTypeColumn = new TableComponent.Column<>("columnType", TypeMapper::getColumnType, TypeMapper::setColumnType, columnTypeEditor);
TableComponent.Column<TypeMapper> columnTypeColumn = new TableComponent.Column<>("columnType", TypeMapper::getColumnType, TypeMapper::setColumnType, columnTypeEditor, null);
// 第三列支持下拉框
TableCellEditor javaTypeEditor = CellEditorFactory.createComboBoxEditor(true, GlobalDict.DEFAULT_JAVA_TYPE_LIST);
TableComponent.Column<TypeMapper> javaTypeColumn = new TableComponent.Column<>("javaType", TypeMapper::getJavaType, TypeMapper::setJavaType, javaTypeEditor);
TableCellRenderer javaTypeRenderer = new ComboBoxTableRenderer<>(GlobalDict.DEFAULT_JAVA_TYPE_LIST);
TableComponent.Column<TypeMapper> javaTypeColumn = new TableComponent.Column<>("javaType", TypeMapper::getJavaType, TypeMapper::setJavaType, javaTypeEditor, javaTypeRenderer);
List<TableComponent.Column<TypeMapper>> columns = Arrays.asList(matchTypeColumn, columnTypeColumn, javaTypeColumn);
// 表格初始化
this.tableComponent = new TableComponent<>(columns, this.currTypeMapperGroup.getElementList(), TypeMapper.class);

View File

@ -13,6 +13,7 @@ import lombok.NonNull;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import java.util.Collections;
import java.util.List;
import java.util.Vector;
@ -68,6 +69,9 @@ public class TableComponent<T extends AbstractItem<T>> extends DefaultTableModel
this.table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// 指定编辑器
for (Column<T> column : this.columns) {
if (column.renderer != null) {
this.table.getColumn(column.name).setCellRenderer(column.renderer);
}
if (column.editor != null) {
this.table.getColumn(column.name).setCellEditor(column.editor);
}
@ -157,5 +161,9 @@ public class TableComponent<T extends AbstractItem<T>> extends DefaultTableModel
* 列编辑器
*/
private TableCellEditor editor;
/**
* 列展示器
*/
private TableCellRenderer renderer;
}
}

View File

@ -1,6 +1,6 @@
<idea-plugin>
<id>com.sjhy.plugin.easycode</id>
<name>Easy Code</name>
<name>EasyCode</name>
<vendor email="1353036300@qq.com" url="http://www.shujuhaiyang.com">Easy Code Office Website</vendor>
<description><![CDATA[
@ -20,6 +20,19 @@
<change-notes><![CDATA[
<p>1.2.7-java.RELEASE</p>
<ul>
<li>1.Fix extended attribute save loss</li>
<li>2.Fix the problem that the order of newly added fields in the table cannot be consistent</li>
<li>3.Optimize UI</li>
<li>4.Optimize module selection, support module name search</li>
<li>5.Optimize cleanup table configuration function</li>
</ul>
<ul>
<li>1.修复扩展属性保存丢失问题</li>
<li>2.修复表新增字段后顺序无法保持一致问题</li>
<li>3.优化UI界面</li>
</ul>
<p>1.2.6-java.RELEASE</p>
<ul>
<li>1.Fix the problem of exported Chinese garbled code</li>

File diff suppressed because one or more lines are too long

View File

@ -14,6 +14,7 @@
对象
$tableInfo 表对象
obj 表原始对象 com.intellij.database.model.DasTable
preName 表前缀 java.lang.String
name 表名转换后的首字母大写java.lang.String
comment 表注释 java.lang.String
fullColumn 所有列 java.util.List&lt;ColumnInfo&gt;
@ -65,6 +66,7 @@
$generateService
run(String, Map&lt;String,Object&gt;) 代码生成服务参数1模板名称参数2附加参数。
$dasUtil Database提供的工具类具体可方法请查看源码适用于高端玩家
$dasUtil.
$dbUtil Database提供的工具类具体可方法请查看源码适用于高端玩家
</pre>
</body>