From 61916b04a56134870e2943ffccbae63b407163fc Mon Sep 17 00:00:00 2001 From: makejava <1353036300@qq.com> Date: Sat, 7 Aug 2021 18:35:26 +0800 Subject: [PATCH] =?UTF-8?q?UI=E4=BC=98=E5=8C=96=EF=BC=8C=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=AE=8C=E6=88=90=EF=BC=8C=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sjhy/plugin/config/Settings.java | 1 + .../java/com/sjhy/plugin/dict/GlobalDict.java | 23 ++ .../sjhy/plugin/dto/SettingsStorageDTO.java | 109 +++++++++ .../com/sjhy/plugin/entity/ColumnConfig.java | 1 + .../com/sjhy/plugin/entity/TypeMapper.java | 6 + .../sjhy/plugin/entity/TypeMapperModel.java | 29 ++- .../{entity => enums}/ColumnConfigType.java | 2 +- .../java/com/sjhy/plugin/enums/MatchType.java | 17 ++ .../service/SettingsStorageService.java | 31 +++ .../impl/SettingsStorageServiceImpl.java | 44 ++++ .../com/sjhy/plugin/ui/ConfigTableDialog.java | 1 + .../java/com/sjhy/plugin/ui/MainSetting.java | 2 +- .../com/sjhy/plugin/ui/MainSettingForm.form | 224 ++++++++++++++++++ .../com/sjhy/plugin/ui/MainSettingForm.java | 135 +++++++++++ .../com/sjhy/plugin/ui/TableSettingPanel.java | 2 +- .../com/sjhy/plugin/ui/TypeMapperSetting.java | 4 +- .../sjhy/plugin/ui/TypeMapperSettingForm.form | 47 ++++ .../sjhy/plugin/ui/TypeMapperSettingForm.java | 96 ++++++++ src/main/resources/META-INF/plugin.xml | 4 +- 19 files changed, 767 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/sjhy/plugin/dict/GlobalDict.java create mode 100644 src/main/java/com/sjhy/plugin/dto/SettingsStorageDTO.java rename src/main/java/com/sjhy/plugin/{entity => enums}/ColumnConfigType.java (87%) create mode 100644 src/main/java/com/sjhy/plugin/enums/MatchType.java create mode 100644 src/main/java/com/sjhy/plugin/service/SettingsStorageService.java create mode 100644 src/main/java/com/sjhy/plugin/service/impl/SettingsStorageServiceImpl.java create mode 100644 src/main/java/com/sjhy/plugin/ui/MainSettingForm.form create mode 100644 src/main/java/com/sjhy/plugin/ui/MainSettingForm.java create mode 100644 src/main/java/com/sjhy/plugin/ui/TypeMapperSettingForm.form create mode 100644 src/main/java/com/sjhy/plugin/ui/TypeMapperSettingForm.java diff --git a/src/main/java/com/sjhy/plugin/config/Settings.java b/src/main/java/com/sjhy/plugin/config/Settings.java index 89d69c7..fd6fa22 100644 --- a/src/main/java/com/sjhy/plugin/config/Settings.java +++ b/src/main/java/com/sjhy/plugin/config/Settings.java @@ -9,6 +9,7 @@ import com.intellij.util.ExceptionUtil; import com.intellij.util.xmlb.XmlSerializerUtil; import com.intellij.util.xmlb.annotations.Transient; import com.sjhy.plugin.entity.*; +import com.sjhy.plugin.enums.ColumnConfigType; import lombok.Data; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/com/sjhy/plugin/dict/GlobalDict.java b/src/main/java/com/sjhy/plugin/dict/GlobalDict.java new file mode 100644 index 0000000..324bbd3 --- /dev/null +++ b/src/main/java/com/sjhy/plugin/dict/GlobalDict.java @@ -0,0 +1,23 @@ +package com.sjhy.plugin.dict; + +/** + * 全局字典 + * + * @author makejava + * @version 1.0.0 + * @date 2021/08/07 11:41 + */ +public interface GlobalDict { + /** + * 版本号 + */ + String VERSION = "1.2.4"; + /** + * 作者名称 + */ + String AUTHOR = "makejava"; + /** + * 默认分组名称 + */ + String DEFAULT_GROUP_NAME = "Default"; +} diff --git a/src/main/java/com/sjhy/plugin/dto/SettingsStorageDTO.java b/src/main/java/com/sjhy/plugin/dto/SettingsStorageDTO.java new file mode 100644 index 0000000..279c51a --- /dev/null +++ b/src/main/java/com/sjhy/plugin/dto/SettingsStorageDTO.java @@ -0,0 +1,109 @@ +package com.sjhy.plugin.dto; + +import com.sjhy.plugin.dict.GlobalDict; +import com.sjhy.plugin.entity.*; +import lombok.Data; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +/** + * 设置储存传输对象 + * + * @author makejava + * @version 1.0.0 + * @date 2021/08/07 11:35 + */ +@Data +public class SettingsStorageDTO { + /** + * 返回默认值,不使用静态常量,防止默认值别篡改 + * + * @return 储存对象 + */ + public static SettingsStorageDTO defaultVal() { + SettingsStorageDTO storage = new SettingsStorageDTO(); + storage.author = GlobalDict.AUTHOR; + storage.version = GlobalDict.VERSION; + storage.userSecure = ""; + // 默认分组名称 + storage.currTypeMapperGroupName = GlobalDict.DEFAULT_GROUP_NAME; + storage.currTemplateGroupName = GlobalDict.DEFAULT_GROUP_NAME; + storage.currColumnConfigGroupName = GlobalDict.DEFAULT_GROUP_NAME; + storage.currGlobalConfigGroupName = GlobalDict.DEFAULT_GROUP_NAME; + // 默认配置信息 + storage.typeMapperGroupMap = new HashMap<>(16); + TypeMapperGroup typeMapperGroup = new TypeMapperGroup(); + typeMapperGroup.setName(GlobalDict.DEFAULT_GROUP_NAME); + typeMapperGroup.setElementList(Arrays.asList(new TypeMapper("varchar", "java.lang.String"), new TypeMapper("varchar\\(\\)", "java.lang.String"))); + storage.typeMapperGroupMap.put(GlobalDict.DEFAULT_GROUP_NAME, typeMapperGroup); + return storage; + } + + /** + * 重置为默认值 + */ + public void resetDefaultVal() { + SettingsStorageDTO defaultVal = defaultVal(); + this.setAuthor(defaultVal.getAuthor()); + this.setVersion(defaultVal.getVersion()); + this.setCurrColumnConfigGroupName(defaultVal.getCurrColumnConfigGroupName()); + this.setCurrTemplateGroupName(defaultVal.getCurrTemplateGroupName()); + this.setCurrGlobalConfigGroupName(defaultVal.getCurrGlobalConfigGroupName()); + this.setCurrTypeMapperGroupName(defaultVal.getCurrTypeMapperGroupName()); + this.setGlobalConfigGroupMap(defaultVal.getGlobalConfigGroupMap()); + this.setColumnConfigGroupMap(defaultVal.getColumnConfigGroupMap()); + this.setTypeMapperGroupMap(defaultVal.getTypeMapperGroupMap()); + this.setTemplateGroupMap(defaultVal.getTemplateGroupMap()); + } + + /** + * 作者 + */ + private String author; + /** + * 版本号 + */ + private String version; + /** + * 用户密钥 + */ + private String userSecure; + /** + * 当前类型映射组名 + */ + private String currTypeMapperGroupName; + /** + * 类型映射组 + */ + private Map typeMapperGroupMap; + /** + * 当前模板组名 + */ + private String currTemplateGroupName; + /** + * 模板组 + */ + private Map templateGroupMap; + /** + * 当前配置表组名 + */ + private String currColumnConfigGroupName; + /** + * 配置表组 + */ + private Map columnConfigGroupMap; + /** + * 当前全局配置组名 + */ + private String currGlobalConfigGroupName; + /** + * 全局配置组 + */ + private Map globalConfigGroupMap; + + public TypeMapperGroup currentTypeMapperGroup() { + return typeMapperGroupMap.get(currColumnConfigGroupName); + } +} diff --git a/src/main/java/com/sjhy/plugin/entity/ColumnConfig.java b/src/main/java/com/sjhy/plugin/entity/ColumnConfig.java index 0771336..cacb3a8 100644 --- a/src/main/java/com/sjhy/plugin/entity/ColumnConfig.java +++ b/src/main/java/com/sjhy/plugin/entity/ColumnConfig.java @@ -1,5 +1,6 @@ package com.sjhy.plugin.entity; +import com.sjhy.plugin.enums.ColumnConfigType; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/sjhy/plugin/entity/TypeMapper.java b/src/main/java/com/sjhy/plugin/entity/TypeMapper.java index ca71cf1..eb68019 100644 --- a/src/main/java/com/sjhy/plugin/entity/TypeMapper.java +++ b/src/main/java/com/sjhy/plugin/entity/TypeMapper.java @@ -1,5 +1,6 @@ package com.sjhy.plugin.entity; +import com.sjhy.plugin.enums.MatchType; import lombok.Data; import lombok.NoArgsConstructor; @@ -13,6 +14,10 @@ import lombok.NoArgsConstructor; @Data @NoArgsConstructor public class TypeMapper { + /** + * 匹配类型 + */ + private MatchType matchType; /** * 列类型 */ @@ -23,6 +28,7 @@ public class TypeMapper { private String javaType; public TypeMapper(String columnType, String javaType) { + this.matchType = MatchType.REGEX; this.columnType = columnType; this.javaType = javaType; } diff --git a/src/main/java/com/sjhy/plugin/entity/TypeMapperModel.java b/src/main/java/com/sjhy/plugin/entity/TypeMapperModel.java index a1599c8..476eda7 100644 --- a/src/main/java/com/sjhy/plugin/entity/TypeMapperModel.java +++ b/src/main/java/com/sjhy/plugin/entity/TypeMapperModel.java @@ -1,6 +1,8 @@ package com.sjhy.plugin.entity; +import com.intellij.util.ui.EditableModel; import com.sjhy.plugin.comm.AbstractTableModel; +import com.sjhy.plugin.enums.MatchType; /** * 类型隐射模型 @@ -9,23 +11,40 @@ import com.sjhy.plugin.comm.AbstractTableModel; * @version 1.0.0 * @since 2018/07/17 13:10 */ -public class TypeMapperModel extends AbstractTableModel { +public class TypeMapperModel extends AbstractTableModel implements EditableModel { @Override protected String[] initColumnName() { - return new String[]{"columnType", "javaType"}; + return new String[]{"matchType", "columnType", "javaType"}; } @Override protected Object[] toObj(TypeMapper entity) { - return new Object[]{entity.getColumnType(), entity.getJavaType()}; + return new Object[]{entity.getMatchType() != null ? entity.getMatchType().name() : MatchType.REGEX.name(), entity.getColumnType(), entity.getJavaType()}; } @Override protected void setVal(TypeMapper obj, int columnIndex, Object val) { - if (columnIndex==0){ + if (columnIndex == 0) { + obj.setMatchType(MatchType.valueOf((String) val)); + } else if (columnIndex == 1) { obj.setColumnType((String) val); - }else{ + } else { obj.setJavaType((String) val); } } + + @Override + public void addRow() { + addRow(new TypeMapper("demo", "java.lang.String")); + } + + @Override + public void exchangeRows(int oldIndex, int newIndex) { + + } + + @Override + public boolean canExchangeRows(int oldIndex, int newIndex) { + return false; + } } diff --git a/src/main/java/com/sjhy/plugin/entity/ColumnConfigType.java b/src/main/java/com/sjhy/plugin/enums/ColumnConfigType.java similarity index 87% rename from src/main/java/com/sjhy/plugin/entity/ColumnConfigType.java rename to src/main/java/com/sjhy/plugin/enums/ColumnConfigType.java index a8ec6f4..c9dc819 100644 --- a/src/main/java/com/sjhy/plugin/entity/ColumnConfigType.java +++ b/src/main/java/com/sjhy/plugin/enums/ColumnConfigType.java @@ -1,4 +1,4 @@ -package com.sjhy.plugin.entity; +package com.sjhy.plugin.enums; /** * 列配置类型 diff --git a/src/main/java/com/sjhy/plugin/enums/MatchType.java b/src/main/java/com/sjhy/plugin/enums/MatchType.java new file mode 100644 index 0000000..37b47e3 --- /dev/null +++ b/src/main/java/com/sjhy/plugin/enums/MatchType.java @@ -0,0 +1,17 @@ +package com.sjhy.plugin.enums; + +/** + * @author makejava + * @version 1.0.0 + * @date 2021/08/07 17:47 + */ +public enum MatchType { + /** + * 正常的 + */ + ORDINARY, + /** + * 正则表达式 + */ + REGEX, +} diff --git a/src/main/java/com/sjhy/plugin/service/SettingsStorageService.java b/src/main/java/com/sjhy/plugin/service/SettingsStorageService.java new file mode 100644 index 0000000..762f389 --- /dev/null +++ b/src/main/java/com/sjhy/plugin/service/SettingsStorageService.java @@ -0,0 +1,31 @@ +package com.sjhy.plugin.service; + +import com.intellij.openapi.components.PersistentStateComponent; +import com.intellij.openapi.components.ServiceManager; +import com.sjhy.plugin.dto.SettingsStorageDTO; +import com.sjhy.plugin.service.impl.SettingsStorageServiceImpl; + +/** + * @author makejava + * @version 1.0.0 + * @date 2021/08/07 11:55 + */ +public interface SettingsStorageService extends PersistentStateComponent { + /** + * 获取实例 + * + * @return {@link SettingsStorageService} + */ + static SettingsStorageService getInstance() { + return ServiceManager.getService(SettingsStorageServiceImpl.class); + } + + /** + * 获取设置存储 + * + * @return {@link SettingsStorageDTO} + */ + static SettingsStorageDTO getSettingsStorage() { + return getInstance().getState(); + } +} diff --git a/src/main/java/com/sjhy/plugin/service/impl/SettingsStorageServiceImpl.java b/src/main/java/com/sjhy/plugin/service/impl/SettingsStorageServiceImpl.java new file mode 100644 index 0000000..a435ca5 --- /dev/null +++ b/src/main/java/com/sjhy/plugin/service/impl/SettingsStorageServiceImpl.java @@ -0,0 +1,44 @@ +package com.sjhy.plugin.service.impl; + +import com.intellij.openapi.components.State; +import com.intellij.openapi.components.Storage; +import com.sjhy.plugin.dto.SettingsStorageDTO; +import com.sjhy.plugin.service.SettingsStorageService; +import lombok.Data; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * 设置储存服务实现 + * + * @author makejava + * @version 1.0.0 + * @date 2021/08/07 11:32 + */ +@Data +@State(name = "EasyCodeSetting", storages = @Storage("easy-code-setting2.xml")) +public class SettingsStorageServiceImpl implements SettingsStorageService { + + private SettingsStorageDTO settingsStorage = SettingsStorageDTO.defaultVal(); + + /** + * 获取配置 + * + * @return 配置对象 + */ + @Nullable + @Override + public SettingsStorageDTO getState() { + return settingsStorage; + } + + /** + * 加载配置 + * + * @param state 配置对象 + */ + @Override + public void loadState(@NotNull SettingsStorageDTO state) { + this.settingsStorage = state; + } +} diff --git a/src/main/java/com/sjhy/plugin/ui/ConfigTableDialog.java b/src/main/java/com/sjhy/plugin/ui/ConfigTableDialog.java index be12b79..d7d7ae1 100644 --- a/src/main/java/com/sjhy/plugin/ui/ConfigTableDialog.java +++ b/src/main/java/com/sjhy/plugin/ui/ConfigTableDialog.java @@ -7,6 +7,7 @@ import com.intellij.ui.BooleanTableCellEditor; import com.intellij.util.ui.ComboBoxCellEditor; import com.sjhy.plugin.constants.MsgValue; import com.sjhy.plugin.entity.*; +import com.sjhy.plugin.enums.ColumnConfigType; import com.sjhy.plugin.service.TableInfoService; import com.sjhy.plugin.tool.CacheDataUtils; import com.sjhy.plugin.tool.CurrGroupUtils; diff --git a/src/main/java/com/sjhy/plugin/ui/MainSetting.java b/src/main/java/com/sjhy/plugin/ui/MainSetting.java index aaf9712..993be87 100644 --- a/src/main/java/com/sjhy/plugin/ui/MainSetting.java +++ b/src/main/java/com/sjhy/plugin/ui/MainSetting.java @@ -332,7 +332,7 @@ public class MainSetting implements Configurable, Configurable.Composite { @Override public Configurable[] getConfigurables() { Configurable[] result = new Configurable[4]; - result[0] = new TypeMapperSetting(settings); + result[0] = new TypeMapperSetting(); result[1] = new TemplateSettingPanel(); result[2] = new TableSettingPanel(); result[3] = new GlobalConfigSettingPanel(); diff --git a/src/main/java/com/sjhy/plugin/ui/MainSettingForm.form b/src/main/java/com/sjhy/plugin/ui/MainSettingForm.form new file mode 100644 index 0000000..260a4a9 --- /dev/null +++ b/src/main/java/com/sjhy/plugin/ui/MainSettingForm.form @@ -0,0 +1,224 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/com/sjhy/plugin/ui/MainSettingForm.java b/src/main/java/com/sjhy/plugin/ui/MainSettingForm.java new file mode 100644 index 0000000..d369a3a --- /dev/null +++ b/src/main/java/com/sjhy/plugin/ui/MainSettingForm.java @@ -0,0 +1,135 @@ +package com.sjhy.plugin.ui; + +import com.intellij.openapi.options.Configurable; +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.sjhy.plugin.dto.SettingsStorageDTO; +import com.sjhy.plugin.service.SettingsStorageService; +import com.sjhy.plugin.tool.StringUtils; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.util.Objects; + +/** + * @author makejava + * @version 1.0.0 + * @date 2021/08/07 09:22 + */ +public class MainSettingForm implements Configurable, Configurable.Composite { + /** + * 设置储存传输对象 + */ + private SettingsStorageDTO settingsStorage; + private JLabel versionLabel; + private JButton resetBtn; + private JButton pushBtn; + private JButton pullBtn; + private JButton exportByNetBtn; + private JButton importByNetBtn; + private JButton exportByFileBtn; + private JButton importByFileBtn; + private JButton exportByClipboardBtn; + private JButton importByClipboardBtn; + private JPanel mainPanel; + private JTextField userSecureEditor; + private JTextField authorEditor; + + public MainSettingForm() { + } + + private void loadStorageValue() { + this.versionLabel.setText(this.settingsStorage.getVersion()); + this.authorEditor.setText(this.settingsStorage.getAuthor()); + this.userSecureEditor.setText(this.settingsStorage.getUserSecure()); + if (StringUtils.isEmpty(this.settingsStorage.getUserSecure())) { + this.pullBtn.setEnabled(false); + this.pushBtn.setEnabled(false); + } else { + this.pullBtn.setEnabled(true); + this.pushBtn.setEnabled(true); + } + } + + private void initEvent() { + this.resetBtn.addActionListener(e -> JBPopupFactory.getInstance() + .createConfirmation("确认恢复默认设置,所有Default分组配置将被重置?", () -> { + // 重置默认值后重新加载配置 + settingsStorage.resetDefaultVal(); + this.loadStorageValue(); + }, 0) + .showInFocusCenter() + ); + + this.userSecureEditor.addCaretListener(e -> { + String userSecure = this.userSecureEditor.getText(); + if (StringUtils.isEmpty(userSecure)) { + this.pullBtn.setEnabled(false); + this.pushBtn.setEnabled(false); + } else { + this.pullBtn.setEnabled(true); + this.pushBtn.setEnabled(true); + } + }); + } + + @Override + public String getDisplayName() { + return "EasyCode"; + } + + @Nullable + @Override + public String getHelpTopic() { + return getDisplayName(); + } + + @Override + public @NotNull Configurable[] getConfigurables() { + Configurable[] result = new Configurable[]{ + new TypeMapperSettingForm(), +// new TemplateSettingPanel(), +// new TableSettingPanel(), +// new GlobalConfigSettingPanel() + }; + return result; + } + + @Override + public @Nullable JComponent createComponent() { + this.settingsStorage = SettingsStorageService.getSettingsStorage(); + // 加载储存数据 + this.loadStorageValue(); + // 初始化事件 + this.initEvent(); + return mainPanel; + } + + @Override + public boolean isModified() { + if (!Objects.equals(this.authorEditor.getText(), settingsStorage.getAuthor())) { + return true; + } + if (!Objects.equals(this.userSecureEditor.getText(), settingsStorage.getUserSecure())) { + return true; + } + return false; + } + + @Override + public void reset() { + this.loadStorageValue(); + } + + @Override + public void apply() throws ConfigurationException { + String author = this.authorEditor.getText(); + if (StringUtils.isEmpty(author)) { + throw new ConfigurationException("作者名称不能为空"); + } + this.settingsStorage.setAuthor(author); + String userSecure = this.userSecureEditor.getText(); + this.settingsStorage.setUserSecure(userSecure); + } +} diff --git a/src/main/java/com/sjhy/plugin/ui/TableSettingPanel.java b/src/main/java/com/sjhy/plugin/ui/TableSettingPanel.java index 68acb4c..2f46a0c 100644 --- a/src/main/java/com/sjhy/plugin/ui/TableSettingPanel.java +++ b/src/main/java/com/sjhy/plugin/ui/TableSettingPanel.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference; 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.enums.ColumnConfigType; import com.sjhy.plugin.tool.CloneUtils; import com.sjhy.plugin.config.Settings; import org.jetbrains.annotations.Nls; diff --git a/src/main/java/com/sjhy/plugin/ui/TypeMapperSetting.java b/src/main/java/com/sjhy/plugin/ui/TypeMapperSetting.java index bd83554..651d85a 100644 --- a/src/main/java/com/sjhy/plugin/ui/TypeMapperSetting.java +++ b/src/main/java/com/sjhy/plugin/ui/TypeMapperSetting.java @@ -78,8 +78,8 @@ public class TypeMapperSetting implements Configurable { private Settings settings; - public TypeMapperSetting(Settings settings) { - this.settings = settings; + public TypeMapperSetting() { + this.settings = Settings.getInstance(); this.typeMapperGroupMap = CloneUtils.cloneByJson(settings.getTypeMapperGroupMap(), new TypeReference>() {}); this.currGroupName = settings.getCurrTypeMapperGroupName(); //添加类型 diff --git a/src/main/java/com/sjhy/plugin/ui/TypeMapperSettingForm.form b/src/main/java/com/sjhy/plugin/ui/TypeMapperSettingForm.form new file mode 100644 index 0000000..43cc777 --- /dev/null +++ b/src/main/java/com/sjhy/plugin/ui/TypeMapperSettingForm.form @@ -0,0 +1,47 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/com/sjhy/plugin/ui/TypeMapperSettingForm.java b/src/main/java/com/sjhy/plugin/ui/TypeMapperSettingForm.java new file mode 100644 index 0000000..d17fdf8 --- /dev/null +++ b/src/main/java/com/sjhy/plugin/ui/TypeMapperSettingForm.java @@ -0,0 +1,96 @@ +package com.sjhy.plugin.ui; + +import com.intellij.icons.AllIcons; +import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.options.Configurable; +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.ui.ComboBox; +import com.intellij.ui.JBColor; +import com.intellij.ui.ToolbarDecorator; +import com.intellij.ui.table.JBTable; +import com.sjhy.plugin.entity.TypeMapperModel; +import com.sjhy.plugin.enums.MatchType; +import com.sjhy.plugin.service.SettingsStorageService; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.awt.*; +import java.util.Arrays; +import java.util.stream.Stream; + +/** + * @author makejava + * @version 1.0.0 + * @date 2021/08/07 15:33 + */ +public class TypeMapperSettingForm implements Configurable { + private JPanel mainPanel; + private JComboBox groupComboBox; + private JPanel groupOperatorPanel; + /** + * 表格 + */ + private JBTable table; + + private void initPanel() { + TypeMapperModel typeMapperModel = new TypeMapperModel(); + typeMapperModel.init(SettingsStorageService.getSettingsStorage().currentTypeMapperGroup().getElementList()); + table = new JBTable(typeMapperModel); + ComboBox comboField = new ComboBox<>(Stream.of(MatchType.values()).map(Enum::name).toArray(value -> new String[2]), 20); + if (comboField.getPopup() != null) { + comboField.getPopup().getList().setBackground(JBColor.MAGENTA); + } + DefaultCellEditor cellEditor = new DefaultCellEditor(comboField); + table.getColumn("matchType").setCellEditor(cellEditor); + table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(table); + // 表格初始化 + this.mainPanel.add(decorator.createPanel(), BorderLayout.CENTER); + // 分组操作 + DefaultActionGroup groupAction = new DefaultActionGroup(Arrays.asList(new AnAction(AllIcons.Actions.Copy) { + @Override + public void actionPerformed(@NotNull AnActionEvent e) { + + } + }, new AnAction(AllIcons.General.Remove) { + @Override + public void actionPerformed(@NotNull AnActionEvent e) { + + } + })); + ActionToolbar groupActionToolbar = ActionManager.getInstance().createActionToolbar("Group Toolbar", groupAction, true); + this.groupOperatorPanel.add(groupActionToolbar.getComponent()); + } + + private void loadStorageValue() { + + } + + @Override + public String getDisplayName() { + return "Type Mapper"; + } + + @Nullable + @Override + public String getHelpTopic() { + return getDisplayName(); + } + + @Override + public @Nullable JComponent createComponent() { + this.initPanel(); + return mainPanel; + } + + @Override + public boolean isModified() { + return false; + } + + @Override + public void apply() throws ConfigurationException { + + } +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index c0afba7..d2f3211 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -227,11 +227,13 @@ + - + +