Add direct CLI for file watcher

This commit is contained in:
Alexander Nozik 2021-11-29 10:48:03 +03:00
parent 5e33bdbce7
commit c2d2813622
3 changed files with 108 additions and 82 deletions

View File

@ -74,9 +74,7 @@ runtime {
installerType = "deb" installerType = "deb"
installerOptions = installerOptions + listOf( installerOptions = installerOptions + listOf(
"--linux-package-name", "numass-viewer", "--linux-package-name", "numass-viewer",
"--linux-shortcut" "--linux-shortcut",
)
imageOptions = listOf(
"--linux-deb-maintainer", "nozik.aa@mipt.ru", "--linux-deb-maintainer", "nozik.aa@mipt.ru",
"--linux-menu-group", "Science", "--linux-menu-group", "Science",
"--linux-shortcut" "--linux-shortcut"

View File

@ -173,8 +173,10 @@ class DataController : Controller(), ContextAware {
sc.remove(id) sc.remove(id)
} }
//
// fun addAllPoints(points: Map<String, NumassPoint>) {
// TODO()
// }
fun addAllPoints(points: Map<String, NumassPoint>) {
TODO()
}
} }

View File

@ -52,11 +52,109 @@ class MainView : View(title = "Numass viewer", icon = dfIconView) {
} }
} }
private fun loadDirectory(path: Path){
app.context.launch {
dataController.clear()
runLater {
pathProperty.set(path)
contentView = null
}
if (Files.exists(path.resolve(NumassDataLoader.META_FRAGMENT_NAME))) {
//build set view
runGoal(app.context, "viewer.load.set[$path]", Dispatchers.IO) {
title = "Load set ($path)"
message = "Building numass set..."
NumassDataLoader(app.context, null, path.fileName.toString(), path)
} ui { loader: NumassDataLoader ->
contentView = spectrumView
dataController.addSet(loader.name, loader)
} except {
alert(
type = Alert.AlertType.ERROR,
header = "Error during set loading",
content = it.toString()
).show()
}
} else {
//build storage
app.context.launch {
val storageElement =
NumassDirectory.INSTANCE.read(app.context, path) as? Storage
withContext(Dispatchers.JavaFx) {
contentView = storageView
storageView.storageProperty.set(storageElement)
}
}
}
}
}
private fun loadFile(path: Path){
app.context.launch {
dataController.clear()
runLater {
pathProperty.set(path)
contentView = null
}
//Reading individual file
val envelope = try {
NumassFileEnvelope(path)
} catch (ex: Exception) {
runLater {
alert(
type = Alert.AlertType.ERROR,
header = "Can't load DF envelope from file $path",
content = ex.toString()
).show()
}
null
}
envelope?.let {
//try to read as point
val point = NumassDataUtils.read(it)
runLater {
contentView = amplitudeView
dataController.addPoint(path.fileName.toString(), point)
}
}
}
}
private fun watchDirectory(path: Path){
app.context.launch {
dataController.clear()
runLater {
pathProperty.set(path)
contentView = directoryWatchView
dataController.watchPathProperty.set(path)
}
}
}
override val root = borderpane { override val root = borderpane {
prefHeight = 600.0 prefHeight = 600.0
prefWidth = 800.0 prefWidth = 800.0
top { top {
//bypass top configuration bar and only watch directory
app.parameters.named["directory"]?.let{ pathString ->
val path = Path.of(pathString).toAbsolutePath()
watchDirectory(path)
toolbar{
prefHeight = 40.0
label("Watching $path") {
padding = Insets(0.0, 0.0, 0.0, 10.0)
font = Font.font("System Bold", 13.0)
}
pane {
hgrow = Priority.ALWAYS
}
}
return@top
}
toolbar { toolbar {
prefHeight = 40.0 prefHeight = 40.0
button("Load directory") { button("Load directory") {
@ -80,42 +178,7 @@ class MainView : View(title = "Numass viewer", icon = dfIconView) {
if (rootDir != null) { if (rootDir != null) {
NumassProperties.setNumassProperty("numass.viewer.lastPath", rootDir.absolutePath) NumassProperties.setNumassProperty("numass.viewer.lastPath", rootDir.absolutePath)
app.context.launch { loadDirectory(rootDir.toPath())
val path = rootDir.toPath()
dataController.clear()
runLater {
pathProperty.set(path)
contentView = null
}
if (Files.exists(path.resolve(NumassDataLoader.META_FRAGMENT_NAME))) {
//build set view
runGoal(app.context, "viewer.load.set[$path]", Dispatchers.IO) {
title = "Load set ($path)"
message = "Building numass set..."
NumassDataLoader(app.context, null, path.fileName.toString(), path)
} ui { loader: NumassDataLoader ->
contentView = spectrumView
dataController.addSet(loader.name, loader)
} except {
alert(
type = Alert.AlertType.ERROR,
header = "Error during set loading",
content = it.toString()
).show()
}
} else {
//build storage
app.context.launch {
val storageElement =
NumassDirectory.INSTANCE.read(app.context, path) as? Storage
withContext(Dispatchers.JavaFx) {
contentView = storageView
storageView.storageProperty.set(storageElement)
}
}
}
}
} }
} catch (ex: Exception) { } catch (ex: Exception) {
NumassProperties.setNumassProperty("numass.viewer.lastPath", null) NumassProperties.setNumassProperty("numass.viewer.lastPath", null)
@ -140,36 +203,7 @@ class MainView : View(title = "Numass viewer", icon = dfIconView) {
if (file != null) { if (file != null) {
NumassProperties.setNumassProperty("numass.viewer.lastPath", NumassProperties.setNumassProperty("numass.viewer.lastPath",
file.parentFile.absolutePath) file.parentFile.absolutePath)
app.context.launch { loadFile(file.toPath())
val path = file.toPath()
dataController.clear()
runLater {
pathProperty.set(file.toPath())
contentView = null
}
//Reading individual file
val envelope = try {
NumassFileEnvelope(path)
} catch (ex: Exception) {
runLater {
alert(
type = Alert.AlertType.ERROR,
header = "Can't load DF envelope from file $path",
content = ex.toString()
).show()
}
null
}
envelope?.let {
//try to read as point
val point = NumassDataUtils.read(it)
runLater {
contentView = amplitudeView
dataController.addPoint(path.fileName.toString(), point)
}
}
}
} }
} catch (ex: Exception) { } catch (ex: Exception) {
NumassProperties.setNumassProperty("numass.viewer.lastPath", null) NumassProperties.setNumassProperty("numass.viewer.lastPath", null)
@ -181,7 +215,7 @@ class MainView : View(title = "Numass viewer", icon = dfIconView) {
button("Watch directory") { button("Watch directory") {
action { action {
val chooser = DirectoryChooser() val chooser = DirectoryChooser()
chooser.title = "Select directory to view" chooser.title = "Select directory to watch"
val homeDir = NumassProperties.getNumassProperty("numass.viewer.lastPath") val homeDir = NumassProperties.getNumassProperty("numass.viewer.lastPath")
try { try {
if (homeDir == null) { if (homeDir == null) {
@ -199,15 +233,7 @@ class MainView : View(title = "Numass viewer", icon = dfIconView) {
if (dir != null) { if (dir != null) {
NumassProperties.setNumassProperty("numass.viewer.lastPath", dir.absolutePath) NumassProperties.setNumassProperty("numass.viewer.lastPath", dir.absolutePath)
app.context.launch { watchDirectory(dir.toPath())
val path = dir.toPath()
dataController.clear()
runLater {
pathProperty.set(path)
contentView = directoryWatchView
dataController.watchPathProperty.set(path)
}
}
} }
} catch (ex: Exception) { } catch (ex: Exception) {
NumassProperties.setNumassProperty("numass.viewer.lastPath", null) NumassProperties.setNumassProperty("numass.viewer.lastPath", null)