@Override
  public void setUp() throws Exception {
    taskList = TasksUiPlugin.getTaskList();

    TaskTestUtil.resetTaskListAndRepositories();
    TasksUiPlugin.getDefault().getLocalTaskRepository();

    cat1 = new TaskCategory("First Category");
    taskList.addCategory(cat1);

    cat1task1 = TasksUiInternal.createNewLocalTask("task 1");
    cat1task1.setPriority(PriorityLevel.P1.toString());
    cat1task1.setCompletionDate(new Date());
    taskList.addTask(cat1task1, cat1);

    cat1task2 = TasksUiInternal.createNewLocalTask("task 2");
    cat1task2.setPriority(PriorityLevel.P2.toString());
    taskList.addTask(cat1task2, cat1);

    assertEquals(cat1.getChildren().size(), 2);

    activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    assertTrue(activePage.closeAllEditors(false));
    assertEquals(0, activePage.getEditorReferences().length);
  }
 @SuppressWarnings("restriction")
 private static boolean hasQueryWithTitle(TaskRepository repository, String title) {
   Set<org.eclipse.mylyn.internal.tasks.core.RepositoryQuery> queries =
       org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin.getTaskList()
           .getRepositoryQueries(repository.getRepositoryUrl());
   for (IRepositoryQuery query : queries) {
     if (query.getSummary().equals(title)) {
       return true;
     }
   }
   return false;
 }
  @Override
  public void run() {
    if (selectedTask == null) {
      return;
    }

    if (selectedTask instanceof LocalTask) {
      // XXX code copied from NewLocalTaskWizard.performFinish() and
      // TaskListManager.createNewLocalTask()
      TaskList taskList = TasksUiPlugin.getTaskList();
      LocalTask newTask =
          new LocalTask(
              "" + taskList.getNextLocalTaskId(), // $NON-NLS-1$
              LocalRepositoryConnector.DEFAULT_SUMMARY);
      newTask.setPriority(PriorityLevel.P3.toString());
      TasksUiInternal.scheduleNewTask(newTask);
      taskList.addTask(newTask, selectedTask);
      TasksUiUtil.openTask(newTask);
      return;
    }

    AbstractRepositoryConnector connector =
        TasksUi.getRepositoryManager().getRepositoryConnector(selectedTask.getConnectorKind());
    IWizard wizard = getNewSubTaskWizard();
    if (wizard != null) {
      WizardDialog dialog = new WizardDialog(WorkbenchUtil.getShell(), wizard);
      dialog.setBlockOnOpen(true);
      dialog.open();
      return;
    }
    TaskData taskData = createTaskData(connector);
    if (taskData != null) {
      try {
        TasksUiInternal.createAndOpenNewTask(taskData);
      } catch (CoreException e) {
        StatusHandler.log(
            new Status(
                IStatus.ERROR,
                TasksUiPlugin.ID_PLUGIN,
                "Failed to open new sub task",
                e)); //$NON-NLS-1$
        TasksUiInternal.displayStatus(
            Messages.NewSubTaskAction_Unable_to_create_subtask,
            new Status(
                IStatus.ERROR,
                TasksUiPlugin.ID_PLUGIN,
                Messages.NewSubTaskAction_Failed_to_create_new_sub_task_ + e.getMessage()));
      }
    }
  }
 @Override
 public Object[] getChildren(Object parent) {
   Set<ITask> children = new HashSet<ITask>();
   if (parent instanceof Person) {
     for (ITaskContainer container : applyFilter(TasksUiPlugin.getTaskList().getRootElements())) {
       for (ITask task : getAllTasks(container.getChildren())) {
         if (task.getOwner() != null
             && task.getOwner().equals(((Person) parent).getHandleIdentifier())
             && TasksUiInternal.shouldShowIncoming(task)) {
           children.add(task);
         }
       }
     }
   }
   return children.toArray();
 }
 @Override
 public Object[] getElements(Object parent) {
   people.clear();
   if (parent instanceof Person) {
     return getChildren(parent);
   } else {
     for (ITaskContainer container : applyFilter(TasksUiPlugin.getTaskList().getRootElements())) {
       for (ITask task : getAllTasks(container.getChildren())) {
         if (task.getOwner() != null && TasksUiInternal.shouldShowIncoming(task)) {
           people.add(
               new Person(task.getOwner(), task.getConnectorKind(), task.getRepositoryUrl()));
         }
       }
     }
   }
   return people.toArray();
 }