Skip to content

Commit 1ec0b83

Browse files
committed
feat: support line mark lunch mybatis sql viewer
1 parent 1640289 commit 1ec0b83

File tree

7 files changed

+311
-2
lines changed

7 files changed

+311
-2
lines changed

src/main/java/io/github/linyimin/plugin/provider/generate/MapperInterfaceGenerateSqlLineMakerProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public LineMarkerInfo<?> getLineMarkerInfo(@NotNull PsiElement element) {
3838
identifierOwner.getNameIdentifier().getTextRange(),
3939
IconUtils.GENERATE_ICON,
4040
tooltip,
41-
null,
41+
new SqlGenerateNavigationHandler(),
4242
GutterIconRenderer.Alignment.CENTER,
4343
() -> "mybatis-sql-viewer");
4444
}

src/main/java/io/github/linyimin/plugin/provider/generate/MapperXmlGenerateSqlLineMakerProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public LineMarkerInfo<?> getLineMarkerInfo(@NotNull PsiElement element) {
3636
xmlTag.getNavigationElement().getTextRange(),
3737
IconUtils.GENERATE_ICON,
3838
tooltip,
39-
null,
39+
new SqlGenerateNavigationHandler(),
4040
GutterIconRenderer.Alignment.CENTER,
4141
() -> "mybatis-sql-viewer");
4242
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.github.linyimin.plugin.provider.generate;
2+
3+
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
4+
import com.intellij.openapi.wm.ToolWindow;
5+
import com.intellij.openapi.wm.ToolWindowManager;
6+
import com.intellij.psi.PsiElement;
7+
import com.intellij.ui.content.Content;
8+
import io.github.linyimin.plugin.window.MybatisSqlViewerToolWindowFactory;
9+
10+
import java.awt.event.MouseEvent;
11+
import java.util.Objects;
12+
13+
/**
14+
* @author yiminlin
15+
* @date 2022/02/01 7:28 下午
16+
**/
17+
public class SqlGenerateNavigationHandler implements GutterIconNavigationHandler<PsiElement> {
18+
19+
@Override
20+
public void navigate(MouseEvent e, PsiElement elt) {
21+
ToolWindow mybatisSqlViewerToolWindow = ToolWindowManager.getInstance(elt.getProject()).getToolWindow("mybatis-sql-viewer");
22+
23+
if (Objects.isNull(mybatisSqlViewerToolWindow)) {
24+
return;
25+
}
26+
27+
mybatisSqlViewerToolWindow.setAutoHide(true);
28+
29+
if (!mybatisSqlViewerToolWindow.isActive()) {
30+
mybatisSqlViewerToolWindow.activate(null);
31+
Content content = mybatisSqlViewerToolWindow.getContentManager().getContent(0);
32+
assert content != null;
33+
mybatisSqlViewerToolWindow.getContentManager().setSelectedContent(content);
34+
}
35+
}
36+
}
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
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.view.MybatisSqlViewerToolWindow">
3+
<grid id="27dc6" binding="root" layout-manager="GridLayoutManager" row-count="4" column-count="4" 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="640" height="377"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children>
11+
<tabbedpane id="691d8" binding="tabbedPane">
12+
<constraints>
13+
<grid row="3" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
14+
</constraints>
15+
<properties/>
16+
<border type="none">
17+
<title-color color="-16777216"/>
18+
</border>
19+
<children>
20+
<scrollpane id="935d5">
21+
<constraints>
22+
<tabbedpane title="params"/>
23+
</constraints>
24+
<properties/>
25+
<border type="none"/>
26+
<children/>
27+
</scrollpane>
28+
<scrollpane id="84ccf">
29+
<constraints>
30+
<tabbedpane title="sql"/>
31+
</constraints>
32+
<properties/>
33+
<border type="none"/>
34+
<children/>
35+
</scrollpane>
36+
<scrollpane id="1709">
37+
<constraints>
38+
<tabbedpane title="result"/>
39+
</constraints>
40+
<properties/>
41+
<border type="none"/>
42+
<children/>
43+
</scrollpane>
44+
<grid id="ac391" layout-manager="GridLayoutManager" row-count="7" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
45+
<margin top="0" left="0" bottom="0" right="0"/>
46+
<constraints>
47+
<tabbedpane title="datasource"/>
48+
</constraints>
49+
<properties/>
50+
<border type="line"/>
51+
<children>
52+
<component id="131db" class="javax.swing.JLabel">
53+
<constraints>
54+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false"/>
55+
</constraints>
56+
<properties>
57+
<text value="Host"/>
58+
</properties>
59+
</component>
60+
<component id="693de" class="javax.swing.JTextField" binding="host">
61+
<constraints>
62+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
63+
<preferred-size width="150" height="-1"/>
64+
</grid>
65+
</constraints>
66+
<properties/>
67+
</component>
68+
<component id="f0bb4" class="javax.swing.JLabel">
69+
<constraints>
70+
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
71+
</constraints>
72+
<properties>
73+
<text value="Port"/>
74+
</properties>
75+
</component>
76+
<component id="8f88c" class="javax.swing.JTextField" binding="port">
77+
<constraints>
78+
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
79+
<preferred-size width="150" height="-1"/>
80+
</grid>
81+
</constraints>
82+
<properties/>
83+
</component>
84+
<component id="a119d" class="javax.swing.JLabel">
85+
<constraints>
86+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="1" use-parent-layout="false"/>
87+
</constraints>
88+
<properties>
89+
<text value="User"/>
90+
</properties>
91+
</component>
92+
<component id="3358e" class="javax.swing.JTextField" binding="user">
93+
<constraints>
94+
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
95+
<preferred-size width="150" height="-1"/>
96+
</grid>
97+
</constraints>
98+
<properties/>
99+
</component>
100+
<component id="9f160" class="javax.swing.JLabel">
101+
<constraints>
102+
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
103+
</constraints>
104+
<properties>
105+
<text value="password"/>
106+
</properties>
107+
</component>
108+
<component id="223ae" class="javax.swing.JLabel">
109+
<constraints>
110+
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
111+
</constraints>
112+
<properties>
113+
<text value="Database"/>
114+
</properties>
115+
</component>
116+
<component id="63cf7" class="javax.swing.JTextField" binding="database">
117+
<constraints>
118+
<grid row="3" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
119+
<preferred-size width="150" height="-1"/>
120+
</grid>
121+
</constraints>
122+
<properties/>
123+
</component>
124+
<component id="16449" class="javax.swing.JPasswordField" binding="password">
125+
<constraints>
126+
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
127+
<preferred-size width="150" height="-1"/>
128+
</grid>
129+
</constraints>
130+
<properties/>
131+
</component>
132+
<component id="92d63" class="javax.swing.JLabel">
133+
<constraints>
134+
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
135+
</constraints>
136+
<properties>
137+
<text value="Url"/>
138+
</properties>
139+
</component>
140+
<component id="436e" class="javax.swing.JTextField" binding="url">
141+
<constraints>
142+
<grid row="4" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
143+
<preferred-size width="150" height="-1"/>
144+
</grid>
145+
</constraints>
146+
<properties>
147+
<editable value="false"/>
148+
<enabled value="false"/>
149+
<text value=""/>
150+
</properties>
151+
</component>
152+
<component id="f8aaa" class="javax.swing.JButton" binding="connectionTestButton" default-binding="true">
153+
<constraints>
154+
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
155+
</constraints>
156+
<properties>
157+
<text value="Connection Test"/>
158+
</properties>
159+
</component>
160+
<component id="e3f8b" class="javax.swing.JLabel">
161+
<constraints>
162+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
163+
</constraints>
164+
<properties>
165+
<text value=""/>
166+
</properties>
167+
</component>
168+
<component id="910c4" class="javax.swing.JTextArea" binding="connectionInfoTextArea">
169+
<constraints>
170+
<grid row="6" column="1" row-span="1" col-span="3" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
171+
<preferred-size width="150" height="50"/>
172+
</grid>
173+
</constraints>
174+
<properties>
175+
<editable value="false"/>
176+
<enabled value="false"/>
177+
</properties>
178+
</component>
179+
</children>
180+
</grid>
181+
</children>
182+
</tabbedpane>
183+
<component id="467c3" class="javax.swing.JLabel">
184+
<constraints>
185+
<grid row="1" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
186+
</constraints>
187+
<properties>
188+
<text value="若需要运行sql语句,请先到datasource中配置数据源信息"/>
189+
</properties>
190+
</component>
191+
<component id="8bfb" class="javax.swing.JLabel">
192+
<constraints>
193+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="1" use-parent-layout="false"/>
194+
</constraints>
195+
<properties>
196+
<text value="Method"/>
197+
</properties>
198+
</component>
199+
<component id="c42e" class="javax.swing.JTextField" binding="methodName">
200+
<constraints>
201+
<grid row="2" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
202+
<preferred-size width="150" height="-1"/>
203+
</grid>
204+
</constraints>
205+
<properties>
206+
<editable value="false"/>
207+
<enabled value="false"/>
208+
</properties>
209+
</component>
210+
<component id="c640d" class="javax.swing.JLabel">
211+
<constraints>
212+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
213+
</constraints>
214+
<properties>
215+
<text value=""/>
216+
</properties>
217+
</component>
218+
</children>
219+
</grid>
220+
</form>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package io.github.linyimin.plugin.view;
2+
3+
import javax.swing.*;
4+
5+
/**
6+
* @author yiminlin
7+
* @date 2022/02/01 12:31 下午
8+
**/
9+
public class MybatisSqlViewerToolWindow {
10+
private JTextField methodName;
11+
private JTabbedPane tabbedPane;
12+
private JTextField host;
13+
private JTextField port;
14+
private JTextField user;
15+
private JTextField database;
16+
private JPasswordField password;
17+
private JTextField url;
18+
private JButton connectionTestButton;
19+
private JPanel root;
20+
private JTextArea connectionInfoTextArea;
21+
22+
public JPanel getContent() {
23+
return root;
24+
}
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.github.linyimin.plugin.window;
2+
3+
import com.intellij.openapi.project.DumbAware;
4+
import com.intellij.openapi.project.Project;
5+
import com.intellij.openapi.wm.ToolWindow;
6+
import com.intellij.openapi.wm.ToolWindowFactory;
7+
import com.intellij.ui.content.Content;
8+
import com.intellij.ui.content.ContentFactory;
9+
import io.github.linyimin.plugin.view.MybatisSqlViewerToolWindow;
10+
import org.jetbrains.annotations.NotNull;
11+
12+
/**
13+
* @author yiminlin
14+
* @date 2022/02/01 11:28 上午
15+
**/
16+
public class MybatisSqlViewerToolWindowFactory implements ToolWindowFactory, DumbAware {
17+
18+
@Override
19+
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
20+
MybatisSqlViewerToolWindow mybatisSqlViewerToolWindow = new MybatisSqlViewerToolWindow();
21+
ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
22+
Content content = contentFactory.createContent(mybatisSqlViewerToolWindow.getContent(), "", false);
23+
toolWindow.getContentManager().addContent(content);
24+
}
25+
26+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
<codeInsight.lineMarkerProvider language="XML" implementationClass="io.github.linyimin.plugin.provider.jump.MapperXmlJumpLineMakerProvider" />
2020
<codeInsight.lineMarkerProvider language="JAVA" implementationClass="io.github.linyimin.plugin.provider.generate.MapperInterfaceGenerateSqlLineMakerProvider" />
2121
<codeInsight.lineMarkerProvider language="XML" implementationClass="io.github.linyimin.plugin.provider.generate.MapperXmlGenerateSqlLineMakerProvider" />
22+
23+
<toolWindow id="mybatis-sql-viewer" doNotActivateOnStart="true" factoryClass="io.github.linyimin.plugin.window.MybatisSqlViewerToolWindowFactory" anchor="right" secondary="false" />
2224
</extensions>
2325

2426
<actions>

0 commit comments

Comments
 (0)