Fixed fragment window closing behavior

This commit is contained in:
Alexander Nozik 2017-11-14 22:21:51 +03:00
parent 1f5b7ea58a
commit d77051b54f
6 changed files with 79 additions and 54 deletions

View File

@ -3,13 +3,16 @@ package inr.numass.control
import hep.dataforge.context.Context import hep.dataforge.context.Context
import hep.dataforge.context.Global import hep.dataforge.context.Global
import hep.dataforge.control.DeviceManager 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.meta.Meta
import hep.dataforge.server.ServerManager import hep.dataforge.server.ServerManager
import hep.dataforge.storage.commons.StorageConnection import hep.dataforge.storage.commons.StorageConnection
import hep.dataforge.storage.commons.StorageManager import hep.dataforge.storage.commons.StorageManager
import inr.numass.client.ClientUtils import inr.numass.client.ClientUtils
import javafx.beans.binding.ListBinding
import javafx.beans.property.SimpleObjectProperty import javafx.beans.property.SimpleObjectProperty
import javafx.beans.property.SimpleStringProperty
import javafx.collections.FXCollections import javafx.collections.FXCollections
import javafx.collections.ObservableList import javafx.collections.ObservableList
import tornadofx.* import tornadofx.*
@ -23,22 +26,16 @@ class BoardController() : Controller(), AutoCloseable {
val contextProperty = SimpleObjectProperty<Context>(Global.instance()) val contextProperty = SimpleObjectProperty<Context>(Global.instance())
var context: Context by contextProperty var context: Context by contextProperty
val metaProperty = SimpleObjectProperty<Meta>(Meta.empty()) // val metaProperty = SimpleObjectProperty<Meta>(Meta.empty())
var meta: Meta by metaProperty // var meta: Meta by metaProperty
val storageManagerProperty = nonNullObjectBinding(contextProperty) { val numassRunProperty = SimpleStringProperty("")
context.pluginManager.getOrLoad(StorageManager::class.java) var numassRun: String by numassRunProperty
} private set
val storageProperty = nonNullObjectBinding(storageManagerProperty , metaProperty) { val storageProperty = nonNullObjectBinding(contextProperty, numassRunProperty) {
val storageMeta = meta.getMeta("storage").builder val rootStorage = context.pluginManager.getOrLoad(StorageManager::class.java).defaultStorage
.putValue("readOnly", false)
.putValue("monitor", true)
context.logger.info("Creating storage for server with meta {}", storageMeta)
val rootStorage = value.buildStorage(storageMeta);
val numassRun = ClientUtils.getRunName(meta)
if (!numassRun.isEmpty()) { if (!numassRun.isEmpty()) {
context.logger.info("Run information found. Selecting run {}", numassRun) context.logger.info("Run information found. Selecting run {}", numassRun)
rootStorage.buildShelf(numassRun, Meta.empty()); rootStorage.buildShelf(numassRun, Meta.empty());
@ -48,7 +45,7 @@ class BoardController() : Controller(), AutoCloseable {
}.apply { }.apply {
onChange { onChange {
val connection = StorageConnection(value) 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.forEachConnection(StorageConnection::class.java) { device.disconnect(it) }//removing all ald storage connections
device.connect(connection) device.connect(connection)
} }
@ -59,45 +56,61 @@ class BoardController() : Controller(), AutoCloseable {
context.optFeature(ServerManager::class.java).orElse(null) context.optFeature(ServerManager::class.java).orElse(null)
} }
val devices: ObservableList<Device> = FXCollections.observableArrayList();
val deviceManagerProperty = objectBinding(contextProperty) { val deviceManagerProperty = objectBinding(contextProperty) {
context.optFeature(DeviceManager::class.java).orElse(null) context.optFeature(DeviceManager::class.java).orElse(null)
} }.apply {
onChange {
val devices: ObservableList<DeviceDisplay<*>> = object : ListBinding<DeviceDisplay<*>>() { value?.let {
init { devices.setAll(it.devices.toList());
bind(deviceManagerProperty)
}
override fun computeValue(): ObservableList<DeviceDisplay<*>> {
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()
} }
} }
} }
// val deviceViews: ObservableList<DeviceDisplay<*>> = object : ListBinding<DeviceDisplay<*>>() {
// init {
// bind(devices)
// }
//
// override fun computeValue(): ObservableList<DeviceDisplay<*>> {
// 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) { fun configure(meta: Meta) {
val context = Context.build("NUMASS", Global.instance(), meta.getMeta("context", meta)); Context.build("NUMASS", Global.instance(), meta.getMeta("context", meta)).apply {
meta.useMeta("storage") {
} pluginManager.getOrLoad(StorageManager::class.java).configure(it);
}
fun load(app: App) { meta.useMetaList("device") {
runAsync { it.forEach {
getConfig(app).ifPresent { pluginManager.getOrLoad(DeviceManager::class.java).buildDevice(it)
configure(it) }
}
meta.useMeta("numass") {
numassRun = ClientUtils.getRunName(it)
}
}.also {
runLater {
context = it
} }
} }
} }
override fun close() { override fun close() {
context.close() context.close()
//Global.terminate()
} }
// val devices: ObservableList<DeviceDisplay<*>> = FXCollections.observableArrayList<DeviceDisplay<*>>(); // val devices: ObservableList<DeviceDisplay<*>> = FXCollections.observableArrayList<DeviceDisplay<*>>();
// //

View File

@ -79,13 +79,22 @@ class BoardView : View("Numass control board", ImageView(dfIcon)) {
vgrow = Priority.ALWAYS; vgrow = Priority.ALWAYS;
vbox { vbox {
prefHeight = 40.0 prefHeight = 40.0
bindChildren(controller.devices) { connection -> controller.devices.onChange { change ->
titledpane( children.setAll(change.list.map {
title = "Device: " + connection.device.name, titledpane(
collapsible = true, title = "Device: " + it.name,
node = connection.getBoardView() collapsible = true,
) node = it.getDisplay().getBoardView()
)
})
} }
// bindChildren(controller.devices) { device ->
// titledpane(
// title = "Device: " + device.name,
// collapsible = true,
// node = device.getDisplay().getBoardView()
// )
// }
} }
} }
} }

