Ejemplo n.º 1
0
  @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);
  }
Ejemplo n.º 2
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()));
      }
    }
  }
 @Override
 public void run() {
   IStructuredSelection selection = getStructuredSelection();
   for (Iterator<?> iter = selection.iterator(); iter.hasNext(); ) {
     final TaskRepository repository = getTaskRepository(iter.next());
     if (repository != null) {
       TaskJob job = TasksUiInternal.updateRepositoryConfiguration(repository);
       // show the progress in the system task bar if this is a user job (i.e. forced)
       job.setProperty(WorkbenchUtil.SHOW_IN_TASKBAR_ICON_PROPERTY, Boolean.TRUE);
     }
   }
 }
Ejemplo n.º 4
0
 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);
 }
  public synchronized void backupNow(boolean synchronous, IProgressMonitor monitor) {

    monitor = Policy.monitorFor(monitor);

    File backupFolder = new File(backupFolderPath);
    if (!backupFolder.exists()) {
      backupFolder.mkdir();
    }

    final TaskDataExportOperation backupJob =
        new TaskDataSnapshotOperation(backupFolderPath, getBackupFileName());
    try {
      if (!synchronous) {
        backupJob.run(monitor);
        removeOldBackups();
      } else {
        IProgressService service = PlatformUI.getWorkbench().getProgressService();
        service.run(false, true, backupJob);
      }
    } catch (InterruptedException e) {
    } catch (Throwable e) {
      if (!errorDisplayed) {
        final Status status =
            new Status(
                IStatus.ERROR,
                TasksUiPlugin.ID_PLUGIN,
                Messages.TaskListBackupManager_Error_occured_during_scheduled_tasklist_backup,
                e);
        errorDisplayed = true;
        if (Display.getCurrent() != null) {
          TasksUiInternal.logAndDisplayStatus(
              Messages.TaskListBackupManager_Scheduled_task_data_backup, status);
        } else {
          PlatformUI.getWorkbench()
              .getDisplay()
              .asyncExec(
                  new Runnable() {
                    public void run() {
                      TasksUiInternal.logAndDisplayStatus(
                          Messages.TaskListBackupManager_Scheduled_task_data_backup, status);
                    }
                  });
        }
      }

      // clean up corrupt backup file
      if (backupJob.getDestinationFile() != null) {
        backupJob.getDestinationFile().delete();
      }
    }
  }
 @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();
 }
Ejemplo n.º 8
0
  public String createEnhanceSearchTask() throws Exception {
    final TaskMapping taskMappingInit =
        new TaskMapping() {

          @Override
          public String getProduct() {
            return "TestProduct";
          }
        };
    final TaskMapping taskMappingSelect =
        new TaskMapping() {
          @Override
          public String getComponent() {
            return "TestComponent";
          }

          @Override
          public String getSummary() {
            return "test EnhanceSearch";
          }

          @Override
          public String getDescription() {
            return "The Description of the Bug 335278";
          }
        };
    final TaskData[] taskDataNew = new TaskData[1];

    // create Task
    taskDataNew[0] =
        TasksUiInternal.createTaskData(repository(), taskMappingInit, taskMappingSelect, null);
    ITask taskNew =
        TasksUiUtil.createOutgoingNewTask(
            taskDataNew[0].getConnectorKind(), taskDataNew[0].getRepositoryUrl());

    ITaskDataWorkingCopy workingCopy =
        TasksUi.getTaskDataManager().createWorkingCopy(taskNew, taskDataNew[0]);
    Set<TaskAttribute> changed = new HashSet<TaskAttribute>();
    workingCopy.save(changed, null);
    RepositoryResponse response =
        BugzillaFixture.current().submitTask(taskDataNew[0], priviledgedClient());
    ((AbstractTask) taskNew).setSubmitting(true);
    assertNotNull(response);
    assertEquals(ResponseKind.TASK_CREATED.toString(), response.getReposonseKind().toString());
    return response.getTaskId();
  }
Ejemplo n.º 9
0
 protected void doPublish(PatchSetPublishDetail publishDetail) {
   TaskAttribute comment = getTaskData().getRoot().getAttribute(TaskAttribute.COMMENT_NEW);
   String editorCommentText = comment != null ? comment.getValue() : "";
   PublishDialog dialog =
       new PublishDialog(getShell(), getTask(), publishDetail, addedDrafts, editorCommentText);
   openOperationDialog(dialog);
   if (dialog.getReturnCode() == Window.OK && comment != null) {
     comment.clearValues();
     getTaskEditorPage().doSave(new NullProgressMonitor());
     try {
       TasksUi.getTaskDataManager().discardEdits(getTask());
     } catch (CoreException e) {
       Status status =
           new Status(
               IStatus.ERROR, GerritUiPlugin.PLUGIN_ID, "Error while clearing task status.", e);
       TasksUiInternal.displayStatus("Clear outgoing task status failed", status);
     }
   }
 }
