private String editTask(Task currentTask) {
    if (currentTask == null) return "";

    taskManager.setCurrentTask(currentTask);
    Story currentStory = storyManager.getCurrentStory();
    if (currentStory != currentTask.getStory()) {
      storyManager.setCurrentStory(currentTask.getStory());
    }
    return "/task/edit";
  }
Beispiel #2
0
  public String save() {
    if (currentTask != null) {
      try {
        Task merged =
            doInTransaction(
                new PersistenceAction<Task>() {

                  public Task execute(EntityManager em) {
                    if (currentTask.isNew()) {
                      em.persist(currentTask);
                    } else if (!em.contains(currentTask)) {
                      return em.merge(currentTask);
                    }
                    return currentTask;
                  }
                });
        if (!currentTask.equals(merged)) {
          setCurrentTask(merged);
          int idx = taskList.indexOf(currentTask);
          if (idx != -1) {
            taskList.set(idx, merged);
          }
        }
        storyManager.getCurrentStory().addTask(merged);
        if (!taskList.contains(merged)) {
          taskList.add(merged);
        }
      } catch (Exception e) {
        getLogger(getClass()).log(Level.SEVERE, "Error on try to save Task: " + currentTask, e);
        addMessage("Error on try to save Task", FacesMessage.SEVERITY_ERROR);
        return null;
      }
    }
    return "show";
  }
Beispiel #3
0
  public String remove() {
    final Task task = tasks.getRowData();
    if (task != null) {
      try {
        doInTransaction(
            new PersistenceActionWithoutResult() {

              public void execute(EntityManager em) {
                if (em.contains(task)) {
                  em.remove(task);
                } else {
                  em.remove(em.merge(task));
                }
              }
            });
        storyManager.getCurrentStory().removeTask(task);
        taskList.remove(task);
      } catch (Exception e) {
        getLogger(getClass()).log(Level.SEVERE, "Error on try to remove Task: " + currentTask, e);
        addMessage("Error on try to remove Task", FacesMessage.SEVERITY_ERROR);
        return null;
      }
    }
    return "show";
  }
Beispiel #4
0
 public void init() {
   Task task = new Task();
   Story currentStory = storyManager.getCurrentStory();
   task.setStory(currentStory);
   setCurrentTask(task);
   if (currentStory != null) {
     taskList = new LinkedList<Task>(currentStory.getTasks());
   } else {
     taskList = new ArrayList<Task>();
   }
   tasks = new ListDataModel<Task>(taskList);
 }
Beispiel #5
0
 public String create() {
   Task task = new Task();
   task.setStory(storyManager.getCurrentStory());
   setCurrentTask(task);
   return "create";
 }
Beispiel #6
0
 public void setStory(Story story) {
   storyManager.setCurrentStory(story);
 }
Beispiel #7
0
 public Story getStory() {
   return storyManager.getCurrentStory();
 }
Beispiel #8
0
 public DataModel<Task> getTasks() {
   this.tasks = new ListDataModel(storyManager.getCurrentStory().getTasks());
   return tasks;
 }