/** * @author boconno3, elee3, asaini, rparames * <p>This method will move a subproject into another subproject or the project collection * given that it is a valid move */ private void moveProject() { TreeNode node = null; String lastSelected = ""; String newProject = ""; if (view.getTree().getLastSelectedPathComponent() instanceof TreeNode) { node = (TreeNode) view.getTree().getLastSelectedPathComponent(); lastSelected = (String) node.getUserObject(); if (model.isSubproject(lastSelected)) { newProject = view.showInputDialog( "What is the name of the subproject you want to add it under? \n\n The subproject must be in the database"); try { if (model.isSubproject(newProject) || (newProject.equalsIgnoreCase("Project Collection"))) { model.moveProject(lastSelected, newProject); } else { view.displayError("The project could not be moved!"); } } catch (Exception e) { return; } } else { view.displayError("The project could not be moved!"); } } try { lastSelected = (String) view.getTree().getLastSelectedPathComponent().toString(); } catch (Exception exception) { return; } }
/** * @author boconno3, elee3, asaini, rparames * <p>This method will add a new project into the project collection if the user has the * project collection selected when they try to create a new subproject */ private void addNewProject() { TreeNode node = null; String lastSelected = ""; if (view.getTree().getLastSelectedPathComponent() instanceof TreeNode) { node = (TreeNode) view.getTree().getLastSelectedPathComponent(); } try { lastSelected = (String) view.getTree().getLastSelectedPathComponent().toString(); } catch (Exception exception) { return; } if (lastSelected.equals("Project Collection")) { String name = view.showInputDialog( "What is the name of the new subproject? (Do not use a component name that already exists)"); if (name == null) { return; } String description = view.showInputDialog("What is the description?"); if (description == null) { return; } model.addNewProject(name, description); } else { if (node != null) { String name = view.showInputDialog( "What is the name of the new subproject? (Do not use a component name that already exists)"); if (name == null) { return; } String parent = (String) node.getUserObject(); if (parent == null) { return; } String description = view.showInputDialog("What is the description?"); if (description == null) { return; } model.addComponent(name, "Subproject", parent, null, null, description); } else { view.displayError("Please select a subproject to add a subproject under"); } } }
/** Required by TreeSelectionListener interface. */ public void valueChanged(TreeSelectionEvent e) { TreeNode node; try { node = (TreeNode) e.getNewLeadSelectionPath().getLastPathComponent(); } catch (Exception exception) { return; } view.displayComponentInfo((String) node.getUserObject()); }
/** * @author boconno3, elee3, asaini, rparames * <p>This method will, if the user has selected a task in the tree that they are a creator * for, allow the user to change the state of the task as long as the destination state is a * viable one */ private void changeTaskState() { TreeNode node = null; if (view.getTree().getLastSelectedPathComponent() instanceof TreeNode) { node = (TreeNode) view.getTree().getLastSelectedPathComponent(); } else { return; } if (node != null) { String state = view.showInputDialog( "What is the new state of the task? \n\n Please input either ONGOING, DELETED, or COMPLETED"); model.changeTaskState((String) node.getUserObject(), state); } }
/** * @author boconno3, elee3, asaini, rparames * <p>This method will, if the user has selected a task in the tree for which they are a * creator, allow them to change the owner of the task as long as the owner exists in the * database */ private void changeTaskOwner() { TreeNode node = null; if (view.getTree().getLastSelectedPathComponent() instanceof TreeNode) { node = (TreeNode) view.getTree().getLastSelectedPathComponent(); } else { return; } if (node != null) { String owner = view.showInputDialog( "Who is the new owner of the task? (User must exist in the current database)"); if (owner == null) { return; } else if (!(model.containsUser(owner))) { view.displayError("That owner is not in the database"); return; } model.changeTaskOwner((String) node.getUserObject(), owner); } }
/** * @author boconno3, elee3, asaini, rparames * <p>This method will, if the user has selected a task in the tree for which they are a * creator, allow the user to change the deadline of the task if the new deadline is a viable * one */ private void changeTaskDeadline() { TreeNode node = null; if (view.getTree().getLastSelectedPathComponent() instanceof TreeNode) { node = (TreeNode) view.getTree().getLastSelectedPathComponent(); } else { return; } if (node != null) { Date date; String deadline = view.showInputDialog( "Please enter the date for the new deadline of the task? (Use the format yyyy/mm/dd) "); try { date = new Date(deadline); } catch (Exception exception) { view.displayError("An invalid date was entered"); return; } model.changeDeadline((String) node.getUserObject(), date); } }
/** * @author boconno3, elee3, asaini, rparames * <p>This method will ask the user for all of the characteristics of a task that they want to * add and will then, depending on where in the tree they have selected, insert the task in * the correct place if it is a valid move */ private void addNewTask() { TreeNode node = null; String lastSelected = ""; if (view.getTree().getLastSelectedPathComponent() instanceof TreeNode) { node = (TreeNode) view.getTree().getLastSelectedPathComponent(); } else { try { lastSelected = (String) view.getTree().getLastSelectedPathComponent().toString(); } catch (Exception exception) { return; } } if (lastSelected.equals("Project Collection")) { view.displayError("You cannot add a task here!"); } else { if (node != null) { Date date; String name = view.showInputDialog( "What is the name of the new task? (Do not use a component name that already exists)"); if (name == null) { return; } String parent = (String) node.getUserObject(); if (parent == null) { return; } String owner = view.showInputDialog( "Who is the owner of the task? (Please enter a user that exists in the current database)"); if (owner == null) { return; } else if (!(model.containsUser(owner))) { view.displayError("That owner is not in the database"); return; } String deadline = view.showInputDialog( "Please enter the date for the deadline of the task? (Use the format yyyy/mm/dd "); try { date = new Date(deadline); } catch (Exception exception) { view.displayError("An invalid date was entered"); return; } if (deadline == null) { return; } String description = view.showInputDialog("Please enter the description for the task: "); if (description == null) { return; } if (parent.equalsIgnoreCase("Project Collection")) { view.displayError("You cannot add a task here!"); } else { model.addComponent(name, "Task", parent, owner, date, description); } } else { view.displayError("Please select a subproject to add a task under"); } } }