Ejemplo n.º 10
0
  @Override
  public void showBusy(boolean busy) {
    if (editorBusyIndicator != null) {
      if (busy) {
        if (TasksUiInternal.isAnimationsEnabled()) {
          editorBusyIndicator.start();
        }
      } else {
        editorBusyIndicator.stop();
      }
    }

    if (!isHeaderFormDisposed()) {
      Form form = getHeaderForm().getForm().getForm();
      if (form != null && !form.isDisposed()) {
        // TODO consider only disabling certain actions
        IToolBarManager toolBarManager = form.getToolBarManager();
        if (toolBarManager instanceof ToolBarManager) {
          ToolBar control = ((ToolBarManager) toolBarManager).getControl();
          if (control != null) {
            control.setEnabled(!busy);
          }
        }

        if (leftToolBar != null) {
          leftToolBar.setEnabled(!busy);
        }
        if (titleLabel != null) {
          titleLabel.setEnabled(!busy);
        }

        CommonUiUtil.setEnabled(form.getBody(), !busy);
        for (IFormPage page : getPages()) {
          if (page instanceof WorkbenchPart) {
            WorkbenchPart part = (WorkbenchPart) page;
            part.showBusy(busy);
          }
        }
      }
    }
  }
Ejemplo n.º 11
0
    @Override
    @SuppressWarnings("restriction")
    public void mouseDoubleClick(MouseEvent event) {
      Object element = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
      if (element instanceof LogicalTask) {
        LogicalTask logicalTask = (LogicalTask) element;
        ViewerCell cell = viewer.getCell(new Point(event.x, event.y));

        int columnIndex = cell.getColumnIndex();
        if (columnIndex != 0) {
          Version[] versions = taskModel.getVersions();
          Version version = versions[columnIndex - 1];

          for (VersionTask versionTask : logicalTask.getVersionTasks()) {
            if (versionTask.getVersion().equals(version)) {
              ITask task = versionTask.getTask();
              org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal
                  .refreshAndOpenTaskListElement(task);
            }
          }
        }
      }
    }
  /**
   * Creates the button layout. This displays options and buttons at the bottom of the editor to
   * allow actions to be performed on the bug.
   */
  @Override
  protected void createActionsLayout(Composite formComposite) {
    Section section =
        getManagedForm().getToolkit().createSection(formComposite, ExpandableComposite.TITLE_BAR);

    section.setText(getSectionLabel(SECTION_NAME.ACTIONS_SECTION));
    section.setExpanded(true);
    section.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, true).applyTo(section);

    Composite buttonComposite = getManagedForm().getToolkit().createComposite(section);
    buttonComposite.setLayout(new GridLayout(4, false));
    buttonComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    section.setClient(buttonComposite);

    addToCategory =
        getManagedForm().getToolkit().createButton(buttonComposite, "Add to Category", SWT.CHECK);
    categoryChooser = new CCombo(buttonComposite, SWT.FLAT | SWT.READ_ONLY);
    categoryChooser.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    categoryChooser.setLayoutData(GridDataFactory.swtDefaults().hint(150, SWT.DEFAULT).create());
    getManagedForm().getToolkit().adapt(categoryChooser, true, true);
    categoryChooser.setFont(TEXT_FONT);
    ITaskList taskList = TasksUiInternal.getTaskList();
    List<AbstractTaskCategory> categories =
        new ArrayList<AbstractTaskCategory>(taskList.getCategories());
    Collections.sort(
        categories,
        new Comparator<AbstractTaskContainer>() {

          public int compare(AbstractTaskContainer c1, AbstractTaskContainer c2) {
            if (c1.equals(TasksUiPlugin.getTaskList().getDefaultCategory())) {
              return -1;
            } else if (c2.equals(TasksUiPlugin.getTaskList().getDefaultCategory())) {
              return 1;
            } else {
              return c1.getSummary().compareToIgnoreCase(c2.getSummary());
            }
          }
        });

    for (IRepositoryElement category : categories) {
      categoryChooser.add(category.getSummary());
    }

    categoryChooser.select(0);
    categoryChooser.setEnabled(false);
    categoryChooser.setData(categories);
    addToCategory.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {
            categoryChooser.setEnabled(addToCategory.getSelection());
          }
        });

    GridDataFactory.fillDefaults()
        .hint(DEFAULT_FIELD_WIDTH, SWT.DEFAULT)
        .span(3, SWT.DEFAULT)
        .applyTo(categoryChooser);

    addActionButtons(buttonComposite);

    getManagedForm().getToolkit().paintBordersFor(buttonComposite);
  }
Ejemplo n.º 13
0
  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;
  }