Exemple #1
0
  /**
   * @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;
    }
  }
Exemple #2
0
  /**
   * @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");
      }
    }
  }
Exemple #3
0
  /**
   * @author boconno3, elee3, asaini, rparames
   *     <p>This method exports a model which has been saved in xml format and will load it into the
   *     current system
   */
  private void exportModelXML() {
    String outputFilePath = view.showInputDialog("Where do you want to save this XML file?");
    try {
      model.exportToXmlFile(outputFilePath);
    } catch (Exception e) {

      view.displayError("Export was unsuccessful!");
      return;
    }
    view.writeToProjectTextArea("Export was successful!");
  }
Exemple #4
0
  /**
   * @author boconno3, elee3, asaini, rparames
   *     <p>This method will load a XML file and set it as the current project
   */
  private void loadXML() {

    String pathInputFile =
        view.showInputDialog("Where would you like to load the MATS model from?");
    try {
      setModel(MATSModel.importFromXmlFile(pathInputFile));
      view.setModel(model);
      view.enableImportedSystemMenuOptions();
    } catch (Exception exception) {
      view.displayError("Importing file failed - exception: " + exception);
      return;
    }

    view.appendToProjectTextArea("Imported Project Successfuly");
  }
Exemple #5
0
  /**
   * @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);
    }
  }
Exemple #6
0
  /**
   * @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);
    }
  }
Exemple #7
0
  /**
   * @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");
      }
    }
  }