From 079f10d047434699e622694cbef526d3f7a9af08 Mon Sep 17 00:00:00 2001 From: Sven Carstensen Date: Thu, 11 Sep 2025 22:10:33 +0200 Subject: [PATCH] Erweiterungen --- .../votianlt/pages/view/AddJobView.java | 46 +++++++++++++++---- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/assecutor/votianlt/pages/view/AddJobView.java b/src/main/java/de/assecutor/votianlt/pages/view/AddJobView.java index 12f1754..99bf2a5 100644 --- a/src/main/java/de/assecutor/votianlt/pages/view/AddJobView.java +++ b/src/main/java/de/assecutor/votianlt/pages/view/AddJobView.java @@ -1509,31 +1509,50 @@ public class AddJobView extends Main { task.setTaskOrder(tasksState.size()); // Set order based on current position tasksState.add(task); + // Use an array to hold the current task reference (allows modification in lambda) + final BaseTask[] currentTask = {task}; + taskTypeCombo.addValueChangeListener(ev -> { TaskType selectedType = ev.getValue(); if (selectedType != null) { // Create new task instance based on type BaseTask newTask = createTaskByType(selectedType); - newTask.setText(task.getText()); - newTask.setCompleted(task.isCompleted()); - newTask.setCompletedAt(task.getCompletedAt()); - newTask.setCompletedBy(task.getCompletedBy()); - newTask.setCompletionNote(task.getCompletionNote()); - + BaseTask oldTask = currentTask[0]; + + newTask.setText(oldTask.getText()); + newTask.setCompleted(oldTask.isCompleted()); + newTask.setCompletedAt(oldTask.getCompletedAt()); + newTask.setCompletedBy(oldTask.getCompletedBy()); + newTask.setCompletionNote(oldTask.getCompletionNote()); + + // Preserve task-specific properties + if (oldTask instanceof ConfirmationTask oldConfirmationTask && newTask instanceof ConfirmationTask newConfirmationTask) { + newConfirmationTask.setButtonText(oldConfirmationTask.getButtonText()); + } else if (oldTask instanceof TodoListTask oldTodoTask && newTask instanceof TodoListTask newTodoTask) { + newTodoTask.setTodoItems(oldTodoTask.getTodoItems()); + } else if (oldTask instanceof PhotoTask oldPhotoTask && newTask instanceof PhotoTask newPhotoTask) { + newPhotoTask.setMinPhotoCount(oldPhotoTask.getMinPhotoCount()); + newPhotoTask.setMaxPhotoCount(oldPhotoTask.getMaxPhotoCount()); + } else if (oldTask instanceof BarcodeTask oldBarcodeTask && newTask instanceof BarcodeTask newBarcodeTask) { + newBarcodeTask.setMinBarcodeCount(oldBarcodeTask.getMinBarcodeCount()); + newBarcodeTask.setMaxBarcodeCount(oldBarcodeTask.getMaxBarcodeCount()); + } + // Replace in state and preserve order - int index = tasksState.indexOf(task); + int index = tasksState.indexOf(oldTask); if (index >= 0) { newTask.setTaskOrder(index); // Preserve the order tasksState.set(index, newTask); + currentTask[0] = newTask; // Update the reference } - + updateTaskConfiguration(configContainer, newTask); } }); // Set initial configuration taskTypeCombo.setValue(TaskType.CONFIRMATION); - updateTaskConfiguration(configContainer, task); + updateTaskConfiguration(configContainer, currentTask[0]); tasksList.add(taskContainer); } @@ -1573,7 +1592,14 @@ public class AddJobView extends Main { buttonTextField.setValue(confirmationTask.getButtonText() != null ? confirmationTask.getButtonText() : ""); buttonTextField.addValueChangeListener(ev -> { - confirmationTask.setButtonText(ev.getValue()); + // Find the current ConfirmationTask in tasksState and update it + for (int i = 0; i < tasksState.size(); i++) { + BaseTask stateTask = tasksState.get(i); + if (stateTask == task && stateTask instanceof ConfirmationTask) { + ((ConfirmationTask) stateTask).setButtonText(ev.getValue()); + break; + } + } }); configContainer.add(buttonTextField); break;