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 32be17d..c2d5d73 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/RootController.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/RootController.kt @@ -38,7 +38,7 @@ class RootController : Controller() { private lateinit var con: Connection - private lateinit var selectedTexture: Texture + private lateinit var selectedTextureModel: GUIModel private var lastExportDir: String = System.getProperty("user.home") @@ -242,7 +242,6 @@ class RootController : Controller() { sdf.format(data.addedOn.time) ) mvc.setTags(data.tags.toList().observable()) - selectedTexture = data mvc.setVisibleMetaTags(true) } @@ -253,12 +252,12 @@ class RootController : Controller() { fun deleteTexture(data: Texture) { val dialogDelete = JFXOkayCancelAlert( "Löschen", - "Textur ${data.name} wirklich löschen?", + "Textur ${selectedTextureModel.data.name} wirklich löschen?", "-fx-button-type: RAISED; -fx-background-color: #2b7bbb; -fx-text-fill: #000000;" ) dialogDelete.okayAction = EventHandler { - con.deleteTexture(data) - mvc.removeTextureFromView(data) + con.deleteTexture(selectedTextureModel.data) + mvc.removeTextureFromView(selectedTextureModel.data) } dialogDelete.cancelAction = EventHandler { // Do nothing @@ -274,20 +273,35 @@ class RootController : Controller() { val uuid = UUID.randomUUID() val newTexture = Texture( uuid, - selectedTexture.name, + selectedTextureModel.data.name, chips.toTypedArray(), - selectedTexture.format, - selectedTexture.resolution, - selectedTexture.addedOn, - selectedTexture.textureHash + selectedTextureModel.data.format, + selectedTextureModel.data.resolution, + selectedTextureModel.data.addedOn, + selectedTextureModel.data.textureHash ) - con.updateTexture(selectedTexture, newTexture, con.getTextureFile(selectedTexture.textureHash)) + try { + con.updateTexture(selectedTextureModel.data, newTexture, con.getTextureFile(selectedTextureModel.data.textureHash)) + selectedTextureModel.setTexture(newTexture) + selectedTextureModel.data = newTexture + } catch (e: Exception) { + println(e) + } } /** * show all available textures at start */ - fun showAll() { + private fun showAll() { queryElements(mvc.getTags()) } + + /** + * set the last selected texture-GUIModell + * @param model the last selected element + */ + fun setSelectedTexture(model: GUIModel){ + selectedTextureModel = model + } + } \ No newline at end of file diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/model/DataModel.kt b/client/src/main/kotlin/org/hso/texturesyncclient/model/DataModel.kt index 0e3b270..cd96006 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/model/DataModel.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/model/DataModel.kt @@ -13,7 +13,7 @@ enum class TextureFormat { data class Texture( val id : UUID, val name : String, - val tags : Array, + var tags : Array, val format : TextureFormat, val resolution : Pair, val addedOn : Calendar, diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt b/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt index cb665da..fdf1fe4 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt @@ -22,9 +22,12 @@ class GUIModel constructor(var data: Texture, img: Image) : VBox(){ private var exportItem = MenuItem("exportiern") private var deleteItem = MenuItem("löschen") + private lateinit var texture: Texture + private val gmc = find(GUIModelController::class) init { + texture = data super.setPadding(Insets(5.0, 5.0, 5.0, 5.0)) super.getChildren().addAll(image, label) super.setOnContextMenuRequested { p0 -> contextMenu.show(this@GUIModel, p0.screenX, p0.screenY) } @@ -38,6 +41,8 @@ class GUIModel constructor(var data: Texture, img: Image) : VBox(){ gmc.lastSelected = this } gmc.previewSelectedAction(data) + gmc.setSelected(this) + } label.paddingTop = 5.0 @@ -62,4 +67,8 @@ class GUIModel constructor(var data: Texture, img: Image) : VBox(){ contextMenu.items.add(deleteItem) } + fun setTexture(data: Texture){ + texture = data + } + } \ No newline at end of file diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModelController.kt b/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModelController.kt index ca6d150..07651f4 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModelController.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModelController.kt @@ -3,7 +3,7 @@ package org.hso.texturesyncclient.model import org.hso.texturesyncclient.controller.RootController import tornadofx.Controller -class GUIModelController: Controller() { +class GUIModelController : Controller() { private val rootc = find(RootController::class) @@ -21,4 +21,8 @@ class GUIModelController: Controller() { fun previewSelectedAction(data: Texture) { rootc.showDetail(data) } + + fun setSelected(model: GUIModel) { + rootc.setSelectedTexture(model) + } } \ No newline at end of file