@Deprecated
  public void promptToAddQuery(TaskRepository taskRepository) {
    IPreferenceStore preferenceStore = TasksUiPlugin.getDefault().getPreferenceStore();
    if (!preferenceStore.getBoolean(PREF_ADD_QUERY)) {
      Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
      MessageDialogWithToggle messageDialog =
          MessageDialogWithToggle.openYesNoQuestion(
              shell,
              Messages.AddRepositoryAction_Add_new_query,
              Messages.AddRepositoryAction_Add_a_query_to_the_Task_List,
              Messages.AddRepositoryAction_Do_not_show_again,
              false,
              preferenceStore,
              PREF_ADD_QUERY);
      preferenceStore.setValue(PREF_ADD_QUERY, messageDialog.getToggleState());
      if (messageDialog.getReturnCode() == IDialogConstants.YES_ID) {
        AbstractRepositoryConnectorUi connectorUi =
            TasksUiPlugin.getConnectorUi(taskRepository.getConnectorKind());
        IWizard queryWizard = connectorUi.getQueryWizard(taskRepository, null);
        if (queryWizard instanceof Wizard) {
          ((Wizard) queryWizard).setForcePreviousAndNextButtons(true);
        }

        WizardDialog queryDialog = new WizardDialog(shell, queryWizard);
        queryDialog.create();
        queryDialog.setBlockOnOpen(true);
        queryDialog.open();
      }
    }
  }
  @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);
  }
  @Override
  @SuppressWarnings("restriction")
  protected IStatus run(IProgressMonitor monitor) {
    try {
      Gist gist = new Gist().setPublic(isPublic);
      gist.setDescription(title);
      GistFile file = new GistFile().setContent(content);
      gist.setFiles(Collections.singletonMap(title, file));
      final Gist created = service.createGist(gist);
      final Display display = PlatformUI.getWorkbench().getDisplay();
      display.asyncExec(
          new Runnable() {

            public void run() {
              GistNotificationPopup popup =
                  new GistNotificationPopup(display, created, title, repository);
              popup.create();
              popup.open();
            }
          });
      TasksUiPlugin.getTaskJobFactory()
          .createSynchronizeRepositoriesJob(GistConnectorUi.getRepositories())
          .schedule();
    } catch (IOException e) {
      GitHubUi.logError(GitHubException.wrap(e));
    }
    return Status.OK_STATUS;
  }
 public ITask getTask(String taskId) throws Exception {
   TaskRepository repository = repository();
   TaskData taskData = fixture.connector().getTaskData(repository, taskId, null);
   ITask task = TasksUi.getRepositoryModel().createTask(repository, taskData.getTaskId());
   TasksUiPlugin.getTaskDataManager().putUpdatedTaskData(task, taskData, true);
   return task;
 }
  @Override
  public void selectionChanged(IAction action, ISelection selection) {
    super.selectionChanged(action, selection);

    task = null;

    if (selection instanceof IStructuredSelection) {

      IStructuredSelection ss = (IStructuredSelection) selection;

      if (!ss.isEmpty()) {

        Iterator<?> iter = ss.iterator();
        while (iter.hasNext()) {
          Object sel = iter.next();
          if (sel instanceof IJiraTask) {
            task = ((IJiraTask) sel).getTask();
            try {
              taskData = TasksUiPlugin.getTaskDataManager().getTaskData(task);
            } catch (CoreException e) {
              handleError(
                  Messages.JiraConnectorUiActions_Cannot_get_task_data + task.getTaskKey(), e);
            }

            break;
          }
        }
      }
    }

    update(action);
  }
  private void updateHeaderLabel() {
    TaskRepository outgoingNewRepository = TasksUiUtil.getOutgoingNewTaskRepository(task);
    final TaskRepository taskRepository =
        (outgoingNewRepository != null)
            ? outgoingNewRepository
            : taskEditorInput.getTaskRepository();

    //		if (taskRepository.getConnectorKind().equals(LocalRepositoryConnector.CONNECTOR_KIND)) {
    //			getHeaderForm().getForm().setText(Messages.TaskEditor_Task_ + task.getSummary());
    //		} else {
    AbstractRepositoryConnectorUi connectorUi =
        TasksUiPlugin.getConnectorUi(taskRepository.getConnectorKind());
    String kindLabel = Messages.TaskEditor_Task;
    if (connectorUi != null) {
      kindLabel = connectorUi.getTaskKindLabel(task);
    }

    String idLabel = task.getTaskKey();
    if (idLabel != null) {
      kindLabel += " " + idLabel; // $NON-NLS-1$
    }

    if (hasLeftToolBar() && titleLabel != null) {
      titleLabel.setText(kindLabel);
      getHeaderForm().getForm().setText(null);
      setHeaderImage(null);
    } else {
      getHeaderForm().getForm().setText(kindLabel);
    }
  }
  /**
   * Returns a commit comment specific to <code>task</code> and <code>resources</code>. If <code>
   * resources</code> is null or the associated projects do not specify a custom commit comment
   * template the global template is used.
   *
   * <p>This method must be invoked on the UI thread.
   *
   * @param checkTaskRepository if true, a warning dialog is displayed in case <code>task</code> is
   *     associated with a different repository than any of the <code>resources</code>
   * @param task the task to generate the commit comment for
   * @param resources that are being committed or null
   * @return a commit comment or an empty string if the user opted to abort generating the commit
   *     message
   * @since 3.5
   */
  public static String getComment(boolean checkTaskRepository, ITask task, IResource[] resources) {
    // lookup project specific template
    String template = null;
    Set<IProject> projects = new HashSet<IProject>();
    if (resources != null) {
      for (IResource resource : resources) {
        IProject project = resource.getProject();
        if (project != null && project.isAccessible() && !projects.contains(project)) {
          TeamPropertiesLinkProvider provider = new TeamPropertiesLinkProvider();
          template = provider.getCommitCommentTemplate(project);
          if (template != null) {
            break;
          }
          projects.add(project);
        }
      }
    }

    boolean proceed = true;

    // prompt if resources do not match task
    if (checkTaskRepository) {
      boolean unmatchedRepositoryFound = false;
      for (IProject project : projects) {
        TaskRepository repository = TasksUiPlugin.getDefault().getRepositoryForResource(project);
        if (repository != null) {
          if (!repository.getRepositoryUrl().equals(task.getRepositoryUrl())) {
            unmatchedRepositoryFound = true;
          }
        }
      }

      if (unmatchedRepositoryFound) {
        if (Display.getCurrent() != null) {
          proceed =
              MessageDialog.openQuestion(
                  WorkbenchUtil.getShell(),
                  Messages.ContextChangeSet_Mylyn_Change_Set_Management,
                  Messages.ContextChangeSet_ATTEMPTING_TO_COMMIT_RESOURCE);
        } else {
          proceed = false;
        }
      }
    }

    if (proceed) {
      if (template == null) {
        template =
            FocusedTeamUiPlugin.getDefault()
                .getPreferenceStore()
                .getString(FocusedTeamUiPlugin.COMMIT_TEMPLATE);
      }
      return FocusedTeamUiPlugin.getDefault()
          .getCommitTemplateManager()
          .generateComment(task, template);
    } else {
      return ""; //$NON-NLS-1$
    }
  }
 public ShowNonMatchingSubtasksAction() {
   setText(Messages.ShowNonMatchingSubtasksAction_Show_Non_Matching_Subtasks);
   setToolTipText(Messages.ShowNonMatchingSubtasksAction_Show_Non_Matching_Subtasks);
   setChecked(
       !TasksUiPlugin.getDefault()
           .getPreferenceStore()
           .getBoolean(ITasksUiPreferenceConstants.FILTER_NON_MATCHING));
 }
 public AddRepositoryAction() {
   setImageDescriptor(TasksUiImages.REPOSITORY_NEW);
   setText(TITLE);
   setId(ID);
   boolean enabled = TasksUiPlugin.getRepositoryManager().hasUserManagedRepositoryConnectors();
   if (!enabled) {
     // bug 279054 enable the action if connector discovery is present/enabled
     Command command = TasksUiInternal.getConfiguredDiscoveryWizardCommand();
     enabled = command != null && command.isEnabled();
   }
   setEnabled(enabled);
 }
 @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;
 }
  public void testScheduledTaskSorting() {
    final TaskListInterestSorter sorter = new TaskListInterestSorter();
    MockTask task1 = new MockTask("local", "MYLN:1", "1");
    MockTask task2 = new MockTask("local", "MYLN:2", "2");

    Calendar start1 = TaskActivityUtil.getCalendar();
    start1.add(Calendar.WEEK_OF_YEAR, -1);
    TaskActivityUtil.snapStartOfWorkWeek(start1);
    Calendar end1 = TaskActivityUtil.getCalendar();
    end1.setTimeInMillis(start1.getTimeInMillis());
    TaskActivityUtil.snapEndOfWeek(end1);
    WeekDateRange range1 = new WeekDateRange(start1, end1);
    TasksUiPlugin.getTaskActivityManager().setScheduledFor(task1, range1);

    Calendar start2 = TaskActivityUtil.getCalendar();
    start2.add(Calendar.HOUR_OF_DAY, -1);
    Calendar end2 = TaskActivityUtil.getCalendar();
    DateRange range2 = new DateRange(start2, end2);
    TasksUiPlugin.getTaskActivityManager().setScheduledFor(task2, range2);

    assertTrue(sorter.compare(new EmptyViewer(), task1, task2) < 0);
  }
  @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()));
      }
    }
  }
