Ejemplo n.º 1
0
  /**
   * 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$
    }
  }
Ejemplo n.º 2
0
  public void testAddScrollListener() {
    Scrollable textWidget = new Composite(WorkbenchUtil.getShell(), SWT.V_SCROLL);

    assertNotNull(textWidget.getVerticalBar());
    assertEquals(0, textWidget.getListeners(SWT.MouseVerticalWheel).length);

    EditorUtil.addScrollListener(textWidget);
    assertEquals(1, textWidget.getListeners(SWT.MouseVerticalWheel).length);

    // test when there is no vertical bar
    textWidget = new Composite(WorkbenchUtil.getShell(), SWT.NONE);
    assertNull(textWidget.getVerticalBar());

    assertEquals(0, textWidget.getListeners(SWT.MouseVerticalWheel).length);

    EditorUtil.addScrollListener(textWidget);
    assertEquals(1, textWidget.getListeners(SWT.MouseVerticalWheel).length);
  }
Ejemplo n.º 3
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()));
      }
    }
  }
Ejemplo n.º 4
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);
  }
Ejemplo n.º 5
0
 public TaskRepository showWizard() {
   return showWizard(WorkbenchUtil.getShell(), null);
 }