Skip to content

Commit f6c9b2b

Browse files
committed
修改数据结构和保存逻辑删除 save button
1 parent 38e658e commit f6c9b2b

File tree

8 files changed

+88
-74
lines changed

8 files changed

+88
-74
lines changed

objectbox-models/default.json

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"entities": [
66
{
77
"id": "1:9070185516669921501",
8-
"lastPropertyId": "6:5499539181800737854",
8+
"lastPropertyId": "8:1187463951019417804",
99
"name": "ApiBean",
1010
"properties": [
1111
{
@@ -18,20 +18,24 @@
1818
},
1919
{
2020
"id": "3:8086421898222647303",
21-
"indexId": "1:4855703933356883490",
2221
"name": "url"
2322
},
24-
{
25-
"id": "4:5827927612626697138",
26-
"name": "parameMap"
27-
},
2823
{
2924
"id": "5:8038266698557329938",
3025
"name": "encryptType"
3126
},
3227
{
3328
"id": "6:5499539181800737854",
29+
"indexId": "4:8865588299107533145",
3430
"name": "projectId"
31+
},
32+
{
33+
"id": "7:9042463734489530509",
34+
"name": "paramsMap"
35+
},
36+
{
37+
"id": "8:1187463951019417804",
38+
"name": "createDate"
3539
}
3640
],
3741
"relations": []
@@ -59,16 +63,19 @@
5963
}
6064
],
6165
"lastEntityId": "2:7225886512415135978",
62-
"lastIndexId": "3:1701380745400854523",
66+
"lastIndexId": "4:8865588299107533145",
6367
"lastRelationId": "0:0",
6468
"lastSequenceId": "0:0",
6569
"modelVersion": 4,
6670
"modelVersionParserMinimum": 4,
6771
"retiredEntityUids": [],
6872
"retiredIndexUids": [
69-
4865196870853324190
73+
4865196870853324190,
74+
4855703933356883490
75+
],
76+
"retiredPropertyUids": [
77+
5827927612626697138
7078
],
71-
"retiredPropertyUids": [],
7279
"retiredRelationUids": [],
7380
"version": 1
7481
}

src/main/java/com/longforus/apidebugger/ui/MainPanel.form

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -188,34 +188,7 @@
188188
<preferredSize width="78" height="78"/>
189189
<requestFocusEnabled value="false"/>
190190
<text value=""/>
191-
</properties>
192-
</component>
193-
<component id="e47f" class="javax.swing.JButton" binding="btnDelApi">
194-
<constraints>
195-
<grid row="4" column="8" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
196-
<forms/>
197-
</constraints>
198-
<properties>
199-
<text value="Delete"/>
200-
</properties>
201-
</component>
202-
<component id="bbb13" class="javax.swing.JButton" binding="mBtnNewApi">
203-
<constraints>
204-
<grid row="3" column="8" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
205-
<forms/>
206-
</constraints>
207-
<properties>
208-
<text value="Copy New"/>
209-
</properties>
210-
</component>
211-
<component id="80e6b" class="javax.swing.JButton" binding="mbtnDp">
212-
<constraints>
213-
<grid row="4" column="4" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
214-
<forms/>
215-
</constraints>
216-
<properties>
217-
<text value=" Default Parameter"/>
218-
<toolTipText value=" Set Current Project Default Parameter"/>
191+
<toolTipText value="Send"/>
219192
</properties>
220193
</component>
221194
<grid id="69c35" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
@@ -264,6 +237,25 @@
264237
<forms/>
265238
</constraints>
266239
</component>
240+
<component id="e47f" class="javax.swing.JButton" binding="btnDelApi">
241+
<constraints>
242+
<grid row="3" column="8" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
243+
<forms/>
244+
</constraints>
245+
<properties>
246+
<text value="Delete"/>
247+
</properties>
248+
</component>
249+
<component id="80e6b" class="javax.swing.JButton" binding="mbtnDp">
250+
<constraints>
251+
<grid row="4" column="6" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
252+
<forms/>
253+
</constraints>
254+
<properties>
255+
<text value=" Default Parameter"/>
256+
<toolTipText value=" Set Current Project Default Parameter"/>
257+
</properties>
258+
</component>
267259
</children>
268260
</grid>
269261
</form>