Exemple #13
0
  private Image getBrandingImage() {
    String connectorKind;
    TaskRepository outgoingNewRepository = TasksUiUtil.getOutgoingNewTaskRepository(task);
    if (outgoingNewRepository != null) {
      connectorKind = outgoingNewRepository.getConnectorKind();
    } else {
      connectorKind = task.getConnectorKind();
    }

    if (LocalRepositoryConnector.CONNECTOR_KIND.equals(connectorKind)) {
      return CommonImages.getImage(TasksUiImages.TASK);
    } else {
      ImageDescriptor overlay;
      if (outgoingNewRepository != null) {
        overlay =
            TasksUiPlugin.getDefault().getBrandManager().getOverlayIcon(outgoingNewRepository);
      } else {
        overlay = TasksUiPlugin.getDefault().getBrandManager().getOverlayIcon(task);
      }
      Image image =
          CommonImages.getImageWithOverlay(TasksUiImages.REPOSITORY, overlay, false, false);
      return image;
    }
  }
 @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();
 }
Exemple #16
0
 private void updateTitleImage() {
   if (task != null) {
     AbstractRepositoryConnectorUi connectorUi =
         TasksUiPlugin.getConnectorUi(task.getConnectorKind());
     if (connectorUi != null) {
       ImageDescriptor overlayDescriptor = connectorUi.getTaskKindOverlay(task);
       setTitleImage(
           CommonImages.getCompositeTaskImage(TasksUiImages.TASK, overlayDescriptor, false));
     } else {
       setTitleImage(CommonImages.getImage(TasksUiImages.TASK));
     }
     //		} else if (getEditorInput() instanceof AbstractRepositoryTaskEditorInput) {
     //			setTitleImage(CommonImages.getImage(TasksUiImages.TASK_REMOTE));
   } else {
     setTitleImage(CommonImages.getImage(TasksUiImages.TASK));
   }
 }
  protected static boolean hasActivity(ITask task, Date startDate, Date endDate) {
    Calendar startCal = Calendar.getInstance();
    startCal.setTime(startDate);

    Calendar endCal = Calendar.getInstance();
    endCal.setTime(endDate);

    return TasksUiPlugin.getTaskActivityManager().getElapsedTime(task, startCal, endCal) > 0;
    //		IInteractionContext interactionContext = ContextCorePlugin.getContextManager().loadContext(
    //				task.getHandleIdentifier());
    //		if (interactionContext != null) {
    //			List<InteractionEvent> events = interactionContext.getInteractionHistory();
    //			if (events.size() > 0) {
    //				InteractionEvent latestEvent = events.get(events.size() - 1);
    //				if (latestEvent.getDate().compareTo(startDate) > 0) {
    //					return true;
    //				}
    //			}
    //		}
    //		return false;
  }
  private static void synchronizeTask(final ITask task, IProgressMonitor monitor) {

    SynchronizeTasksJob job =
        (SynchronizeTasksJob)
            TasksUiPlugin.getTaskJobFactory()
                .createSynchronizeTasksJob(getConnector(task), asSet(task));

    job.addJobChangeListener(
        new JobChangeAdapter() {
          @Override
          public void done(IJobChangeEvent event) {
            if (task instanceof AbstractTask && ((AbstractTask) task).getStatus() != null) {
              TasksUiInternal.asyncDisplayStatus(
                  org.eclipse.mylyn.internal.tasks.ui.util.Messages
                      .TasksUiInternal_Task_Synchronization_Failed,
                  ((AbstractTask) task).getStatus());
            }
          }
        });

    job.run(monitor);
  }
  @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;
  }
