KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > bugs > bugzilla > BZBugEngine


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.bugzilla;
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 import org.netbeans.modules.tasklist.bugs.*;
34 import org.openide.awt.HtmlBrowser;
35 import org.openide.awt.StatusDisplayer;
36
37 import javax.swing.*;
38
39 /**
40  * Bridge which provides Bugzilla data to the BugList
41  * This class is almost exactally the same as IZBugEngine.
42  *
43  * @author Tor Norbye, serff
44  */

45 public class BZBugEngine implements BugEngine { // XXX remove the publicness
46

47     public BZBugEngine() {
48     }
49
50     /**
51      * Return the user name of the engine
52      */

53     public String JavaDoc getName() {
54         return (NbBundle.getMessage(BZBugEngine.class, "BugZilla")); // NOI18N;
55
}
56
57     public JComponent getQueryCustomizer(BugQuery query, boolean edit) {
58         return new BugzillaQueryPanel(query, edit);
59     }
60
61     public void refresh(final BugQuery query, final BugList list) {
62         // Do in the background
63
RequestProcessor.postRequest(new Runnable JavaDoc() {
64             public void run() {
65                 doRefresh(query, list);
66             }
67         });
68     }
69
70     /**
71      * TODO Change this so it adds pugs to the model one at a time. I hate waiting...
72      */

73     public void doRefresh(BugQuery inQuery, BugList list) {
74         TaskListView v = TaskListView.getCurrent();
75         BugsView view = null;
76         if (v instanceof BugsView) {
77             view = (BugsView) v;
78             view.setCursor(Utilities.createProgressCursor(view));
79         }
80         try {
81             // Do a bug query
82
String JavaDoc baseurl = inQuery.getBaseUrl() + "/buglist.cgi?";
83             String JavaDoc query = inQuery.getQueryString();
84             if ((baseurl == null || baseurl.equals("")) || (query == null || query.equals(""))) {
85                 //They didn't enter anything on the gui
86
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(BZBugEngine.class,
87                         "BadQuery")); // NOI18N
88
return;
89             }
90             System.out.println("Baseurl = " + baseurl + " query = " + query);
91
92             StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(BZBugEngine.class,
93                     "Refreshing")); // NOI18N
94
URL JavaDoc url = null;
95             try {
96                 url = new URL JavaDoc(baseurl);
97             } catch (MalformedURLException JavaDoc e) {
98                 ErrorManager.getDefault().notify(e);
99             }
100             if (url != null) {
101                 Bugzilla bz = new Bugzilla(url);
102                 try {
103                     StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(BZBugEngine.class,
104                             "DoingQuery")); // NOI18N
105
int bugids[] = bz.query(query);
106
107                     // Provide some update
108

109                     int n = bugids.length;
110                     LinkedList JavaDoc issues = new LinkedList JavaDoc();
111                     for (int i = 0; i < n; i++) {
112                         StatusDisplayer.getDefault().setStatusText(MessageFormat.format(NbBundle.getMessage(BZBugEngine.class,
113                                 "QueryingBug"), // NOI18N
114
new String JavaDoc[]{Integer.toString(bugids[i])}));
115
116                         Issue izbug = bz.getBug(bugids[i]);
117
118                         Bug bug = new Bug(Integer.toString(izbug.getId()),
119                                 izbug.getSummary(),
120                                 izbug.getPriority(),
121                                 izbug.getType(),
122                                 izbug.getComponent(),
123                                 izbug.getSubcomponent(),
124                                 izbug.getCreated(),
125                                 "",
126                                 izbug.getAssignedTo(),
127                                 izbug.getReportedBy(),
128                                 izbug.getStatus(),
129                                 izbug.getTargetMilestone(),
130                                 0);
131                         bug.setEngine(this);
132
133                         issues.add(bug);
134                     }
135
136                     // Successful list fetch -- replace the contents
137
list.setBugs(issues);
138                 } catch (org.xml.sax.SAXException JavaDoc se) {
139                     ErrorManager.getDefault().notify(se);
140                     System.out.println("Couldn't read bug list: sax exception");
141                 } catch (java.net.UnknownHostException JavaDoc uhe) {
142                     StatusDisplayer.getDefault().setStatusText(MessageFormat.format(NbBundle.getMessage(BZBugEngine.class,
143                             "NoNet"), // NOI18N
144
new String JavaDoc[]{baseurl}));
145
146                 } catch (java.io.IOException JavaDoc ioe) {
147                     ErrorManager.getDefault().notify(ioe);
148                     System.out.println("Couldn't read bug list: io exception");
149                 }
150                 StatusDisplayer.getDefault().setStatusText("");
151             }
152         } finally {
153             if (view != null) {
154                 view.setCursor(null);
155             }
156         }
157     }
158
159     /**
160      * View a particular bug.
161      */

162     public void viewBug(Bug bug, String JavaDoc server) {
163 // String urlstring = "http://192.168.3.3/bugzilla/show_bug.cgi?id=" + bug.getId();
164
// String urlstring = "http://bugzilla.mozilla.org/show_bug.cgi?id=" + bug.getId();
165
// Show URL
166
try {
167             // XXX why server/service doe not contain bugzilla too?
168
URL JavaDoc url = new URL JavaDoc(new URL JavaDoc(server), "bugzilla/show_bug.cgi?id=" + bug.getId());
169             HtmlBrowser.URLDisplayer.getDefault().showURL(url);
170         } catch (MalformedURLException JavaDoc e) {
171             ErrorManager.getDefault().notify(e);
172         }
173     }
174 }
175
Popular Tags