Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui')
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/FavoritesView.java14
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/OfflineView.java12
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/ViewBugzillaAction.java4
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/editor/AbstractBugEditor.java8
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/editor/ExistingBugEditor.java8
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/editor/NewBugEditor.java2
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/Favorite.java110
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/FavoritesFile.java318
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/AbstractFavoritesAction.java56
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/AddFavoriteAction.java112
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/AddToFavoritesAction.java49
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/DeleteFavoriteAction.java69
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/ViewFavoriteAction.java58
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaOutlineNode.java2
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/query/GetQueryDialog.java203
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/query/SaveQueryDialog.java90
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/query/SavedQueryFile.java249
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/wizard/AbstractBugWizard.java6
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/wizard/NewBugWizard.java2
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/wizard/WizardProductPage.java2
20 files changed, 1344 insertions, 30 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/FavoritesView.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/FavoritesView.java
index 98a75c0c4..4a66d316c 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/FavoritesView.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/FavoritesView.java
@@ -33,13 +33,13 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.mylar.bugzilla.BugzillaPlugin;
-import org.eclipse.mylar.bugzilla.IBugzillaConstants;
-import org.eclipse.mylar.bugzilla.favorites.Favorite;
-import org.eclipse.mylar.bugzilla.favorites.FavoritesFile;
-import org.eclipse.mylar.bugzilla.favorites.actions.AbstractFavoritesAction;
-import org.eclipse.mylar.bugzilla.favorites.actions.DeleteFavoriteAction;
-import org.eclipse.mylar.bugzilla.favorites.actions.ViewFavoriteAction;
+import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
+import org.eclipse.mylar.bugzilla.core.IBugzillaConstants;
+import org.eclipse.mylar.bugzilla.ui.favorites.Favorite;
+import org.eclipse.mylar.bugzilla.ui.favorites.FavoritesFile;
+import org.eclipse.mylar.bugzilla.ui.favorites.actions.AbstractFavoritesAction;
+import org.eclipse.mylar.bugzilla.ui.favorites.actions.DeleteFavoriteAction;
+import org.eclipse.mylar.bugzilla.ui.favorites.actions.ViewFavoriteAction;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/OfflineView.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/OfflineView.java
index 91cfb0590..8f4a32104 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/OfflineView.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/OfflineView.java
@@ -34,13 +34,13 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.mylar.bugzilla.BugzillaPlugin;
-import org.eclipse.mylar.bugzilla.IBugzillaConstants;
+import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
-import org.eclipse.mylar.bugzilla.offlineReports.AbstractOfflineReportsAction;
-import org.eclipse.mylar.bugzilla.offlineReports.DeleteOfflineReportAction;
-import org.eclipse.mylar.bugzilla.offlineReports.OfflineReportsFile;
-import org.eclipse.mylar.bugzilla.offlineReports.ViewOfflineReportAction;
+import org.eclipse.mylar.bugzilla.core.IBugzillaConstants;
+import org.eclipse.mylar.bugzilla.core.offline.AbstractOfflineReportsAction;
+import org.eclipse.mylar.bugzilla.core.offline.DeleteOfflineReportAction;
+import org.eclipse.mylar.bugzilla.core.offline.OfflineReportsFile;
+import org.eclipse.mylar.bugzilla.core.offline.ViewOfflineReportAction;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/ViewBugzillaAction.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/ViewBugzillaAction.java
index 4d565e250..1c6373829 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/ViewBugzillaAction.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/ViewBugzillaAction.java
@@ -20,8 +20,8 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.mylar.bugzilla.BugzillaPlugin;
-import org.eclipse.mylar.bugzilla.IBugzillaConstants;
+import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
+import org.eclipse.mylar.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.bugzilla.ui.editor.AbstractBugEditor;
import org.eclipse.mylar.bugzilla.ui.editor.ExistingBugEditorInput;
import org.eclipse.ui.IWorkbenchPage;
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 b26eed1c8..d865bcc71 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
@@ -37,14 +37,14 @@ import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.mylar.bugzilla.BugzillaPlugin;
-import org.eclipse.mylar.bugzilla.BugzillaPreferences;
-import org.eclipse.mylar.bugzilla.IBugzillaAttributeListener;
-import org.eclipse.mylar.bugzilla.IBugzillaConstants;
import org.eclipse.mylar.bugzilla.core.Attribute;
import org.eclipse.mylar.bugzilla.core.BugPost;
+import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
+import org.eclipse.mylar.bugzilla.core.BugzillaPreferences;
import org.eclipse.mylar.bugzilla.core.Comment;
+import org.eclipse.mylar.bugzilla.core.IBugzillaAttributeListener;
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
+import org.eclipse.mylar.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.bugzilla.ui.OfflineView;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaOutlineNode;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaOutlinePage;
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 887e56d41..826f95791 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
@@ -33,19 +33,19 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.JFaceColors;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.mylar.bugzilla.BugzillaPlugin;
-import org.eclipse.mylar.bugzilla.IBugzillaConstants;
-import org.eclipse.mylar.bugzilla.compare.BugzillaCompareInput;
import org.eclipse.mylar.bugzilla.core.Attribute;
import org.eclipse.mylar.bugzilla.core.BugPost;
import org.eclipse.mylar.bugzilla.core.BugReport;
import org.eclipse.mylar.bugzilla.core.BugzillaException;
+import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
import org.eclipse.mylar.bugzilla.core.BugzillaRepository;
import org.eclipse.mylar.bugzilla.core.Comment;
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
+import org.eclipse.mylar.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.bugzilla.core.Operation;
-import org.eclipse.mylar.bugzilla.favorites.actions.AddToFavoritesAction;
+import org.eclipse.mylar.bugzilla.core.compare.BugzillaCompareInput;
import org.eclipse.mylar.bugzilla.ui.OfflineView;
+import org.eclipse.mylar.bugzilla.ui.favorites.actions.AddToFavoritesAction;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaOutlineNode;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaReportSelection;
import org.eclipse.swt.SWT;
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 e822b7a70..10bb28ce4 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
@@ -17,10 +17,10 @@ import javax.security.auth.login.LoginException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.mylar.bugzilla.BugzillaPlugin;
import org.eclipse.mylar.bugzilla.core.Attribute;
import org.eclipse.mylar.bugzilla.core.BugPost;
import org.eclipse.mylar.bugzilla.core.BugzillaException;
+import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
import org.eclipse.mylar.bugzilla.ui.OfflineView;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaOutlineNode;
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/Favorite.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/Favorite.java
new file mode 100644
index 000000000..9eb9b348a
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/Favorite.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2003 - 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.bugzilla.ui.favorites;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.Map;
+
+import org.eclipse.mylar.bugzilla.core.BugReport;
+import org.eclipse.mylar.bugzilla.core.search.BugzillaSearchResultCollector;
+
+
+/**
+ * Class representing an item in the favorites view
+ */
+public class Favorite implements Serializable {
+
+ /** Automatically generated serialVersionUID */
+ private static final long serialVersionUID = 3258129158977632310L;
+
+ /** Bug id */
+ private int id;
+ /** Bug description */
+ private String description;
+ /** Query that created the match */
+ private String query;
+ /** Bug's attributes (severity, priority, etc.) */
+ private Map<String, Object> attributes;
+ /** Date when the favorite was recommended. */
+ private Date date;
+
+ private String server;
+
+ /**
+ * Constructor.
+ *
+ * @param bug
+ * The bug this favorite represents.
+ */
+ public Favorite(BugReport bug) {
+ this(bug.getServer(), bug.getId(), bug.getSummary(), "", BugzillaSearchResultCollector.getAttributeMap(bug));
+ }
+
+ /**
+ * Constructor.
+ */
+ public Favorite(String server, int id, String description, String query, Map<String, Object> attributes) {
+ this.server = server;
+ this.id = id;
+ this.description = description;
+ this.query = query;
+ this.attributes = attributes;
+ date = new Date();
+ }
+
+ /**
+ * returns the server for the bug
+ */
+ public String getServer(){
+ return server;
+ }
+
+ /**
+ * Returns bug's id.
+ */
+ public int getId() {
+ return id;
+ }
+
+ /**
+ * Returns bug's description.
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Returns bug attributes.
+ */
+ public Map<String, Object> getAttributes() {
+ return attributes;
+ }
+
+ /**
+ * Returns the query that created the match.
+ */
+ public String getQuery() {
+ return query;
+ }
+
+ /**
+ * Returns date when the favorite was added to the view.
+ */
+ public Date getDate() {
+ return date;
+ }
+
+ @Override
+ public String toString() {
+ return id + " - " + description;
+ }
+}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/FavoritesFile.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/FavoritesFile.java
new file mode 100644
index 000000000..7eecfc372
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/FavoritesFile.java
@@ -0,0 +1,318 @@
+/*******************************************************************************
+ * Copyright (c) 2003 - 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.bugzilla.ui.favorites;
+
+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.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
+import org.eclipse.mylar.bugzilla.core.IBugzillaConstants;
+
+
+/**
+ * Class to persist the data for the favorites list
+ */
+public class FavoritesFile
+{
+ /** The file that the favorites are written to */
+ private File file;
+
+ /** The directory to where the file is located */
+ /** A list of favorites */
+ private ArrayList<Favorite> list = new ArrayList<Favorite>();
+
+
+ /** Sort by bug ID */
+ public static final int ID_SORT = 0;
+
+ /** Sort by bug priority */
+ public static final int PRIORITY_SORT = 1;
+
+ /** Sort by bug priority */
+ public static final int SEVERITY_SORT = 2;
+
+ /** Sort by bug state */
+ public static final int STATE_SORT = 3;
+
+ /** Default sort by bug ID */
+ public static int lastSel = 0;
+
+ /**
+ * Constructor that reads the favorites data persisted in the plugin's state
+ * directory, if it exists.
+ *
+ * @param file
+ * The file where the favorites are persisted
+ * @throws IOException
+ * Error opening or closing the favorites file
+ * @throws ClassNotFoundException
+ * Error deserializing objects from the favorites file
+ */
+ public FavoritesFile(File file) throws ClassNotFoundException, IOException {
+ this.file = file;
+ if (file.exists()) {
+ readFile();
+ }
+ }
+
+ /**
+ * Add a favorite to the favorites list
+ * @param entry The bug to add
+ */
+ public void add(Favorite entry) {
+ // add the entry to the list and write the file to disk
+ list.add(entry);
+ writeFile();
+ }
+
+ /**
+ * Find a bug in the favorites list
+ * @param id The bug id that we are looking for
+ * @return The index of the bug in the array if it exists, else 0
+ */
+ public int find(int id) {
+ for (int i = 0; i < list.size(); i++) {
+ Favorite currFav = list.get(i);
+ if (currFav.getId() == id)
+ return i;
+ }
+ return 0;
+ }
+
+ /**
+ * Get the list of favorites
+ * @return The list of favorites
+ */
+ public ArrayList<Favorite> elements() {
+ return list;
+ }
+
+ /**
+ * Write the favorites to disk
+ */
+ 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());
+
+ // 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 favorites file.");
+ BugzillaPlugin.log(e);
+ }
+ }
+
+ /**
+ * Read the favorites in from the file on disk
+ *
+ * @throws IOException
+ * Error opening or closing the favorites file
+ * @throws ClassNotFoundException
+ * Error deserializing objects from the favorites file
+ */
+ private void readFile() throws ClassNotFoundException, IOException {
+ ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
+
+ // get the number of favorites in the file
+ int size = in.readInt();
+
+ // read in each of the favorites in the file
+ for (int nX = 0; nX < size; nX++) {
+ Favorite item = (Favorite) in.readObject();
+ // add the favorite to the favorites list
+ list.add(item);
+ }
+ in.close();
+
+ sort(lastSel);
+ }
+
+ /**
+ * Remove some bugs from the favorites list
+ * @param indicesToRemove An array of the indicies of the bugs to be removed
+ */
+ public void remove(List<Favorite> sel) {
+ list.removeAll(sel);
+
+ // rewrite the file so that the data is persistant
+ writeFile();
+ }
+
+ /**
+ * Remove all of the items in the favortes menu
+ */
+ public void removeAll() {
+ list.clear();
+
+ // rewrite the file so that the data is persistant
+ writeFile();
+ }
+
+ /**
+ * Function to sort the favorites list
+ * @param sortOrder The way to sort the bugs in the favorites list
+ */
+ public void sort(int sortOrder) {
+ Favorite[] a = list.toArray(new Favorite[list.size()]);
+
+ // decide which sorting method to use and sort the favorites
+ switch(sortOrder) {
+ case ID_SORT:
+ Arrays.sort(a, new SortID());
+ lastSel = ID_SORT;
+ break;
+ case PRIORITY_SORT:
+ Arrays.sort(a, new SortPriority());
+ lastSel = PRIORITY_SORT;
+ break;
+
+ case SEVERITY_SORT:
+ Arrays.sort(a, new SortSeverity());
+ lastSel = SEVERITY_SORT;
+ break;
+
+ case STATE_SORT:
+ Arrays.sort(a, new SortState());
+ lastSel = STATE_SORT;
+ break;
+ }
+
+ // remove all of the elements from the list so that we can re-add
+ // them in a sorted order
+ list.clear();
+
+ // add the sorted elements to the list and the table
+ for (int j = 0; j < a.length; j++) {
+ add(a[j]);
+ }
+ }
+
+ /**
+ * Inner class to sort by bug id
+ */
+ private class SortID implements Comparator<Favorite> {
+ /**
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(Favorite f1, Favorite f2) {
+ Integer id1 = (Integer) f1.getAttributes().get(IBugzillaConstants.HIT_MARKER_ATTR_ID);
+ Integer id2 = (Integer) f2.getAttributes().get(IBugzillaConstants.HIT_MARKER_ATTR_ID);
+
+ if(id1 != null && id2 != null)
+ return id1.compareTo(id2);
+ else if(id1 == null && id2 != null)
+ return -1;
+ else if(id1 != null && id2 == null)
+ return 1;
+ else
+ return 0;
+ }
+ }
+
+ /**
+ * Inner class to sort by priority
+ */
+ private class SortPriority implements Comparator<Favorite>
+ {
+ /*
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(Favorite f1, Favorite f2) {
+ Integer pri1 = (Integer) f1.getAttributes().get(IBugzillaConstants.HIT_MARKER_ATTR_PRIORITY);
+ Integer pri2 = (Integer) f2.getAttributes().get(IBugzillaConstants.HIT_MARKER_ATTR_PRIORITY);
+
+ if(pri1 != null && pri2 != null)
+ return pri1.compareTo(pri2);
+ else if(pri1 == null && pri2 != null)
+ return -1;
+ else if(pri1 != null && pri2 == null)
+ return 1;
+ else
+ return 0;
+ }
+ }
+
+ /**
+ * Inner class to sort by severity
+ */
+ private class SortSeverity implements Comparator<Favorite> {
+ /*
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(Favorite f1, Favorite f2) {
+ Integer sev1 = (Integer) f1.getAttributes().get(IBugzillaConstants.HIT_MARKER_ATTR_SEVERITY);
+ Integer sev2 = (Integer) f2.getAttributes().get(IBugzillaConstants.HIT_MARKER_ATTR_SEVERITY);
+
+ if(sev1 != null && sev2 != null)
+ return sev1.compareTo(sev2);
+ else if(sev1 == null && sev2 != null)
+ return -1;
+ else if(sev1 != null && sev2 == null)
+ return 1;
+ else
+ return 0;
+ }
+ }
+
+ /**
+ * Inner class to sort by state
+ */
+ private class SortState implements Comparator<Favorite>
+ {
+ /*
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(Favorite f1, Favorite f2) {
+ Integer sta1 = (Integer) f1.getAttributes().get(IBugzillaConstants.HIT_MARKER_ATTR_STATE);
+ Integer sta2 = (Integer) f2.getAttributes().get(IBugzillaConstants.HIT_MARKER_ATTR_STATE);
+
+ if(sta1 != null && sta2 != null)
+ {
+ int rc = sta1.compareTo(sta2);
+ if(rc == 0)
+ {
+ Integer res1 = (Integer) f1.getAttributes().get(IBugzillaConstants.HIT_MARKER_ATTR_RESULT);
+ Integer res2 = (Integer) f2.getAttributes().get(IBugzillaConstants.HIT_MARKER_ATTR_RESULT);
+
+ return res1.compareTo(res2);
+ }
+ else
+ return rc;
+ }
+ else if(sta1 == null && sta2 != null)
+ return -1;
+ else if(sta1 != null && sta2 == null)
+ return 1;
+ else
+ return 0;
+ }
+ }
+}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/AbstractFavoritesAction.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/AbstractFavoritesAction.java
new file mode 100644
index 000000000..2caf881be
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/AbstractFavoritesAction.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2003 - 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.bugzilla.ui.favorites.actions;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * Class that contains shared functions for the favorites actions
+ */
+public class AbstractFavoritesAction extends Action
+{
+
+ /**
+ * Set the actions icon
+ * @param filename The icons file
+ */
+ protected void setIcon(String filename)
+ {
+ URL url = null;
+ try
+ {
+ // try to change the default icon
+ url = new URL(BugzillaPlugin.getDefault().getBundle().getEntry("/"), filename);
+ setImageDescriptor(ImageDescriptor.createFromURL(url));
+ }
+ catch (MalformedURLException e)
+ {
+ // Simply don't change the default icon
+ }
+ }
+
+ /**
+ * Convienience method for getting the current shell
+ * @return The current shell
+ */
+ protected Shell getShell()
+ {
+ return BugzillaPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
+ }
+
+}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/AddFavoriteAction.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/AddFavoriteAction.java
new file mode 100644
index 000000000..68846e25a
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/AddFavoriteAction.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2003 - 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.bugzilla.ui.favorites.actions;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
+import org.eclipse.mylar.bugzilla.core.IBugzillaConstants;
+import org.eclipse.mylar.bugzilla.core.search.BugzillaSearchResultView;
+import org.eclipse.mylar.bugzilla.ui.FavoritesView;
+import org.eclipse.mylar.bugzilla.ui.favorites.Favorite;
+
+
+/**
+ * Bookmark a returned Bugzilla Search result.
+ */
+public class AddFavoriteAction extends AbstractFavoritesAction {
+
+ /** Selected objects */
+ private List<Favorite> selected;
+
+ /** The view where the Bugzilla search results are displayed */
+ private BugzillaSearchResultView resultView;
+
+ /**
+ * Constructor
+ * @param text The label for the context menu item
+ * @param resultView The view where the Bugzilla search results are displayed
+ */
+ public AddFavoriteAction(String text, BugzillaSearchResultView resultView) {
+ setText(text);
+ setIcon("icons/elcl16/bug-favorite.gif");
+ this.resultView = resultView;
+ selected = null;
+ }
+
+ /**
+ * Bookmark the selected items
+ * @see org.eclipse.ui.actions.ActionDelegate#run(IAction)
+ */
+ @Override
+ public void run()
+ {
+ FavoritesView.checkWindow();
+
+ selected = new ArrayList<Favorite>();
+ buildSelection();
+
+ // go through each of the selected items and add its data to the favorites file
+ for (int i = 0; i < selected.size(); i++)
+ {
+ BugzillaPlugin.getDefault().getFavorites().add(selected.get(i));
+ }
+ FavoritesView.add();
+ FavoritesView.updateActionEnablement();
+ }
+
+ /**
+ * Gets the entire selection and puts each bug report into a list. Only the
+ * relevent parts of each bug report are put into the list.
+ */
+ @SuppressWarnings("unchecked")
+ private void buildSelection() {
+ ISelection s = resultView.getViewer().getSelection();
+ if (s instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection) s;
+ for (Iterator<IMarker> it = selection.iterator(); it.hasNext();) {
+ IMarker marker = it.next();
+
+ try
+ {
+ // try to get the attribute for the marker
+ Integer attributeId = (Integer) marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_ID);
+ // add the selected item to the list of items that are selected
+ String description = (String) marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_DESC);
+ String query = (String) marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_QUERY);
+
+ // create a map to add attributes to so that the favorites file can sort
+ HashMap<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(IBugzillaConstants.HIT_MARKER_ATTR_ID, attributeId);
+ attributes.put(IBugzillaConstants.HIT_MARKER_ATTR_PRIORITY, marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_PRIORITY));
+ attributes.put(IBugzillaConstants.HIT_MARKER_ATTR_SEVERITY, marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_SEVERITY));
+ attributes.put(IBugzillaConstants.HIT_MARKER_ATTR_STATE, marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_STATE));
+ attributes.put(IBugzillaConstants.HIT_MARKER_ATTR_RESULT, marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_RESULT));
+
+ Favorite favorite = new Favorite(BugzillaPlugin.getDefault().getServerName(), attributeId.intValue(), description, query, attributes);
+ selected.add(favorite);
+ }
+ catch (CoreException ignored)
+ {
+ // do nothing
+ }
+ }
+ }
+ }
+
+}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/AddToFavoritesAction.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/AddToFavoritesAction.java
new file mode 100644
index 000000000..263bdc4ca
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/AddToFavoritesAction.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2003 - 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.bugzilla.ui.favorites.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.mylar.bugzilla.core.BugzillaImages;
+import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
+import org.eclipse.mylar.bugzilla.ui.FavoritesView;
+import org.eclipse.mylar.bugzilla.ui.editor.ExistingBugEditorInput;
+import org.eclipse.mylar.bugzilla.ui.favorites.Favorite;
+import org.eclipse.ui.part.EditorPart;
+
+
+/**
+ * Action used to add the supplied editor's bug to the favorites list.
+ */
+public class AddToFavoritesAction extends Action {
+ private EditorPart editorPart;
+
+ /**
+ * Creates a new <code>AddToFavoritesAction</code>.
+ *
+ * @param editor
+ * The editor for the bug that is being added to the favorites
+ * list.
+ */
+ public AddToFavoritesAction(EditorPart editor) {
+ editorPart = editor;
+ setText("&Add to favorites");
+ setImageDescriptor(BugzillaImages.IMG_TOOL_ADD_TO_FAVORITES);
+ }
+
+ @Override
+ public void run() {
+ ExistingBugEditorInput input = (ExistingBugEditorInput) editorPart.getEditorInput();
+ Favorite entry = new Favorite(input.getBug());
+ FavoritesView.checkWindow();
+ BugzillaPlugin.getDefault().getFavorites().add(entry);
+ FavoritesView.add();
+ }
+}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/DeleteFavoriteAction.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/DeleteFavoriteAction.java
new file mode 100644
index 000000000..49829d002
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/DeleteFavoriteAction.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2003 - 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.bugzilla.ui.favorites.actions;
+
+import org.eclipse.mylar.bugzilla.ui.FavoritesView;
+
+/**
+ * Action of removing a bookmark
+ */
+public class DeleteFavoriteAction extends AbstractFavoritesAction
+{
+ /** The instance of the favorites view */
+ private FavoritesView view;
+
+ /** True if all of the bookmarks are to be deleted */
+ private boolean deleteAll;
+
+ /**
+ * Constructor
+ * @param favoritesView The favorites view being used
+ * @param deleteAllFavorites <code>true</code> if all of the favorites should be deleted, else <code>false</code>
+ */
+ public DeleteFavoriteAction(FavoritesView favoritesView, boolean deleteAllFavorites)
+ {
+ deleteAll = deleteAllFavorites;
+
+ // set the appropriate icons and tool tips for the action depending
+ // on whether it will delete all items or not
+ if (deleteAll)
+ {
+ setToolTipText("Remove all favorites");
+ setText("Remove all");
+ setIcon("icons/remove-all.gif");
+ }
+ else
+ {
+ setToolTipText( "Remove selected favorites" );
+ setText( "Remove" );
+ setIcon( "icons/remove.gif" );
+ }
+
+ view = favoritesView;
+ }
+
+ /**
+ * Delete the appropriate favorites
+ * @see org.eclipse.jface.action.IAction#run()
+ */
+ @Override
+ public void run()
+ {
+ FavoritesView.checkWindow();
+
+ // call the appropriate delete function
+ if (deleteAll)
+ view.deleteAllFavorites();
+ else
+ view.deleteSelectedFavorites();
+ FavoritesView.updateActionEnablement();
+ }
+}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/ViewFavoriteAction.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/ViewFavoriteAction.java
new file mode 100644
index 000000000..f83e5bb4b
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/favorites/actions/ViewFavoriteAction.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2003 - 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.bugzilla.ui.favorites.actions;
+
+import java.util.List;
+
+import org.eclipse.mylar.bugzilla.ui.BugzillaOpenStructure;
+import org.eclipse.mylar.bugzilla.ui.FavoritesView;
+import org.eclipse.mylar.bugzilla.ui.ViewBugzillaAction;
+
+
+/**
+ * View a bug from the favorites menu
+ */
+public class ViewFavoriteAction extends AbstractFavoritesAction
+{
+
+ /** The view to get the result to launch a viewer on */
+ private FavoritesView view;
+
+ /**
+ * Constructor
+ * @param resultsView The view to launch a viewer on
+ */
+ public ViewFavoriteAction( FavoritesView resultsView )
+ {
+ setToolTipText( "View selected favorites" );
+ setText( "View selected" );
+ setIcon( "icons/openresult.gif" );
+ view = resultsView;
+ }
+
+ /**
+ * View the selected bugs in the editor window
+ * @see org.eclipse.jface.action.IAction#run()
+ */
+ @Override
+ public void run()
+ {
+ FavoritesView.checkWindow();
+ List<BugzillaOpenStructure> selectedBugs = view.getBugIdsOfSelected();
+
+ // if there are some selected bugs view the bugs in the editor window
+ if (!selectedBugs.isEmpty())
+ {
+ ViewBugzillaAction viewBugs = new ViewBugzillaAction("Display bugs in editor", selectedBugs);
+ viewBugs.schedule();
+ }
+ }
+}
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 c8ae32c23..e5c8f1ba9 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
@@ -13,8 +13,8 @@ package org.eclipse.mylar.bugzilla.ui.outline;
import java.util.ArrayList;
import java.util.Iterator;
-import org.eclipse.mylar.bugzilla.BugzillaImages;
import org.eclipse.mylar.bugzilla.core.BugReport;
+import org.eclipse.mylar.bugzilla.core.BugzillaImages;
import org.eclipse.mylar.bugzilla.core.Comment;
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
import org.eclipse.mylar.bugzilla.ui.wizard.NewBugModel;
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/query/GetQueryDialog.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/query/GetQueryDialog.java
new file mode 100644
index 000000000..37a9ba2f4
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/query/GetQueryDialog.java
@@ -0,0 +1,203 @@
+/*******************************************************************************
+ * Copyright (c) 2003 - 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.bugzilla.ui.query;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.mylar.bugzilla.core.search.BugzillaSearchPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * Dialog to display, manage and run stored queries.
+ */
+public class GetQueryDialog extends Dialog
+{
+
+ /** The Ok button. */
+ private Button okButton;
+
+ /** The title of the dialog. */
+ private String title;
+
+ private SavedQueryFile input;
+
+ public GetQueryDialog(Shell parentShell, String dialogTitle, SavedQueryFile in) {
+ super(parentShell);
+ this.title = dialogTitle;
+ input = in;
+ setShellStyle(SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+ }
+
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setText(title);
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ // create OK and Details buttons
+ okButton = createButton(parent, IDialogConstants.OK_ID, "Run", true);
+ okButton.setEnabled(false);
+ createButton(parent, IDialogConstants.CANCEL_ID, "Close", false);
+ }
+
+ /**
+ * Creates the list widget to display stored queries.
+ */
+ @Override
+ final protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite)super.createDialogArea(parent);
+
+ createMainDialogArea(composite);
+
+ return composite;
+ }
+
+ protected void createMainDialogArea(Composite parent) {
+ Label label = new Label(parent, SWT.LEFT);
+ label.setText("Select a saved query:");
+ rememberPattern = new List(parent, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
+ ArrayList<String> names = input.getNames();
+ int pos = 0;
+
+ for (Iterator<String> it = names.iterator(); it.hasNext(); ) {
+ rememberPattern.add(it.next(), pos);
+ pos++;
+ }
+
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 5;
+ gd.heightHint = 60;
+
+ rememberPattern.setLayoutData(gd);
+ rememberPattern.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ selIndex = rememberPattern.getSelectionIndex();
+ okButton.setEnabled(selIndex >= 0);
+ }
+ });
+ rememberPattern.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ okPressed();
+ }
+ });
+
+ // Configure the context menu
+ MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
+ menuMgr.add(new RunQueryAction("&Run query"));
+ menuMgr.add(new Separator());
+ menuMgr.add(new RemoveAction("Remo&ve"));
+ menuMgr.add(new RemoveAllAction("Remove &all"));
+ Menu menu = menuMgr.createContextMenu(rememberPattern);
+ rememberPattern.setMenu(menu);
+
+ }
+
+ final protected void setPageComplete(boolean complete) {
+ if (okButton != null) {
+ okButton.setEnabled(complete);
+ }
+ }
+
+ private String queryNameText;
+
+ private List rememberPattern;
+
+ public String getText() {
+ return queryNameText;
+ }
+
+ /**
+ * Deletes a selected named query.
+ */
+ private void remove() {
+ int index = rememberPattern.getSelectionIndex();
+ if(index != -1)
+ BugzillaSearchPage.getInput().remove(new int []{index});
+ rememberPattern.remove(index);
+ rememberPattern.setSelection(-1);
+ selIndex = -1;
+ okButton.setEnabled(false);
+ }
+
+ private void removeAll() {
+ BugzillaSearchPage.getInput().removeAll();
+ rememberPattern.removeAll();
+ rememberPattern.setSelection(-1);
+ selIndex = -1;
+ okButton.setEnabled(false);
+ }
+
+ /** Index of the selected query, or -1 if none. */
+ int selIndex = -1;
+
+ /**
+ * Returns index of the selected query or -1 if none are selected.
+ */
+ public int getSelected() {
+ return selIndex;
+ }
+
+ private class RunQueryAction extends Action {
+ RunQueryAction(String text) {
+ super(text);
+ }
+
+ @Override
+ public void run() {
+ GetQueryDialog.this.okPressed();
+ }
+ }
+
+ private class RemoveAction extends Action {
+ RemoveAction(String text) {
+ super(text);
+ }
+
+ @Override
+ public void run() {
+ GetQueryDialog.this.remove();
+ }
+ }
+
+ private class RemoveAllAction extends Action {
+ RemoveAllAction(String text) {
+ super(text);
+ }
+
+ @Override
+ public void run() {
+ GetQueryDialog.this.removeAll();
+ }
+ }
+}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/query/SaveQueryDialog.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/query/SaveQueryDialog.java
new file mode 100644
index 000000000..e8788c59c
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/query/SaveQueryDialog.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2003 - 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.bugzilla.ui.query;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Dialog for naming a saved query.
+ */
+public class SaveQueryDialog extends Dialog
+{
+ private Text queryName;
+
+ /**
+ * The Ok button.
+ */
+ private Button okButton;
+
+ /**
+ * The title of the dialog.
+ */
+ private String title;
+
+ public SaveQueryDialog(Shell parentShell, String dialogTitle) {
+ super(parentShell);
+ this.title = dialogTitle;
+ setShellStyle(SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+ }
+
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setText(title);
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ // create OK and cancel buttons
+ okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
+ okButton.setEnabled(false);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ // create composite
+ Composite composite = (Composite)super.createDialogArea(parent);
+
+ createMainDialogArea(composite);
+ return composite;
+ }
+
+ protected void createMainDialogArea(Composite parent) {
+ queryName = new Text(parent, SWT.SINGLE | SWT.BORDER);
+ queryName.setLayoutData(new GridData(GridData.BEGINNING | GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
+ queryName.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ if (queryName.getText().compareTo("") != 0 && queryName.getText() != null)
+ okButton.setEnabled(true);
+ else
+ okButton.setEnabled(false);
+ queryNameText = queryName.getText();
+ }
+ });
+ }
+
+ String queryNameText;
+
+ public String getText() {
+ return queryNameText;
+ }
+}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/query/SavedQueryFile.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/query/SavedQueryFile.java
new file mode 100644
index 000000000..11da9d2df
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/query/SavedQueryFile.java
@@ -0,0 +1,249 @@
+/*******************************************************************************
+ * Copyright (c) 2003 - 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.bugzilla.ui.query;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
+
+
+/**
+ * This class manages accessing and persisting named Bugzilla queries.
+ */
+public class SavedQueryFile
+{
+ /** The file that the queries are written to */
+ private File file;
+
+ /** The directory to where the file is located */
+ private File directory;
+
+ /** A list of remembered queries */
+ private ArrayList<String> list = new ArrayList<String>();
+ private ArrayList<String> nameList = new ArrayList<String>();
+ private ArrayList<String> sumList = new ArrayList<String>();
+
+ /**
+ * Constructor
+ * @param dirPath The path to the directory where the favorites file should be written to
+ * @param fileName The file that the favorites should be written to
+ */
+ public SavedQueryFile(String dirPath, String fileName)
+ {
+ // create a new file and if it exists, read the data from the file
+ // else create the file and directories if they dont exist
+ file = new File(dirPath + fileName);
+ if (file.exists()) {
+ readFile();
+ }
+ else {
+ directory = new File(dirPath);
+ if (!directory.exists())
+ directory.mkdirs();
+ writeFile();
+ }
+ }
+
+ /**
+ * Add a query to the list
+ * @param entry The query to add
+ */
+ public int add(String entry, String name, String sum)
+ {
+ // add the entry to the list and write the file to disk
+ int index = find(name);
+ if (index == -1) {
+ list.add(entry);
+ nameList.add(name);
+ sumList.add(sum);
+ writeFile();
+ }
+ else {
+ boolean isDuplicate = MessageDialog.openConfirm(BugzillaPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Save Bugzilla Query",
+ name + " already exists. Do you want to replace it?");
+ if (isDuplicate) {
+ list.add(index, entry);
+ nameList.add(index,name);
+ sumList.add(index,sum);
+ list.remove(index+1);
+ nameList.remove(index+1);
+ sumList.remove(index+1);
+ writeFile();
+ }
+ }
+
+ index = find(entry);
+ return index;
+ }
+
+
+ /**
+ * Find a bug in the query list
+ * @param name The name of the query that we are looking for
+ * @return The index of the query in the array if it exists, else -1
+ */
+ public int find(String name)
+ {
+ for (int i = 0; i < list.size(); i++) {
+ String str = nameList.get(i);
+ if (name.compareTo(str) == 0)
+ return i;
+ }
+ return -1;
+ }
+
+ /**
+ * Get the list of queries
+ * @return The list of queries
+ */
+ public ArrayList<String> elements()
+ {
+ return list;
+ }
+
+ /**
+ * Write the queries to disk
+ */
+ private void writeFile()
+ {
+ try {
+ OutputStream os = new FileOutputStream(file);
+ DataOutputStream data = new DataOutputStream(os);
+
+ // Write the size of the list so that we can read it back in easier
+ data.writeInt(list.size());
+
+ // write each element in the array list
+ for (int i = 0; i < list.size(); i++) {
+ String item = list.get(i);
+ String itemName = nameList.get(i);
+ String summary = sumList.get(i);
+
+ // write the string in a machine independant manner
+ data.writeUTF(item);
+ data.writeUTF(itemName);
+ data.writeUTF(summary);
+ }
+
+ // close the file
+ data.close();
+ }
+ catch (IOException e) {
+ // put up a message and log the error if there is a problem writing to the file
+ BugzillaPlugin.getDefault().logAndShowExceptionDetailsDialog(e, "occurred while saving your Bugzilla queries", "I/O Error");
+ }
+ }
+
+ /**
+ * Read the queries in from the file on disk
+ */
+ private void readFile()
+ {
+ try {
+ InputStream is = new FileInputStream(file);
+ DataInputStream data = new DataInputStream(is);
+
+ // get the number of favorites in the file
+ int size = data.readInt();
+
+ // read in each of the favorites in the file
+ for (int nX = 0; nX < size; nX++) {
+ String item, name, summary;
+
+ // get the data from disk in a machine independant way
+ item = data.readUTF();
+ name = data.readUTF();
+ summary = data.readUTF();
+
+ // add the favorite to the favorites list
+ list.add(item);
+ nameList.add(name);
+ sumList.add(summary);
+ }
+
+ // close the input stream
+ data.close();
+ }
+ catch (IOException e) {
+ // put up a message and log the error if there is a problem reading from the file
+ BugzillaPlugin.getDefault().logAndShowExceptionDetailsDialog(e, "occurred while restoring saved Bugzilla queries.", "I/O Error");
+ }
+ }
+
+ /**
+ * Remove some queries from the list
+ * @param indicesToRemove An array of the indicies of the queries to be removed
+ */
+ public void remove(int[] indicesToRemove)
+ {
+ int timesShifted = 0;
+
+ // remove each of the indicated items from the array
+ for (int i = 0; i < indicesToRemove.length; i++) {
+ list.remove(indicesToRemove[i] - timesShifted);
+ nameList.remove(indicesToRemove[i] - timesShifted);
+ sumList.remove(indicesToRemove[i] - timesShifted);
+ timesShifted++;
+ }
+
+ // rewrite the file so that the data is persistant
+ writeFile();
+
+ // remove the items from the combo box
+ timesShifted = 0;
+ }
+
+ /**
+ * Remove all of the items in the favortes menu
+ */
+ public void removeAll() {
+ // remove every element from the favorites list
+ while (list.size() > 0) {
+ list.remove(0);
+ nameList.remove(0);
+ sumList.remove(0);
+ }
+
+ // rewrite the file so that the data is persistant
+ writeFile();
+ }
+
+ /**
+ * Get the query parameters of the currently selected remembered query
+ * @return The query url
+ */
+ public String getQueryParameters(int index) {
+ return list.get(index);
+ }
+
+ /**
+ * Get the summary text of the currently selected remembered query
+ * @return The summary text
+ */
+ public String getSummaryText(int index) {
+ return sumList.get(index);
+
+ }
+
+ public ArrayList<String> getNames() {
+ return nameList;
+ }
+}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/wizard/AbstractBugWizard.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/wizard/AbstractBugWizard.java
index 4aaa5c6a0..e52831098 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/wizard/AbstractBugWizard.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/wizard/AbstractBugWizard.java
@@ -19,12 +19,12 @@ import javax.security.auth.login.LoginException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.mylar.bugzilla.BugzillaPlugin;
-import org.eclipse.mylar.bugzilla.BugzillaPreferences;
-import org.eclipse.mylar.bugzilla.IBugzillaConstants;
import org.eclipse.mylar.bugzilla.core.Attribute;
import org.eclipse.mylar.bugzilla.core.BugPost;
import org.eclipse.mylar.bugzilla.core.BugzillaException;
+import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
+import org.eclipse.mylar.bugzilla.core.BugzillaPreferences;
+import org.eclipse.mylar.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.bugzilla.ui.editor.ExistingBugEditorInput;
import org.eclipse.search.internal.ui.SearchMessages;
import org.eclipse.search.internal.ui.util.ExceptionHandler;
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/wizard/NewBugWizard.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/wizard/NewBugWizard.java
index 5e5178d28..48e3393db 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/wizard/NewBugWizard.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/wizard/NewBugWizard.java
@@ -15,7 +15,7 @@ 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.BugzillaPlugin;
import org.eclipse.mylar.bugzilla.core.BugzillaRepository;
import org.eclipse.mylar.bugzilla.ui.OfflineView;
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/wizard/WizardProductPage.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/wizard/WizardProductPage.java
index 45fc32384..682cd66e6 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/wizard/WizardProductPage.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/wizard/WizardProductPage.java
@@ -13,7 +13,7 @@ package org.eclipse.mylar.bugzilla.ui.wizard;
import java.util.Iterator;
import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.mylar.bugzilla.BugzillaPlugin;
+import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
import org.eclipse.mylar.bugzilla.core.BugzillaRepository;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IWorkbench;

Back to the top