Exemple #20
0
 @Override
 protected FormToolkit createToolkit(Display display) {
   // create a toolkit that shares colors between editors.
   return new FormToolkit(TasksUiPlugin.getDefault().getFormColors(display));
 }
  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;
  }
 public void update() {
   setChecked(
       !TasksUiPlugin.getDefault()
           .getPreferenceStore()
           .getBoolean(ITasksUiPreferenceConstants.FILTER_NON_MATCHING));
 }
 @Override
 public void run() {
   TasksUiPlugin.getDefault()
       .getPreferenceStore()
       .setValue(ITasksUiPreferenceConstants.FILTER_NON_MATCHING, !isChecked());
 }
Exemple #24
0
  @Override
  protected void addPages() {
    initialize();

    // determine factories
    Set<String> conflictingIds = new HashSet<String>();
    ArrayList<AbstractTaskEditorPageFactory> pageFactories =
        new ArrayList<AbstractTaskEditorPageFactory>();
    for (AbstractTaskEditorPageFactory pageFactory :
        TasksUiPlugin.getDefault().getTaskEditorPageFactories()) {
      if (pageFactory.canCreatePageFor(getTaskEditorInput())
          && WorkbenchUtil.allowUseOf(pageFactory)) {
        pageFactories.add(pageFactory);
        String[] ids = pageFactory.getConflictingIds(getTaskEditorInput());
        if (ids != null) {
          conflictingIds.addAll(Arrays.asList(ids));
        }
      }
    }
    for (Iterator<AbstractTaskEditorPageFactory> it = pageFactories.iterator(); it.hasNext(); ) {
      if (conflictingIds.contains(it.next().getId())) {
        it.remove();
      }
    }

    // sort by priority
    Collections.sort(
        pageFactories,
        new Comparator<AbstractTaskEditorPageFactory>() {
          public int compare(AbstractTaskEditorPageFactory o1, AbstractTaskEditorPageFactory o2) {
            return o1.getPriority() - o2.getPriority();
          }
        });

    // create pages
    for (AbstractTaskEditorPageFactory factory : pageFactories) {
      try {
        IFormPage page = factory.createPage(this);
        int index = addPage(page);
        setPageImage(index, factory.getPageImage(this, page));
        setPageText(index, factory.getPageText(this, page));
        if (factory.getPriority() == AbstractTaskEditorPageFactory.PRIORITY_TASK) {
          setActivePage(index);
        }
        if (page instanceof ISelectionProvider) {
          ((ISelectionProvider) page).addSelectionChangedListener(getActionBarContributor());
        }
      } catch (Exception e) {
        StatusHandler.log(
            new Status(
                IStatus.ERROR,
                TasksUiPlugin.ID_PLUGIN,
                "Could not create editor via factory: " + factory,
                e)); //$NON-NLS-1$
      }
    }

    updateTitleImage();
    updateHeaderToolBar();
    installTitleDrag(getHeaderForm().getForm().getForm());

    // do this late to allow pages to replace the selection provider
    getEditorSite().registerContextMenu(menuManager, getEditorSite().getSelectionProvider(), true);
  }