diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 196dbd3..ec349c8 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,4 +1,5 @@ import c_interface_adapters.ProjectSelectionPresenter; +import d_frameworks_and_drivers.database_management.DatabaseInitializer.DBInitializer; import javafx.application.Application; public class Main { diff --git a/src/main/java/a_enterprise_business_rules/entities/Column.java b/src/main/java/a_enterprise_business_rules/entities/Column.java index abff9dc..293a34b 100644 --- a/src/main/java/a_enterprise_business_rules/entities/Column.java +++ b/src/main/java/a_enterprise_business_rules/entities/Column.java @@ -252,10 +252,9 @@ public String toString() { */ @Override public boolean equals(Object o) { - if (!(o instanceof Column)) { + if (!(o instanceof Column c)) { return false; } - Column c = (Column) o; // Checking the equality of each of the attributes boolean allAttributesAreEqual = c.getName().equals(this.getName()) && c.getID().equals(this.getID()) && diff --git a/src/main/java/a_enterprise_business_rules/entities/Project.java b/src/main/java/a_enterprise_business_rules/entities/Project.java index c6b2cf6..3c3b086 100644 --- a/src/main/java/a_enterprise_business_rules/entities/Project.java +++ b/src/main/java/a_enterprise_business_rules/entities/Project.java @@ -1,6 +1,8 @@ package a_enterprise_business_rules.entities; +import b_application_business_rules.entity_models.ColumnModel; + import java.util.List; import java.util.Collections; @@ -36,7 +38,7 @@ public class Project { /** * The columns in the kanban board for this project. */ - private List columns; + private List columns; /** * Creates a new project, based in the inputted values. @@ -46,7 +48,7 @@ public class Project { * @param description A description of the task. * @param columns The columns of the project. */ - public Project(String name, UUID ID, String description, List columns) { + public Project(String name, UUID ID, String description, List columns) { this.name = name; this.columns = columns; this.description = description; @@ -112,7 +114,7 @@ public void setDescription(String newDescription) { * * @return an List of s. */ - public List getColumns() { + public List getColumns() { return this.columns; } @@ -121,7 +123,7 @@ public List getColumns() { * * @param newColumns The new columns for the project. */ - public void setColumns(List newColumns) { + public void setColumns(List newColumns) { this.columns = newColumns; } @@ -130,7 +132,7 @@ public void setColumns(List newColumns) { * * @param newColumn The column to add. */ - public void addColumn(Column newColumn) { + public void addColumn(ColumnModel newColumn) { this.columns.add(newColumn); } @@ -140,7 +142,7 @@ public void addColumn(Column newColumn) { * @param newColumn The column to add to the project. * @param position The position/index to add the column at. */ - public void addColumnToPosition(Column newColumn, int position) { + public void addColumnToPosition(ColumnModel newColumn, int position) { this.columns.add(position, newColumn); } @@ -154,7 +156,7 @@ public void addColumnToPosition(Column newColumn, int position) { * @throws IllegalArgumentException Throws exception when the specified index is out * of bounds. */ - public void moveColumnToPosition(Column columnToMove, int positionToMoveTo) + public void moveColumnToPosition(ColumnModel columnToMove, int positionToMoveTo) throws NoSuchElementException, IllegalArgumentException { // The moving of the columns is done by removing the object from the List // and then adding it back at the indicated index @@ -189,7 +191,7 @@ public void moveColumnToPosition(Column columnToMove, int positionToMoveTo) * @throws NoSuchElementException Throws exception when the specified column to * remove is not in the project. */ - public void removeColumn(Column columnToRemove) throws NoSuchElementException { + public void removeColumn(ColumnModel columnToRemove) throws NoSuchElementException { if (!this.columns.remove(columnToRemove)) { // the java.util.List.remove method returns a bool, // indicating whether the object was removed or not. @@ -201,6 +203,25 @@ public void removeColumn(Column columnToRemove) throws NoSuchElementException { } } + /** + * Removes a column with the specified ID from the list of columns in the current project. + * + * @param idOfColumnToRemove The ID of the column to be removed. + * @throws NoSuchElementException If no column with the given ID is found in the project. + */ + public void removeColumn(UUID idOfColumnToRemove) throws NoSuchElementException { + for (ColumnModel column : columns) { + if (column.getID().equals(idOfColumnToRemove)) { + columns.remove(column); + return; + } + } + throw new NoSuchElementException( + "The column with ID " + idOfColumnToRemove + " is not in this project"); + } + + + /** * Swaps the order of two columns in the column. * @@ -242,10 +263,9 @@ public void swapColumnOrder(Column col1, Column col2) { */ @Override public boolean equals(Object o) { - if (!(o instanceof Project)) { + if (!(o instanceof Project p)) { return false; } - Project p = (Project) o; // Checking the equality of each of the attributes boolean allAttributesAreEqual = p.getName().equals(this.getName()) && p.getID().equals(this.getID()) && diff --git a/src/main/java/a_enterprise_business_rules/entities/Task.java b/src/main/java/a_enterprise_business_rules/entities/Task.java index 8bd1723..2ab6572 100644 --- a/src/main/java/a_enterprise_business_rules/entities/Task.java +++ b/src/main/java/a_enterprise_business_rules/entities/Task.java @@ -185,10 +185,9 @@ public String toString() { */ @Override public boolean equals(Object o) { - if (!(o instanceof Task)) { + if (!(o instanceof Task t)) { return false; } - Task t = (Task) o; // Checking the equality of each of the attributes boolean allAttributesAreEqual = t.getName().equals(this.getName()) && t.getID().equals(this.getID()) && diff --git a/src/main/java/b_application_business_rules/boundaries/ProjectSelectionInputBoundary.java b/src/main/java/b_application_business_rules/boundaries/ProjectSelectionInputBoundary.java index 5b68d4a..514e69e 100644 --- a/src/main/java/b_application_business_rules/boundaries/ProjectSelectionInputBoundary.java +++ b/src/main/java/b_application_business_rules/boundaries/ProjectSelectionInputBoundary.java @@ -6,9 +6,16 @@ import java.util.UUID; public interface ProjectSelectionInputBoundary { + void setCurrentProject(Project project); + void setCurrentProject(ProjectModel project); + + //void setCurrentProject(Project project); + void createProject(String name, String description); + void createProject(); + void createProject(ProjectModel projectModel); void deleteProject(UUID projectID); diff --git a/src/main/java/b_application_business_rules/boundaries/ProjectViewingAndModificationInputBoundary.java b/src/main/java/b_application_business_rules/boundaries/ProjectViewingAndModificationInputBoundary.java index 64e361d..ba01331 100644 --- a/src/main/java/b_application_business_rules/boundaries/ProjectViewingAndModificationInputBoundary.java +++ b/src/main/java/b_application_business_rules/boundaries/ProjectViewingAndModificationInputBoundary.java @@ -17,7 +17,7 @@ import java.util.UUID; public interface ProjectViewingAndModificationInputBoundary { - public void removeCurrentProject(); + void removeCurrentProject(); void addNewTask(UUID idOfColumn, String taskName, String taskDescription, LocalDateTime dueDate); diff --git a/src/main/java/b_application_business_rules/boundaries/ProjectViewingAndModificationOutputBoundary.java b/src/main/java/b_application_business_rules/boundaries/ProjectViewingAndModificationOutputBoundary.java index f36ec24..b89a760 100644 --- a/src/main/java/b_application_business_rules/boundaries/ProjectViewingAndModificationOutputBoundary.java +++ b/src/main/java/b_application_business_rules/boundaries/ProjectViewingAndModificationOutputBoundary.java @@ -6,6 +6,7 @@ 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; @@ -33,6 +34,9 @@ public interface ProjectViewingAndModificationOutputBoundary { void displayRenamedColumn(ColumnModel columnModel); void displayDeletedColumn(ColumnModel columnModel); + + //void displayRenamedColumn(ColumnModel column); + void dislayChangedTaskDetails(UUID taskID, TaskViewModel task); void dislayChangedTaskDate(UUID taskID, TaskViewModel task); void displayRenamedProject(ProjectViewModel project, UUID projectId); diff --git a/src/main/java/b_application_business_rules/entity_models/ColumnModel.java b/src/main/java/b_application_business_rules/entity_models/ColumnModel.java index ee99929..6ba40a1 100644 --- a/src/main/java/b_application_business_rules/entity_models/ColumnModel.java +++ b/src/main/java/b_application_business_rules/entity_models/ColumnModel.java @@ -3,12 +3,7 @@ import a_enterprise_business_rules.entities.Column; import a_enterprise_business_rules.entities.Task; -import java.util.List; -import java.util.Collections; - -import java.util.UUID; - -import java.util.NoSuchElementException; +import java.util.*; /** * A column model within the productivity application. @@ -237,6 +232,22 @@ public String toString() { return columnModelStringRepresentation; } + /** + * Returns a Column Entity from Column Model. + * + * {@inheritDoc} + * + * @return a Column Entity. + */ + public Column getColumnEntity() { + List taskEntities = new ArrayList<>(); + for (TaskModel taskModel: taskModels) { + taskEntities.add(taskModel.getTaskEntity()); + } + + return new Column(name, taskEntities, ID); + } + // TODO:turn this into its own class // private UUID getValidColumnID(){ // this.ID = UUID.randomUUID(); diff --git a/src/main/java/b_application_business_rules/entity_models/ProjectModel.java b/src/main/java/b_application_business_rules/entity_models/ProjectModel.java index a129852..eaf698a 100644 --- a/src/main/java/b_application_business_rules/entity_models/ProjectModel.java +++ b/src/main/java/b_application_business_rules/entity_models/ProjectModel.java @@ -1,18 +1,11 @@ package b_application_business_rules.entity_models; import a_enterprise_business_rules.entities.Project; -import a_enterprise_business_rules.entities.Column; -import java.util.List; -import java.util.Collections; - -import java.util.UUID; - -import java.util.NoSuchElementException; +import java.util.*; /** - * A project model within the productivity application. - * + * A project model within the productivity application.* * Each project model will have a name, unique identifier, a description, and a * list * of column models (which contain task modelss). @@ -65,10 +58,10 @@ public ProjectModel(Project project) { this.name = project.getName(); // Converting the List of Column objects to a List of ColumnModel objects - List columns = project.getColumns(); // Get the columns + List columns = project.getColumns(); // Get the columns // Converts Columns to ColumnModels and puts it in the columnModels attribute - for (int i = 0; i < columns.size(); i++) { - this.addColumnModel(new ColumnModel(columns.get(i))); + for (ColumnModel cols : columns) { + this.addColumnModel(cols); } this.description = project.getDescription(); @@ -218,7 +211,7 @@ public void removeColumnModel(ColumnModel columnModelToRemove) throws NoSuchElem // the java.util.List.remove method returns a bool, // indicating whether the object was removed or not. // If it wasn't removed, we want to throw an exception, - // saying that the column model isn't in the column model list, thus, it can't be + // saying that the task models isn't in the column model, thus, it can't be // removed. // If it was removed, we don't have to do anything extra. throw new NoSuchElementException( @@ -249,7 +242,7 @@ public void swapColumnModelOrder(ColumnModel col1, ColumnModel col2) { exceptionMessage += col2.toString(); } - // Throws the exception if at least 1 of the column model are missing, + // Throws the exception if at least 1 of the task modelss are missing, // using the exception message created above if (!col1InColumnModel || !col2InColumnModel) { throw new NoSuchElementException(exceptionMessage); @@ -260,5 +253,20 @@ public void swapColumnModelOrder(ColumnModel col1, ColumnModel col2) { this.columnModels, this.columnModels.indexOf(col1), this.columnModels.indexOf(col2)); } + /** + * Returns a Project Entity from Project Model. + * + * {@inheritDoc} + * + * @return a Project Entity. + */ + public Project getProjectEntity() { + List columnEntities = new ArrayList<>(); + for (ColumnModel columnModel: columnModels) { + columnEntities.add(columnModel); + } + + return new Project(name, ID, description, columnEntities); + } } diff --git a/src/main/java/b_application_business_rules/entity_models/TaskModel.java b/src/main/java/b_application_business_rules/entity_models/TaskModel.java index 5fca7e9..e1675b6 100644 --- a/src/main/java/b_application_business_rules/entity_models/TaskModel.java +++ b/src/main/java/b_application_business_rules/entity_models/TaskModel.java @@ -203,4 +203,15 @@ public String toString() { + "Due Date: " + this.dueDateTime.toString() + "]"; } + /** + * Returns a Task Entity from Task Model. + * + * {@inheritDoc} + * + * @return a Task Entity. + */ + public Task getTaskEntity() { + return new Task(name, ID, description, isCompleted, dueDateTime); + } + } \ No newline at end of file diff --git a/src/main/java/b_application_business_rules/use_cases/CurrentProjectRepository.java b/src/main/java/b_application_business_rules/use_cases/CurrentProjectRepository.java index 98d30c0..9815308 100644 --- a/src/main/java/b_application_business_rules/use_cases/CurrentProjectRepository.java +++ b/src/main/java/b_application_business_rules/use_cases/CurrentProjectRepository.java @@ -1,5 +1,6 @@ package b_application_business_rules.use_cases; +import a_enterprise_business_rules.entities.Project; import b_application_business_rules.entity_models.ProjectModel; import java.util.UUID; @@ -30,6 +31,7 @@ public void removeCurrentProject() { public void deleteProject(UUID projectID) {} - public void getProjectByID(UUID projectID) { + public Project getProjectByID(UUID projectID) { + return null; } } diff --git a/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBInsert.java b/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBInsert.java index 840c7c0..fc7f88e 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBInsert.java +++ b/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBInsert.java @@ -6,12 +6,12 @@ import java.util.UUID; public interface IDBInsert { - public void DBInsert(ProjectModel projectModel); + void DBInsert(ProjectModel projectModel); - public void DBInsert(ColumnModel columnModel); + void DBInsert(ColumnModel columnModel); - public void DBInsert(TaskModel taskModel); + void DBInsert(TaskModel taskModel); - public void DBInsert(UUID uuid); + void DBInsert(UUID uuid); } diff --git a/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBRemove.java b/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBRemove.java index 77741cd..8fea701 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBRemove.java +++ b/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBRemove.java @@ -11,7 +11,7 @@ import java.util.UUID; public interface IDBRemove { - public void DBRemove(ProjectModel projectModel, UUID uuid); - public void DBRemove(TaskModel taskModel, UUID uuid); - public void DBRemove(ColumnModel columnModel, UUID uuid); + void DBRemove(ProjectModel projectModel, UUID uuid); + void DBRemove(TaskModel taskModel, UUID uuid); + void DBRemove(ColumnModel columnModel, UUID uuid); } diff --git a/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBSearch.java b/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBSearch.java index 7a2b53e..fab3b1a 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBSearch.java +++ b/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IDBSearch.java @@ -5,7 +5,7 @@ import java.util.*; public interface IDBSearch { - public ArrayList DBColumnSearch(String id); + ArrayList DBColumnSearch(String id); - public ArrayList DBTaskSearch(String id); + ArrayList DBTaskSearch(String id); } diff --git a/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IEntityIDsToList.java b/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IEntityIDsToList.java index b87ad1d..de18d5d 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IEntityIDsToList.java +++ b/src/main/java/b_application_business_rules/use_cases/project_selection_gateways/IEntityIDsToList.java @@ -3,6 +3,6 @@ import b_application_business_rules.entity_models.*; public interface IEntityIDsToList { - public String EntityIDsToList(ProjectModel projectModel); - public String EntityIDsToList(ColumnModel columnModel); + String EntityIDsToList(ProjectModel projectModel); + String EntityIDsToList(ColumnModel columnModel); } diff --git a/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/CreateProject.java b/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/CreateProject.java index ff7a4d4..5fe670a 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/CreateProject.java +++ b/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/CreateProject.java @@ -1,85 +1,100 @@ -//package b_application_business_rules.use_cases.project_selection_use_cases; -//import b_application_business_rules.boundaries.ProjectSelectionInputBoundary; -//import b_application_business_rules.boundaries.ProjectSelectionOutputBoundary; -//import b_application_business_rules.entity_models.ProjectModel; -//import b_application_business_rules.entity_models.ColumnModel; -//import java.util.List; -//import java.util.UUID; -// -//public class CreateProject implements ProjectSelectionInputBoundary { -// private ProjectSelectionOutputBoundary outputBoundary; -// -// public CreateProject(ProjectSelectionOutputBoundary outputBoundary) { -// this.outputBoundary = outputBoundary; -// } -// -// -// @Override -// public void setCurrentProject(ProjectModel project) { -// -// } -// -// @Override -// public void createProject(String name, String description) { -// -// } -// -// @Override -// public void createProject(ProjectModel projectModel){ -// try{ -// // Create the new Project entity -// Project project = createProjectEntity(projectModel); -// Project project = new Project(projectModel.getName(), projectModel.getID(), projectModel.getDescription(), -// projectModel.getColumnModels()); -// -// // Notify via the output boundary if created successfully -// outputBoundary.projectCreated(new ProjectModel(project.getName(), project.getID(), project.getDescription(), -// project.getColumns())); // ??? -// } catch (Exception e){ -// // Notify via the output boundary if cretion failed -// outputBoundary.projectCreationFailed(e.getMessage()); -// } -// } -// -// @Override -// public void projectDeletionFailed(String message) { -// -// } -// -// @Override -// public void projectDeleted(UUID projectID) { -// -// } -// -// @Override -// public void openProject(UUID currentProjectID) { -// -// } -// -// @Override -// public void renameProject(UUID projectUUID) { -// -// } -// -// @Override -// public void deleteProject(UUID projectUUID) { -// -// } -// -// // Validate projectModel data -// private void validateProjectModel(ProjectModel projectModel) { -// if (projectModel.getName() == null || projectModel.getName().isEmpty()){ -// throw new IllegalArgumentException("Project name cannot be empty."); -// } -// -// // to be continued -// } -// -// // Create the Project entity from the ProjectModel (Project factory ?) -// private Project createProjectEntity(ProjectModel projectModel) { -// return new Project(projectModel.getName(), projectModel.getID(), projectModel.getDescription(), -// projectModel.getColumnModels()); // ??? -// } -// -//} -// +package b_application_business_rules.use_cases.project_selection_use_cases; +import a_enterprise_business_rules.entities.Project; +import b_application_business_rules.boundaries.ProjectSelectionInputBoundary; +import b_application_business_rules.boundaries.ProjectSelectionOutputBoundary; +import b_application_business_rules.entity_models.ProjectModel; +import b_application_business_rules.entity_models.ColumnModel; +import java.util.List; +import java.util.UUID; + +public class CreateProject implements ProjectSelectionInputBoundary { + private final ProjectSelectionOutputBoundary outputBoundary; + + public CreateProject(ProjectSelectionOutputBoundary outputBoundary) { + this.outputBoundary = outputBoundary; + } + + @Override + public void setCurrentProject(Project project) { + + } + + /** + * @param project + */ + @Override + public void setCurrentProject(ProjectModel project) { + + } + + @Override + public void createProject(String name, String description) { + + } + + /** + * + */ + @Override + public void createProject() { + + } + + @Override + public void createProject(ProjectModel projectModel){ + try{ + // Create the new Project entity + Project project = createProjectEntity(projectModel); + Project project1 = new Project(projectModel.getName(), projectModel.getID(), projectModel.getDescription(), + projectModel.getColumnModels()); + + // Notify via the output boundary if created successfully + outputBoundary.projectCreated(new ProjectModel(project.getName(), project.getID(), project.getDescription(), + projectModel.getColumnModels())); // ??? + } catch (Exception e){ + // Notify via the output boundary if cretion failed + outputBoundary.projectCreationFailed(e.getMessage()); + } + } + + @Override + public void projectDeletionFailed(String message) { + + } + + @Override + public void projectDeleted(UUID projectID) { + + } + + @Override + public void openProject(UUID currentProjectID) { + + } + + @Override + public void renameProject(UUID projectUUID) { + + } + + @Override + public void deleteProject(UUID projectUUID) { + + } + + // Validate projectModel data + private void validateProjectModel(ProjectModel projectModel) { + if (projectModel.getName() == null || projectModel.getName().isEmpty()){ + throw new IllegalArgumentException("Project name cannot be empty."); + } + + // to be continued + } + + // Create the Project entity from the ProjectModel (Project factory ?) + private Project createProjectEntity(ProjectModel projectModel) { + return new Project(projectModel.getName(), projectModel.getID(), projectModel.getDescription(), + projectModel.getColumnModels()); // ??? + } + +} diff --git a/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/DeleteProject.java b/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/DeleteProject.java index 801030f..376b698 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/DeleteProject.java +++ b/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/DeleteProject.java @@ -1,76 +1,89 @@ -//package b_application_business_rules.use_cases.project_selection_use_cases; -//import a_enterprise_business_rules.entities.Project; -//import b_application_business_rules.boundaries.ProjectSelectionInputBoundary; -//import b_application_business_rules.entity_models.ProjectModel; -//import b_application_business_rules.use_cases.CurrentProjectRepository; -// -//import java.util.UUID; -// -// -//public class DeleteProject implements ProjectSelectionInputBoundary{ -// private ProjectSelectionInputBoundary outputBoundary; -// private CurrentProjectRepository projectRepository; -// -// public DeleteProject(ProjectSelectionInputBoundary outputBoundary, CurrentProjectRepository projectRepository){ -// this.outputBoundary = outputBoundary; -// this.projectRepository = projectRepository; -// } -// -// @Override -// public void setCurrentProject(Project project) { -// -// } -// -// @Override -// public void createProject(String name, String description) { -// -// } -// -// @Override -// public void createProject(ProjectModel projectModel) { -// -// } -// -// @Override -// public void projectDeletionFailed(String message) { -// -// } -// -// @Override -// public void projectDeleted(UUID projectID) { -// -// } -// -// @Override -// public void openProject(UUID currentProjectID) { -// -// } -// -// @Override -// public void renameProject(UUID projectUUID) { -// -// } -// -// @Override -// public void deleteProject(UUID projectID) { -// try { -// // Check if the project exists first -// Project project = projectRepository.getProjectByID(projectID); -// if (project == null){ -// outputBoundary.projectDeletionFailed("Project with the ID " + projectID + " was not found."); -// return; -// } -// -// // Delete the project -// projectRepository.deleteProject(projectID); -// -// // Notify via the output boundary if deletion is successful -// outputBoundary.projectDeleted(projectID); -// } catch (Exception e){ -// // Notify via output boundary if the deletion failed -// outputBoundary.projectDeletionFailed(e.getMessage()); -// } -// } -//} -// -// +package b_application_business_rules.use_cases.project_selection_use_cases; +import a_enterprise_business_rules.entities.Project; +import b_application_business_rules.boundaries.ProjectSelectionInputBoundary; +import b_application_business_rules.entity_models.ProjectModel; +import b_application_business_rules.use_cases.CurrentProjectRepository; + +import java.util.UUID; + +public class DeleteProject implements ProjectSelectionInputBoundary{ + private final ProjectSelectionInputBoundary outputBoundary; + private final CurrentProjectRepository projectRepository; + + public DeleteProject(ProjectSelectionInputBoundary outputBoundary, CurrentProjectRepository projectRepository){ + this.outputBoundary = outputBoundary; + this.projectRepository = projectRepository; + } + + /** + * @param project + */ + @Override + public void setCurrentProject(ProjectModel project) { + + } + + @Override + public void setCurrentProject(Project project) { + + } + + @Override + public void createProject(String name, String description) { + + } + + /** + * + */ + @Override + public void createProject() { + + } + + @Override + public void createProject(ProjectModel projectModel) { + + } + + @Override + public void projectDeletionFailed(String message) { + + } + + @Override + public void projectDeleted(UUID projectID) { + + } + + @Override + public void openProject(UUID currentProjectID) { + + } + + @Override + public void renameProject(UUID projectUUID) { + + } + + @Override + public void deleteProject(UUID projectID) { + try { + // Check if the project exists first + Project project = projectRepository.getProjectByID(projectID); + if (project == null){ + outputBoundary.projectDeletionFailed("Project with the ID " + projectID + " was not found."); + return; + } + + // Delete the project + projectRepository.deleteProject(projectID); + + // Notify via the output boundary if deletion is successful + outputBoundary.projectDeleted(projectID); + } catch (Exception e){ + // Notify via output boundary if the deletion failed + outputBoundary.projectDeletionFailed(e.getMessage()); + } + } +} diff --git a/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/ProjectSelectionInteractor.java b/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/ProjectSelectionInteractor.java index 56f3c37..113febd 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/ProjectSelectionInteractor.java +++ b/src/main/java/b_application_business_rules/use_cases/project_selection_use_cases/ProjectSelectionInteractor.java @@ -1,14 +1,14 @@ package b_application_business_rules.use_cases.project_selection_use_cases; -import b_application_business_rules.boundaries.ProjectSelectionInputBoundary; -import b_application_business_rules.boundaries.ProjectSelectionOutputBoundary; -import b_application_business_rules.entity_models.ColumnModel; +import a_enterprise_business_rules.entities.Project; + import b_application_business_rules.entity_models.ProjectModel; +import b_application_business_rules.entity_models.ColumnModel; import b_application_business_rules.entity_models.TaskModel; + +import b_application_business_rules.boundaries.ProjectSelectionInputBoundary; +import b_application_business_rules.boundaries.ProjectSelectionOutputBoundary; import b_application_business_rules.use_cases.CurrentProjectRepository; -import a_enterprise_business_rules.entities.Project; -import c_interface_adapters.view_models.ColumnViewModel; -import c_interface_adapters.view_models.TaskViewModel; import java.time.LocalDateTime; import java.util.ArrayList; @@ -24,11 +24,13 @@ public class ProjectSelectionInteractor implements ProjectSelectionInputBoundary { // The currentProjectRepository holds the reference to the CurrentProjectRepository instance. - private CurrentProjectRepository currentProjectRepository = CurrentProjectRepository.getInstance(); + private final CurrentProjectRepository currentProjectRepository = CurrentProjectRepository.getInstance(); // The presenter holds the reference to the ProjectSelectionOutputBoundary instance, // which is responsible for displaying the results of the use cases. - private ProjectSelectionOutputBoundary presenter; + private final ProjectSelectionOutputBoundary presenter; + private ProjectModel projectModel; + private String message; /** * Initializes the ProjectSelectionInteractor with the provided presenter. @@ -39,6 +41,11 @@ public ProjectSelectionInteractor(ProjectSelectionOutputBoundary presenter) { this.presenter = presenter; } + @Override + public void setCurrentProject(Project project) { + + } + /** * Sets the current project in the CurrentProjectRepository and notifies the presenter to display it. * This method is called when a project is selected by the user in the UI. @@ -68,6 +75,22 @@ public void createProject(String projectName, String projectDescription) { presenter.displayCurrentProject(projectModel); } + /** + * + */ + @Override + public void createProject() { + + } + + /** + * @param projectModel + */ + @Override + public void createProject(ProjectModel projectModel) { + + } + @Override public void openProject(UUID currentProjectID) { // TODO: Pass the ProjectModel of the Project with the given UUID to the presenter. @@ -108,5 +131,21 @@ public void deleteProject(UUID projectUUID) { "Revised project P1", projectUUID, "", new ArrayList<>()); presenter.displayDeletedProject(projectModel); } + + /** + * @param message + */ + @Override + public void projectDeletionFailed(String message) { + + } + + /** + * @param projectID + */ + @Override + public void projectDeleted(UUID projectID) { + + } } diff --git a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/AddColumn.java b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/AddColumn.java index e69de29..73507f2 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/AddColumn.java +++ b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/AddColumn.java @@ -0,0 +1,50 @@ +package b_application_business_rules.use_cases.project_viewing_and_modification_use_cases; + +import a_enterprise_business_rules.entities.Column; +import a_enterprise_business_rules.entities.Project; +import b_application_business_rules.entity_models.ColumnModel; +import b_application_business_rules.use_cases.CurrentProjectRepository; +import b_application_business_rules.use_cases.project_selection_gateways.IDBInsert; +import d_frameworks_and_drivers.database_management.DBControllers.DBManagerInsertController; + +import java.util.ArrayList; +import java.util.UUID; + +/** + * The AddColumn class is responsible for adding a new column to the currently opened project in the database and the project entity. + */ +public class AddColumn { + + /** + * The Column object representing the new column to be added. + */ + private final Column column; + + /** + * The current project being worked on. Received from Singleton data class. + */ + private final Project currentProject = CurrentProjectRepository.getInstance().getCurrentProject().getProjectEntity(); + + /** + * Constructs an AddColumn object with the specified column name and column ID. + * + * @param columnName The name of the new column. + * @param idOfColumn The ID of the new column. + */ + public AddColumn(String columnName, UUID idOfColumn) { + this.column = new Column(columnName, new ArrayList<>(), idOfColumn); + } + + /** + * Adds the new column to the database and the currently opened project entity. + * This method performs necessary database access and updates the project entity with the new column. + */ + public void addColumn() { + // Update database to add the column. + IDBInsert dbInsertManager = new DBManagerInsertController(); + dbInsertManager.DBInsert(new ColumnModel(this.column)); + + // Add the column to the currently opened Project entity. + currentProject.addColumn(new ColumnModel(column)); + } +} diff --git a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/DeleteColumn.java b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/DeleteColumn.java index e69de29..cdd4142 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/DeleteColumn.java +++ b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/DeleteColumn.java @@ -0,0 +1,57 @@ +package b_application_business_rules.use_cases.project_viewing_and_modification_use_cases; + +import a_enterprise_business_rules.entities.Column; +import a_enterprise_business_rules.entities.Project; +import b_application_business_rules.entity_models.ColumnModel; +import b_application_business_rules.use_cases.CurrentProjectRepository; +import b_application_business_rules.use_cases.project_selection_gateways.IDBRemove; +import d_frameworks_and_drivers.database_management.DBControllers.DBManagerRemoveController; + +import java.util.UUID; + +/** + * The DeleteColumn class is responsible for deleting a column from the currently opened project in both the project entity and the database. + * It allows removing a column with the specified ID from the project and updates the database accordingly. + */ +public class DeleteColumn { + + /** + * The Column object representing the column to be deleted. + */ + private final Column column; + + /** + * The ID of the column to be deleted. + */ + private final UUID idOfColumn; + + /** + * The current project being worked on. Received from Singleton data class. + */ + private final Project currentProject = CurrentProjectRepository.getInstance().getCurrentProject().getProjectEntity(); + + /** + * Constructs a DeleteColumn object with the specified ID of the column to be deleted. + * + * @param idOfColumn The ID of the column to be deleted. + */ + public DeleteColumn(UUID idOfColumn) { + this.idOfColumn = idOfColumn; + this.column = new Column("", null, idOfColumn); + } + + /** + * Deletes the column from the currently opened project in both the project entity and the database. + * This method removes the specified column from the project and updates the database accordingly. + * It delegates the removal of the column from the project entity to the currentProject object, + * and it also calls the necessary database access to update the database and remove the column. + */ + public void deleteColumn() { + // Remove the Column with idOfColumn from the currently opened project currentProject. + currentProject.removeColumn(idOfColumn); + + // Update the database to remove the column. + IDBRemove dbRemoveManager = new DBManagerRemoveController(); + dbRemoveManager.DBRemove(new ColumnModel(column), idOfColumn); + } +} diff --git a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/ProjectViewingAndModificationInteractor.java b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/ProjectViewingAndModificationInteractor.java index 68f5244..deafa28 100644 --- a/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/ProjectViewingAndModificationInteractor.java +++ b/src/main/java/b_application_business_rules/use_cases/project_viewing_and_modification_use_cases/ProjectViewingAndModificationInteractor.java @@ -24,7 +24,7 @@ public class ProjectViewingAndModificationInteractor implements ProjectViewingAn // The presenter holds the reference to the ProjectViewingAndModificationOutputBoundary instance, // which is responsible for displaying the results of the use cases. - private ProjectViewingAndModificationOutputBoundary presenter; + private final ProjectViewingAndModificationOutputBoundary presenter; /** * Initializes the ProjectViewingAndModificationInteractor with the provided presenter. @@ -48,14 +48,21 @@ public void removeCurrentProject() { public void addNewTask(UUID idOfColumn, String taskName, String taskDescription, LocalDateTime dueDate) { } - + /** + * The method to add a column to the project. + * + * @param columnBoxId the UUID of the column to be deleted. + */ @Override public void deleteColumn(UUID columnBoxId) { - // TODO: DO NECESSARY STUFF. - ColumnModel c = new ColumnModel("Test", new ArrayList<>(), columnBoxId); + DeleteColumn deleteColumnUseCase = new DeleteColumn(columnBoxId); + deleteColumnUseCase.deleteColumn(); + + ColumnModel c = new ColumnModel("Deleted column", new ArrayList<>(), columnBoxId); presenter.displayDeletedColumn(c); } + @Override public void renameColumn(UUID columnBoxId) { // TODO: DO NECESSARY STUFF. @@ -117,13 +124,22 @@ public void deleteProject(ProjectModel project, UUID projectId) { } /** + * The method to add a column to the project. * + * @param columnName the name of the column to be created. */ @Override public void addColumn(String columnName) { - // TODO: DO NECESSARY STUFF. - ColumnModel c = new ColumnModel(columnName, new ArrayList<>(), UUID.randomUUID()); - presenter.displayNewColumn(c); + // Genereate random UUID for column + UUID idOfColumn = UUID.randomUUID(); + + // initializing use case to add column and initiate adding to the columm + AddColumn addColumnUseCase = new AddColumn(columnName, idOfColumn); + addColumnUseCase.addColumn(); + // Creates the ColumnModel to send data to presenter. + ColumnModel columnModelForPresenter = new ColumnModel(columnName, new ArrayList<>(), idOfColumn); + // Send data to presenter. + presenter.displayNewColumn(columnModelForPresenter); } diff --git a/src/main/java/c_interface_adapters/DBAdapterInterface.java b/src/main/java/c_interface_adapters/DBAdapterInterface.java index 2530f97..340877c 100644 --- a/src/main/java/c_interface_adapters/DBAdapterInterface.java +++ b/src/main/java/c_interface_adapters/DBAdapterInterface.java @@ -10,6 +10,6 @@ */ public interface DBAdapterInterface { -public List IDstoProjectModelList(); +List IDstoProjectModelList(); } diff --git a/src/main/java/c_interface_adapters/ProjectSelectionController.java b/src/main/java/c_interface_adapters/ProjectSelectionController.java index d979688..0de232d 100644 --- a/src/main/java/c_interface_adapters/ProjectSelectionController.java +++ b/src/main/java/c_interface_adapters/ProjectSelectionController.java @@ -13,16 +13,17 @@ import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.geometry.Insets; +import javafx.geometry.Pos; import javafx.scene.control.*; -import javafx.scene.layout.GridPane; +import javafx.scene.layout.*; import java.net.URL; import java.time.LocalDateTime; import java.util.*; -import javafx.scene.layout.ColumnConstraints; -import javafx.scene.layout.HBox; -import javafx.scene.layout.Priority; +import javafx.scene.text.Font; +import javafx.scene.text.FontWeight; +import javafx.scene.text.Text; import javafx.stage.Stage; import javafx.util.Pair; @@ -68,11 +69,19 @@ public void initialize(URL url, ResourceBundle resourceBundle) { new ColumnViewModel("COLUMN 2", new ArrayList<>(), UUID.randomUUID()) ); ProjectViewModel p1 = new ProjectViewModel( - "Project P1", UUID.randomUUID(),"P1 description", ColumnsList + "Project 111111", UUID.randomUUID(),"P1 description", ColumnsList ); + ProjectViewModel p2 = new ProjectViewModel( + "Project 111111", UUID.randomUUID(),"P2 description", ColumnsList + ); + + ProjectViewModel p3 = new ProjectViewModel( + "Project 111111", UUID.randomUUID(),"P2 description", ColumnsList + ); - List projectsInSystem = Arrays.asList(p1); + + List projectsInSystem = Arrays.asList(p1, p2, p3); projectSelectionViewModel = new ProjectSelectionViewModel(projectsInSystem); // TODO: END ------------------------------------------------------------ // Populate the project selection UI with the projects @@ -102,24 +111,58 @@ private void setPresenter() { * such as renaming or deleting the project. */ private void populateProjectSelectionUI() { - projectsGrid.setHgap(10); - projectsGrid.setVgap(10); + projectsGrid.setHgap(20); + projectsGrid.setVgap(100); - for (int col = 0; col < 4; col++) { + for (int col = 0; col < 2; col++) { ColumnConstraints columnConstraints = new ColumnConstraints(); columnConstraints.setHgrow(Priority.ALWAYS); columnConstraints.setFillWidth(true); - - projectsGrid.getColumnConstraints().add(columnConstraints); } int row = 0; int col = 0; + + RowConstraints rowConstraints = new RowConstraints(); + rowConstraints.setVgrow(Priority.ALWAYS); + rowConstraints.setFillHeight(true); + projectsGrid.getRowConstraints().add(rowConstraints); + while (projectSelectionViewModel.hasNext()) { ProjectViewModel project = projectSelectionViewModel.next(); // Create the currentProjectButton - Button currentProjectButton = new Button(project.getName()); + + Label projectName = new Label(project.getName()); + Label projectDescription = new Label(project.getDescription()); + + projectName.setId("projectName"); + + + projectName.setFont(Font.font("Arial", FontWeight.BOLD, 15)); + + VBox nameAndDescriptionContainer = new VBox(projectName, projectDescription); + + nameAndDescriptionContainer.setAlignment(Pos.CENTER); + nameAndDescriptionContainer.setPadding(new Insets(10)); + nameAndDescriptionContainer.setSpacing(5); + + projectName.setMaxWidth(150); + projectDescription.setMaxWidth(150); + projectName.setWrapText(true); + projectDescription.setWrapText(true); + + // Center the text in each label + projectName.setAlignment(Pos.CENTER); + projectDescription.setAlignment(Pos.CENTER); + + Button currentProjectButton = new Button(); + + currentProjectButton.setGraphic(nameAndDescriptionContainer); + + currentProjectButton.getStyleClass().add("current-project-button"); + + currentProjectButton.setUserData(project.getID()); currentProjectButton.setOnAction(this::handleChosenProjectButton); currentProjectButton.setWrapText(true); // Allow the button to wrap its text and show the whole content @@ -127,10 +170,12 @@ private void populateProjectSelectionUI() { currentProjectButton.setMaxWidth(Double.MAX_VALUE); // Allow the button to take up available space // Create the MenuButton - MenuButton menuButton = new MenuButton("Menu"); + MenuButton menuButton = new MenuButton(); MenuItem renameProjectMenuItem = new MenuItem("Rename Project"); MenuItem deleteProjectMenuItem = new MenuItem("Delete Project"); + menuButton.getStyleClass().add("menu-button-custom"); + // Add event handlers for the MenuItems renameProjectMenuItem.setOnAction(event -> handleRenameProject(project.getID())); deleteProjectMenuItem.setOnAction(event -> handleDeleteProject(project.getID())); @@ -138,8 +183,6 @@ private void populateProjectSelectionUI() { // Add MenuItems to the MenuButton menuButton.getItems().addAll(renameProjectMenuItem, deleteProjectMenuItem); - // Add some spacing between the buttons using padding - HBox.setMargin(menuButton, new Insets(0, 0, 0, 5)); // Add currentProjectButton and menuButton to a container (HBox) for better layout control HBox buttonContainer = new HBox(currentProjectButton, menuButton); @@ -147,11 +190,12 @@ private void populateProjectSelectionUI() { projectsGrid.add(buttonContainer, col, row); col++; - if (col >= 4) { + if (col >= 2) { col = 0; row++; } } + addCreateProjectButton(col, row); } @@ -185,6 +229,9 @@ private void handleDeleteProject(UUID projectUUID) { private void addCreateProjectButton(int col, int row) { Button createProjectButton = new Button("+"); createProjectButton.setOnAction(this::handleCreateProjectPopup); + + createProjectButton.getStyleClass().add("create-project-button-style"); + projectsGrid.add(createProjectButton, col, row); } diff --git a/src/main/java/c_interface_adapters/ProjectSelectionPresenter.java b/src/main/java/c_interface_adapters/ProjectSelectionPresenter.java index 79757ea..d830e2f 100644 --- a/src/main/java/c_interface_adapters/ProjectSelectionPresenter.java +++ b/src/main/java/c_interface_adapters/ProjectSelectionPresenter.java @@ -10,8 +10,10 @@ import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; import javafx.stage.Stage; import java.io.IOException; @@ -60,6 +62,45 @@ public void start(Stage stage) throws Exception { initializeScene(stage); } + @Override + public void displayCurrentProject() { + + } + + @Override + public void projectCreated(ProjectModel projectModel) { + + } + + @Override + public void projectCreationFailed(String errorMessage) { + + } + + /** + * + */ +// @Override +// public void displayCurrentProject() { +// +// } +// +// /** +// * @param projectModel +// */ +// @Override +// public void projectCreated(ProjectModel projectModel) { +// +// } +// +// /** +// * @param errorMessage +// */ +// @Override +// public void projectCreationFailed(String errorMessage) { +// +// } + /** * Displays the current project by loading and setting the scene with the appropriate FXML file. * The FXML file contains the layout and UI elements for viewing and modifying the project details. @@ -72,7 +113,9 @@ public void displayCurrentProject(ProjectModel projectModel) { ProjectViewingAndModificationController openedProjectController = fxmlLoader.getController(); openedProjectController.setup(projectModel); stage.setTitle("scene 2"); - stage.setScene(new Scene(root)); + Scene scene = new Scene(root); + scene.getStylesheets().add(getClass().getResource("ProjectViewingAndModificationStyle.css").toExternalForm()); + stage.setScene(scene); } catch (IOException e) { throw new RuntimeException(e); } @@ -95,23 +138,28 @@ public void displayRenamedProject(ProjectModel projectModel) { if (scene != null) { // Find the GridPane that holds the projects (projectsGrid) for (Node node : scene.getRoot().getChildrenUnmodifiable()) { - if (node instanceof GridPane) { - GridPane projectsGrid = (GridPane) node; + if (node instanceof GridPane projectsGrid) { // Iterate over the children of the projectsGrid (HBoxes representing projects) for (Node gridChild : projectsGrid.getChildren()) { - if (gridChild instanceof HBox) { - HBox hbox = (HBox) gridChild; + if (gridChild instanceof HBox hbox) { // Check if the HBox ID matches the UUID of the renamed project Object hboxId = hbox.getId(); // Assuming you set the projectUUID as hboxId of the HBox if (hboxId != null && hboxId.equals(projectUUID)) { // The HBox matches the provided projectUUID // Now, find the projectNameButton inside the HBox for (Node hboxChild : hbox.getChildren()) { - if (hboxChild instanceof Button) { - Button projectNameButton = (Button) hboxChild; + if (hboxChild instanceof Button nameAndDescriptionButton) { + VBox nameAndDescriptionContainer = + (VBox) (nameAndDescriptionButton.getGraphic()); - // Update the projectNameButton with the new project name - projectNameButton.setText(newProjectName); + for (Node nodeInNameAndDescriptionContainer: + nameAndDescriptionContainer.getChildren()) { + if (nodeInNameAndDescriptionContainer.getId().equals("projectName")) { + Label projectName = (Label) nodeInNameAndDescriptionContainer; + projectName.setText(newProjectName); + break; + } + } break; } } @@ -142,21 +190,52 @@ public void displayDeletedProject(ProjectModel projectModel) { if (scene != null) { // Find the GridPane that holds the projects (projectsGrid) for (Node node : scene.getRoot().getChildrenUnmodifiable()) { - if (node instanceof GridPane) { - GridPane projectsGrid = (GridPane) node; + if (node instanceof GridPane projectsGrid) { + int numColumns = 2; // Specify the number of columns + int numRows = projectsGrid.getRowCount(); // Get the number of rows currently in the grid + // Iterate over the children of the projectsGrid (HBoxes representing projects) Iterator iterator = projectsGrid.getChildren().iterator(); while (iterator.hasNext()) { Node gridChild = iterator.next(); - if (gridChild instanceof HBox) { - HBox hbox = (HBox) gridChild; + if (gridChild instanceof HBox hbox) { // Check if the HBox ID matches the UUID of the project to be deleted Object hboxId = hbox.getId(); // Assuming you set the projectUUID as hboxId of the HBox if (hboxId != null && hboxId.equals(projectUUID)) { iterator.remove(); // Use the iterator to safely remove the HBox from the projectsGrid + break; } } } + + // Rearrange the remaining nodes to fill the empty spaces + int col = 0; + int row = 0; + for (Node child : projectsGrid.getChildren()) { + GridPane.setColumnIndex(child, col); + GridPane.setRowIndex(child, row); + + col++; + if (col >= numColumns) { + col = 0; + row++; + } + } + + // Fill the empty spaces with new HBoxes if needed + while (row < numRows) { + HBox placeholderHBox = new HBox(); + GridPane.setColumnIndex(placeholderHBox, col); + GridPane.setRowIndex(placeholderHBox, row); + projectsGrid.getChildren().add(placeholderHBox); + + col++; + if (col >= numColumns) { + col = 0; + row++; + } + } + break; } } @@ -164,6 +243,7 @@ public void displayDeletedProject(ProjectModel projectModel) { } + /** * Initializes the scene with the provided stage by loading the FXML file containing the layout * and UI elements for choosing a project. @@ -179,6 +259,7 @@ public void initializeScene(Stage stage) { Stage stage1 = stage; stage1.setTitle("Choose project"); stage1.setScene(scene); + scene.getStylesheets().add(getClass().getResource("ProjectSelectionStyle.css").toExternalForm()); stage1.show(); } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/main/java/c_interface_adapters/ProjectViewingAndModificationController.java b/src/main/java/c_interface_adapters/ProjectViewingAndModificationController.java index 8d89870..4a63e3d 100644 --- a/src/main/java/c_interface_adapters/ProjectViewingAndModificationController.java +++ b/src/main/java/c_interface_adapters/ProjectViewingAndModificationController.java @@ -10,6 +10,7 @@ import c_interface_adapters.view_models.TaskViewModel; import javafx.event.ActionEvent; import javafx.fxml.FXML; +import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.HBox; @@ -33,6 +34,12 @@ public class ProjectViewingAndModificationController { Label projectName; @FXML HBox columnsContainer; + @FXML + Label projectDescription; + @FXML + Button backButton; + @FXML + Button addColumnButton; ProjectViewingAndModificationInputBoundary interactor; ProjectViewingAndModificationPresenter presenter; @@ -49,9 +56,17 @@ public ProjectViewingAndModificationController() { public void setup(ProjectModel projectModel) { + setButtonStyles(); + populateProjectDetails(projectModel); List columnsInProject = projectModel.getColumnModels(); presenter.populateColumns(columnsInProject, this); + + } + + private void setButtonStyles() { + backButton.getStyleClass().add("back-button-custom"); + addColumnButton.getStyleClass().add("add-column-button-custom"); } void deleteColumn(UUID id) { @@ -138,7 +153,9 @@ void handleAddTaskToColumn(VBox columnBox, String taskName, String taskDescripti */ private void populateProjectDetails(ProjectModel project) { + projectName.setText(project.getName()); + projectDescription.setText(project.getDescription()); } /** @@ -149,7 +166,7 @@ private void populateProjectDetails(ProjectModel project) { private void clickBackButton() { interactor.removeCurrentProject(); Stage stage = (Stage) columnsContainer.getScene().getWindow(); - ((ProjectViewingAndModificationPresenter) presenter).setStage(stage); + presenter.setStage(stage); presenter.displayAllProjects(); } @@ -173,9 +190,40 @@ void setPresenter() { } @FXML private void handleAddColumnClick() { - presenter.displayAddColumnPopup(); - String tempColumnName = "New Column"; - interactor.addColumn(tempColumnName); + String columnName = presenter.displayAddColumnPopup(); + interactor.addColumn(columnName); } - +// public void moveTask(TaskModel task, VBox targetColumn) { +// // Get the current column containing the task +// VBox sourceColumn = findColumnContainingTask(task); +// +// // If the task is already in the target column, do nothing +// if (sourceColumn == targetColumn) { +// return; +// } +// +// // Remove the task from the source column +// sourceColumn.getChildren().removeIf(node -> node instanceof HBox && ((HBox) node).getUserData() == task); +// +// // Add the task to the target column +// targetColumn.getChildren().add(createCard(task)); +// +// // Perform any other necessary actions based on your requirements +// } +// +// private Node createCard(TaskModel task) { +// +// } +// +// private VBox findColumnContainingTask(TaskModel task) { +// List columns = columnsContainer.getChildren(); +// for (VBox column : columns) { +// for (Node node : column.getChildren()) { +// if (node instanceof HBox && ((HBox) node).getUserData() == task) { +// return column; +// } +// } +// } +// return null; // Task not found in any column +// } } \ No newline at end of file diff --git a/src/main/java/c_interface_adapters/ProjectViewingAndModificationPresenter.java b/src/main/java/c_interface_adapters/ProjectViewingAndModificationPresenter.java index 380c72c..74c5e23 100644 --- a/src/main/java/c_interface_adapters/ProjectViewingAndModificationPresenter.java +++ b/src/main/java/c_interface_adapters/ProjectViewingAndModificationPresenter.java @@ -2,28 +2,36 @@ import b_application_business_rules.boundaries.ProjectViewingAndModificationOutputBoundary; import b_application_business_rules.entity_models.ColumnModel; +import b_application_business_rules.entity_models.ProjectModel; import b_application_business_rules.entity_models.TaskModel; import a_enterprise_business_rules.entities.Task; import c_interface_adapters.view_models.ProjectViewModel; import c_interface_adapters.view_models.TaskViewModel; +import javafx.animation.TranslateTransition; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.geometry.Insets; +import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.*; -import javafx.scene.layout.GridPane; -import javafx.scene.layout.HBox; -import javafx.scene.layout.Priority; -import javafx.scene.layout.VBox; +import javafx.scene.layout.*; +import javafx.scene.text.Font; +import javafx.scene.text.FontWeight; +import javafx.scene.image.WritableImage; +import javafx.scene.input.*; +import javafx.scene.layout.*; +import javafx.scene.text.Text; import javafx.stage.Modality; import javafx.stage.Stage; +import javafx.scene.control.Label; +import javafx.scene.paint.Color; +import javafx.scene.shape.Rectangle; +import javafx.util.Duration; import java.io.IOException; -import java.util.Iterator; -import java.util.List; -import java.util.UUID; +import java.util.*; /** * The ProjectViewingAndModificationPresenter class is responsible for managing the presentation @@ -35,6 +43,10 @@ public class ProjectViewingAndModificationPresenter extends Application implemen private Stage stage; private ProjectViewingAndModificationController controller; + private final List VBoxContainer = new ArrayList(); + + private VBox dragDestination; + /** * Initializes the JavaFX application and sets up the initial scene to display the current * project details and associated tasks. @@ -50,7 +62,7 @@ public void start(Stage stage) throws IOException { stage.setTitle("Current project"); stage.setScene(scene); stage.show(); - }; + } public ProjectViewingAndModificationPresenter(ProjectViewingAndModificationController controller) { this.controller = controller; @@ -88,9 +100,11 @@ public void displayAllProjects() { try { Parent root = FXMLLoader.load(getClass().getResource("ProjectSelection.fxml")); stage.setTitle("scene 1"); - stage.setScene(new Scene(root)); - } catch (IOException e) { - throw new RuntimeException(e); + Scene scene = new Scene(root); + scene.getStylesheets().add(getClass().getResource("ProjectSelectionStyle.css").toExternalForm()); + stage.setScene(scene); + } catch (Exception e) { + e.printStackTrace(); } } @@ -99,6 +113,27 @@ public void displayNewTask(UUID columnBoxID, TaskViewModel newTask) { } +// public void dispayProjectDescription(ProjectModel project) { +// Stage popupStage = new Stage(); +// String projectDescription = project.getDescription(); // Provide the project's description here +// // Create the label to display the project description +// Label descriptionLabel = new Label(projectDescription); +// descriptionLabel.setWrapText(true); // Enable text wrapping for long descriptions +// +// // Create a StackPane to hold the label +// StackPane root = new StackPane(descriptionLabel); +// +// // Set the size for the new window +// Scene scene = new Scene(root, 400, 300); +// +// // Set the stage properties +// popupStage.setTitle("Project Description"); +// popupStage.setScene(scene); +// +// // Show the new window +// popupStage.show(); +// } + @Override public void displayRenamedTask(UUID taskID, TaskViewModel task) { @@ -120,8 +155,7 @@ public void displayRenamedColumn(ColumnModel column) { for (Node node : scene.getRoot().getChildrenUnmodifiable()) { if (node.getId().equals("scrollPaneContainer")) { - if (node instanceof ScrollPane){ - ScrollPane scrollPane = (ScrollPane) node; + if (node instanceof ScrollPane scrollPane){ HBox columnsContainer = (HBox) scrollPane.getContent(); Iterator iterator = columnsContainer.getChildren().iterator(); @@ -134,7 +168,7 @@ public void displayRenamedColumn(ColumnModel column) { if (item.getId().equals("columnHeader")) { Label columnNameUI = (Label) (((HBox) item).getChildren().get(0)); columnNameUI.setText(columnName); - }; + } break; } @@ -159,8 +193,7 @@ public void displayDeletedColumn(ColumnModel columnModel) { for (Node node : scene.getRoot().getChildrenUnmodifiable()) { if (node.getId().equals("scrollPaneContainer")) { - if (node instanceof ScrollPane){ - ScrollPane scrollPane = (ScrollPane) node; + if (node instanceof ScrollPane scrollPane){ HBox columnsContainer = (HBox) scrollPane.getContent(); Iterator iterator = columnsContainer.getChildren().iterator(); @@ -262,19 +295,36 @@ public void displayNewColumn(ColumnModel column) { VBox columnBox = new VBox(); columnBox.setPrefSize(180, 380); + columnBox.setStyle("-fx-background-color: #F6F8FA"); + + // Set styling of the header. HBox columnNameAndOptions = new HBox(); + HBox.setHgrow(columnNameAndOptions, Priority.ALWAYS); + + columnNameAndOptions.setSpacing(40); + columnNameAndOptions.setAlignment(Pos.BASELINE_RIGHT); + + VBox.setMargin(columnNameAndOptions, new Insets(10)); + VBox.setVgrow(columnNameAndOptions, Priority.ALWAYS); + columnBox.setId(column.getID().toString()); // Add label for the name of the column Label columnLabel = new Label(column.getName()); columnLabel.setId("columnTitle"); + columnLabel.setFont(Font.font("Arial", FontWeight.BOLD, 15)); // Add menu button and menu items. MenuButton columnOptions = new MenuButton(""); MenuItem renameColumnButton = new MenuItem("Rename Column"); MenuItem deleteColumnButton = new MenuItem("Delete Column"); + Button addTaskButton = new Button("Add Task"); + addTaskButton.setOnAction(event -> controller.presenter.handleAddTaskPopup(columnBox, + controller)); + HBox TaskBtnVBox = new HBox(addTaskButton); + // Add event handler on menu item. renameColumnButton.setOnAction(event -> { controller.renameColumm(column.getID());}); @@ -286,10 +336,15 @@ public void displayNewColumn(ColumnModel column) { // Set the size constraints for columnNameAndOptions HBox.setHgrow(columnLabel, Priority.ALWAYS); // Make the label expand horizontally HBox.setHgrow(columnOptions, Priority.NEVER); // Make the button keep its preferred width + HBox.setHgrow(TaskBtnVBox, Priority.NEVER); // Make the button keep its preferred width - columnNameAndOptions.getChildren().addAll(columnLabel, columnOptions); + columnNameAndOptions.getChildren().addAll(columnLabel, columnOptions, TaskBtnVBox); + columnNameAndOptions.setSpacing(5); columnNameAndOptions.setId("columnHeader"); + // set styling of menu button + columnOptions.getStyleClass().add("menu-button-custom"); + // Set the size constraints for columnBox VBox.setVgrow(columnNameAndOptions, Priority.NEVER); // Make columnNameAndOptions keep its preferred height @@ -299,15 +354,21 @@ public void displayNewColumn(ColumnModel column) { controller.presenter.populateTasksForEachColumn(columnBox, column.getTaskModels(), controller); - Button addTaskButton = new Button("Add Task"); - addTaskButton.setOnAction(event -> controller.presenter.handleAddTaskPopup(columnBox, - controller)); - - columnBox.getChildren().add(addTaskButton); + //columnBox.getChildren().add(TaskBtnVBox); + //VBox.setVgrow(TaskBtnVBox, Priority.NEVER); +// TaskBtnVBox.setAlignment(Pos.BOTTOM_RIGHT); + columnBox.setSpacing(10); scrollPane.setContent(columnBox); // Add the column UI to the container of all columns (HBox) controller.columnsContainer.getChildren().add(scrollPane); + this.VBoxContainer.add(columnBox); + + columnBox.setOnDragOver(event -> { + //System.out.println("INSIDE DESTINATION"); + this.dragDestination = columnBox; + event.consume(); + }); } /** @@ -320,14 +381,28 @@ public void displayNewColumn(ColumnModel column) { * @param projectViewingAndModificationController */ void populateTasksForEachColumn(VBox columnBox, List tasks, ProjectViewingAndModificationController projectViewingAndModificationController) { - // Iterate through the list of tasks and create an HBox for each task - for (TaskModel task : tasks) { - HBox hbox = new HBox(); + // Create a set to store the unique IDs of the HBox nodes added to the columnBox + Set addedHBoxIds = new HashSet<>(); - Label taskName = new Label(task.getName()); -// Button taskOptionsButton = new Button("..."); - // Create menu button and its options. + // Iterate through the list of tasks and create an HBox for each task + for (TaskModel task : tasks) { + // Create the card content + + Rectangle cardBackground = new Rectangle(columnBox.getWidth(), 50, Color.LIGHTBLUE); + Text textContent = new Text(task.getName()); + cardBackground.setArcHeight(10.0d); + cardBackground.setArcWidth(10.0d); + StackPane cardContent = new StackPane(cardBackground, textContent); + + // Create the card (HBox) to hold the content + HBox hbox = new HBox(cardContent); + hbox.setStyle("-fx-border-radius: 10.0d;" + + "-fx-border-color: black;" + + "-fx-border-width: 2px;"); // Add a border for better visibility + hbox.setBackground(new Background(new BackgroundFill(Color.LIGHTGRAY, new CornerRadii(10.0d), Insets.EMPTY))); + + //Create menu button and its options. MenuButton taskOptionsButton = new MenuButton(""); MenuItem renameTaskButton = new MenuItem("Rename Task"); MenuItem changeTaskDetailsButton = new MenuItem("Change Task " + @@ -343,28 +418,125 @@ void populateTasksForEachColumn(VBox columnBox, List tasks, ProjectVi //projectViewingAndModificationController.changeTaskDetails( //task, hbox); }); + deleteTaskButton.setOnAction(event -> { projectViewingAndModificationController.deleteTask(task, hbox);}); // Add to MenuButton taskOptionsButton.getItems().addAll(renameTaskButton, changeTaskDetailsButton, deleteTaskButton); + taskOptionsButton.getStyleClass().add("menu-button-custom"); + taskOptionsButton.setStyle("-fx-font-size: 8px;"); - // Associate an instance of a Task for each button. - taskOptionsButton.setUserData(task); + RadioButton completeTaskButton = new RadioButton(); +// completeTaskButton.setOnAction(event -> controller.completeTask(task)); taskOptionsButton.setOnAction(actionEvent -> { projectViewingAndModificationController.handleTaskOptions(actionEvent, task, columnBox); }); - hbox.getChildren().addAll(taskName, taskOptionsButton); - columnBox.getChildren().add(hbox); + hbox.getChildren().addAll(textContent, taskOptionsButton, completeTaskButton); + SetHBoxFeatures(columnBox, hbox); + + hbox.setSpacing(5); // Set spacing between text and menuButton + hbox.setPadding(new Insets(2)); // Add some padding for better appearance + columnBox.setSpacing(10); + if (!addedHBoxIds.contains(hbox.getId())) { + // Add the HBox to the columnBox if it doesn't exist + columnBox.getChildren().add(hbox); + addedHBoxIds.add(hbox.getId()); // Add the HBox ID to the set + } } } + private void SetHBoxFeatures(VBox columnBox, HBox hbox) { + // Set the unique identifier for the HBox + hbox.setId(UUID.randomUUID().toString()); + + // Set mouse event handlers for dragging the card + hbox.setOnDragDetected(event -> { + Dragboard dragboard = hbox.startDragAndDrop(TransferMode.MOVE); + + ClipboardContent content = new ClipboardContent(); + content.putString(hbox.getId()); // Use the unique identifier for the HBox as the data to be transferred + dragboard.setContent(content); + WritableImage snapshot = hbox.snapshot(null, null); + dragboard.setDragView(snapshot); + + event.consume(); + }); + + hbox.setOnDragOver(event -> { + //System.out.println("INSIDE 1"); + if (event.getGestureSource() == hbox && event.getDragboard().hasString()) { + //System.out.println("INSIDE 1.5"); + event.acceptTransferModes(TransferMode.MOVE); + } + + event.consume(); + }); + + hbox.setOnDragDone(event -> { + //System.out.println("INSIDE 2"); + + Dragboard dragboard = event.getDragboard(); + boolean success = false; + + if (dragboard.hasString()) { + // Find the source HBox based on the unique identifier + HBox sourceHBox = findHBoxById(dragboard.getString()); + + // Move the HBox to the new column + if (sourceHBox != null) { + //System.out.println("INSIDE SUCCESS"); + // Find the destination VBox (the column box that the HBox is dragged into) + + //System.out.println(hbox.getParent().equals(sourceHBox.getParent())); + //VBox destinationColumnBox = (VBox) hbox.getParent(); + + // Remove the HBox from its current column box and add it to the destination column box + //VBox destinationColumnBox = findTargetDestinationVBox(event); + + if (this.dragDestination != null) { + // Remove the HBox from its current column box and add it to the destination column box + ((VBox) sourceHBox.getParent()).getChildren().remove(sourceHBox); + TranslateTransition transition = new TranslateTransition(Duration.millis(100), sourceHBox); + transition.setToX(this.dragDestination.getLayoutX() - hbox.getLayoutX()); + transition.play(); + + transition.setOnFinished(event1 -> { + this.dragDestination.getChildren().add(sourceHBox); + }); + success = true; + } else { + System.out.println("Destination VBox not found!"); + } + } + } + + event.setDropCompleted(success); + event.consume(); + }); + + // Set the style when the cursor enters the HBox + hbox.setOnMouseEntered(e -> { + hbox.setStyle("-fx-border-color: rgba(69,89,164,.5); -fx-border-width: 3px; -fx-border-radius: 10.0d;"); + hbox.setBackground(new Background(new BackgroundFill(Color.rgb(64, 65, 79, 1), new CornerRadii(10.0d), Insets.EMPTY))); + }); + + // Set the style when the cursor exits the HBox + hbox.setOnMouseExited(e -> { + hbox.setStyle("-fx-border-radius: 10.0d;" + + "-fx-border-color: black;" + + "-fx-border-width: 2px;"); + hbox.setBackground(new Background(new BackgroundFill(Color.LIGHTGRAY, new CornerRadii(10.0d), Insets.EMPTY))); + }); + } + + /** * Handles displaying a popup window when the "Add Task" button is clicked. The popup allows the * user to enter task details such as name, description, and due date, and then add the task to @@ -533,4 +705,29 @@ public String displayAddColumnPopup() { // Return the user input (column name) return nameTextField.getText(); } +// public static HBox createKanbanCard(HBox originalCard, TaskModel taskModel) { +// // Create the card content +// Rectangle cardBackground = new Rectangle(100, 50, Color.LIGHTBLUE); +// Text textContent = new Text(taskModel.getName()); +// StackPane cardContent = new StackPane(cardBackground, textContent); +// cardBackground.setArcHeight(10.0d); +// cardBackground.setArcWidth(10.0d); +// +// // Create the card (HBox) to hold the content +// HBox card = new HBox(cardContent); +// card.getStyleClass().add("kanban-card"); +// +// return card; +// } + + private HBox findHBoxById(String id) { + for (VBox vBox : this.VBoxContainer) { + for (Node node2 : vBox.getChildren() ) { + if (node2 instanceof HBox && node2.getId().equals(id)) { + return (HBox) node2; + } + } + } + return null; + } } \ No newline at end of file diff --git a/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/EntityIDsToListController.java b/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/EntityIDsToListController.java index b1d7515..831b696 100644 --- a/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/EntityIDsToListController.java +++ b/src/main/java/d_frameworks_and_drivers/database_management/DBControllers/EntityIDsToListController.java @@ -19,7 +19,7 @@ public String EntityIDsToList(ProjectModel projectModel) { String columnModelListString = ""; for ( ColumnModel col: columnModelList ) { - columnModelListString.join(", ", col.getID().toString()); + String.join(", ", col.getID().toString()); } return columnModelListString; } @@ -35,7 +35,7 @@ public String EntityIDsToList(ColumnModel columnModel) { String taskModelListString = ""; for ( TaskModel task: taskModelList ) { - taskModelListString.join(", ", task.getID().toString()); + String.join(", ", task.getID().toString()); } return taskModelListString; } diff --git a/src/main/resources/c_interface_adapters/ProjectSelection.fxml b/src/main/resources/c_interface_adapters/ProjectSelection.fxml index cf93944..f7752f1 100644 --- a/src/main/resources/c_interface_adapters/ProjectSelection.fxml +++ b/src/main/resources/c_interface_adapters/ProjectSelection.fxml @@ -9,12 +9,12 @@ -