1 19 20 package org.netbeans.modules.tasklist.bugs.scarab; 21 22 import java.util.ArrayList ; 23 import java.util.Date ; 24 import java.util.Iterator ; 25 import java.util.LinkedList ; 26 import java.net.URL ; 27 import java.net.MalformedURLException ; 28 import java.text.MessageFormat ; 29 import java.util.List ; 30 31 import org.openide.ErrorManager; 32 import org.openide.util.NbBundle; 33 import org.openide.util.RequestProcessor; 34 import org.openide.util.Utilities; 35 36 import org.netbeans.modules.tasklist.core.TaskListView; 37 import org.netbeans.modules.tasklist.bugs.*; 38 import org.openide.awt.HtmlBrowser; 39 import org.openide.awt.StatusDisplayer; 40 41 import javax.swing.*; 42 43 49 public final class ScarabEngine implements BugEngine { 50 51 public ScarabEngine() { 52 } 53 54 57 public String getName() { 58 return (NbBundle.getMessage(ScarabEngine.class, "Scarab")); } 60 61 public JComponent getQueryCustomizer(final BugQuery query, 62 final boolean edit) { 63 64 return new SourcePanel(); 65 } 66 67 public void refresh(final BugQuery query, final BugList list) { 68 RequestProcessor.postRequest(new Runnable () { 70 public void run() { 71 doRefresh(query, list); 72 } 73 }); 74 } 75 76 79 public void doRefresh(final BugQuery inQuery, final BugList list) { 80 if( !(inQuery instanceof ScarabBugQuery) ){ 81 throw new IllegalArgumentException ("ScarabEngine.doRefresh only excepts ScarabBugQuery argument"); } 83 final ScarabBugQuery sbQuery = (ScarabBugQuery)inQuery; 84 final TaskListView v = TaskListView.getCurrent(); 85 BugsView view = null; 86 if (v instanceof BugsView) { 87 view = (BugsView) v; 88 view.setCursor(Utilities.createProgressCursor(view)); 89 } 90 try { 91 if ((inQuery.getBaseUrl() == null || inQuery.getBaseUrl().equals("")) || (inQuery.getQueryString() == null || inQuery.getQueryString().equals(""))) { StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(ScarabEngine.class, 95 "BadQuery")); return; 97 } 98 final String baseurl = inQuery.getBaseUrl(); 100 final String query = "downloadtype=1&go="+inQuery.getQueryString(); 102 System.out.println("Baseurl = " + baseurl + " query = " + query); 104 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(ScarabEngine.class, 105 "Refreshing")); URL url = null; 107 try { 108 url = new URL (baseurl); 109 } catch (MalformedURLException e) { 110 ErrorManager.getDefault().notify(e); 111 } 112 if (url != null) { 113 final Scarab scarab = new Scarab(url); 114 try { 115 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(ScarabEngine.class, 116 "DoingQuery")); 118 final List issues = scarab.query(query); 120 final List bugs = new ArrayList (); 121 for (Iterator it = issues.iterator(); it.hasNext();) { 122 123 final Issue issue = (Issue)it.next(); 124 StatusDisplayer.getDefault().setStatusText(MessageFormat.format(NbBundle.getMessage(ScarabEngine.class, 125 "QueryingBug"), new String []{issue.getId()})); 127 128 final Object priorityObj = issue.getAttribute(sbQuery.getAttributeName(Issue.PRIORITY)); 129 final int priority = ( priorityObj != null && priorityObj instanceof Number ) 130 ? ((Number )priorityObj).intValue() 131 : 0; 132 final Object votesObj = issue.getAttribute(sbQuery.getAttributeName(Issue.VOTES)); 133 final int votes = ( votesObj != null && votesObj instanceof Number ) 134 ? ((Number )votesObj).intValue() 135 : 0; 136 137 final Bug bug = new Bug(issue.getId(), 138 (String ) issue.getAttribute(sbQuery.getAttributeName(Issue.SUMMARY)), 139 priority, 140 issue.getType(), 141 (String ) issue.getAttribute(sbQuery.getAttributeName(Issue.COMPONENT)), 142 (String ) issue.getAttribute(sbQuery.getAttributeName(Issue.SUBCOMPONENT)), 143 issue.getCreated(), 144 (String ) issue.getAttribute(sbQuery.getAttributeName(Issue.KEYWORDS)), 145 (String ) issue.getAttribute(sbQuery.getAttributeName(Issue.ASSIGNED_TO)), 146 issue.getReportedBy(), 147 (String ) issue.getAttribute(sbQuery.getAttributeName(Issue.STATUS)), 148 (String ) issue.getAttribute(sbQuery.getAttributeName(Issue.TARGET)), 149 votes); 150 bug.setEngine(this); 151 152 bugs.add(bug); 153 } 154 list.setBugs(bugs); 155 156 } catch (org.xml.sax.SAXException se) { 157 ErrorManager.getDefault().notify(se); 158 System.out.println("Couldn't read bug list: sax exception"); } catch (java.net.UnknownHostException uhe) { 160 StatusDisplayer.getDefault().setStatusText(MessageFormat.format(NbBundle.getMessage(ScarabEngine.class, 161 "NoNet"), new String []{baseurl})); 163 164 } catch (java.io.IOException ioe) { 165 ErrorManager.getDefault().notify(ioe); 166 System.out.println("Couldn't read bug list: io exception"); } 168 StatusDisplayer.getDefault().setStatusText(""); } 170 } finally { 171 if (view != null) { 172 view.setCursor(null); 173 } 174 } 175 } 176 177 180 public void viewBug(final Bug bug, final String server) { 181 try { 183 final URL url = new URL (new URL (server), "id/" + bug.getId()); 185 HtmlBrowser.URLDisplayer.getDefault().showURL(url); 186 } catch (MalformedURLException e) { 187 ErrorManager.getDefault().notify(e); 188 } 189 } 190 } 191 | Popular Tags |