src/main/java/com/longforus/apidebugger/ui/MainPanel.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.teamdev.jxbrowser.chromium.Browser;
1313
import com.teamdev.jxbrowser.chromium.BrowserContext;
1414
import com.teamdev.jxbrowser.chromium.BrowserException;
15+
import com.teamdev.jxbrowser.chromium.JSFunction;
1516
import com.teamdev.jxbrowser.chromium.JSValue;
1617
import com.teamdev.jxbrowser.chromium.ProtocolService;
1718
import com.teamdev.jxbrowser.chromium.URLResponse;
@@ -50,7 +51,6 @@
5051
import javax.swing.JTextField;
5152
import javax.swing.JTextPane;
5253
import javax.swing.SizeRequirements;
53-
import javax.swing.border.Border;
5454
import javax.swing.event.MouseInputAdapter;
5555
import javax.swing.text.Element;
5656
import javax.swing.text.View;
@@ -73,7 +73,6 @@ public class MainPanel extends JFrame {
7373
private JComboBox mCbEncrypt;
7474
private JTable mTbParams;
7575
private JTextPane mTpInfo;
76-
private JButton mBtnNewApi;
7776
private JLabel lbStatus;
7877
private JPanel baseP;
7978
private JButton btnDelUrl;
@@ -229,15 +228,13 @@ private void initEvent() {
229228
}
230229
}
231230
});
232-
mBtnNewApi.addActionListener(e -> UIActionHandler.INSTANCE.onNewApi());
233231
mBtnSend.addActionListener(e -> UIActionHandler.INSTANCE.onSend());
234232
btnClear.addActionListener(e -> UIActionHandler.INSTANCE.onClearParams());
235233
mCbMethod.addItemListener(e -> UIActionHandler.INSTANCE.onMethodChanged(mCbMethod.getSelectedIndex()));
236234
mCbEncrypt.addItemListener(e -> UIActionHandler.INSTANCE.onEncryptTypeChanged(((IEncryptHandler) e.getItem()).getTypeCode()));
237235
}
238236

