Skip to content

Commit 3e7ff6d

Browse files
author
Hanseter
committed
Make sure the schema can be updated the same way the data can be updated
1 parent 58296ed commit 3e7ff6d

3 files changed

Lines changed: 24 additions & 18 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>com.github.hanseter</groupId>
88
<artifactId>json-properties-fx</artifactId>
9-
<version>1.0.18</version>
9+
<version>1.0.19</version>
1010

1111
<packaging>bundle</packaging>
1212
<name>JSON Properties Editor Fx</name>

src/main/kotlin/com/github/hanseter/json/editor/JsonPropertiesEditor.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class JsonPropertiesEditor @JvmOverloads constructor(
122122
callback: OnEditCallback
123123
) {
124124
if (idsToPanes.contains(objId)) {
125-
updateObject(objId, obj)
125+
updateObject(objId, obj, schema)
126126
return
127127
}
128128

@@ -155,17 +155,17 @@ class JsonPropertiesEditor @JvmOverloads constructor(
155155

156156
fun updateObject(
157157
objId: String,
158-
obj: JSONObject
158+
obj: JSONObject,
159+
schema: JSONObject
159160
) {
160161
val pane = idsToPanes[objId] ?: return
161162
pane.fillData(obj)
163+
pane.updateSchemaIfChanged(schema)
162164
}
163165

164166
fun removeObject(objId: String) {
165167
(idsToPanes.remove(objId)?.treeItem)?.also {
166-
(treeTableView.root as FilterableTreeItem).remove(
167-
it
168-
)
168+
(treeTableView.root as FilterableTreeItem).remove(it)
169169
}
170170
rebindValidProperty()
171171
}

src/main/kotlin/com/github/hanseter/json/editor/JsonPropertiesPane.kt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,23 @@ class JsonPropertiesPane(
161161
contentHandler.updateData(data)
162162
}
163163

164+
fun updateSchemaIfChanged(new: JSONObject) {
165+
if (new.similar(rawSchema)) return
166+
val data = contentHandler.data
167+
updateSchema(new)
168+
fillData(data)
169+
}
170+
171+
private fun updateSchema(new: JSONObject) {
172+
rawSchema = new
173+
174+
val parsedSchema = SchemaNormalizer.parseSchema(new, resolutionScope, readOnly)
175+
176+
schema = SimpleEffectiveSchema(null, parsedSchema, title)
177+
178+
rebuildControlTree()
179+
}
180+
164181
private fun fillSheet(data: JSONObject) {
165182
val type = RootBindableType(data)
166183
objectControl?.bindTo(type)
@@ -171,18 +188,7 @@ class JsonPropertiesPane(
171188
val newData = changeListener(PropertiesEditInput(type.getValue()!!, rawSchema))
172189

173190
if (newData.schema != null) {
174-
175-
rawSchema = newData.schema
176-
177-
val parsedSchema = SchemaNormalizer.parseSchema(
178-
newData.schema,
179-
resolutionScope,
180-
readOnly,
181-
)
182-
183-
schema = SimpleEffectiveSchema(null, parsedSchema, title)
184-
185-
rebuildControlTree()
191+
updateSchema(newData.schema)
186192
}
187193

188194
fillData(newData.data)

0 commit comments

Comments
 (0)