Class ChatUpdateController
Extends ChatSetupController
to provide functionality for updating an existing
chat’s details (e.g., chat name, response attitude, quiz difficulty) and downloading
chat messages as a text file. Implements the abstract method
setupConfirmChatButton()
to handle chat updates and navigation back to the
chat screen. Interacts with the database via ChatDAO
and MessageDAO
for updating chats and retrieving messages, respectively.
- See Also:
-
Field Summary
Fields inherited from class ai.tutor.cab302exceptionalhandlers.controller.ChatSetupController
backgroundOverlay, chatDAO, chatNameInput, chatTopic, currentUser, db, downloadButton, educationLevel, exitButton, messageDAO, quizDifficulty, quizLength, responseAttitude, settingsTitle, startChatButton, userDAO
-
Constructor Summary
ConstructorsConstructorDescriptionChatUpdateController
(SQLiteConnection db, User currentUser, Chat currentChat) Constructs a ChatUpdateController with a database connection, authenticated user, and the chat to update. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Initiates the download of chat messages for the current chat as a text file.protected Chat
Retrieves the current chat being updated.void
Initializes the chat update screen’s UI components and event handlers.protected void
Sets up the confirm chat button to update the current chat.void
updateChatDetails
(String name, String responseAttitude, String quizDifficulty, int quizLength, String educationLevel, String studyArea) Updates the details of the current chat.Methods inherited from class ai.tutor.cab302exceptionalhandlers.controller.ChatSetupController
chatReturn
-
Constructor Details
-
ChatUpdateController
public ChatUpdateController(SQLiteConnection db, User currentUser, Chat currentChat) throws IllegalStateException, RuntimeException, SQLException Constructs a ChatUpdateController with a database connection, authenticated user, and the chat to update.Calls the superclass constructor to initialize the database connection, current user, and DAO instances (
UserDAO
,ChatDAO
,MessageDAO
). Sets thecurrentChat
to be updated. Throws an exception if the user is null.- Parameters:
db
- The SQLite database connectioncurrentUser
- The currently authenticated usercurrentChat
- The chat to be updated- Throws:
IllegalStateException
- If the user is nullRuntimeException
- If unexpected errors occur during setupSQLException
- If database initialization fails
-
-
Method Details
-
initialize
public void initialize()Initializes the chat update screen’s UI components and event handlers.Calls the superclass’s
ChatSetupController.initialize()
to set up shared functionality (e.g., exit button, background exit), then configures the UI with existing chat details usingconfigureChatSettings()
.- Overrides:
initialize
in classChatSetupController
-
getCurrentChat
Retrieves the current chat being updated.Overrides the abstract
ChatSetupController.getCurrentChat()
method to provide the chat context for the update mode. Returns thecurrentChat
field, which is set by the subclass when initializing the update interface.- Specified by:
getCurrentChat
in classChatSetupController
- Returns:
- The current
Chat
object being updated, or null if not set - See Also:
-
setupConfirmChatButton
protected void setupConfirmChatButton()Sets up the confirm chat button to update the current chat.Configures
ChatSetupController.startChatButton
to update the chat usingupdateChatDetails(String, String, String, int, String, String)
with user inputs from the UI, then navigates back to the chat screen viaChatSetupController.chatReturn()
. Displays an error alert if the update fails.- Specified by:
setupConfirmChatButton
in classChatSetupController
-
downloadChat
protected void downloadChat()Initiates the download of chat messages for the current chat as a text file.Checks if a chat is selected using
getCurrentChat()
, retrieves all messages for the chat usingMessageDAO
, formats them into a text file, and prompts the user to save it using aFileChooser
. Displays alerts for no chat selected, no messages, or successful/failed operations. Subclasses are responsible for providing the chat context.- Overrides:
downloadChat
in classChatSetupController
-
updateChatDetails
public void updateChatDetails(String name, String responseAttitude, String quizDifficulty, int quizLength, String educationLevel, String studyArea) throws IllegalArgumentException, NoSuchElementException, SQLException Updates the details of the current chat.Validates the required inputs (chat name, response attitude, quiz difficulty), updates the
currentChat
object with new values, and saves the changes to the database usingChatSetupController.chatDAO
. Optional fields (education level, study area) are set to null if empty.- Parameters:
name
- The updated name of the chatresponseAttitude
- The updated AI response attitude (e.g., formal, casual)quizDifficulty
- The updated quiz difficulty level (e.g., easy, medium, hard)quizLength
- The updated number of questions in a quizeducationLevel
- The updated user education level (optional, can be null)studyArea
- The updated user study area or topic (optional, can be null)- Throws:
IllegalArgumentException
- If the chat name, response attitude, or quiz difficulty is emptyNoSuchElementException
- If the chat does not exist in the databaseSQLException
- If database operations fail
-