239237
private void initTextPanel() {
240-
241238
mTpInfo.addMouseListener(new MouseInputAdapter() {
242239
@Override
243240
public void mouseClicked(MouseEvent e) {
@@ -355,8 +352,8 @@ protected void finalize() throws Throwable {
355352
}
356353

357354
public String getCurApiUrl() {
358-
if (mCbBaseUrl.getSelectedItem() != null) {
359-
return mCbApiUrl.getSelectedItem().toString();
355+
if (mCbApiUrl.getEditor().getItem() != null) {
356+
return mCbApiUrl.getEditor().getItem().toString();
360357
}
361358
return "";
362359
}
@@ -452,17 +449,8 @@ public String getCurBaseUrl() {
452449
mBtnSend.setPreferredSize(new Dimension(78, 78));
453450
mBtnSend.setRequestFocusEnabled(false);
454451
mBtnSend.setText("");
452+
mBtnSend.setToolTipText("Send");
455453
baseP.add(mBtnSend, cc.xywh(11, 4, 1, 2));
456-
btnDelApi = new JButton();
457-
btnDelApi.setText("Delete");
458-
baseP.add(btnDelApi, cc.xy(9, 5));
459-
mBtnNewApi = new JButton();
460-
mBtnNewApi.setText("Copy New");
461-
baseP.add(mBtnNewApi, cc.xy(9, 4));
462-
mbtnDp = new JButton();
463-
mbtnDp.setText(" Default Parameter");
464-
mbtnDp.setToolTipText(" Set Current Project Default Parameter");
465-
baseP.add(mbtnDp, cc.xyw(5, 5, 3));
466454
final JPanel panel2 = new JPanel();
467455
panel2.setLayout(new com.intellij.uiDesigner.core.GridLayoutManager(1, 3, new Insets(0, 0, 0, 0), -1, -1));
468456
panel2.setBackground(new Color(-15856893));
@@ -485,6 +473,13 @@ public String getCurBaseUrl() {
485473
com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW,
486474
com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
487475
baseP.add(mBrowserView, cc.xywh(1, 8, 13, 2));
476+
btnDelApi = new JButton();
477+
btnDelApi.setText("Delete");
478+
baseP.add(btnDelApi, cc.xy(9, 4));
479+
mbtnDp = new JButton();
480+
mbtnDp.setText(" Default Parameter");
481+
mbtnDp.setToolTipText(" Set Current Project Default Parameter");
482+
baseP.add(mbtnDp, cc.xyw(7, 5, 3));
488483
}
489484

490485
/** @noinspection ALL */
-5.75 KB
Loading

src/main/kotlin/com/longforus/apidebugger/HttpManage.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ object HttpManage {
4848

4949
@Throws(IOException::class)
5050
override fun onResponse(call: Call, response: Response) {
51-
UIActionHandler.onSaveApi(mainPanel.cbApiUrl.selectedItem)
51+
UIActionHandler.onSaveApi(mainPanel.cbApiUrl.editor.item)
5252
mainPanel.lbStatus.text = "onResponse code: ${response.code()} "
53-
mainPanel.tpInfo.append("consuming: ${System.currentTimeMillis() - startTime}ms \n ", Color.BLUE)
53+
mainPanel.tpInfo.append("\nconsuming: ${System.currentTimeMillis() - startTime}ms \n", Color.BLUE)
5454
if (response.isSuccessful) {
5555
val body = response.body() ?: return
5656
val bytes = body.bytes()
5757
val resStr = String(bytes)
58-
mainPanel.tpInfo.append("response size: ${bytes.size} byte \n ", Color.BLUE)
58+
mainPanel.tpInfo.append("response size: ${bytes.size} byte \n", Color.BLUE)
5959
val json = mGson.fromJson<JsonObject>(resStr, JsonObject::class.java)
6060
val jsonStr = mGson.toJson(json, JsonObject::class.java)
6161
MyValueHandler.curShowJsonStr = jsonStr

src/main/kotlin/com/longforus/apidebugger/UIActionHandler.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ object UIActionHandler {
2929
val apiBean: ApiBean
3030
if (selectedItem is String) {
3131
apiBean = ApiBean(selectedItem, it.id)
32-
apiBean.encryptType = mainPanel.selectedEncryptID
33-
apiBean.method = mainPanel.selectedMethodType
34-
apiBean.paramsMap = getParamsMap(mainPanel.tbParams)
35-
it.apis.add(0, apiBean)
36-
val model = mainPanel.cbApiUrl.model as DefaultComboBoxModel
37-
model.insertElementAt(apiBean, 0)
38-
MyValueHandler.curApi = apiBean
32+
if (!it.apis.contains(apiBean)) {
33+
apiBean.encryptType = mainPanel.selectedEncryptID
34+
apiBean.method = mainPanel.selectedMethodType
35+
apiBean.paramsMap = getParamsMap(mainPanel.tbParams)
36+
it.apis.add(0, apiBean)
37+
val model = mainPanel.cbApiUrl.model as DefaultComboBoxModel
38+
model.insertElementAt(apiBean, 0)
39+
mainPanel.cbApiUrl.selectedIndex = 0
40+
MyValueHandler.curApi = apiBean
41+
}
3942
} else {
4043
apiBean = selectedItem as ApiBean
4144
apiBean.encryptType = mainPanel.selectedEncryptID
@@ -63,7 +66,6 @@ object UIActionHandler {
6366
val clone = MyValueHandler.curApi?.clone() as ApiBean?
6467
clone?.let {
6568
OB.apiBox.put(it)
66-
MyValueHandler.curProject?.apis?.add(it)
6769
MyValueHandler.curApi = it
6870
mainPanel.cbApiUrl.insertItemAt(it, 0)
6971
mainPanel.cbApiUrl.selectedIndex = 0

src/main/kotlin/com/longforus/apidebugger/bean/ApiBean.kt

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,30 @@ import io.objectbox.annotation.Index
1010
* Description :
1111
*/
1212
@Entity
13-
data class ApiBean(@Id
13+
class ApiBean(@Id(assignable = true)
1414
var id: Long = 0,
1515
var method: Int = 0,
16-
@Index
1716
var url: String = "",
1817
@Convert(converter = MapDbConverter::class,
1918
dbType = String::class)
2019
var paramsMap: MutableMap<String, String> = HashMap(),
21-
var encryptType: Int = 0,var projectId:Long = 0): kotlin.Cloneable {
20+
var encryptType: Int = 0, @Index var projectId: Long = 0, val createDate: Long = System.currentTimeMillis()) : kotlin.Cloneable {
2221

23-
constructor(url: String,projectId: Long) : this() {
22+
constructor(url: String, projectId: Long) : this() {
2423
this.url = url
2524
this.projectId = projectId
25+
this.id = hashCode().toLong()
2626
}
2727

2828

29-
3029
companion object {
31-
fun getTableValueList(bean:ApiBean):MutableList<TableBean>{
30+
fun getTableValueList(bean: ApiBean): MutableList<TableBean> {
3231
if (bean.paramsMap.isEmpty()) {
3332
return mutableListOf()
3433
}
3534
val list = mutableListOf<TableBean>()
3635
bean.paramsMap.forEach {
37-
list.add(TableBean(true,it.key,it.value))
36+
list.add(TableBean(true, it.key, it.value))
3837
}
3938
return list
4039
}
@@ -47,13 +46,32 @@ var id: Long = 0,
4746

4847

4948
public override fun clone(): Any {
50-
val map = HashMap<String,String>()
49+
val map = HashMap<String, String>()
5150
paramsMap.forEach { t, u ->
5251
map[t] = u
5352
}
54-
return ApiBean(method = this.method,url = this.url+"",paramsMap = map,encryptType = this.encryptType,projectId = this.projectId)
53+
val bean = ApiBean(method = this.method, url = this.url + "", paramsMap = map, encryptType = this.encryptType, projectId = this.projectId)
54+
bean.id = bean.hashCode().toLong()
55+
return bean
5556
}
5657

58+
override fun equals(other: Any?): Boolean {
59+
if (this === other) return true
60+
if (javaClass != other?.javaClass) return false
61+
62+
other as ApiBean
63+
64+
if (url != other.url) return false
65+
if (projectId != other.projectId) return false
66+
67+
return true
68+
}
69+
70+
override fun hashCode(): Int {
71+
var result = url.hashCode()
72+
result = 31 * result + projectId.hashCode()
73+
return result
74+
}
5775

5876

5977
}

src/main/kotlin/com/longforus/apidebugger/bean/ProjectBean.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ data class ProjectBean(
2828
field.clear()
2929
field.addAll(OB.apiBox.query {
3030
equal(ApiBean_.projectId, id)
31-
}.find().sortedByDescending { apiBean -> apiBean.id })
31+
}.find().sortedByDescending { apiBean -> apiBean.createDate })
3232
return field
3333
}
3434

0 commit comments

Comments
 (0)