Erweiterungen

This commit is contained in:
2025-09-11 22:10:33 +02:00
parent 3e22a9c520
commit 079f10d047

View File

@@ -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;