Skip to content

Commit 3302d7f

Browse files
author
seal
committed
add property keyword config setting as ('var' or 'val'),the default keyword changed to 'val'.
1 parent 9f491ce commit 3302d7f

File tree

6 files changed

+160
-3
lines changed

6 files changed

+160
-3
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin>
22
<id>wu.seal.tool.jsontokotlin</id>
33
<name>JsonToKotlinClass</name>
4-
<version>1.0.1</version>
4+
<version>1.0.2</version>
55
<vendor email="[email protected]" url="https://www.github.com/wuseal">Seal</vendor>
66

77
<description><![CDATA[
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package wu.seal.jsontokotlin
2+
3+
import com.intellij.ide.util.PropertiesComponent
4+
5+
/**
6+
* ConfigManager
7+
* main purpose to obtain the detail corresponding config And the entry of modify
8+
* Created by LENOVO on 2017/9/13.
9+
*/
10+
interface IConfigManager {
11+
12+
private val IS_PROPERTIES_VAR_KEY: String
13+
get() = "isPropertiesVar_key"
14+
15+
private val TARGET_JSON_CONVERTER_LIB_KEY: String
16+
get() = "target_json_converter_lib_key"
17+
18+
var isPropertiesVar: Boolean
19+
get() = PropertiesComponent.getInstance().isTrueValue(IS_PROPERTIES_VAR_KEY)
20+
set(value) = PropertiesComponent.getInstance().setValue(IS_PROPERTIES_VAR_KEY, value)
21+
22+
23+
var targetJsonConverterLib: TargetJsonConverter
24+
get() = TargetJsonConverter.valueOf(PropertiesComponent.getInstance().getValue(TARGET_JSON_CONVERTER_LIB_KEY) ?: TargetJsonConverter.None.name)
25+
set(value) = PropertiesComponent.getInstance().setValue(TARGET_JSON_CONVERTER_LIB_KEY, value.name)
26+
}
27+
28+
29+
/**
30+
* This means which Json convert library you are using in you project
31+
*/
32+
enum class TargetJsonConverter {
33+
None, Gson, FastJson, Jackson
34+
}
35+
36+
37+
object ConfigManager : IConfigManager
38+
39+
40+
fun test() {
41+
println(ConfigManager.isPropertiesVar)
42+
ConfigManager.isPropertiesVar = true
43+
println(ConfigManager.isPropertiesVar)
44+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package wu.seal.jsontokotlin
2+
3+
import com.intellij.openapi.ui.DialogWrapper
4+
import com.intellij.util.ui.JBDimension
5+
import java.awt.BorderLayout
6+
import java.awt.ComponentOrientation
7+
import javax.swing.*
8+
9+
/**
10+
*
11+
* Created by LENOVO on 2017/9/13.
12+
*/
13+
14+
interface IConfigSettingDialog {
15+
16+
fun show()
17+
18+
fun dismiss()
19+
20+
}
21+
22+
23+
class ConfigSettingDialog(canBeParent: Boolean) : DialogWrapper(canBeParent), IConfigSettingDialog {
24+
25+
init {
26+
init()
27+
title = "Config Settings"
28+
}
29+
30+
31+
override fun createCenterPanel(): JComponent? {
32+
val tabbedPane = JTabbedPane()
33+
34+
val propertyPane = JPanel(BorderLayout(5, 5))
35+
propertyPane.componentOrientation = ComponentOrientation.LEFT_TO_RIGHT
36+
val radioButtonVal = JRadioButton("Val")
37+
38+
radioButtonVal.addActionListener {
39+
ConfigManager.isPropertiesVar = false
40+
}
41+
val radioButtonVar = JRadioButton("Var")
42+
radioButtonVar.addActionListener {
43+
ConfigManager.isPropertiesVar = true
44+
}
45+
46+
if (ConfigManager.isPropertiesVar) {
47+
48+
radioButtonVar.isSelected = true
49+
} else {
50+
radioButtonVal.isSelected = true
51+
}
52+
53+
val buttonGroupProperty = ButtonGroup()
54+
buttonGroupProperty.add(radioButtonVal)
55+
buttonGroupProperty.add(radioButtonVar)
56+
57+
propertyPane.add(radioButtonVal, BorderLayout.NORTH)
58+
propertyPane.add(radioButtonVar, BorderLayout.CENTER)
59+
tabbedPane.add("Property Keyword", propertyPane)
60+
61+
tabbedPane.minimumSize = JBDimension(300, 180)
62+
63+
return tabbedPane
64+
}
65+
66+
67+
override fun dismiss() {
68+
close(CANCEL_EXIT_CODE)
69+
}
70+
71+
72+
override fun createActions(): Array<Action> {
73+
return arrayOf(okAction)
74+
}
75+
76+
}

src/wu/seal/jsontokotlin/KotlinMaker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ private String modifyPropertyForArrayObjType(String property) {
144144
}
145145

146146
private void addProperty(StringBuilder stringBuilder, String property, String type, String value) {
147-
stringBuilder.append("\t\tvar ").append(property).append(": ").append(type).append(",");
147+
String propertyKeyword = PropertyKeyword.INSTANCE.get();
148+
stringBuilder.append("\t\t" + propertyKeyword + " ").append(property).append(": ").append(type).append(",");
148149
if (value != null) {
149150
stringBuilder.append("// ").append(value).append("\n");
150151
} else {

src/wu/seal/jsontokotlin/MakeKotlinClassAction.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import javax.swing.*;
2525
import javax.swing.text.JTextComponent;
2626
import java.awt.*;
27+
import java.awt.event.ActionEvent;
2728

2829
/**
2930
* Created by Seal.Wu on 2017/8/18.
@@ -79,8 +80,22 @@ protected JPanel createMessagePanel() {
7980
}
8081

8182
myField = createTextFieldComponent();
82-
messagePanel.add(createScrollableTextComponent(), BorderLayout.SOUTH);
8383

84+
85+
messagePanel.add(createScrollableTextComponent(), BorderLayout.CENTER);
86+
JButton settingButton = new JButton("Config Settings");
87+
settingButton.addActionListener(new AbstractAction() {
88+
@Override
89+
public void actionPerformed(ActionEvent e) {
90+
new ConfigSettingDialog(false).show();
91+
}
92+
});
93+
JPanel settingContainer = new JPanel();
94+
BoxLayout boxLayout = new BoxLayout(settingContainer, BoxLayout.LINE_AXIS);
95+
settingContainer.setLayout(boxLayout);
96+
settingButton.setHorizontalAlignment(SwingConstants.RIGHT);
97+
settingContainer.add(settingButton);
98+
messagePanel.add(settingContainer, BorderLayout.SOUTH);
8499
return messagePanel;
85100
}
86101

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package wu.seal.jsontokotlin
2+
3+
/**
4+
* Created by LENOVO on 2017/9/13.
5+
*/
6+
7+
interface IPropertyKeyword {
8+
9+
val varProperty: String
10+
get() = "var"
11+
val valProperty: String
12+
get() = "val"
13+
14+
fun get(): String
15+
16+
}
17+
18+
object PropertyKeyword : IPropertyKeyword {
19+
override fun get() = if (ConfigManager.isPropertiesVar) varProperty else valProperty
20+
21+
}

0 commit comments

Comments
 (0)