/*
 * Copyright (c) 2010 Henrik Gustafsson <henrik.gustafsson@fnord.se>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
package se.fnord.rt.ui;

import org.eclipse.jface.wizard.IWizard;
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.ITaskComment;
import org.eclipse.mylyn.tasks.core.ITaskMapping;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi;
import org.eclipse.mylyn.tasks.ui.wizards.ITaskRepositoryPage;
import org.eclipse.mylyn.tasks.ui.wizards.RepositoryQueryWizard;

import se.fnord.rt.core.RequestTrackerRepositoryConnector;

public class RequestTrackerRepositoryConnectorUI extends AbstractRepositoryConnectorUi {

    public RequestTrackerRepositoryConnectorUI() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public String getConnectorKind() {
        return RequestTrackerRepositoryConnector.REPOSITORY_CONNECTOR_KIND;
    }

    @Override
    public boolean hasSearchPage() {
        return true;
    }

    @Override
    public ITaskRepositoryPage getSettingsPage(TaskRepository taskRepository) {
        return new RequestTrackerTaskRepositoryPage(taskRepository);
    }

    @Override
    public IWizard getQueryWizard(TaskRepository repository, IRepositoryQuery queryToEdit) {
        RepositoryQueryWizard wizard = new RepositoryQueryWizard(repository);
        wizard.addPage(new RTQueryPage(repository, queryToEdit));
        return wizard;
    }

    @Override
    public IWizard getNewTaskWizard(TaskRepository taskRepository, ITaskMapping selection) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getTaskKindLabel(ITask task) {
        return "Issue";
    }
    
    @Override
    public String getReplyText(TaskRepository taskRepository, ITask task, ITaskComment taskComment, boolean includeTask) {
        return taskComment.getAuthor().getName() + " wrote:";
    }
    
}

@@ -864,16 +864,71 @@
 Wizard;%0A
+import org.eclipse.mylyn.tasks.core.IRepositoryPerson;%0A
 import o
@@ -2709,59 +2709,333 @@
     
-return taskComment.getAuthor().getName() + %22 wrote:
+final IRepositoryPerson author = taskComment.getAuthor();%0A        if (author != null) %7B%0A            if (author.getName() != null)%0A                return author.getName() + %22 wrote%22;%0A            if (author.getPersonId() != null)%0A                return author.getPersonId() + %22 wrote%22;%0A        %7D%0A        return %22Commenter wrote
 %22;%0A 

Fix NPE in getReplyText()