Killed WorkManager because it was ugly.

This commit is contained in:
Alexander Nozik 2017-07-20 22:18:46 +03:00
parent 7de7187f08
commit e218a17f09
4 changed files with 24 additions and 51 deletions

View File

@ -5,9 +5,6 @@ import hep.dataforge.context.Global
import hep.dataforge.exceptions.StorageException
import hep.dataforge.fx.fragments.FragmentWindow
import hep.dataforge.fx.fragments.LogFragment
import hep.dataforge.fx.work.Work
import hep.dataforge.fx.work.WorkManager
import hep.dataforge.fx.work.WorkManagerFragment
import hep.dataforge.meta.Metoid
import hep.dataforge.names.AlphanumComparator
import hep.dataforge.names.Named
@ -59,9 +56,9 @@ class MainView : View("Numass data viewer") {
}
}
private val processFragment = FragmentWindow.build(processManagerButton) {
WorkManagerFragment(getWorkManager())
}
// private val processFragment = FragmentWindow.build(processManagerButton) {
// WorkManagerFragment(getWorkManager())
// }
private val storageProperty = SimpleObjectProperty<Storage>();
@ -76,7 +73,7 @@ class MainView : View("Numass data viewer") {
} else {
chooser.initialDirectory = File(storageRoot)
}
} catch (ex: Exception){
} catch (ex: Exception) {
NumassProperties.setNumassProperty("numass.storage.root", null)
}
@ -150,38 +147,28 @@ class MainView : View("Numass data viewer") {
}
private fun loadDirectory(path: URI) {
getWorkManager().startWork("viewer.loadDirectory") { work: Work ->
work.title = "Load storage ($path)"
work.progress = -1.0
work.status = "Building numass storage tree..."
try {
runAsync {
updateTitle("Load storage ($path)")
updateProgress(-1.0, -1.0);
updateMessage("Building numass storage tree...")
val root = NumassStorage(context, FileStorageFactory.buildStorageMeta(path, true, true));
setRootStorage(root)
Platform.runLater { storagePathLabel.text = "Storage: " + path }
} catch (ex: Exception) {
work.progress = 0.0
work.status = "Failed to load storage " + path
log.log(Level.SEVERE, null, ex)
}
updateProgress(1.0, 1.0)
}
}
private val context: Context
get() = Global.instance()
@Synchronized private fun getWorkManager(): WorkManager {
return Global.instance().getFeature(WorkManager::class.java);
}
fun setRootStorage(root: NumassStorage) {
getWorkManager().cleanup()
getWorkManager().startWork("viewer.storage.load") { callback: Work ->
callback.title = "Fill data to UI (" + root.name + ")"
callback.progress = -1.0
runAsync {
updateTitle("Fill data to UI (" + root.name + ")")
updateProgress(-1.0, 1.0)
Platform.runLater { statusBar.progress = -1.0 }
callback.status = "Loading numass storage tree..."
updateMessage("Loading numass storage tree...")
try {
storageProperty.set(root)
@ -191,8 +178,8 @@ class MainView : View("Numass data viewer") {
// callback.setProgress(1, 1);
Platform.runLater { statusBar.progress = 0.0 }
callback.status = "Numass storage tree loaded."
callback.setProgressToMax()
updateMessage("Numass storage tree loaded.")
updateProgress(1.0, 1.0)
}
}

View File

@ -2,7 +2,6 @@ package inr.numass.viewer
import hep.dataforge.context.Context
import hep.dataforge.context.Global
import hep.dataforge.fx.work.WorkManager
import hep.dataforge.io.ColumnedDataWriter
import hep.dataforge.kodex.buildMeta
import hep.dataforge.meta.Meta
@ -69,7 +68,7 @@ class NumassLoaderView : View() {
private val spectrumPlot: PlotContainer = PlotContainer.centerIn(spectrumPlotPane)
private val hvPlot: PlotContainer = PlotContainer.centerIn(hvPane)
private val detectorBinningSelector: ChoiceBox<Int> = ChoiceBox(FXCollections.observableArrayList(1, 2, 5, 10, 20, 50))
private val detectorNormalizeSwitch: CheckBox = CheckBox("Normailize")
private val detectorNormalizeSwitch: CheckBox = CheckBox("Normalize")
private val detectorDataExportButton: Button = Button("Export")
val dataProperty = SimpleObjectProperty<NumassSet>()
@ -202,8 +201,8 @@ class NumassLoaderView : View() {
}
if (newData != null) {
getWorkManager().startWork("viewer.numass.load") { work ->
work.title = "Load numass data (" + newData.name + ")"
runAsync {
updateTitle("Load numass data (" + newData.name + ")")
//setup info
updateInfo(newData)
@ -228,9 +227,6 @@ class NumassLoaderView : View() {
return Global.getDefaultContext();
}
fun getWorkManager(): WorkManager {
return getContext().getFeature(WorkManager::class.java);
}
fun loadData(data: NumassSet?) {
this.data = data;
@ -311,10 +307,6 @@ class NumassLoaderView : View() {
private fun updateDetectorPane(data: NumassSet) {
Platform.runLater { detectorPlotFrame.clear() }
val work = getWorkManager().getWork("viewer.numass.load.detector")
work.maxProgress = data.points.count().toDouble();
work.progress = 0.0
val binning = detectorBinningSelector.value
val valueAxis = if (detectorNormalizeSwitch.isSelected) {
@ -323,8 +315,9 @@ class NumassLoaderView : View() {
NumassAnalyzer.COUNT_KEY
}
/// detectorPlot.plot = detectorPlotFrame
runAsync {
detectorPlot.progressProperty().bind(progressProperty());
val totalCount = data.points.count();
val index = AtomicInteger(0);
data.points.map { point ->
val seriesName = String.format("%d: %.2f", index.incrementAndGet(), point.voltage)
@ -335,14 +328,11 @@ class NumassLoaderView : View() {
).apply {
configure(plottableConfig)
}.also {
work.increaseProgress(1.0)
detectorPlot.setProgress(work.progress/work.maxProgress)
updateProgress(index.get() as Long, totalCount);
}
}.collect(Collectors.toList())
} ui { plots ->
detectorPlotFrame.setAll(plots)
work.setProgressToMax()
detectorPlot.setProgress(1.0)
detectorDataExportButton.isDisable = false
}
}

View File

@ -3,7 +3,6 @@ package inr.numass.viewer
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger
import hep.dataforge.context.Global
import hep.dataforge.fx.work.WorkManager
import hep.dataforge.storage.commons.StorageManager
import javafx.scene.image.Image
import javafx.stage.Stage
@ -20,7 +19,6 @@ class Viewer : App(MainView::class) {
(LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as Logger).level = Level.INFO
Global.setDefaultContext(Global.instance())
StorageManager().startGlobal()
WorkManager().startGlobal()
super.start(stage)
}
}

View File

@ -1,7 +1,6 @@
package inr.numass.viewer.test
import hep.dataforge.context.Global
import hep.dataforge.fx.work.WorkManager
import inr.numass.data.api.NumassSet
import inr.numass.data.storage.NumassStorageFactory
import inr.numass.viewer.NumassLoaderView
@ -18,7 +17,6 @@ class NumassTest : App(NumassLoaderView::class) {
super.start(stage)
val storage = NumassStorageFactory.buildLocal(File("D:\\Work\\Numass\\data\\2017_05\\"))
Global.setDefaultContext(Global.instance())
WorkManager().startGlobal()
val view = find<NumassLoaderView>();
view.data = storage.provide("Fill_1/set_4", NumassSet::class.java).get();
}