Skip to content

Commit

Permalink
feat: support for file jump configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
linyimin0812 committed Apr 16, 2023
1 parent d808f45 commit e9bfbbc
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 9 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
- 随机参数
- 默认参数
- 自定义参数
- mapper接口/方法跳转XML文件
- XML文件跳转mapper接口/方法
- mapper接口/方法跳转XML文件([可配置](#4-配置))
- XML文件跳转mapper接口/方法([可配置](#4-配置))
- 基于mock参数将mapper接口方法的xml转换成真实SQL
- 按照文件/项目维度扫描XML文件,并生成对应的真实SQL语句,并进行规约/索引相关校验

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

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

# 4. 参考
# 4. 配置

相关配置:<kbd>Preferences(Settings)</kbd> > <kbd>Tools</kbd> > <kbd>Mybatis Sql Viewer</kbd>

![](./docs/mybatis-sql-viewer-configuration.png)

# 5. 参考

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

Expand Down
12 changes: 9 additions & 3 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ This plugin supports two modes: MyBatis mode and non-MyBatis mode. The differenc
- Random parameters
- Default parameters
- Custom parameters
- Navigate from mapper interface/method to XML file
- Navigate from XML file to mapper interface/method
- Navigate from mapper interface/method to XML file([Configurable](#4-Configuration))
- Navigate from XML file to mapper interface/method([Configurable](#4-Configuration))
- Convert mapper interface method XML to real SQL based on mock parameters
- Scan XML files based on file/project dimensions, generate corresponding real SQL statements, and perform specification/index verification

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

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

# 4. Reference
# 5. Configuration

<kbd>Preferences(Settings)</kbd> > <kbd>Tools</kbd> > <kbd>Mybatis Sql Viewer</kbd>

![](./docs/mybatis-sql-viewer-configuration.png)

# 5. Reference

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

Expand Down
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group 'org.linyimin'
version '2.0.0'
version '2.0.1'

sonarqube {
properties {
Expand Down Expand Up @@ -46,6 +46,13 @@ intellij {
}
patchPluginXml {
changeNotes = """
<h4>2.0.1</h4>
<ul>
<li>Support for configurable file navigation</li>
</ul>
<ul>
<li>支持文件跳转可配置化</li>
</ul>
<h4>2.0.0</h4>
<ul>
<li>Supports mybatis mode and non-mybatis mode</li>
Expand Down
Binary file added docs/mybatis-sql-viewer-configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.intellij.psi.xml.XmlTag;
import io.github.linyimin.plugin.configuration.GlobalConfig;
import io.github.linyimin.plugin.provider.MapperInterfaceProcessor;
import io.github.linyimin.plugin.settings.SqlViewerSettingsState;
import io.github.linyimin.plugin.utils.IconUtils;
import io.github.linyimin.plugin.utils.JavaUtils;
import org.apache.commons.collections.CollectionUtils;
Expand All @@ -27,7 +28,9 @@ public class MapperInterfaceJumpLineMakerProvider extends RelatedItemLineMarkerP
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo> result) {

if (!GlobalConfig.isMybatisMode) {
SqlViewerSettingsState state = SqlViewerSettingsState.getInstance();

if (!GlobalConfig.isMybatisMode || !state.fileJumpEnable) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.intellij.psi.xml.XmlTokenType;
import io.github.linyimin.plugin.configuration.GlobalConfig;
import io.github.linyimin.plugin.provider.MapperXmlProcessor;
import io.github.linyimin.plugin.settings.SqlViewerSettingsState;
import io.github.linyimin.plugin.utils.IconUtils;
import org.apache.commons.collections.CollectionUtils;
import org.jetbrains.annotations.NotNull;
Expand All @@ -30,7 +31,9 @@ public class MapperXmlJumpLineMakerProvider extends RelatedItemLineMarkerProvide
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo> result) {

if (!GlobalConfig.isMybatisMode) {
SqlViewerSettingsState state = SqlViewerSettingsState.getInstance();

if (!GlobalConfig.isMybatisMode || !state.fileJumpEnable) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.github.linyimin.plugin.settings;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* @author yiminlin
* @date 2023/04/16 14:18
**/
@State(name = "io.github.linyimin.plugin.settings.SqlViewerSettingsState", storages = {@Storage("mybatis-sql-config.xml")})
public class SqlViewerSettingsState implements PersistentStateComponent<SqlViewerSettingsState> {

public boolean fileJumpEnable = true;

@Override
public @Nullable SqlViewerSettingsState getState() {
return this;
}

@Override
public void loadState(@NotNull SqlViewerSettingsState state) {
XmlSerializerUtil.copyBean(state, this);
}

public static SqlViewerSettingsState getInstance() {
return ApplicationManager.getApplication().getService(SqlViewerSettingsState.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="io.github.linyimin.plugin.ui.SqlViewerSettingsPanel">
<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">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<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">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<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"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<vspacer id="1632e">
<constraints>
<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"/>
</constraints>
</vspacer>
<grid id="73245" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<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"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="cfc8c" class="javax.swing.JCheckBox" binding="fileJumpEnableBox">
<constraints>
<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"/>
</constraints>
<properties>
<text value="Enable File Jump"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package io.github.linyimin.plugin.ui;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.ui.MessageDialogBuilder;
import com.intellij.openapi.ui.Messages;
import com.intellij.ui.TitledSeparator;
import io.github.linyimin.plugin.settings.SqlViewerSettingsState;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;

/**
* @author yiminlin
* @date 2023/04/16 14:30
**/
public class SqlViewerSettingsPanel implements Configurable, Disposable {
private JPanel functionalityTitledBorderPanel;
private JCheckBox fileJumpEnableBox;
private JPanel myMainPanel;

private boolean needRestart = false;

public SqlViewerSettingsPanel() {
init();
}

private void init() {

}

@Override
public @Nls(capitalization = Nls.Capitalization.Title) String getDisplayName() {
return "Mybatis Sql Viewer";
}

@Override
public @Nullable JComponent createComponent() {
return myMainPanel;
}

@Override
public boolean isModified() {
SqlViewerSettingsState state = SqlViewerSettingsState.getInstance();

needRestart = state.fileJumpEnable != fileJumpEnableBox.isSelected();

return needRestart;
}

@Override
public void reset() {
SqlViewerSettingsState state = SqlViewerSettingsState.getInstance();
fileJumpEnableBox.setSelected(state.fileJumpEnable);
}

@Override
public void apply() throws ConfigurationException {

SqlViewerSettingsState state = SqlViewerSettingsState.getInstance();

state.fileJumpEnable = fileJumpEnableBox.isSelected();

if (!needRestart) {
return;
}

int yesNo = MessageDialogBuilder.yesNo("Settings changed!", "Requires restarting the IDE to take effect. " +
"Do you want to restart to apply the settings?")
.yesText("Restart")
.noText("Not Now").show();

if (yesNo == Messages.YES) {
ApplicationManagerEx.getApplicationEx().restart(true);
}

}

@Override
public void dispose() {

}

private void createUIComponents() {
functionalityTitledBorderPanel = new JPanel(new BorderLayout());
TitledSeparator functionalitySeparator = new TitledSeparator("Functionality Settings");
functionalityTitledBorderPanel.add(functionalitySeparator, BorderLayout.CENTER);
}
}
Empty file.
6 changes: 6 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@

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

<toolWindow id="mybatis-sql-viewer" icon="/mybatis-sql-viewer.svg" doNotActivateOnStart="true" factoryClass="io.github.linyimin.plugin.ui.MybatisSqlViewerToolWindowFactory" anchor="bottom" secondary="false" />

<applicationConfigurable parentId="tools" instance="io.github.linyimin.plugin.ui.SqlViewerSettingsPanel"
id="io.github.linyimin.plugin.settings.SqlViewerSettings"
displayName="Mybatis Sql Viewer"/>

</extensions>

<project-components>
Expand Down

0 comments on commit e9bfbbc

Please sign in to comment.