Skip to content

Commit e9bfbbc

Browse files
committed
feat: support for file jump configuration
1 parent d808f45 commit e9bfbbc

11 files changed

+211
-9
lines changed

README.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@
8383
- 随机参数
8484
- 默认参数
8585
- 自定义参数
86-
- mapper接口/方法跳转XML文件
87-
- XML文件跳转mapper接口/方法
86+
- mapper接口/方法跳转XML文件([可配置](#4-配置))
87+
- XML文件跳转mapper接口/方法([可配置](#4-配置))
8888
- 基于mock参数将mapper接口方法的xml转换成真实SQL
8989
- 按照文件/项目维度扫描XML文件,并生成对应的真实SQL语句,并进行规约/索引相关校验
9090

@@ -299,7 +299,13 @@ mock数据完成后,会存储主键id的范围(持久化存储到本地文
299299

300300
![mock clean](./docs/mock_clean.jpg)
301301

302-
# 4. 参考
302+
# 4. 配置
303+
304+
相关配置:<kbd>Preferences(Settings)</kbd> > <kbd>Tools</kbd> > <kbd>Mybatis Sql Viewer</kbd>
305+
306+
![](./docs/mybatis-sql-viewer-configuration.png)
307+
308+
# 5. 参考
303309

304310
在实现过程中参考了许多非常优秀的项目,拷贝了很多代码,特此感谢。
305311

README_EN.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ This plugin supports two modes: MyBatis mode and non-MyBatis mode. The differenc
8383
- Random parameters
8484
- Default parameters
8585
- Custom parameters
86-
- Navigate from mapper interface/method to XML file
87-
- Navigate from XML file to mapper interface/method
86+
- Navigate from mapper interface/method to XML file([Configurable](#4-Configuration))
87+
- Navigate from XML file to mapper interface/method([Configurable](#4-Configuration))
8888
- Convert mapper interface method XML to real SQL based on mock parameters
8989
- Scan XML files based on file/project dimensions, generate corresponding real SQL statements, and perform specification/index verification
9090

@@ -307,7 +307,13 @@ After the completion of mock data, the range of primary key IDs will be stored (
307307

308308
![mock clean](./docs/mock_clean.jpg)
309309

310-
# 4. Reference
310+
# 5. Configuration
311+
312+
<kbd>Preferences(Settings)</kbd> > <kbd>Tools</kbd> > <kbd>Mybatis Sql Viewer</kbd>
313+
314+
![](./docs/mybatis-sql-viewer-configuration.png)
315+
316+
# 5. Reference
311317

312318
Many excellent projects were referenced and much code was copied during the implementation process. I would like to express my gratitude for this.
313319

build.gradle

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group 'org.linyimin'
9-
version '2.0.0'
9+
version '2.0.1'
1010

1111
sonarqube {
1212
properties {
@@ -46,6 +46,13 @@ intellij {
4646
}
4747
patchPluginXml {
4848
changeNotes = """
49+
<h4>2.0.1</h4>
50+
<ul>
51+
<li>Support for configurable file navigation</li>
52+
</ul>
53+
<ul>
54+
<li>支持文件跳转可配置化</li>
55+
</ul>
4956
<h4>2.0.0</h4>
5057
<ul>
5158
<li>Supports mybatis mode and non-mybatis mode</li>
144 KB
Loading

src/main/java/io/github/linyimin/plugin/provider/jump/MapperInterfaceJumpLineMakerProvider.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.intellij.psi.xml.XmlTag;
1010
import io.github.linyimin.plugin.configuration.GlobalConfig;
1111
import io.github.linyimin.plugin.provider.MapperInterfaceProcessor;
12+
import io.github.linyimin.plugin.settings.SqlViewerSettingsState;
1213
import io.github.linyimin.plugin.utils.IconUtils;
1314
import io.github.linyimin.plugin.utils.JavaUtils;
1415
import org.apache.commons.collections.CollectionUtils;
@@ -27,7 +28,9 @@ public class MapperInterfaceJumpLineMakerProvider extends RelatedItemLineMarkerP
2728
@Override
2829
protected void collectNavigationMarkers(@NotNull PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo> result) {
2930

30-
if (!GlobalConfig.isMybatisMode) {
31+
SqlViewerSettingsState state = SqlViewerSettingsState.getInstance();
32+
33+
if (!GlobalConfig.isMybatisMode || !state.fileJumpEnable) {
3134
return;
3235
}
3336

src/main/java/io/github/linyimin/plugin/provider/jump/MapperXmlJumpLineMakerProvider.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.intellij.psi.xml.XmlTokenType;
1212
import io.github.linyimin.plugin.configuration.GlobalConfig;
1313
import io.github.linyimin.plugin.provider.MapperXmlProcessor;
14+
import io.github.linyimin.plugin.settings.SqlViewerSettingsState;
1415
import io.github.linyimin.plugin.utils.IconUtils;
1516
import org.apache.commons.collections.CollectionUtils;
1617
import org.jetbrains.annotations.NotNull;
@@ -30,7 +31,9 @@ public class MapperXmlJumpLineMakerProvider extends RelatedItemLineMarkerProvide
3031
@Override
3132
protected void collectNavigationMarkers(@NotNull PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo> result) {
3233

33-
if (!GlobalConfig.isMybatisMode) {
34+
SqlViewerSettingsState state = SqlViewerSettingsState.getInstance();
35+
36+
if (!GlobalConfig.isMybatisMode || !state.fileJumpEnable) {
3437
return;
3538
}
3639

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.github.linyimin.plugin.settings;
2+
3+
import com.intellij.openapi.application.ApplicationManager;
4+
import com.intellij.openapi.components.PersistentStateComponent;
5+
import com.intellij.openapi.components.State;
6+
import com.intellij.openapi.components.Storage;
7+
import com.intellij.util.xmlb.XmlSerializerUtil;
8+
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
10+
11+
/**
12+
* @author yiminlin
13+
* @date 2023/04/16 14:18
14+
**/
15+
@State(name = "io.github.linyimin.plugin.settings.SqlViewerSettingsState", storages = {@Storage("mybatis-sql-config.xml")})
16+
public class SqlViewerSettingsState implements PersistentStateComponent<SqlViewerSettingsState> {
17+
18+
public boolean fileJumpEnable = true;
19+
20+
@Override
21+
public @Nullable SqlViewerSettingsState getState() {
22+
return this;
23+
}
24+
25+
@Override
26+
public void loadState(@NotNull SqlViewerSettingsState state) {
27+
XmlSerializerUtil.copyBean(state, this);
28+
}
29+
30+
public static SqlViewerSettingsState getInstance() {
31+
return ApplicationManager.getApplication().getService(SqlViewerSettingsState.class);
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="io.github.linyimin.plugin.ui.SqlViewerSettingsPanel">
3+
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="0" left="0" bottom="0" right="0"/>
5+
<constraints>
6+
<xy x="20" y="20" width="500" height="400"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children>
11+
<grid id="e9527" binding="functionalityTitledBorderPanel" custom-create="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
12+
<margin top="0" left="0" bottom="0" right="0"/>
13+
<constraints>
14+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
15+
</constraints>
16+
<properties/>
17+
<border type="none"/>
18+
<children/>
19+
</grid>
20+
<vspacer id="1632e">
21+
<constraints>
22+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
23+
</constraints>
24+
</vspacer>
25+
<grid id="73245" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
26+
<margin top="0" left="0" bottom="0" right="0"/>
27+
<constraints>
28+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="4" use-parent-layout="false"/>
29+
</constraints>
30+
<properties/>
31+
<border type="none"/>
32+
<children>
33+
<component id="cfc8c" class="javax.swing.JCheckBox" binding="fileJumpEnableBox">
34+
<constraints>
35+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
36+
</constraints>
37+
<properties>
38+
<text value="Enable File Jump"/>
39+
</properties>
40+
</component>
41+
</children>
42+
</grid>
43+
</children>
44+
</grid>
45+
</form>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package io.github.linyimin.plugin.ui;
2+
3+
import com.intellij.openapi.Disposable;
4+
import com.intellij.openapi.application.ex.ApplicationManagerEx;
5+
import com.intellij.openapi.options.Configurable;
6+
import com.intellij.openapi.options.ConfigurationException;
7+
import com.intellij.openapi.ui.MessageDialogBuilder;
8+
import com.intellij.openapi.ui.Messages;
9+
import com.intellij.ui.TitledSeparator;
10+
import io.github.linyimin.plugin.settings.SqlViewerSettingsState;
11+
import org.jetbrains.annotations.Nls;
12+
import org.jetbrains.annotations.Nullable;
13+
14+
import javax.swing.*;
15+
import java.awt.*;
16+
17+
/**
18+
* @author yiminlin
19+
* @date 2023/04/16 14:30
20+
**/
21+
public class SqlViewerSettingsPanel implements Configurable, Disposable {
22+
private JPanel functionalityTitledBorderPanel;
23+
private JCheckBox fileJumpEnableBox;
24+
private JPanel myMainPanel;
25+
26+
private boolean needRestart = false;
27+
28+
public SqlViewerSettingsPanel() {
29+
init();
30+
}
31+
32+
private void init() {
33+
34+
}
35+
36+
@Override
37+
public @Nls(capitalization = Nls.Capitalization.Title) String getDisplayName() {
38+
return "Mybatis Sql Viewer";
39+
}
40+
41+
@Override
42+
public @Nullable JComponent createComponent() {
43+
return myMainPanel;
44+
}
45+
46+
@Override
47+
public boolean isModified() {
48+
SqlViewerSettingsState state = SqlViewerSettingsState.getInstance();
49+
50+
needRestart = state.fileJumpEnable != fileJumpEnableBox.isSelected();
51+
52+
return needRestart;
53+
}
54+
55+
@Override
56+
public void reset() {
57+
SqlViewerSettingsState state = SqlViewerSettingsState.getInstance();
58+
fileJumpEnableBox.setSelected(state.fileJumpEnable);
59+
}
60+
61+
@Override
62+
public void apply() throws ConfigurationException {
63+
64+
SqlViewerSettingsState state = SqlViewerSettingsState.getInstance();
65+
66+
state.fileJumpEnable = fileJumpEnableBox.isSelected();
67+
68+
if (!needRestart) {
69+
return;
70+
}
71+
72+
int yesNo = MessageDialogBuilder.yesNo("Settings changed!", "Requires restarting the IDE to take effect. " +
73+
"Do you want to restart to apply the settings?")
74+
.yesText("Restart")
75+
.noText("Not Now").show();
76+
77+
if (yesNo == Messages.YES) {
78+
ApplicationManagerEx.getApplicationEx().restart(true);
79+
}
80+
81+
}
82+
83+
@Override
84+
public void dispose() {
85+
86+
}
87+
88+
private void createUIComponents() {
89+
functionalityTitledBorderPanel = new JPanel(new BorderLayout());
90+
TitledSeparator functionalitySeparator = new TitledSeparator("Functionality Settings");
91+
functionalityTitledBorderPanel.add(functionalitySeparator, BorderLayout.CENTER);
92+
}
93+
}

src/main/resources/META-INF/messages/MybatisSqlViewerBundle.properties

Whitespace-only changes.

src/main/resources/META-INF/plugin.xml

+6
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@
5959

6060
<projectService serviceImplementation="io.github.linyimin.plugin.configuration.MybatisSqlStateComponent" order="first" />
6161
<projectService serviceImplementation="io.github.linyimin.plugin.sql.DatasourceComponent" order="first" />
62+
<applicationService serviceImplementation="io.github.linyimin.plugin.settings.SqlViewerSettingsState"/>
6263

6364
<toolWindow id="mybatis-sql-viewer" icon="/mybatis-sql-viewer.svg" doNotActivateOnStart="true" factoryClass="io.github.linyimin.plugin.ui.MybatisSqlViewerToolWindowFactory" anchor="bottom" secondary="false" />
65+
66+
<applicationConfigurable parentId="tools" instance="io.github.linyimin.plugin.ui.SqlViewerSettingsPanel"
67+
id="io.github.linyimin.plugin.settings.SqlViewerSettings"
68+
displayName="Mybatis Sql Viewer"/>
69+
6470
</extensions>
6571

6672
<project-components>

0 commit comments

Comments
 (0)