Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/BugzillaStructureBridge.java')
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/BugzillaStructureBridge.java158
1 files changed, 134 insertions, 24 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/BugzillaStructureBridge.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/BugzillaStructureBridge.java
index a774fa336..272e8c2fd 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/BugzillaStructureBridge.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/BugzillaStructureBridge.java
@@ -13,15 +13,32 @@
*/
package org.eclipse.mylar.tasks.bugzilla;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.mylar.bugzilla.core.BugReport;
import org.eclipse.mylar.bugzilla.core.BugzillaRepository;
+import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
+import org.eclipse.mylar.bugzilla.search.BugzillaSearchHit;
import org.eclipse.mylar.bugzilla.ui.editor.AbstractBugEditor;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaOutlineNode;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaReportSelection;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaTools;
import org.eclipse.mylar.core.IMylarStructureBridge;
+import org.eclipse.mylar.core.MylarPlugin;
+import org.eclipse.mylar.tasks.MylarTasksPlugin;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.eclipse.ui.progress.IProgressService;
import org.eclipse.ui.views.markers.internal.ProblemMarker;
@@ -35,6 +52,7 @@ public class BugzillaStructureBridge implements IMylarStructureBridge {
public BugzillaStructureBridge() {
super();
+ readCacheFile();
}
/**
@@ -54,42 +72,72 @@ public class BugzillaStructureBridge implements IMylarStructureBridge {
return null;
}
- public Object getObjectForHandle(String handle) {
+ private BugReport result;
+
+ public Object getObjectForHandle(final String handle) {
+ result = null;
+
String [] parts = handle.split(";");
if (parts.length >= 2){
-// String server = parts[0]; TODO add back in when we deal with multiple servers
- int id = Integer.parseInt(parts[1]);
+ String server = parts[0];
+ final int id = Integer.parseInt(parts[1]);
+
+ String bugHandle = server + ";" + id;
+
int commentNumber = -1;
if(parts.length == 3){
commentNumber = Integer.parseInt(parts[2]);
}
- try{
- // get the bugzillaOutlineNode for the element
- IEditorPart editorPart = null;
- try{
- editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- }catch(NullPointerException e){
- // do nothing, this just means that there is no active page
- }
- if(editorPart != null && editorPart instanceof AbstractBugEditor){
- AbstractBugEditor abe = ((AbstractBugEditor)editorPart);
- BugzillaOutlineNode node = abe.getModel();
- return findNode(node, commentNumber);
- }
-
- // TODO There is a huge slowdown here always getting the object - maybe make bugzilla store the bug for a while in memory or as temp ofline?
- BugzillaOutlineNode node = BugzillaOutlineNode.parseBugReport(BugzillaRepository.getInstance().getCurrentBug(id));
- return findNode(node, commentNumber);
- }catch(Exception e){
- return null;
+
+ // get the bugzillaOutlineNode for the element
+ IEditorPart editorPart = null;
+ try{
+ editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ }catch(NullPointerException e){
+ // do nothing, this just means that there is no active page
+ }
+ if(editorPart != null && editorPart instanceof AbstractBugEditor){
+ AbstractBugEditor abe = ((AbstractBugEditor)editorPart);
+ BugzillaOutlineNode node = abe.getModel();
+ return findNode(node, commentNumber);
}
+
+ // try to get from the cache, if it doesn't exist, startup an operation to get it
+ result = getFromCache(bugHandle);
+ if(result == null){
+ WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
+ protected void execute(IProgressMonitor monitor) throws CoreException {
+ monitor.beginTask("Downloading Bug# " + id, IProgressMonitor.UNKNOWN);
+ try {
+ result = BugzillaRepository.getInstance().getCurrentBug(id);
+ }catch(Exception e){
+ result = null;
+ }
+ }};
+
+ // Use the progess service to execute the runnable
+ IProgressService service = PlatformUI.getWorkbench().getProgressService();
+ try {
+ service.run(false, false, op);
+ } catch (InvocationTargetException e) {
+ // Operation was canceled
+ } catch (InterruptedException e) {
+ // Handle the wrapped exception
+ }
+
+ if(result != null)
+ cache(bugHandle, result);
+ }
+
+ BugzillaOutlineNode node = BugzillaOutlineNode.parseBugReport(result);
+ return findNode(node, commentNumber);
}
else{
return null;
}
}
-
- private BugzillaOutlineNode findNode(BugzillaOutlineNode startNode, int commentNumber){
+
+ private BugzillaOutlineNode findNode(BugzillaOutlineNode startNode, int commentNumber){
if(commentNumber == -1){
return startNode;
@@ -111,6 +159,11 @@ public class BugzillaStructureBridge implements IMylarStructureBridge {
}
public String getParentHandle(String handle) {
+
+ //check so that we don't need to try to get the parent if we are already at the bug report
+ if(!handle.matches(".*;.*;.*"))
+ return null;
+
BugzillaOutlineNode bon = (BugzillaOutlineNode)getObjectForHandle(handle);
if(bon != null && bon.getParent() != null)
return BugzillaTools.getHandle(bon.getParent());
@@ -133,6 +186,9 @@ public class BugzillaStructureBridge implements IMylarStructureBridge {
if(object instanceof BugzillaOutlineNode){
BugzillaOutlineNode b = (BugzillaOutlineNode)object;
return BugzillaTools.getName(b);
+ } else if (object instanceof BugzillaReportNode){
+ BugzillaSearchHit hit = ((BugzillaReportNode)object).getHit();
+ return hit.getServer() + ": Bug#: " + hit.getId() + ": " + hit.getDescription();
}
return "";
}
@@ -165,4 +221,58 @@ public class BugzillaStructureBridge implements IMylarStructureBridge {
public String getResourceExtension(String elementHandle) {
return getResourceExtension();
}
+
+ /*
+ *
+ * STUFF FOR CACHING BUG REPORTS
+ *
+ */
+
+ // bug report cache
+ private Map<String, BugReport> cache = new HashMap<String, BugReport>();
+
+ public void cache(String handle, BugReport report) {
+ cache.put(handle, report);
+ cacheFile.add(report);
+ }
+
+ public void clearCache(){
+ cache.clear();
+ cacheFile.removeAll();
+ }
+
+ private BugReport getFromCache(String bugHandle) {
+ return cache.get(bugHandle);
+ }
+
+ public Set<String> getCachedHandles(){
+ return cache.keySet();
+ }
+
+ private BugzillaCacheFile cacheFile;
+
+ private IPath getCacheFile() {
+ IPath stateLocation = Platform.getPluginStateLocation(MylarTasksPlugin.getDefault());
+ IPath configFile = stateLocation.append("offlineReports");
+ return configFile;
+ }
+
+ private void readCacheFile() {
+ IPath cachPath = getCacheFile();
+
+ try {
+ cacheFile = new BugzillaCacheFile(cachPath.toFile());
+ ArrayList<IBugzillaBug> cached = cacheFile.elements();
+ for(IBugzillaBug bug: cached){
+ if(bug instanceof BugReport)
+ cache.put(BugzillaTools.getHandle(bug), (BugReport)bug);
+ }
+ } catch (Exception e) {
+ MylarPlugin.log(e, "occurred while restoring saved offline Bugzilla reports.");
+ }
+ }
+
+ public BugReport getCached(String handle) {
+ return cache.get(handle);
+ }
}

Back to the top