From 51af1fe88a97af6ace622b234cf4f588a23cfd6c Mon Sep 17 00:00:00 2001 From: Nicolas Payette Date: Sat, 11 Nov 2017 20:19:57 +0100 Subject: [PATCH] make sure default property is initialized last, fix #162 When importing from JSON, in the case of choosers, the selected item(s) was/where set before the actual items, and thus ignored by the Swing widget. This makes sure that the default property (which is usually the main setter) gets set last. --- api/src/main/scala/uk/ac/surrey/xw/api/ExtraWidget.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/api/src/main/scala/uk/ac/surrey/xw/api/ExtraWidget.scala b/api/src/main/scala/uk/ac/surrey/xw/api/ExtraWidget.scala index f617f6a..55cfd9b 100644 --- a/api/src/main/scala/uk/ac/surrey/xw/api/ExtraWidget.scala +++ b/api/src/main/scala/uk/ac/surrey/xw/api/ExtraWidget.scala @@ -16,8 +16,11 @@ trait ExtraWidget extends Component { val kind: WidgetKind[this.type] def init(propertyMap: PropertyMap): Unit = - for ((propertyKey, value) ← propertyMap) - setProperty(propertyKey, value) + propertyMap.toSeq + // make sure the default property gets set last + // (see https://github.com/CRESS-Surrey/eXtraWidgets/issues/162) + .sortBy { case (k, v) ⇒ kind.defaultProperty.map(_.key).contains(k) } + .foreach { case (k, v) ⇒ setProperty(k, v) } def setProperty( propertyKey: PropertyKey,