From d77051b54f0e824417687ec9d9ce0b7bafa467db Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 14 Nov 2017 22:21:51 +0300 Subject: [PATCH] Fixed fragment window closing behavior --- .../inr/numass/control/BoardController.kt | 95 +++++++++++-------- .../kotlin/inr/numass/control/BoardView.kt | 21 ++-- .../kotlin/inr/numass/control/ServerApp.kt | 5 +- .../config/{server.xml => control.xml} | 2 +- .../inr/numass/control/cryotemp/PKT8Device.kt | 2 +- .../numass/control/cryotemp/PKT8Display.kt | 8 +- 6 files changed, 79 insertions(+), 54 deletions(-) rename numass-control/control-room/src/main/resources/config/{server.xml => control.xml} (90%) diff --git a/numass-control/control-room/src/main/kotlin/inr/numass/control/BoardController.kt b/numass-control/control-room/src/main/kotlin/inr/numass/control/BoardController.kt index 39bbcf59..8335eef6 100644 --- a/numass-control/control-room/src/main/kotlin/inr/numass/control/BoardController.kt +++ b/numass-control/control-room/src/main/kotlin/inr/numass/control/BoardController.kt @@ -3,13 +3,16 @@ package inr.numass.control import hep.dataforge.context.Context import hep.dataforge.context.Global import hep.dataforge.control.DeviceManager +import hep.dataforge.control.devices.Device +import hep.dataforge.kodex.useMeta +import hep.dataforge.kodex.useMetaList import hep.dataforge.meta.Meta import hep.dataforge.server.ServerManager import hep.dataforge.storage.commons.StorageConnection import hep.dataforge.storage.commons.StorageManager import inr.numass.client.ClientUtils -import javafx.beans.binding.ListBinding import javafx.beans.property.SimpleObjectProperty +import javafx.beans.property.SimpleStringProperty import javafx.collections.FXCollections import javafx.collections.ObservableList import tornadofx.* @@ -23,22 +26,16 @@ class BoardController() : Controller(), AutoCloseable { val contextProperty = SimpleObjectProperty(Global.instance()) var context: Context by contextProperty - val metaProperty = SimpleObjectProperty(Meta.empty()) - var meta: Meta by metaProperty +// val metaProperty = SimpleObjectProperty(Meta.empty()) +// var meta: Meta by metaProperty - val storageManagerProperty = nonNullObjectBinding(contextProperty) { - context.pluginManager.getOrLoad(StorageManager::class.java) - } + val numassRunProperty = SimpleStringProperty("") + var numassRun: String by numassRunProperty + private set - val storageProperty = nonNullObjectBinding(storageManagerProperty , metaProperty) { - val storageMeta = meta.getMeta("storage").builder - .putValue("readOnly", false) - .putValue("monitor", true) + val storageProperty = nonNullObjectBinding(contextProperty, numassRunProperty) { + val rootStorage = context.pluginManager.getOrLoad(StorageManager::class.java).defaultStorage - context.logger.info("Creating storage for server with meta {}", storageMeta) - val rootStorage = value.buildStorage(storageMeta); - - val numassRun = ClientUtils.getRunName(meta) if (!numassRun.isEmpty()) { context.logger.info("Run information found. Selecting run {}", numassRun) rootStorage.buildShelf(numassRun, Meta.empty()); @@ -48,7 +45,7 @@ class BoardController() : Controller(), AutoCloseable { }.apply { onChange { val connection = StorageConnection(value) - devices.map { it.device }.forEach { device -> + devices.forEach { device -> device.forEachConnection(StorageConnection::class.java) { device.disconnect(it) }//removing all ald storage connections device.connect(connection) } @@ -59,45 +56,61 @@ class BoardController() : Controller(), AutoCloseable { context.optFeature(ServerManager::class.java).orElse(null) } + val devices: ObservableList = FXCollections.observableArrayList(); + val deviceManagerProperty = objectBinding(contextProperty) { context.optFeature(DeviceManager::class.java).orElse(null) - } - - val devices: ObservableList> = object : ListBinding>() { - init { - bind(deviceManagerProperty) - } - - override fun computeValue(): ObservableList> { - val manager = deviceManagerProperty.value - return if (manager == null) { - FXCollections.emptyObservableList(); - } else { - manager.deviceNames() - .filter { it.length == 1 } // select top level devices - .map { manager.optDevice(it) } - .filter { it.isPresent } - .map { it.get().getDisplay() } - .toList().observable() + }.apply { + onChange { + value?.let { + devices.setAll(it.devices.toList()); } } } +// val deviceViews: ObservableList> = object : ListBinding>() { +// init { +// bind(devices) +// } +// +// override fun computeValue(): ObservableList> { +// val manager = deviceManagerProperty.value +// return if (manager == null) { +// FXCollections.emptyObservableList(); +// } else { +// manager.deviceNames() +// .filter { it.length == 1 } // select top level devices +// .map { manager.optDevice(it) } +// .filter { it.isPresent } +// .map { it.get().getDisplay() } +// .toList().observable() +// } +// } +// } + fun configure(meta: Meta) { - val context = Context.build("NUMASS", Global.instance(), meta.getMeta("context", meta)); - - } - - fun load(app: App) { - runAsync { - getConfig(app).ifPresent { - configure(it) + Context.build("NUMASS", Global.instance(), meta.getMeta("context", meta)).apply { + meta.useMeta("storage") { + pluginManager.getOrLoad(StorageManager::class.java).configure(it); + } + meta.useMetaList("device") { + it.forEach { + pluginManager.getOrLoad(DeviceManager::class.java).buildDevice(it) + } + } + meta.useMeta("numass") { + numassRun = ClientUtils.getRunName(it) + } + }.also { + runLater { + context = it } } } override fun close() { context.close() + //Global.terminate() } // val devices: ObservableList> = FXCollections.observableArrayList>(); // diff --git a/numass-control/control-room/src/main/kotlin/inr/numass/control/BoardView.kt b/numass-control/control-room/src/main/kotlin/inr/numass/control/BoardView.kt index 4c229d04..b5b35dad 100644 --- a/numass-control/control-room/src/main/kotlin/inr/numass/control/BoardView.kt +++ b/numass-control/control-room/src/main/kotlin/inr/numass/control/BoardView.kt @@ -79,13 +79,22 @@ class BoardView : View("Numass control board", ImageView(dfIcon)) { vgrow = Priority.ALWAYS; vbox { prefHeight = 40.0 - bindChildren(controller.devices) { connection -> - titledpane( - title = "Device: " + connection.device.name, - collapsible = true, - node = connection.getBoardView() - ) + controller.devices.onChange { change -> + children.setAll(change.list.map { + titledpane( + title = "Device: " + it.name, + collapsible = true, + node = it.getDisplay().getBoardView() + ) + }) } +// bindChildren(controller.devices) { device -> +// titledpane( +// title = "Device: " + device.name, +// collapsible = true, +// node = device.getDisplay().getBoardView() +// ) +// } } } } diff --git a/numass-control/control-room/src/main/kotlin/inr/numass/control/ServerApp.kt b/numass-control/control-room/src/main/kotlin/inr/numass/control/ServerApp.kt index fa094307..001aa6fe 100644 --- a/numass-control/control-room/src/main/kotlin/inr/numass/control/ServerApp.kt +++ b/numass-control/control-room/src/main/kotlin/inr/numass/control/ServerApp.kt @@ -11,7 +11,10 @@ class ServerApp : App(BoardView::class) { override fun start(stage: Stage) { - controller.load(this) + getConfig(this@ServerApp).ifPresent { + controller.configure(it) + } + super.start(stage) } diff --git a/numass-control/control-room/src/main/resources/config/server.xml b/numass-control/control-room/src/main/resources/config/control.xml similarity index 90% rename from numass-control/control-room/src/main/resources/config/server.xml rename to numass-control/control-room/src/main/resources/config/control.xml index c8f3f674..e125c450 100644 --- a/numass-control/control-room/src/main/resources/config/server.xml +++ b/numass-control/control-room/src/main/resources/config/control.xml @@ -3,7 +3,7 @@ - + diff --git a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt index 1396a919..26c4e5e9 100644 --- a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt +++ b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt @@ -309,7 +309,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, try { logger.info("Starting measurement") handler.holdBy(this) - send("s") + handler.send(this,"s") afterStart() } catch (ex: ControlException) { portError("Failed to start measurement", ex) diff --git a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Display.kt b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Display.kt index 0698483d..c048c681 100644 --- a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Display.kt +++ b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Display.kt @@ -177,10 +177,10 @@ class PKT8Display : DeviceDisplay(), MeasurementListener { .filter { channel -> !plottables.has(channel.name) } .forEachOrdered { channel -> //frame config from device configuration - val plottable = TimePlot(channel.name) - plottable.configure(channel.meta()) - plottables.add(plottable) - plotFrame.add(plottable) + val plot = TimePlot(channel.name) + plot.configure(channel.meta()) + plottables.add(plot) + plotFrame.add(plot) } if (device.meta().hasMeta("plotConfig")) { plottables.configure(device.meta().getMeta("plotConfig"))