mylyn-suite/depends-on-bugzilla/src/org/apidesign/netbinox/test/mylyn/TestBugzilla.java
author Jaroslav Tulach <jtulach@netbeans.org>
Wed Oct 21 09:44:59 2009 +0200
changeset 16 0867d5dd57ab
parent 15 998ca7288106
child 17 07ed910f2471
permissions -rw-r--r--
Shortening the longest line
     1 /*
     2  *  Copyright (C) 2009 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     3  *
     4  *  This program is free software; you can redistribute it and/or
     5  *  modify it under the terms of the GNU General Public License
     6  *  as published by the Free Software Foundation; version 2
     7  *  of the License.
     8  *
     9  *  This program is distributed in the hope that it will be useful,
    10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  *  GNU General Public License for more details.
    13  *
    14  *  You should have received a copy of the GNU General Public License
    15  *  along with this program; if not, write to the Free Software
    16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    17  */
    18 
    19 package org.apidesign.netbinox.test.mylyn;
    20 
    21 import java.awt.event.ActionEvent;
    22 import java.awt.event.ActionListener;
    23 import java.util.ArrayList;
    24 import java.util.List;
    25 import javax.swing.JOptionPane;
    26 import org.eclipse.core.runtime.NullProgressMonitor;
    27 import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute;
    28 import org.eclipse.mylyn.internal.bugzilla.core.BugzillaRepositoryConnector;
    29 import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery;
    30 import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
    31 import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
    32 import org.eclipse.mylyn.tasks.core.TaskRepository;
    33 import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
    34 import org.eclipse.mylyn.tasks.core.data.TaskData;
    35 import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;
    36 
    37 public final class TestBugzilla implements ActionListener {
    38     
    39     public void actionPerformed(ActionEvent event) {
    40         String url = "http://issues.apache.org/bugzilla";
    41         // BEGIN: netbinox.mylyn.bugzilla
    42         TaskRepository repository = new TaskRepository("bugzilla", url);
    43 
    44         TaskRepositoryManager trm = new TaskRepositoryManager();
    45         BugzillaRepositoryConnector brc = new BugzillaRepositoryConnector();
    46 
    47         trm.addRepository(repository);
    48         trm.addRepositoryConnector(brc);
    49 
    50         String url = "/buglist.cgi?" +
    51                     "query_format=advanced" +
    52                     "&short_desc_type=allwordssubstr" +
    53                     "&limit=5";
    54         IRepositoryQuery query = new RepositoryQuery(
    55             repository.getConnectorKind(), ""
    56         );
    57         query.setUrl(url);
    58         final List<TaskData> collectedData = new ArrayList<TaskData>();
    59         TaskDataCollector collector = new TaskDataCollector() {
    60             public void accept(TaskData taskData) {
    61                 collectedData.add(taskData);
    62             }
    63         };
    64         NullProgressMonitor nullProgressMonitor = new NullProgressMonitor();
    65         brc.performQuery(
    66             repository, query, collector, null, nullProgressMonitor
    67         );
    68         // END: netbinox.mylyn.bugzilla
    69 
    70         StringBuffer sb = new StringBuffer();
    71         int i = 0;
    72         sb.append("Info: listed 5 issues from ");
    73         sb.append(repository.getUrl());
    74         sb.append("\n\n");
    75         for (TaskData td : collectedData) {
    76             sb.append(td.getTaskId());
    77             sb.append(" - ");
    78             sb.append(getSummary(td));
    79             sb.append("\n");
    80             if (i++ > 5) {
    81                 break;
    82             }
    83         }
    84 
    85         JOptionPane.showMessageDialog(null, sb.toString());
    86     }
    87 
    88     private String getSummary(TaskData td) {
    89         TaskAttribute a = td.getRoot().getMappedAttribute(BugzillaAttribute.SHORT_DESC.getKey());
    90         String ret = a.getValue();
    91         return ret;
    92     }
    93 
    94 }