KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > bugs > issuezilla > IZBugEngine


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.bugs.issuezilla;
21
22 import java.util.LinkedList JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25 import java.text.MessageFormat JavaDoc;
26
27 import org.openide.ErrorManager;
28 import org.openide.util.NbBundle;
29 import org.openide.util.RequestProcessor;
30 import org.openide.util.Utilities;
31
32 import org.netbeans.modules.tasklist.core.TaskListView;
33
34 import org.netbeans.modules.tasklist.bugs.*;
35 import org.netbeans.modules.tasklist.bugs.bugzilla.BugzillaQueryPanel;
36 import org.netbeans.modules.tasklist.bugs.bugzilla.SourcePanel;
37 import org.openide.awt.HtmlBrowser;
38 import org.openide.awt.StatusDisplayer;
39
40 import javax.swing.*;
41
42 /**
43  * Bridge which provides Issuezilla data to the BugList
44  *
45  * @author Tor Norbye
46  */

47 public class IZBugEngine implements BugEngine { // XXX remove the publicness
48

49     public IZBugEngine() {
50     }
51
52     /**
53      * Return the user name of the engine
54      */

55     public String JavaDoc getName() {
56         return (NbBundle.getMessage(IZBugEngine.class, "IssueZilla")); // NOI18N;
57
}
58
59     public void refresh(final BugQuery query, final BugList list) {
60         // Do in the background
61
RequestProcessor.getDefault().post(new Runnable JavaDoc() {
62             public void run() {
63                 doRefresh(query, list);
64             }
65         });
66     }
67
68     public JComponent getQueryCustomizer(BugQuery query, boolean edit) {
69         return new SourcePanel(true);
70     }
71
72     public void doRefresh(BugQuery inQuery, BugList list) {
73         TaskListView v = TaskListView.getCurrent();
74         BugsView view = null;
75         if (v instanceof BugsView) {
76             view = (BugsView) v;
77             view.setCursor(Utilities.createProgressCursor(view));
78         }
79         try {
80
81             // Do a bug query
82
String JavaDoc query = null;
83             String JavaDoc baseurl = null;
84 // query = System.getProperty("netbeans.tasklist.bugquery");
85
// if (query == null) {
86
// // TEMPORARY HACK TODO
87
// TopManager.getDefault().notify(new NotifyDescriptor.Message("Tasklist bug summary:\nAdd -J-Dnetbeans.tasklist.bugquery=http://your.bug.url?<query>\nto your runide.sh startup arguments. (This is\nobviously only a temporary hack solution until\nI've added a query customizer.)\n\nTo determine what query to use, go to issuezilla:\n http://www.netbeans.org/issues/query.cgi\nand create a custom query. Then, add that query as <query> above.\n\nAnd don't forget to make sure to set your\nproxies if you're behind a firewall! You can do that through Tools -> Setup Wizard."));
88
// return;
89
// } else {
90
// //get the baseurl
91
// int index = query.indexOf("?");
92
// if (index != -1) {
93
// baseurl = query.substring(0, index + 1);
94
// query = query.substring(index + 1);
95
// } else {
96
// //we have to have the URL
97
// TopManager.getDefault().notify(new NotifyDescriptor.Message("Tasklist bug summary:\nAdd -J-Dnetbeans.tasklist.bugquery=You must have the full URL for this query (Ex. http://www.netbeans.org/issues/buglist.cgi?<query>"));
98
// }
99
// }
100
baseurl = inQuery.getBaseUrl() + "/buglist.cgi?";
101             query = inQuery.getQueryString();
102
103             if ((baseurl == null || baseurl.equals("")) || (query == null || query.equals(""))) {
104                 //They didn't enter anything on the gui
105
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(IZBugEngine.class,
106                         "BadQuery")); // NOI18N
107
return;
108             }
109
110             //String query= "issue_type=DEFECT&component=projects&issue_status=UNCONFIRMED&issue_status=NEW&issue_status=STARTED&issue_status=REOPENED&version=4.0+dev&email1=&emailtype1=substring&emailassigned_to1=1&email2=&emailtype2=substring&emailreporter2=1&issueidtype=include&issue_id=&changedin=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&short_desc=&short_desc_type=substring&long_desc=&long_desc_type=substring&issue_file_loc=&issue_file_loc_type=substring&status_whiteboard=&status_whiteboard_type=substring&keywords=&keywords_type=anywords&field0-0-0=noop&type0-0-0=noop&value0-0-0=&cmdtype=doit&newqueryname=&order=Reuse+same+sort+as+last+time";
111

112
113             StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(IZBugEngine.class,
114                     "Refreshing")); // NOI18N
115
URL JavaDoc url = null;
116             try {
117                 url = new URL JavaDoc(baseurl);
118             } catch (MalformedURLException JavaDoc e) {
119                 ErrorManager.getDefault().notify(e);
120             }
121             if (url != null) {
122                 Issuezilla iz = new Issuezilla(url);
123                 try {
124                     StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(IZBugEngine.class,
125                             "DoingQuery")); // NOI18N
126

127                     int bugids[] = iz.query(query);
128
129                     // Provide some update
130

131                     int n = bugids.length;
132                     LinkedList JavaDoc issues = new LinkedList JavaDoc();
133                     for (int i = 0; i < n; i++) {
134                         StatusDisplayer.getDefault().setStatusText(MessageFormat.format(NbBundle.getMessage(IZBugEngine.class,
135                                 "QueryingBug"), // NOI18N
136
new String JavaDoc[]{Integer.toString(bugids[i])}));
137
138                         Issue izbug = iz.getBug(bugids[i]);
139
140                         Bug bug = new Bug(Integer.toString(izbug.getId()),
141                                 izbug.getSummary(),
142                                 izbug.getPriority(),
143                                 izbug.getType(),
144                                 izbug.getComponent(),
145                                 izbug.getSubcomponent(),
146                                 izbug.getCreated(),
147                                 izbug.getKeywords(),
148                                 izbug.getAssignedTo(),
149                                 izbug.getReportedBy(),
150                                 izbug.getStatus(),
151                                 izbug.getTargetMilestone(),
152                                 izbug.getVotes());
153                         bug.setEngine(this);
154
155                         issues.add(bug);
156                     }
157
158                     // Successful list fetch -- replace the contents
159
list.setBugs(issues);
160                 } catch (org.xml.sax.SAXException JavaDoc se) {
161                     ErrorManager.getDefault().notify(se);
162                     System.out.println("Couldn't read bug list: sax exception");
163                 } catch (java.net.UnknownHostException JavaDoc uhe) {
164                     StatusDisplayer.getDefault().setStatusText(MessageFormat.format(NbBundle.getMessage(IZBugEngine.class,
165                             "NoNet"), // NOI18N
166
new String JavaDoc[]{baseurl}));
167
168                 } catch (java.io.IOException JavaDoc ioe) {
169                     ErrorManager.getDefault().notify(ioe);
170                     System.out.println("Couldn't read bug list: io exception");
171                 }
172                 StatusDisplayer.getDefault().setStatusText("");
173             }
174
175         } finally {
176             if (view != null) {
177                 view.setCursor(null);
178             }
179         }
180     }
181
182     /**
183      * View a particular bug.
184      */

185     public void viewBug(Bug bug, String JavaDoc service) {
186 // String urlstring = "http://www.netbeans.org/issues/show_bug.cgi?id=" +
187
// bug.getId();
188
// Show URL
189
try {
190             URL JavaDoc url = new URL JavaDoc(new URL JavaDoc(service), "issues/show_bug.cgi?id=" + bug.getId());
191             HtmlBrowser.URLDisplayer.getDefault().showURL(url);
192         } catch (MalformedURLException JavaDoc e) {
193             ErrorManager.getDefault().notify(e);
194         }
195     }
196 }
197
Popular Tags