Skip to content

Commit

Permalink
Merge pull request #74 from CSC207-2023Y-UofT/Refactor-controllers-an…
Browse files Browse the repository at this point in the history
…d-presenters

Refactor controllers and presenters.
  • Loading branch information
rtutz authored Aug 10, 2023
2 parents 03e5153 + 72b7853 commit d806111
Show file tree
Hide file tree
Showing 15 changed files with 1,959 additions and 1,349 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import b_application_business_rules.entity_models.ProjectModel;

import java.io.IOException;

public interface ProjectSelectionOutputBoundary {

void displayCurrentProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
//
//this boundary will be responsable for telling the outer classes what to do and what to show

import a_enterprise_business_rules.entities.Column;
import a_enterprise_business_rules.entities.Project;
import a_enterprise_business_rules.entities.Task;
import b_application_business_rules.entity_models.ColumnModel;
import b_application_business_rules.entity_models.TaskModel;
import c_interface_adapters.view_models.ProjectViewModel;
import c_interface_adapters.view_models.ColumnViewModel;
import c_interface_adapters.view_models.TaskViewModel;


Expand All @@ -27,20 +22,14 @@ public interface ProjectViewingAndModificationOutputBoundary {

void displayNewTask(UUID columnBoxID, TaskViewModel newTask);

void displayRenamedTask(UUID taskID, TaskViewModel task);

void displayRemovedTask(UUID taskID, TaskViewModel task);

void displayRenamedColumn(ColumnModel columnModel);

void displayDeletedColumn(ColumnModel columnModel);

//void displayRenamedColumn(ColumnModel column);

void displayChangedTaskDetails(UUID taskID, TaskViewModel task, HBox hbox);
void displayChangedTaskDetails(UUID taskID, TaskViewModel task, UUID columnID);

void dislayChangedTaskDate(UUID taskID, TaskViewModel task);
void displayRenamedProject(ProjectViewModel project, UUID projectId);
void displayDeleteProject(ProjectViewModel project, UUID projectId);

void displayNewColumn(ColumnModel c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void setDescription(String newDescription) {
IDBRemove databaseRemover = new DBManagerRemoveController();
databaseRemover.DBRemove(this.currentProjectModel, this.currentProjectModel.getID());

this.currentProjectModel.setName(newDescription);
this.currentProjectModel.setDescription(newDescription);

IDBInsert databaseInserter = new DBManagerInsertController();
databaseInserter.DBInsert(this.currentProjectModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ public void createProject(ProjectModel projectModel) {
@Override
public void openProject(UUID currentProjectID) {
IDbIdToModel iDbIdToModel = new DbIDToModel();
// TODO: Pass the ProjectModel of the Project with the given UUID to the
// presenter.
// TODO: i.e. presenter.displayCurrentProjct(projectModel);

// Temporary implementation for testing purposes.
List<TaskModel> TaskList = Arrays.asList(
new TaskModel("Task1", UUID.randomUUID(), "Task1", true,
LocalDateTime.now()),
new TaskModel("Task2", UUID.randomUUID(), "Task2", true,
LocalDateTime.now()));
List<ColumnModel> ColumnsList = Arrays.asList(
new ColumnModel("COLUMN 1", TaskList, UUID.randomUUID()),
new ColumnModel("COLUMN 2", new ArrayList<>(), UUID.randomUUID()));
ProjectModel projectModel = new ProjectModel(
"Project P1", UUID.randomUUID(), "", ColumnsList);
// // TODO: Pass the ProjectModel of the Project with the given UUID to the
// // presenter.
// // TODO: i.e. presenter.displayCurrentProjct(projectModel);
//
// // Temporary implementation for testing purposes.
// List<TaskModel> TaskList = Arrays.asList(
// new TaskModel("Task1", UUID.randomUUID(), "Task1", true,
// LocalDateTime.now()),
// new TaskModel("Task2", UUID.randomUUID(), "Task2", true,
// LocalDateTime.now()));
// List<ColumnModel> ColumnsList = Arrays.asList(
// new ColumnModel("COLUMN 1", TaskList, UUID.randomUUID()),
// new ColumnModel("COLUMN 2", new ArrayList<>(), UUID.randomUUID()));
// ProjectModel projectModel = new ProjectModel(
// "Project P1", UUID.randomUUID(), "", ColumnsList);
ProjectModel ProjectFromDB = iDbIdToModel.IdToProjectModel(currentProjectID.toString());
setCurrentProject(ProjectFromDB);
presenter.displayCurrentProject(ProjectFromDB);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import d_frameworks_and_drivers.database_management.DBControllers.DBManagerSearchController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.UUID;

Expand Down Expand Up @@ -64,7 +65,9 @@ public void updateTaskDetail(UUID taskID, TaskModel updatedTask, UUID parentColu
String oldTaskName = oldTaskInfo.get(1);
String oldTaskDescription = oldTaskInfo.get(2);
boolean oldTaskStatus = Boolean.parseBoolean(oldTaskInfo.get(3));
LocalDateTime oldTaskDate = LocalDateTime.parse(oldTaskInfo.get(4));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
LocalDateTime oldTaskDate = LocalDateTime.parse(oldTaskInfo.get(4), formatter);
// LocalDateTime oldTaskDate = LocalDateTime.parse(oldTaskInfo.get(4));
TaskModel oldTask = TaskModelFactory.create(oldTaskName, taskID,
oldTaskDescription, oldTaskStatus, oldTaskDate);

Expand Down
128 changes: 128 additions & 0 deletions src/main/java/c_interface_adapters/DragAndDropImplementation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package c_interface_adapters;

import javafx.animation.TranslateTransition;
import javafx.scene.Node;
import javafx.scene.image.WritableImage;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.util.Duration;

/**
* The DragAndDropImplementation class is responsible for encapsulating the logic and behavior associated
* with implementing drag-and-drop functionality within the user interface (UI). It provides methods to configure
* the drag-and-drop behavior of UI components and handles state changes that occur during the drag-and-drop
* interactions.
*
* This class serves as a modular solution for incorporating drag-and-drop interactions into UI elements,
* promoting reusability and maintainability across different parts of the application. By managing the
* complexity of drag-and-drop interactions, the DragAndDropImplementation class allows presenter classes to
* focus on higher-level application logic and user experience.
*/
public class DragAndDropImplementation {
/**
* Configures drag-and-drop handling for the given column box.
*
* @param columnBox The VBox representing the column.
* @param projectViewingAndModificationPresenter
*/
void configureDragAndDropHandling(VBox columnBox, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) {
columnBox.setOnDragOver(event -> {
projectViewingAndModificationPresenter.dragDestination = columnBox;
event.consume();
});
}

/**
* Configures drag-and-drop behavior for an HBox.
*
* @param hbox The HBox to configure drag-and-drop behavior for.
* @param projectViewingAndModificationPresenter
*/
void configureDragAndDropBehavior(HBox hbox, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) {
hbox.setOnDragDetected(event -> {
Dragboard dragboard = hbox.startDragAndDrop(TransferMode.MOVE);
ClipboardContent content = new ClipboardContent();
content.putString(hbox.getId());
dragboard.setContent(content);
WritableImage snapshot = hbox.snapshot(null, null);
dragboard.setDragView(snapshot);
event.consume();
});

hbox.setOnDragOver(event -> {
if (event.getGestureSource() == hbox && event.getDragboard().hasString()) {
event.acceptTransferModes(TransferMode.MOVE);
}
event.consume();
});

hbox.setOnDragDone(event -> {
new DragAndDropImplementation().handleDragDone(hbox, event, projectViewingAndModificationPresenter);
event.consume();
});
}

/**
* Handles the completion of a drag-and-drop operation.
*
* @param hbox The source HBox being dragged.
* @param event The DragEvent associated with the operation.
* @param projectViewingAndModificationPresenter
*/
void handleDragDone(HBox hbox, DragEvent event, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) {
Dragboard dragboard = event.getDragboard();
boolean success = false;
if (dragboard.hasString()) {
HBox sourceHBox = new DragAndDropImplementation().findHBoxById(dragboard.getString(), projectViewingAndModificationPresenter);
if (sourceHBox != null && projectViewingAndModificationPresenter.dragDestination != null) {
new DragAndDropImplementation().moveHBoxToDestination(sourceHBox, hbox, projectViewingAndModificationPresenter);
success = true;
}
}
event.setDropCompleted(success);
// ... Perform additional tasks after drag-and-drop
}

/**
* Moves an HBox to a specified destination HBox within a VBox.
*
* @param sourceHBox The source HBox being moved.
* @param destinationHBox The destination HBox where the source HBox should be placed.
* @param projectViewingAndModificationPresenter
*/
void moveHBoxToDestination(HBox sourceHBox, HBox destinationHBox, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) {
VBox sourceColumnBox = (VBox) sourceHBox.getParent();
sourceColumnBox.getChildren().remove(sourceHBox);

TranslateTransition transition = new TranslateTransition(Duration.millis(100), sourceHBox);
transition.setToX(projectViewingAndModificationPresenter.dragDestination.getLayoutX() - destinationHBox.getLayoutX());
transition.play();

transition.setOnFinished(event -> {
projectViewingAndModificationPresenter.dragDestination.getChildren().add(sourceHBox);
});
}

/**
* Finds an HBox by its unique identifier within the set of VBox containers.
*
* @param id The unique identifier of the HBox to find.
* @param projectViewingAndModificationPresenter
* @return The found HBox, or null if not found.
*/
HBox findHBoxById(String id, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) {
System.out.println("this.VBoxContainer " + projectViewingAndModificationPresenter.VBoxContainer);
for (VBox vBox : projectViewingAndModificationPresenter.VBoxContainer) {
for (Node node2 : vBox.getChildren() ) {
if (node2 instanceof HBox && node2.getId().equals(id)) {
return (HBox) node2;
}
}
}
return null;
}
}
97 changes: 97 additions & 0 deletions src/main/java/c_interface_adapters/PopupUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package c_interface_adapters;

import b_application_business_rules.entity_models.TaskModel;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Pair;

import java.util.UUID;

public class PopupUI {
/**
* Displays a popup window to add a new task to the selected column. *
*
* @param columnBox The VBox representing the Column UI where the task will be added.
* @param projectViewingAndModificationPresenter
*/
public void handleAddTaskPopup(VBox columnBox, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) {
Stage popupStage = new PresenterUtility().createPopupStage("Add Task");
GridPane gridPane = new PresenterUtility().createGridPane();
new PresenterUtility().addComponentsToGridPane(gridPane, projectViewingAndModificationPresenter);
Button addTaskToColumnButton = new PresenterUtility().createAddTaskButton(popupStage, columnBox, projectViewingAndModificationPresenter);

gridPane.add(addTaskToColumnButton, 0, 3, 2, 1);

Scene popupScene = new Scene(gridPane, 800, 200);
popupStage.setScene(popupScene);

popupStage.showAndWait();
}

/**
* Displays a pop-up window to change task details. *
*
* @param task The task to be edited.
* @param hbox The HBox containing the task.
* @param columnID The ID of the column containing the task.
* @param projectViewingAndModificationPresenter
*/
void handleChangeTaskPopup(TaskModel task, HBox hbox, UUID columnID, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) {
Stage popupStage = new PresenterUtility().createPopupStage("Change Task Details");
GridPane gridPane = new PresenterUtility().createGridPane();
new PresenterUtility().addComponentsToGridPane(gridPane, projectViewingAndModificationPresenter);
Button changeTaskButton = new PresenterUtility().createChangeTaskButton(task, hbox, columnID, popupStage, projectViewingAndModificationPresenter);

gridPane.add(changeTaskButton, 0, 3, 2, 1);

Scene popupScene = new Scene(gridPane, 800, 200);
popupStage.setScene(popupScene);

popupStage.showAndWait();
}

/**
* Displays a pop-up window to add a new column. *
*
* @param addButtonClicked A boolean array to store the result of the pop-up.
* @param projectViewingAndModificationPresenter
* @return A Pair containing the flag indicating the button clicked and the entered column name (trimmed).
*/
public Pair<Boolean, String> displayAddColumnPopup(boolean[] addButtonClicked, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) {
Stage popupStage = new PresenterUtility().createPopupStage("Add New Column");
VBox layout = new PopupUI().createPopupLayout(addButtonClicked, popupStage, projectViewingAndModificationPresenter);
Scene popupScene = new Scene(layout);

popupStage.setScene(popupScene);
popupStage.showAndWait();

return new Pair<>(addButtonClicked[0], new PresenterUtility().getColumnInput(layout));
}

/**
* Creates the layout for the pop-up.
*
* @param addButtonClicked The array to store the result of the pop-up.
* @param popupStage The pop-up stage.
* @param projectViewingAndModificationPresenter
* @return A VBox containing the layout components.
*/
VBox createPopupLayout(boolean[] addButtonClicked, Stage popupStage, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) {
Label nameLabel = new Label("Column Name:");
TextField nameTextField = new TextField();
Button addButton = new PresenterUtility().createAddButton(addButtonClicked, popupStage, nameTextField, projectViewingAndModificationPresenter);
Button cancelButton = new PresenterUtility().createCancelButton(popupStage, nameTextField, projectViewingAndModificationPresenter);

VBox layout = new VBox(10);
layout.setPadding(new Insets(10));
layout.getChildren().addAll(nameLabel, nameTextField, addButton, cancelButton);
return layout;
}
}
Loading

0 comments on commit d806111

Please sign in to comment.