示例#1
0
  /**
   * Show a project
   *
   * @param function the action being taken
   * @param p the project
   * @param parentId the parent project id
   * @throws Exception
   */
  private void showProject(Action function, Project p, Integer parentId) throws Exception {

    // set the link panel to show this project's links
    linkPanel.setOwner(p);

    // show all possible parent projects
    parentProjectComboBox.removeAllItems();
    parentProjectComboBox.addItem("");
    Collection<Project> projects = TaskModel.getReference().getProjects();
    if (projects != null) {
      for (Project project : projects) {
        // add open projects that are not the current one
        if ((p == null || p.getKey() != project.getKey())
            && project.getStatus().equals(Resource.getResourceString("OPEN")))
          parentProjectComboBox.addItem(getProjectString(project));
      }
    }

    // if we are showing an existing project - fill in the gui fields for it
    if (p != null) {
      // task number
      projectIdText.setText(Integer.toString(p.getKey()));
      projectIdText.setEditable(false);

      // window title - "Item N"
      windowTitle = Resource.getResourceString("Item_") + " " + p.getKey();

      // due date
      GregorianCalendar gc = new GregorianCalendar();
      Date dd = p.getDueDate();
      if (dd != null) {
        gc.setTime(dd);
        dueDateChooser.setCalendar(gc);
      }

      GregorianCalendar gc2 = new GregorianCalendar();
      dd = p.getStartDate();
      if (dd != null) gc2.setTime(dd);
      startDateChooser.setCalendar(gc2);

      int daysleft = DateUtil.daysLeft(p.getDueDate());
      daysLeftText.setText(Integer.toString(daysleft));

      String cat = p.getCategory();
      if (cat != null && !cat.equals("")) {
        categoryBox.setSelectedItem(cat);
      } else {
        categoryBox.setSelectedIndex(0);
      }

      description.setText(p.getDescription());

      statusComboBox.setEditable(false);

      Collection<Task> ptasks = TaskModel.getReference().getTasks(p.getKey());
      totalTaskCount.setText(Integer.toString(ptasks.size()));

      int openTasks = 0;
      for (Task pt : ptasks) {
        if (!TaskModel.isClosed(pt)) {
          openTasks++;
        }
      }
      openTaskCount.setText(Integer.toString(openTasks));

      // set parent project
      Integer pid = p.getParent();
      if (pid != null) {
        Project par = TaskModel.getReference().getProject(pid.intValue());
        if (TaskModel.isClosed(par)) {
          // if parent closed - would not have been added before
          parentProjectComboBox.addItem(getProjectString(par));
        }
        parentProjectComboBox.setSelectedItem(getProjectString(par));
      }

      // add the task list
      if (taskPanel == null) {
        taskPanel = new TaskListPanel(TaskView.getProjectString(p));
        taskPanel.addClosedTaskFilter();
        taskBorder.add(
            taskPanel, GridBagConstraintsFactory.create(0, 0, GridBagConstraints.BOTH, 1.0, 1.0));
      }

    } else {
      // set fields for a new project

      projectIdText.setText("NEW");
      projectIdText.setEditable(false);

      // title
      windowTitle = Resource.getResourceString("NEW_Item");
      statusComboBox.addItem(Resource.getResourceString("OPEN"));
      statusComboBox.setEnabled(false);
      categoryBox.setSelectedIndex(0);
      description.setText(""); // desc
      totalTaskCount.setText("");
      openTaskCount.setText("");

      // parent id may have been passed in
      if (parentId != null) {
        Project par = TaskModel.getReference().getProject(parentId.intValue());
        if (TaskModel.isClosed(par)) {
          parentProjectComboBox.addItem(getProjectString(par));
        }
        parentProjectComboBox.setSelectedItem(getProjectString(par));

        String cat = par.getCategory();
        if (cat != null && !cat.equals("")) {
          categoryBox.setSelectedItem(cat);
        } else {
          categoryBox.setSelectedIndex(0);
        }

        GregorianCalendar gc = new GregorianCalendar();
        Date dd = par.getDueDate();
        if (dd != null) {
          gc.setTime(dd);
          dueDateChooser.setCalendar(gc);
        }

        Date sd = par.getStartDate();
        if (sd != null) {
          gc.setTime(sd);
          startDateChooser.setCalendar(gc);
        }
      }
    }

    // can't change status on a new project
    if (p == null) {
      statusComboBox.setEnabled(false);
    }

    // cloning takes the fields filled in for an existing task and resets
    // only those
    // that don't apply to the clone
    if (function == Action.CLONE) {
      // need new task number
      projectIdText.setText("CLONE");
      projectIdText.setEditable(false);

      statusComboBox.removeAllItems();
      statusComboBox.addItem(Resource.getResourceString("OPEN"));
      statusComboBox.setEnabled(false);

    }
    // change existing task
    else if (function == Action.CHANGE) {

      String state = null;
      if (p != null) state = p.getStatus();

      // set next state pulldown - projects only move between open and
      // closed
      statusComboBox.removeAllItems();
      statusComboBox.addItem(Resource.getResourceString("OPEN"));
      statusComboBox.addItem(Resource.getResourceString("CLOSED"));
      statusComboBox.setSelectedItem(state);
      statusComboBox.setEnabled(true);
    }
  }
示例#2
0
  /** Save project. */
  private void saveProject() {

    // validate that description is present
    if (description.getText() == null || description.getText().equals("")) {
      Errmsg.getErrorHandler().notice(Resource.getResourceString("empty_desc"));
      return;
    }
    try {

      String num = projectIdText.getText();

      Project p = new Project();

      if (!num.equals("NEW") && !num.equals("CLONE")) {
        p.setKey(Integer.parseInt(num));
      }

      // fill in the fields from the screen
      Calendar cal = startDateChooser.getCalendar();
      if (cal == null) cal = new GregorianCalendar();
      p.setStartDate(cal.getTime()); // start date

      cal = dueDateChooser.getCalendar();
      if (cal != null) {
        p.setDueDate(cal.getTime()); // due date

        // validate due date
        if (DateUtil.isAfter(p.getStartDate(), p.getDueDate())) {
          throw new Warning(Resource.getResourceString("sd_dd_warn"));
        }
      }

      p.setDescription(description.getText());
      p.setStatus((String) statusComboBox.getSelectedItem());

      String cat = (String) categoryBox.getSelectedItem();
      if (cat.equals("") || cat.equals(CategoryModel.UNCATEGORIZED)) {
        p.setCategory(null);
      } else {
        p.setCategory(cat);
      }

      p.setParent(null);
      String proj = (String) parentProjectComboBox.getSelectedItem();
      try {
        p.setParent(getProjectId(proj));

      } catch (Exception e) {
        // no project selected
      }

      TaskModel.getReference().saveProject(p);
      p.setKey(p.getKey());

      showProject(Action.CHANGE, p, null);
    } catch (Warning w) {
      Errmsg.getErrorHandler().notice(w.getMessage());
    } catch (Exception e) {
      Errmsg.getErrorHandler().errmsg(e);
    }
  }