View File

@ -11,7 +11,10 @@ class ServerApp : App(BoardView::class) {
override fun start(stage: Stage) { override fun start(stage: Stage) {
controller.load(this) getConfig(this@ServerApp).ifPresent {
controller.configure(it)
}
super.start(stage) super.start(stage)
} }

View File

@ -3,7 +3,7 @@
<server port="8337"/> <server port="8337"/>
<storage path="D:/temp/test"/> <storage path="D:/temp/test"/>
<numass run="serverTest"/> <numass run="serverTest"/>
<device type="numass:pkt8" port = "virtual" abuf = "120"> <device type="numass.pkt8" port="virtual" abuf="120">
<!--<connection ip="192.168.111.137" port="4001"/>--> <!--<connection ip="192.168.111.137" port="4001"/>-->
<channel designation="a" name="a-channel" r0="1000" transformationType="hyperbolic" coefs="[1.0,1.0]" <channel designation="a" name="a-channel" r0="1000" transformationType="hyperbolic" coefs="[1.0,1.0]"
color="black"/> color="black"/>

View File

@ -309,7 +309,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor<PKT8Result>(context,
try { try {
logger.info("Starting measurement") logger.info("Starting measurement")
handler.holdBy(this) handler.holdBy(this)
send("s") handler.send(this,"s")
afterStart() afterStart()
} catch (ex: ControlException) { } catch (ex: ControlException) {
portError("Failed to start measurement", ex) portError("Failed to start measurement", ex)

View File

@ -177,10 +177,10 @@ class PKT8Display : DeviceDisplay<PKT8Device>(), MeasurementListener {
.filter { channel -> !plottables.has(channel.name) } .filter { channel -> !plottables.has(channel.name) }
.forEachOrdered { channel -> .forEachOrdered { channel ->
//frame config from device configuration //frame config from device configuration
val plottable = TimePlot(channel.name) val plot = TimePlot(channel.name)
plottable.configure(channel.meta()) plot.configure(channel.meta())
plottables.add(plottable) plottables.add(plot)
plotFrame.add(plottable) plotFrame.add(plot)
} }
if (device.meta().hasMeta("plotConfig")) { if (device.meta().hasMeta("plotConfig")) {
plottables.configure(device.meta().getMeta("plotConfig")) plottables.configure(device.meta().getMeta("plotConfig"))