TaskData createTaskData(
     ITaskMapping initializationData, ITaskMapping selectionData, IProgressMonitor monitor)
     throws CoreException {
   AbstractTaskDataHandler taskDataHandler = connector().getTaskDataHandler();
   TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository());
   TaskData taskData =
       new TaskData(
           mapper,
           repository().getConnectorKind(),
           repository().getRepositoryUrl(),
           ""); //$NON-NLS-1$
   boolean result =
       taskDataHandler.initializeTaskData(repository(), taskData, initializationData, monitor);
   if (!result) {
     throw new CoreException(
         new Status(
             IStatus.ERROR,
             TasksUiPlugin.ID_PLUGIN,
             "Initialization of task failed. The provided data is insufficient.")); //$NON-NLS-1$
   }
   if (selectionData != null) {
     connector().getTaskMapping(taskData).merge(selectionData);
   }
   return taskData;
 }
  @Override
  protected boolean updateSelection(IStructuredSelection selection) {
    selectedTask = null;
    if (selection.size() == 1) {
      Object selectedObject = selection.getFirstElement();
      if (selectedObject instanceof LocalTask) {
        selectedTask = (AbstractTask) selectedObject;
      } else if (selectedObject instanceof ITask) {
        selectedTask = (AbstractTask) selectedObject;
        AbstractRepositoryConnector connector =
            TasksUi.getRepositoryManager().getRepositoryConnector(selectedTask.getConnectorKind());
        AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();

        TaskRepository repository =
            TasksUiPlugin.getRepositoryManager().getRepository(selectedTask.getRepositoryUrl());
        if (taskDataHandler == null
            || !taskDataHandler.canInitializeSubTaskData(repository, selectedTask)) {
          selectedTask = null;
        }
      }
    }
    return selectedTask != null;
  }
  private TaskData createTaskData(AbstractRepositoryConnector connector) {
    final AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
    if (taskDataHandler == null) {
      return null;
    }

    String repositoryUrl = selectedTask.getRepositoryUrl();
    TaskData parentTaskData = null;
    try {
      parentTaskData = TasksUi.getTaskDataManager().getTaskData(selectedTask);
    } catch (CoreException e) {
      StatusHandler.log(
          new Status(
              IStatus.ERROR,
              TasksUiPlugin.ID_PLUGIN,
              "Could not retrieve task data for task:" + selectedTask.getUrl(),
              e)); //$NON-NLS-1$
    }
    if (parentTaskData == null) {
      TasksUiInternal.displayStatus(
          Messages.NewSubTaskAction_Unable_to_create_subtask,
          new Status(
              IStatus.WARNING,
              TasksUiPlugin.ID_PLUGIN,
              Messages.NewSubTaskAction_Could_not_retrieve_task_data_for_task_
                  + selectedTask.getUrl()));
      return null;
    }

    final TaskRepository taskRepository =
        TasksUiPlugin.getRepositoryManager().getRepository(repositoryUrl);
    if (!taskDataHandler.canInitializeSubTaskData(taskRepository, selectedTask)) {
      return null;
    }

    final TaskData selectedTaskData = parentTaskData;
    final TaskAttributeMapper attributeMapper = taskDataHandler.getAttributeMapper(taskRepository);
    final TaskData taskData =
        new TaskData(
            attributeMapper,
            taskRepository.getConnectorKind(),
            taskRepository.getRepositoryUrl(),
            ""); //$NON-NLS-1$
    final boolean[] result = new boolean[1];
    IProgressService service = PlatformUI.getWorkbench().getProgressService();
    try {
      CommonUiUtil.run(
          service,
          new ICoreRunnable() {
            public void run(IProgressMonitor monitor) throws CoreException {
              result[0] =
                  taskDataHandler.initializeSubTaskData(
                      taskRepository, taskData, selectedTaskData, monitor);
            }
          });
    } catch (CoreException e) {
      TasksUiInternal.displayStatus(
          Messages.NewSubTaskAction_Unable_to_create_subtask, e.getStatus());
      return null;
    } catch (OperationCanceledException e) {
      // canceled
      return null;
    }

    if (result[0]) {
      // open editor
      return taskData;
    } else {
      TasksUiInternal.displayStatus(
          Messages.NewSubTaskAction_Unable_to_create_subtask,
          new Status(
              IStatus.INFO,
              TasksUiPlugin.ID_PLUGIN,
              Messages
                  .NewSubTaskAction_The_connector_does_not_support_creating_subtasks_for_this_task));
    }
    return null;
  }