From fb2ce921ffc2bd524b59e8b84328cd148c7f9190 Mon Sep 17 00:00:00 2001
From: sminto
Date: Wed, 22 Jun 2005 20:03:47 +0000
Subject: Repairing Active Search: - cache bugzilla results - update
refresh in ui
---
.../bugzilla/ui/editor/AbstractBugEditor.java | 2 +-
.../bugzilla/ui/editor/ExistingBugEditor.java | 6 +-
.../mylyn/bugzilla/ui/editor/NewBugEditor.java | 2 +-
.../bugzilla/ui/outline/BugzillaOutlineNode.java | 27 ++--
.../ui/outline/BugzillaReportSelection.java | 21 ++-
.../mylyn/bugzilla/ui/outline/BugzillaTools.java | 19 +--
.../ui/outline/IBugzillaReportSelection.java | 2 +
.../org/eclipse/mylyn/tasks/MylarTasksPlugin.java | 17 ++-
.../mylyn/tasks/bugzilla/BugzillaCacheFile.java | 131 +++++++++++++++++
.../tasks/bugzilla/BugzillaReferencesProvider.java | 40 +++++-
.../tasks/bugzilla/BugzillaStructureBridge.java | 158 +++++++++++++++++----
.../tasks/bugzilla/search/BugzillaMylarSearch.java | 19 ++-
.../bugzilla/ui/BugzillaNodeLabelProvider.java | 17 ++-
.../eclipse/mylyn/tasks/ui/views/TaskListView.java | 82 ++++++++---
14 files changed, 449 insertions(+), 94 deletions(-)
create mode 100644 org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/BugzillaCacheFile.java
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/editor/AbstractBugEditor.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/editor/AbstractBugEditor.java
index 5eac9e07d..b06aa3b5f 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/editor/AbstractBugEditor.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/editor/AbstractBugEditor.java
@@ -1359,7 +1359,7 @@ public abstract class AbstractBugEditor extends EditorPart implements Listener {
protected class GenericListener implements Listener {
public void handleEvent(Event event) {
IBugzillaBug bug = getBug();
- fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(new BugzillaReportSelection(bug.getId(), bug.getServer(), bug.getLabel(), false))));
+ fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(new BugzillaReportSelection(bug.getId(), bug.getServer(), bug.getLabel(), false, bug.getSummary()))));
}
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/editor/ExistingBugEditor.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/editor/ExistingBugEditor.java
index 26f64a735..fcb36ccd7 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/editor/ExistingBugEditor.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/editor/ExistingBugEditor.java
@@ -659,7 +659,7 @@ public class ExistingBugEditor extends AbstractBugEditor
*/
protected class DescriptionListener implements Listener {
public void handleEvent(Event event) {
- fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(new BugzillaReportSelection(bug.getId(), bug.getServer(), "Description", true))));
+ fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(new BugzillaReportSelection(bug.getId(), bug.getServer(), "Description", true, bug.getSummary()))));
}
}
@@ -680,7 +680,7 @@ public class ExistingBugEditor extends AbstractBugEditor
}
public void handleEvent(Event event) {
- fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(new BugzillaReportSelection(bug.getId(), bug.getServer(), comment.getCreated().toString(), comment))));
+ fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(new BugzillaReportSelection(bug.getId(), bug.getServer(), comment.getCreated().toString(), comment, bug.getSummary()))));
}
}
@@ -690,7 +690,7 @@ public class ExistingBugEditor extends AbstractBugEditor
*/
protected class NewCommentListener implements Listener {
public void handleEvent(Event event) {
- fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(new BugzillaReportSelection(bug.getId(), bug.getServer(), "New Comment", false))));
+ fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(new BugzillaReportSelection(bug.getId(), bug.getServer(), "New Comment", false, bug.getSummary()))));
}
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/editor/NewBugEditor.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/editor/NewBugEditor.java
index 5b4fede6d..e822b7a70 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/editor/NewBugEditor.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/editor/NewBugEditor.java
@@ -345,7 +345,7 @@ public class NewBugEditor extends AbstractBugEditor {
*/
protected class DescriptionListener implements Listener {
public void handleEvent(Event event) {
- fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(new BugzillaReportSelection(bug.getId(), bug.getServer(), "New Description", false))));
+ fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(new BugzillaReportSelection(bug.getId(), bug.getServer(), "New Description", false, bug.getSummary()))));
}
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaOutlineNode.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaOutlineNode.java
index e92b50648..a705b9f75 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaOutlineNode.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaOutlineNode.java
@@ -46,6 +46,8 @@ public class BugzillaOutlineNode implements IBugzillaReportSelection {
private Object data = null;
+ private String bugSummary;
+
private boolean fromEditor = false;
private boolean isCommentHeader = false;
@@ -67,7 +69,7 @@ public class BugzillaOutlineNode implements IBugzillaReportSelection {
* @param parent
* The parent of this node
*/
- public BugzillaOutlineNode(int id, String server, String key, Image image, Object data) {
+ public BugzillaOutlineNode(int id, String server, String key, Image image, Object data, String summary) {
this.id = id;
this.server = server;
this.key = key;
@@ -75,6 +77,7 @@ public class BugzillaOutlineNode implements IBugzillaReportSelection {
this.image = image;
this.data = data;
this.parent = null;
+ this.bugSummary = summary;
}
public boolean isFromEditor(){
@@ -208,11 +211,11 @@ public class BugzillaOutlineNode implements IBugzillaReportSelection {
int bugId = bug.getId();
String bugServer = bug.getServer();
Image defaultImage = BugzillaImages.getImageDescriptor(BugzillaImages.BUG).createImage();
- BugzillaOutlineNode topNode = new BugzillaOutlineNode(bugId, bugServer, bug.getLabel(), defaultImage, bug);
+ BugzillaOutlineNode topNode = new BugzillaOutlineNode(bugId, bugServer, bug.getLabel(), defaultImage, bug, bug.getSummary());
- topNode.addChild(new BugzillaOutlineNode(bugId, bugServer, "New Description", defaultImage, null));
+ topNode.addChild(new BugzillaOutlineNode(bugId, bugServer, "New Description", defaultImage, null, bug.getSummary()));
- BugzillaOutlineNode titleNode = new BugzillaOutlineNode(bugId, bugServer, "NewBugModel Object", defaultImage, null);
+ BugzillaOutlineNode titleNode = new BugzillaOutlineNode(bugId, bugServer, "NewBugModel Object", defaultImage, null, bug.getSummary());
titleNode.addChild(topNode);
return titleNode;
@@ -232,9 +235,9 @@ public class BugzillaOutlineNode implements IBugzillaReportSelection {
int bugId = bug.getId();
String bugServer = bug.getServer();
Image defaultImage = BugzillaImages.getImageDescriptor(BugzillaImages.BUG).createImage();
- BugzillaOutlineNode topNode = new BugzillaOutlineNode(bugId, bugServer, bug.getLabel(), defaultImage, bug);
+ BugzillaOutlineNode topNode = new BugzillaOutlineNode(bugId, bugServer, bug.getLabel(), defaultImage, bug, bug.getSummary());
- BugzillaOutlineNode desc = new BugzillaOutlineNode(bugId, bugServer, "Description", defaultImage, bug.getDescription());
+ BugzillaOutlineNode desc = new BugzillaOutlineNode(bugId, bugServer, "Description", defaultImage, bug.getDescription(), bug.getSummary());
desc.setIsDescription(true);
topNode.addChild(desc);
@@ -245,18 +248,18 @@ public class BugzillaOutlineNode implements IBugzillaReportSelection {
Comment comment = iter.next();
if(comments == null){
- comments = new BugzillaOutlineNode(bugId, bugServer, "Comments", defaultImage, comment);
+ comments = new BugzillaOutlineNode(bugId, bugServer, "Comments", defaultImage, comment, bug.getSummary());
comments.setIsCommentHeader(true);
}
- comments.addChild(new BugzillaOutlineNode(bugId, bugServer, comment.getCreated().toString(), defaultImage, comment));
+ comments.addChild(new BugzillaOutlineNode(bugId, bugServer, comment.getCreated().toString(), defaultImage, comment, bug.getSummary()));
}
if(comments != null){
topNode.addChild(comments);
}
- topNode.addChild(new BugzillaOutlineNode(bugId, bugServer, "New Comment", defaultImage, null));
+ topNode.addChild(new BugzillaOutlineNode(bugId, bugServer, "New Comment", defaultImage, null, bug.getSummary()));
- BugzillaOutlineNode titleNode = new BugzillaOutlineNode(bugId, bugServer, "BugReport Object", defaultImage, null);
+ BugzillaOutlineNode titleNode = new BugzillaOutlineNode(bugId, bugServer, "BugReport Object", defaultImage, null, bug.getSummary());
titleNode.addChild(topNode);
return titleNode;
@@ -328,4 +331,8 @@ public class BugzillaOutlineNode implements IBugzillaReportSelection {
public void setIsDescription(boolean isDescription) {
this.isDescription = isDescription;
}
+
+ public String getBugSummary() {
+ return bugSummary;
+ }
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaReportSelection.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaReportSelection.java
index 385aa61ba..8dd61ac02 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaReportSelection.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaReportSelection.java
@@ -28,6 +28,8 @@ public class BugzillaReportSelection implements IBugzillaReportSelection {
/** The contents of the selection. */
protected String contents;
+ protected String bugSummary;
+
/**
* The comment, if a comment was selected. If the selection was not a
* comment, then this is null
.
@@ -43,8 +45,8 @@ public class BugzillaReportSelection implements IBugzillaReportSelection {
* @param server
* The server of the Bugzilla object that the selection was on.
*/
- public BugzillaReportSelection(int id, String server) {
- this(id, server, null, null);
+ public BugzillaReportSelection(int id, String server, String summary) {
+ this(id, server, null, null, summary);
}
/**
@@ -58,8 +60,8 @@ public class BugzillaReportSelection implements IBugzillaReportSelection {
* @param contents
* The contents of the selection.
*/
- public BugzillaReportSelection(int id, String server, String contents, boolean isDescription) {
- this(id, server, contents, null);
+ public BugzillaReportSelection(int id, String server, String contents, boolean isDescription, String summary) {
+ this(id, server, contents, null, summary);
this.isDescription = isDescription;
}
@@ -76,8 +78,8 @@ public class BugzillaReportSelection implements IBugzillaReportSelection {
* comment was not selected, then this should be
* null
.
*/
- public BugzillaReportSelection(int id, String server, Comment comment) {
- this(id, server, null, comment);
+ public BugzillaReportSelection(int id, String server, Comment comment, String summary) {
+ this(id, server, null, comment, summary);
}
/**
@@ -94,11 +96,12 @@ public class BugzillaReportSelection implements IBugzillaReportSelection {
* comment was not selected, then this should be
* null
.
*/
- public BugzillaReportSelection(int id, String server, String contents, Comment comment) {
+ public BugzillaReportSelection(int id, String server, String contents, Comment comment, String summary) {
this.id = id;
this.server = server;
this.contents = contents;
this.comment = comment;
+ this.bugSummary = summary;
}
public boolean hasComment() {
@@ -159,4 +162,8 @@ public class BugzillaReportSelection implements IBugzillaReportSelection {
public void setIsDescription(boolean isDescription) {
this.isDescription = isDescription;
}
+
+ public String getBugSummary() {
+ return bugSummary;
+ }
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaTools.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaTools.java
index 133bfa7ef..0216b88b2 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaTools.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaTools.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.mylar.bugzilla.ui.outline;
+import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
+
/**
* Miscellaneous constants and functions for this plugin.
@@ -40,15 +42,8 @@ public class BugzillaTools {
return handle;
}
- /**
- * The name for the given bug report
- *
- * @param bugSel
- * The bugzilla selection.
- * @return The name for the bugzilla selection
- */
public static String getName(IBugzillaReportSelection bugSel) {
- String name = bugSel.getServer() + ": Bug#: " + bugSel.getId();
+ String name = bugSel.getServer() + ": Bug#: " + bugSel.getId() + ": " + bugSel.getBugSummary();
if (bugSel.hasComment()) {
name+= " : Comment#: " + bugSel.getComment().getNumber();
} else if(bugSel.isCommentHeader()){
@@ -58,5 +53,13 @@ public class BugzillaTools {
}
return name;
}
+
+ public static String getHandle(IBugzillaBug bug) {
+ return bug.getServer() + ";" + bug.getId();
+ }
+
+ public static String getName(IBugzillaBug bug) {
+ return bug.getServer() + ": Bug#: " + bug.getId() + ": " + bug.getSummary();
+ }
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/IBugzillaReportSelection.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/IBugzillaReportSelection.java
index f56c68fc7..98d88af55 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/IBugzillaReportSelection.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/IBugzillaReportSelection.java
@@ -83,6 +83,8 @@ public interface IBugzillaReportSelection extends ISelection {
public boolean isCommentHeader();
public boolean isDescription();
+
+ public String getBugSummary();
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/MylarTasksPlugin.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/MylarTasksPlugin.java
index 14e024a9d..e4fdcea01 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/MylarTasksPlugin.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/MylarTasksPlugin.java
@@ -53,7 +53,9 @@ public class MylarTasksPlugin extends AbstractUIPlugin implements IStartup {
/** The bridge between Bugzilla and mylar */
private static BugzillaMylarBridge bridge = null;
- private static BugzillaStructureBridge structureBridge = new BugzillaStructureBridge();
+ private BugzillaStructureBridge structureBridge;
+
+ private static BugzillaReferencesProvider referencesProvider = new BugzillaReferencesProvider();
private static ITaskActivityListener TASK_LIST_LISTENER = new ITaskActivityListener() {
@@ -118,9 +120,11 @@ public class MylarTasksPlugin extends AbstractUIPlugin implements IStartup {
final IWorkbench workbench = PlatformUI.getWorkbench();
workbench.getDisplay().asyncExec(new Runnable() {
public void run() {
-
+
+ structureBridge = new BugzillaStructureBridge();
+
MylarPlugin.getDefault().addBridge(structureBridge);
- MylarPlugin.getTaskscapeManager().addListener(new BugzillaReferencesProvider());
+ MylarPlugin.getTaskscapeManager().addListener(referencesProvider);
MylarUiPlugin.getDefault().addAdapter(BugzillaStructureBridge.EXTENSION, new BugzillaUiBridge());
MylarPlugin.getDefault().getSelectionMonitors().add(new BugzillaEditingMonitor());
@@ -218,7 +222,12 @@ public class MylarTasksPlugin extends AbstractUIPlugin implements IStartup {
this.bugzillaProvider = bugzillaProvider;
}
- public static BugzillaStructureBridge getStructureBridge() {
+ public BugzillaStructureBridge getStructureBridge() {
return structureBridge;
}
+
+ public static BugzillaReferencesProvider getReferenceProvider() {
+ return referencesProvider;
+
+ }
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/BugzillaCacheFile.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/BugzillaCacheFile.java
new file mode 100644
index 000000000..7da0be56e
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/BugzillaCacheFile.java
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2005 University Of British Columbia and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * University Of British Columbia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylar.tasks.bugzilla;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.mylar.bugzilla.BugzillaPlugin;
+import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
+
+/**
+ * COPIED FROM @see org.eclipse.mylar.bugzilla.offlineReports.OfflineReportsFile
+ *
+ * @author Shawn Minto
+ */
+public class BugzillaCacheFile {
+
+ private File file;
+
+ private ArrayList list = new ArrayList();
+
+ protected int latestNewBugId = 0;
+
+ public BugzillaCacheFile(File file) throws ClassNotFoundException, IOException {
+ this.file = file;
+ if (file.exists()) {
+ readFile();
+ }
+ }
+
+ public void add(IBugzillaBug entry) {
+ // add the entry to the list and write the file to disk
+ list.add(entry);
+ writeFile();
+ }
+
+ public void update() {
+ writeFile();
+ }
+
+ public int getNextOfflineBugId() {
+ latestNewBugId++;
+ return latestNewBugId;
+ }
+
+ public int find(int id) {
+ for (int i = 0; i < list.size(); i++) {
+ IBugzillaBug currBug = list.get(i);
+ if (currBug != null && (currBug.getId() == id) && !currBug.isLocallyCreated())
+ return i;
+ }
+ return -1;
+ }
+
+ public ArrayList elements() {
+ return list;
+ }
+
+ private void writeFile() {
+ try {
+ ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
+
+ // Write the size of the list so that we can read it back in easier
+ out.writeInt(list.size());
+
+ out.writeInt(latestNewBugId);
+
+ // write each element in the array list
+ for (int i = 0; i < list.size(); i++) {
+ Object item = list.get(i);
+ out.writeObject(item);
+ }
+ out.close();
+ }
+ catch (IOException e) {
+ // put up a message and log the error if there is a problem writing to the file
+ MessageDialog.openError(null,
+ "I/O Error",
+ "Bugzilla could not write to offline reports file.");
+ BugzillaPlugin.log(e);
+ }
+ }
+
+ private void readFile() throws ClassNotFoundException, IOException {
+ ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
+
+ // get the number of offline reports in the file
+ int size = in.readInt();
+
+ // get the bug id of the most recently created offline report
+ latestNewBugId = in.readInt();
+
+ // read in each of the offline reports in the file
+ for (int nX = 0; nX < size; nX++) {
+ IBugzillaBug item = (IBugzillaBug) in.readObject();
+ // add the offline report to the offlineReports list
+ list.add(item);
+ }
+ in.close();
+ }
+
+ public void remove(List sel) {
+ list.removeAll(sel);
+
+ // rewrite the file so that the data is persistant
+ writeFile();
+ }
+
+ public void removeAll() {
+ list.clear();
+
+ // rewrite the file so that the data is persistant
+ writeFile();
+ }
+}
+
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/BugzillaReferencesProvider.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/BugzillaReferencesProvider.java
index 04a557dee..6b810f142 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/BugzillaReferencesProvider.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/BugzillaReferencesProvider.java
@@ -13,8 +13,11 @@
*/
package org.eclipse.mylar.tasks.bugzilla;
+import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IJavaElement;
@@ -25,6 +28,7 @@ import org.eclipse.mylar.core.model.ITaskscapeNode;
import org.eclipse.mylar.core.search.IActiveSearchListener;
import org.eclipse.mylar.core.search.IMylarSearchOperation;
import org.eclipse.mylar.core.search.RelationshipProvider;
+import org.eclipse.mylar.tasks.MylarTasksPlugin;
import org.eclipse.mylar.tasks.bugzilla.search.BugzillaMylarSearch;
@@ -76,11 +80,16 @@ public class BugzillaReferencesProvider extends RelationshipProvider {
public void searchCompleted(List> nodes) {
Iterator> itr = nodes.iterator();
+ BugzillaStructureBridge bridge = MylarTasksPlugin.getDefault().getStructureBridge();
+
while(itr.hasNext()) {
Object o = itr.next();
if(o instanceof BugzillaReportNode){
BugzillaReportNode bugzillaNode = (BugzillaReportNode)o;
- incrementInterest(degreeOfSeparation, BugzillaStructureBridge.EXTENSION, bugzillaNode.getElementHandle());
+ String handle = bugzillaNode.getElementHandle();
+ if(bridge.getCached(handle) == null)
+ cache(handle, bugzillaNode);
+ incrementInterest(degreeOfSeparation, BugzillaStructureBridge.EXTENSION, handle);
}
}
gathered = true;
@@ -94,7 +103,7 @@ public class BugzillaReferencesProvider extends RelationshipProvider {
search.run(new NullProgressMonitor());
}
- @Override
+ @Override
protected String getSourceId() {
return ID;
}
@@ -103,4 +112,31 @@ public class BugzillaReferencesProvider extends RelationshipProvider {
public String getName() {
return NAME;
}
+
+ /*
+ *
+ * STUFF FOR TEMPORARILY CACHING A PROXY REPORT
+ *
+ * TODO remove the proxys and update the BugzillaStructureBridge cache so that on restart,
+ * we dont have to get all of the bugs
+ *
+ */
+ private static final Map reports = new HashMap();
+
+ public BugzillaReportNode getCached(String handle){
+ return reports.get(handle);
+ }
+
+ protected void cache(String handle, BugzillaReportNode bugzillaNode) {
+ reports.put(handle, bugzillaNode);
+ }
+
+ public void clearCachedReports(){
+ reports.clear();
+ }
+
+ public Collection extends String> getCachedHandles() {
+ return reports.keySet();
+ }
+
}
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 cache = new HashMap();
+
+ 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 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 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);
+ }
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/search/BugzillaMylarSearch.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/search/BugzillaMylarSearch.java
index 4e59546d5..dea6339ee 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/search/BugzillaMylarSearch.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/search/BugzillaMylarSearch.java
@@ -24,7 +24,6 @@ import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
import org.eclipse.mylar.core.search.IActiveSearchListener;
import org.eclipse.mylar.core.search.IMylarSearchOperation;
-import org.eclipse.mylar.tasks.MylarTasksPlugin;
import org.eclipse.mylar.tasks.bugzilla.BugzillaMylarBridge;
import org.eclipse.mylar.tasks.bugzilla.BugzillaReportNode;
import org.eclipse.mylar.tasks.bugzilla.Util;
@@ -73,16 +72,16 @@ public class BugzillaMylarSearch implements IMylarSearchOperation {
// search on them
for(IMember m : members){
- // FIXME: decide whether to do leave the caching in for now or not
+ // FIXME: decide whether to do leave the caching of searches in for now or not
// check if we have the info cached
- List landmarkDoi = MylarTasksPlugin.getBridge()
- .getFromLandmarksHash(m, scope);
-
- if (landmarkDoi != null) {
- //TODO decide when to queue up and do a refresh search
- notifySearchCompleted(landmarkDoi);
- continue;
- }
+// List landmarkDoi = MylarTasksPlugin.getBridge()
+// .getFromLandmarksHash(m, scope);
+
+// if (landmarkDoi != null) {
+// //TODO decide when to queue up and do a refresh search
+// notifySearchCompleted(landmarkDoi);
+// continue;
+// }
// create a search operation so that we can search
BugzillaMylarSearchOperation op = new BugzillaMylarSearchOperation(
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/ui/BugzillaNodeLabelProvider.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/ui/BugzillaNodeLabelProvider.java
index a60e03546..01a2f5791 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/ui/BugzillaNodeLabelProvider.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/bugzilla/ui/BugzillaNodeLabelProvider.java
@@ -15,8 +15,10 @@ package org.eclipse.mylar.tasks.bugzilla.ui;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.mylar.bugzilla.core.BugReport;
import org.eclipse.mylar.core.model.ITaskscapeNode;
import org.eclipse.mylar.tasks.MylarTasksPlugin;
+import org.eclipse.mylar.tasks.bugzilla.BugzillaReportNode;
import org.eclipse.mylar.ui.MylarImages;
import org.eclipse.swt.graphics.Image;
@@ -34,10 +36,17 @@ public class BugzillaNodeLabelProvider implements ILabelProvider {
*/
public String getText(Object element) {
ITaskscapeNode node = (ITaskscapeNode)element;
- String name = MylarTasksPlugin.getStructureBridge().getName(
- MylarTasksPlugin.getStructureBridge().getObjectForHandle(node.getElementHandle())
- );
- return name;
+
+ // try to get from the cache before downloading
+ Object report;
+ BugzillaReportNode reportNode = MylarTasksPlugin.getReferenceProvider().getCached(node.getElementHandle());
+ BugReport cachedReport = MylarTasksPlugin.getDefault().getStructureBridge().getCached(node.getElementHandle());
+ if(reportNode != null && cachedReport == null){
+ report = reportNode;
+ } else{
+ report = MylarTasksPlugin.getDefault().getStructureBridge().getObjectForHandle(node.getElementHandle());
+ }
+ return MylarTasksPlugin.getDefault().getStructureBridge().getName(report);
}
public void addListener(ILabelProviderListener listener) {
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/views/TaskListView.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/views/TaskListView.java
index 7dc995324..65dfa12e4 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/views/TaskListView.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/views/TaskListView.java
@@ -11,12 +11,17 @@
package org.eclipse.mylar.tasks.ui.views;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import javax.security.auth.login.LoginException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
@@ -42,6 +47,8 @@ import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerDropAdapter;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.jface.window.Window;
+import org.eclipse.mylar.bugzilla.core.BugReport;
+import org.eclipse.mylar.bugzilla.core.BugzillaRepository;
import org.eclipse.mylar.core.ITaskscapeListener;
import org.eclipse.mylar.core.MylarPlugin;
import org.eclipse.mylar.dt.MylarWebRef;
@@ -50,6 +57,7 @@ import org.eclipse.mylar.tasks.Category;
import org.eclipse.mylar.tasks.ITask;
import org.eclipse.mylar.tasks.MylarTasksPlugin;
import org.eclipse.mylar.tasks.Task;
+import org.eclipse.mylar.tasks.bugzilla.BugzillaStructureBridge;
import org.eclipse.mylar.tasks.ui.BugzillaTaskEditorInput;
import org.eclipse.mylar.ui.MylarImages;
import org.eclipse.mylar.ui.MylarUiPlugin;
@@ -80,9 +88,12 @@ import org.eclipse.ui.IViewSite;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
import org.eclipse.ui.internal.Workbench;
import org.eclipse.ui.part.DrillDownAdapter;
import org.eclipse.ui.part.ViewPart;
+import org.eclipse.ui.progress.IProgressService;
/**
* @author Mik Kersten
@@ -609,27 +620,58 @@ public class TaskListView extends ViewPart {
private void makeActions() {
refresh = new Action() {
-
+
@Override
- public void run() {
-// Object[] expanded = viewer.getExpandedElements();
-// for (int i = 0; i < expanded.length; i++) {
-// Object element = expanded[i];
-// if (element instanceof BugzillaTask) {
-// ((BugzillaTask)element).refresh();
-// }
-// }
-
- List tasks = MylarTasksPlugin.getTaskListManager().getTaskList().getRootTasks();
-
- for (ITask task : tasks) {
- if (task instanceof BugzillaTask) {
- ((BugzillaTask)task).refresh();
- }
- refreshChildren(task.getChildren());
- }
-
- viewer.refresh();
+ public void run() {
+ // TODO background?
+ // perform the update in an operation so that we get a progress monitor
+ // update the structure bridge cache with the reference provider cached bugs
+ WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
+ protected void execute(IProgressMonitor monitor) throws CoreException {
+
+ List tasks = MylarTasksPlugin.getTaskListManager().getTaskList().getRootTasks();
+
+ for (ITask task : tasks) {
+ if (task instanceof BugzillaTask) {
+ ((BugzillaTask)task).refresh();
+ }
+ refreshChildren(task.getChildren());
+ }
+
+ // clear the caches
+ Set cachedHandles = new HashSet();
+ cachedHandles.addAll(MylarTasksPlugin.getDefault().getStructureBridge().getCachedHandles());
+ cachedHandles.addAll(MylarTasksPlugin.getReferenceProvider().getCachedHandles());
+ MylarTasksPlugin.getDefault().getStructureBridge().clearCache();
+ MylarTasksPlugin.getReferenceProvider().clearCachedReports();
+
+ BugzillaStructureBridge bridge = MylarTasksPlugin.getDefault().getStructureBridge();
+ monitor.beginTask("Downloading Bugs" , cachedHandles.size());
+ for(String key: cachedHandles){
+ try {
+ String [] parts = key.split(";");
+ final int id = Integer.parseInt(parts[1]);
+ BugReport bug = BugzillaRepository.getInstance().getCurrentBug(id);
+ if(bug != null)
+ bridge.cache(key, bug);
+ }catch(Exception e){}
+
+ monitor.worked(1);
+ }
+ monitor.done();
+ viewer.refresh();
+ }
+ };
+
+ // Use the progess service to execute the runnable
+ IProgressService service = PlatformUI.getWorkbench().getProgressService();
+ try {
+ service.run(true, false, op);
+ } catch (InvocationTargetException e) {
+ // Operation was canceled
+ } catch (InterruptedException e) {
+ // Handle the wrapped exception
+ }
}
};
refresh.setText("Refresh all Bugzilla reports");
--
cgit v1.2.3