From ed558106e53bd7416b7e53637f8e89804526baca Mon Sep 17 00:00:00 2001 From: localhorst Date: Sat, 8 Jun 2019 12:47:34 +0200 Subject: [PATCH] update texture to server when tags are changed --- .../controller/RootController.kt | 20 ++++++++++++++++++- .../view/mainView/DetailView.kt | 7 ++----- .../view/mainView/MainViewController.kt | 11 ++++++++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/controller/RootController.kt b/client/src/main/kotlin/org/hso/texturesyncclient/controller/RootController.kt index 93bdcab..6f8ecd1 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/RootController.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/RootController.kt @@ -35,6 +35,8 @@ class RootController : Controller() { private lateinit var con: Connection + private lateinit var selectedTexture: Texture + private var lastExportDir: String = System.getProperty("user.home") /** @@ -100,7 +102,7 @@ class RootController : Controller() { println(e) println("[file] Connection to Server NOT successful") } - }else{ + } else { println("[file] no address in settings file") } } else { @@ -190,6 +192,7 @@ class RootController : Controller() { mvc.setPreview3DTexture(con.getTexturePreview(data.textureHash)) mvc.setMeta(data.name, data.resolution.toString(), "") mvc.setTags(data.tags.toList().observable()) + selectedTexture = data } /** @@ -212,4 +215,19 @@ class RootController : Controller() { dialogDelete.showAndWait() } + + fun updateTexture(chips: ObservableList) { + val uuid = UUID.randomUUID() + val newTexture = Texture( + uuid, + selectedTexture.name, + chips.toTypedArray(), + selectedTexture.format, + selectedTexture.resolution, + selectedTexture.addedOn, + selectedTexture.textureHash + ) + con.updateTexture(selectedTexture, newTexture, con.getTextureFile(selectedTexture.textureHash)) + } + } \ No newline at end of file diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/DetailView.kt b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/DetailView.kt index 30601c3..d586886 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/DetailView.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/DetailView.kt @@ -15,6 +15,8 @@ import tornadofx.* class DetailView: View() { + private val mvc: MainViewController by inject() + val preview = Preview3D() val metaLabel = Label("Auflösung: 8MP\nName: Texture.png\nAndere: was anderes") val cvTags = JFXChipView() @@ -74,10 +76,5 @@ class DetailView: View() { "-jfx-button-type: RAISED;" + "-fx-font-size: 25px" } - - btnImport.setOnAction { - - } - } } \ No newline at end of file diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt index 701351c..bd8ff50 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt @@ -19,6 +19,7 @@ class MainViewController : Controller() { private val preview = mv.detailView.preview private val metaLabel = mv.detailView.metaLabel private val cvTags = mv.detailView.cvTags + private var lockUpdate: Boolean = false //lock update func when the system changes the detailview chipview // FolderView functions fun addElement(element: GUIModel) { @@ -40,12 +41,17 @@ class MainViewController : Controller() { } fun setTags(chips: ObservableList) { + lockUpdate = false //dont trigger update with onChange cvTags.chips.clear() cvTags.chips.addAll(chips) + lockUpdate = true //allow update with onChange } fun updateTags() { - println(cvTags.chips) + if (lockUpdate) { //the chipView was changed by the user + println("Tags changed") + rootc.updateTexture(cvTags.chips) + } } // DetailView actions @@ -70,7 +76,8 @@ class MainViewController : Controller() { fun removeTextureFromView(data: Texture) { // stream all children nodes, filter them as GUIModel with data.id == data.id, for any found object if it's still present remove it from the folderView - folderView.children.stream().filter { x -> (x as GUIModel).data.id == data.id }.findAny().ifPresent{ x -> folderView.children.remove(x)} + folderView.children.stream().filter { x -> (x as GUIModel).data.id == data.id }.findAny() + .ifPresent { x -> folderView.children.remove(x) } }