diff options
21 files changed, 503 insertions, 203 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugReport.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugReport.java index e125e9a40..283436dad 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugReport.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugReport.java @@ -74,6 +74,8 @@ public class BugReport implements Serializable, IBugzillaBug { /** Whether or not this bug report is saved offline. */ protected boolean savedOffline = false; + protected boolean hasChanges = false; + /** * Constructor * @param id The id of the bug @@ -407,4 +409,12 @@ public class BugReport implements Serializable, IBugzillaBug { public void setOfflineState(boolean newOfflineState) { savedOffline = newOfflineState; } + + public boolean hasChanges() { + return hasChanges; + } + + public void setHasChanged(boolean b) { + hasChanges = b; + } } diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaPlugin.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaPlugin.java index c1f1cae51..5ce02058f 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaPlugin.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaPlugin.java @@ -19,6 +19,7 @@ import java.net.URLConnection; import java.net.Proxy.Type; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; import java.util.List; import javax.net.ssl.HttpsURLConnection; @@ -32,11 +33,13 @@ import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.mylar.bugzilla.core.IOfflineBugListener.BugzillaOfflineStaus; import org.eclipse.mylar.bugzilla.core.favorites.FavoritesFile; import org.eclipse.mylar.bugzilla.core.internal.ProductConfiguration; import org.eclipse.mylar.bugzilla.core.internal.ProductConfigurationFactory; import org.eclipse.mylar.bugzilla.core.offline.OfflineReportsFile; import org.eclipse.mylar.bugzilla.core.search.IBugzillaResultEditorMatchAdapter; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.eclipse.update.internal.core.UpdateCore; import org.eclipse.update.internal.ui.UpdateUI; @@ -63,6 +66,8 @@ public class BugzillaPlugin extends AbstractUIPlugin { /** The file that contains all of the offline bug reports */ private OfflineReportsFile offlineReportsFile; + private List<IOfflineBugListener> listeners = new ArrayList<IOfflineBugListener>(); + /** Product configuration for the current server */ private ProductConfiguration productConfiguration; @@ -344,4 +349,28 @@ public class BugzillaPlugin extends AbstractUIPlugin { public int getMaxResults() { return getPreferenceStore().getInt(IBugzillaConstants.MAX_RESULTS); } + + public void addOfflineStatusListener(IOfflineBugListener listener){ + if(!listeners.contains(listener)){ + listeners.add(listener); + } + } + + public void removeOfflineStatusListener(IOfflineBugListener listener){ + listeners.remove(listener); + } + + public List<IOfflineBugListener> getOfflineStatusListeners(){ + return listeners; + } + + public void fireOfflineStatusChanged(final IBugzillaBug bug, final BugzillaOfflineStaus status){ + Display.getDefault().asyncExec(new Runnable(){ + public void run() { + for (IOfflineBugListener listener: listeners) { + listener.offlineStatusChange(bug, status); + } + } + }); + } } diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/IBugzillaBug.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/IBugzillaBug.java index 3af1c1975..6b9dadf05 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/IBugzillaBug.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/IBugzillaBug.java @@ -83,4 +83,6 @@ public interface IBugzillaBug extends Serializable { * @param newOfflineState <code>true</code> if this bug is saved offline */ public void setOfflineState(boolean newOfflineState); + + public boolean hasChanges(); } diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/IOfflineBugListener.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/IOfflineBugListener.java new file mode 100644 index 000000000..f9ca44cf7 --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/IOfflineBugListener.java @@ -0,0 +1,12 @@ +package org.eclipse.mylar.bugzilla.core; + + +public interface IOfflineBugListener { + + public enum BugzillaOfflineStaus { + SAVED, SAVED_WITH_OUTGOING_CHANGES, DELETED, SAVED_WITH_INCOMMING_CHANGES, CONFLICT + } + + public void offlineStatusChange(IBugzillaBug bug, BugzillaOfflineStaus status); + +} diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/NewBugModel.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/NewBugModel.java index cea1e7772..d9f811a2c 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/NewBugModel.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/NewBugModel.java @@ -193,4 +193,8 @@ public class NewBugModel implements Serializable, IBugzillaBug { public void setOfflineState(boolean newOfflineState) { savedOffline = newOfflineState; } + + public boolean hasChanges() { + return true; + } } diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/compare/BugzillaCompareNode.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/compare/BugzillaCompareNode.java index 27e05eeda..0461d42fd 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/compare/BugzillaCompareNode.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/compare/BugzillaCompareNode.java @@ -197,7 +197,8 @@ public class BugzillaCompareNode implements IStreamContentAccessor, IStructureCo BugzillaCompareNode attributes = new BugzillaCompareNode("Attributes", null, attributeImage); for (Iterator<Attribute> iter = bug.getAttributes().iterator(); iter.hasNext();) { Attribute attribute = iter.next(); - + if(attribute.getName().compareTo("delta_ts") == 0 || attribute.getName().compareTo("Last Modified") == 0 || attribute.getName().compareTo("longdesclength") == 0) + continue; // Since the bug report may not be saved offline, get the attribute's new // value, which is what is in the submit viewer. attributes.addChild(new BugzillaCompareNode(attribute.getName(), attribute.getNewValue(), attributeImage)); diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/offline/OfflineReportsFile.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/offline/OfflineReportsFile.java index 197090aec..fe713c8a8 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/offline/OfflineReportsFile.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/offline/OfflineReportsFile.java @@ -16,16 +16,24 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; import java.util.List; +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.compare.structuremergeviewer.DiffNode; +import org.eclipse.compare.structuremergeviewer.Differencer; +import org.eclipse.compare.structuremergeviewer.IDiffElement; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.mylar.bugzilla.core.BugReport; import org.eclipse.mylar.bugzilla.core.BugzillaPlugin; import org.eclipse.mylar.bugzilla.core.IBugzillaBug; import org.eclipse.mylar.bugzilla.core.IBugzillaConstants; +import org.eclipse.mylar.bugzilla.core.IOfflineBugListener.BugzillaOfflineStaus; +import org.eclipse.mylar.bugzilla.core.compare.BugzillaCompareInput; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; /** @@ -75,10 +83,74 @@ public class OfflineReportsFile * Add an offline report to the offline reports list * @param entry The bug to add */ - public void add(IBugzillaBug entry) { - // add the entry to the list and write the file to disk - list.add(entry); - writeFile(); + public boolean add(IBugzillaBug entry, boolean saveChosen) { + try{ + BugzillaOfflineStaus status = BugzillaOfflineStaus.SAVED; + // check for bug and do a compare + int index = -1; + if ((index = find(entry.getId())) >= 0) { + IBugzillaBug oldBug = list.get(index); + if(oldBug instanceof BugReport && entry instanceof BugReport && !saveChosen){ + CompareConfiguration config = new CompareConfiguration(); + config.setLeftEditable(false); + config.setRightEditable(false); + config.setLeftLabel("Local Bug Report"); + config.setRightLabel("Remote Bug Report"); + config.setLeftImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT)); + config.setRightImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT)); + final BugzillaCompareInput in = new BugzillaCompareInput(config); + in.setLeft((BugReport)oldBug); + in.setRight((BugReport)entry); + in.setTitle("Bug #" + oldBug.getId()); + PlatformUI.getWorkbench().getProgressService().run(true, true, in); + if(in.getCompareResult() == null){ + return true; + } else if(oldBug.hasChanges()){ + if(!MessageDialog.openQuestion(null, "Update Local Copy", "Local copy of Bug# " + entry.getId() + " Has Changes.\nYour added comment will be saved, but all other changes will be lost .\nDo you want to continue?")){ + return false; + } + ((BugReport)entry).setNewComment(((BugReport)oldBug).getNewComment()); + ((BugReport)entry).setHasChanged(true); + status = BugzillaOfflineStaus.CONFLICT; + } else { + DiffNode node = (DiffNode)in.getCompareResult(); + IDiffElement[] children = node.getChildren(); + if(children.length != 0){ + for (IDiffElement element : children) { + if(((DiffNode)element).getKind() == Differencer.CHANGE){ + status = BugzillaOfflineStaus.SAVED_WITH_INCOMMING_CHANGES; + break; + } + } + } else { + return true; + } + + } + // Display.getDefault().asyncExec(new Runnable(){ + // public void run() { + // + // CompareUI.openCompareDialog(in); + // } + // }); + } + list.remove(index); + } + if(entry.hasChanges() && status != BugzillaOfflineStaus.CONFLICT){ + status = BugzillaOfflineStaus.SAVED_WITH_OUTGOING_CHANGES; + } + // add the entry to the list and write the file to disk + list.add(entry); + writeFile(); + BugzillaPlugin.getDefault().fireOfflineStatusChanged(entry, status); + return true; + } catch (InterruptedException x) { + // cancelled by user + } catch (InvocationTargetException x) { + BugzillaPlugin.log(x); + MessageDialog.openError(null, "Compare Failed", x.getTargetException().getMessage()); + } + return false; } /** @@ -86,6 +158,7 @@ public class OfflineReportsFile * Used when existing offline reports are modified and saved. */ public void update() { + // check for bug and do a compare writeFile(); } @@ -208,83 +281,83 @@ public class OfflineReportsFile writeFile(); } - /** - * Function to sort the offline reports list - * @param sortOrder The way to sort the bugs in the offline reports list - */ - public void sort(int sortOrder) { - IBugzillaBug[] a = list.toArray(new IBugzillaBug[list.size()]); - - // decide which sorting method to use and sort the offline reports - switch(sortOrder) { - case ID_SORT: - Arrays.sort(a, new SortID()); - lastSel = ID_SORT; - break; - case TYPE_SORT: - Arrays.sort(a, new SortType()); - lastSel = TYPE_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]); - } - } +// /** +// * Function to sort the offline reports list +// * @param sortOrder The way to sort the bugs in the offline reports list +// */ +// public void sort(int sortOrder) { +// IBugzillaBug[] a = list.toArray(new IBugzillaBug[list.size()]); +// +// // decide which sorting method to use and sort the offline reports +// switch(sortOrder) { +// case ID_SORT: +// Arrays.sort(a, new SortID()); +// lastSel = ID_SORT; +// break; +// case TYPE_SORT: +// Arrays.sort(a, new SortType()); +// lastSel = TYPE_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<IBugzillaBug> { - public int compare(IBugzillaBug f1, IBugzillaBug f2) { - Integer id1 = f1.getId(); - Integer id2 = f2.getId(); - - 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 bug type (locally created or from the server) - */ - private class SortType implements Comparator<IBugzillaBug> { - public int compare(IBugzillaBug f1, IBugzillaBug f2) { - boolean isLocal1 = f1.isLocallyCreated(); - boolean isLocal2 = f2.isLocallyCreated(); - - if (isLocal1 && !isLocal2) { - return -1; - } - else if (!isLocal1 && isLocal2) { - return 1; - } - - // If they are both the same type, sort by ID - Integer id1 = f1.getId(); - Integer id2 = f2.getId(); - - 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 bug id +// */ +// private class SortID implements Comparator<IBugzillaBug> { +// public int compare(IBugzillaBug f1, IBugzillaBug f2) { +// Integer id1 = f1.getId(); +// Integer id2 = f2.getId(); +// +// 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 bug type (locally created or from the server) +// */ +// private class SortType implements Comparator<IBugzillaBug> { +// public int compare(IBugzillaBug f1, IBugzillaBug f2) { +// boolean isLocal1 = f1.isLocallyCreated(); +// boolean isLocal2 = f2.isLocallyCreated(); +// +// if (isLocal1 && !isLocal2) { +// return -1; +// } +// else if (!isLocal1 && isLocal2) { +// return 1; +// } +// +// // If they are both the same type, sort by ID +// Integer id1 = f1.getId(); +// Integer id2 = f2.getId(); +// +// 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; +// } +// } /** * Saves the given report to the offlineReportsFile, or, if it already @@ -293,7 +366,7 @@ public class OfflineReportsFile * @param bug * The bug to add/update. */ - public static void saveOffline(IBugzillaBug bug) { + public static void saveOffline(IBugzillaBug bug, boolean saveChosen) { OfflineReportsFile file = BugzillaPlugin.getDefault().getOfflineReports(); // If there is already an offline report for this bug, update the file. if (bug.isSavedOffline()) { @@ -308,9 +381,9 @@ public class OfflineReportsFile // MessageDialog.openInformation(null, "Bug's Id is already used.", "There is already a bug saved offline with an identical id."); // return; } - file.add(bug); + file.add(bug, saveChosen); bug.setOfflineState(true); - file.sort(OfflineReportsFile.lastSel); +// file.sort(OfflineReportsFile.lastSel); } } diff --git a/org.eclipse.mylyn.bugzilla.ui/icons/etool16/task-bug-con.gif b/org.eclipse.mylyn.bugzilla.ui/icons/etool16/task-bug-con.gif Binary files differnew file mode 100644 index 000000000..83c6e094d --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.ui/icons/etool16/task-bug-con.gif diff --git a/org.eclipse.mylyn.bugzilla.ui/icons/etool16/task-bug-in.gif b/org.eclipse.mylyn.bugzilla.ui/icons/etool16/task-bug-in.gif Binary files differnew file mode 100644 index 000000000..a62cc75e1 --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.ui/icons/etool16/task-bug-in.gif diff --git a/org.eclipse.mylyn.bugzilla.ui/icons/etool16/task-bug-out.gif b/org.eclipse.mylyn.bugzilla.ui/icons/etool16/task-bug-out.gif Binary files differnew file mode 100644 index 000000000..4b9634f78 --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.ui/icons/etool16/task-bug-out.gif diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/BugzillaImages.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/BugzillaImages.java index 0ff7cdee2..a1234e439 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/BugzillaImages.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/BugzillaImages.java @@ -65,6 +65,10 @@ public class BugzillaImages { public static final ImageDescriptor BUG = create(T_ELCL, "bug.gif"); public static final ImageDescriptor IMG_COMMENT = create(T_ELCL, "bug-comment.gif"); public static final ImageDescriptor TASK_BUGZILLA = create(T_TOOL, "task-bug.gif"); + public static final ImageDescriptor TASK_BUGZILLA_INCOMMING = create(T_TOOL, "task-bug-in.gif");; + public static final ImageDescriptor TASK_BUGZILLA_CONFLICT = create(T_TOOL, "task-bug-con.gif");; + public static final ImageDescriptor TASK_BUGZILLA_OUTGOING = create(T_TOOL, "task-bug-out.gif");; + public static final ImageDescriptor TASK_BUGZILLA_NEW = create(T_TOOL, "task-bug-new.gif"); public static final ImageDescriptor CATEGORY_QUERY = create(T_TOOL, "category-query.gif"); public static final ImageDescriptor CATEGORY_QUERY_NEW = create(T_TOOL, "category-query-new.gif"); @@ -74,7 +78,7 @@ public class BugzillaImages { public static final ImageDescriptor REMOVE = create("", "remove.gif"); public static final ImageDescriptor SELECT_ALL = create("", "selectAll.gif"); public static final ImageDescriptor OPEN = create("", "openresult.gif"); - + private static ImageDescriptor create(String prefix, String name) { diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/BugzillaUiPlugin.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/BugzillaUiPlugin.java index 9f1d35ea2..0d9a2254f 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/BugzillaUiPlugin.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/BugzillaUiPlugin.java @@ -24,6 +24,7 @@ public class BugzillaUiPlugin extends AbstractUIPlugin { private BugzillaTaskListManager bugzillaTaskListManager; private BugzillaRefreshManager bugzillaRefreshManager; + private static BugzillaUiPlugin plugin; @@ -42,6 +43,7 @@ public class BugzillaUiPlugin extends AbstractUIPlugin { BugzillaPlugin.setResultEditorMatchAdapter(new BugzillaResultMatchAdapter()); bugzillaTaskListManager = new BugzillaTaskListManager(); bugzillaRefreshManager = new BugzillaRefreshManager(); + BugzillaPlugin.getDefault().addOfflineStatusListener(bugzillaTaskListManager); } /** diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/OfflineView.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/OfflineView.java index d6d790516..0af2d5795 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/OfflineView.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/OfflineView.java @@ -14,7 +14,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.eclipse.jface.action.Action; import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; @@ -37,6 +36,7 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.mylar.bugzilla.core.BugzillaPlugin; import org.eclipse.mylar.bugzilla.core.IBugzillaBug; import org.eclipse.mylar.bugzilla.core.IBugzillaConstants; +import org.eclipse.mylar.bugzilla.core.IOfflineBugListener.BugzillaOfflineStaus; import org.eclipse.mylar.bugzilla.core.offline.OfflineReportsFile; import org.eclipse.mylar.bugzilla.ui.actions.AbstractOfflineReportsAction; import org.eclipse.mylar.bugzilla.ui.actions.DeleteOfflineReportAction; @@ -51,6 +51,7 @@ import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; @@ -213,13 +214,13 @@ public class OfflineView extends ViewPart { toolbar.add(selectAll); // create actions to handle the sorting of the OfflineReports - sortByIDAction = new SortByAction(OfflineReportsFile.ID_SORT); - sortByIDAction.setText("by &Bug ID"); - sortByIDAction.setToolTipText("Sorts by Bug number"); - - sortByTypeAction = new SortByAction(OfflineReportsFile.TYPE_SORT); - sortByTypeAction.setText("by &Bug Type"); - sortByTypeAction.setToolTipText("Sorts by locally created/from server status"); +// sortByIDAction = new SortByAction(OfflineReportsFile.ID_SORT); +// sortByIDAction.setText("by &Bug ID"); +// sortByIDAction.setToolTipText("Sorts by Bug number"); +// +// sortByTypeAction = new SortByAction(OfflineReportsFile.TYPE_SORT); +// sortByTypeAction.setText("by &Bug Type"); +// sortByTypeAction.setToolTipText("Sorts by locally created/from server status"); // get the menu manager and create a submenu to contain sorting IMenuManager menu = actionBars.getMenuManager(); @@ -227,51 +228,51 @@ public class OfflineView extends ViewPart { // add the sorting actions to the menu bar menu.add(submenu); - submenu.add(sortByIDAction); - submenu.add(sortByTypeAction); +// submenu.add(sortByIDAction); +// submenu.add(sortByTypeAction); - updateSortingState(); +// updateSortingState(); } - /** - * Function to make sure that the appropriate sort is checked - */ - void updateSortingState() { - int curCriterion = OfflineReportsFile.lastSel; - - sortByIDAction.setChecked(curCriterion == OfflineReportsFile.ID_SORT); - sortByTypeAction.setChecked(curCriterion == OfflineReportsFile.TYPE_SORT); - viewer.setInput(viewer.getInput()); - } - - // Sorting actions for the OfflineReports view - SortByAction sortByIDAction, sortByTypeAction/*, sortBySeverityAction, sortByPriorityAction, sortByStatusAction*/; - - /** - * Inner class to handle sorting - * @author Shawn Minto - */ - class SortByAction extends Action { - /** The criteria to sort the OfflineReports menu based on */ - private int criterion; - - /** - * Constructor - * @param criteria The criteria to sort the OfflineReports menu based on - */ - public SortByAction(int criteria) { - this.criterion = criteria; - } - - /** - * Perform the sort - */ - @Override - public void run() { - BugzillaPlugin.getDefault().getOfflineReports().sort(criterion); - updateSortingState(); - } - } +// /** +// * Function to make sure that the appropriate sort is checked +// */ +// void updateSortingState() { +// int curCriterion = OfflineReportsFile.lastSel; +// +// sortByIDAction.setChecked(curCriterion == OfflineReportsFile.ID_SORT); +// sortByTypeAction.setChecked(curCriterion == OfflineReportsFile.TYPE_SORT); +// viewer.setInput(viewer.getInput()); +// } +// +// // Sorting actions for the OfflineReports view +// SortByAction sortByIDAction, sortByTypeAction/*, sortBySeverityAction, sortByPriorityAction, sortByStatusAction*/; + +// /** +// * Inner class to handle sorting +// * @author Shawn Minto +// */ +// class SortByAction extends Action { +// /** The criteria to sort the OfflineReports menu based on */ +// private int criterion; +// +// /** +// * Constructor +// * @param criteria The criteria to sort the OfflineReports menu based on +// */ +// public SortByAction(int criteria) { +// this.criterion = criteria; +// } +// +// /** +// * Perform the sort +// */ +// @Override +// public void run() { +// BugzillaPlugin.getDefault().getOfflineReports().sort(criterion); +// updateSortingState(); +// } +// } /** * Create context menu. @@ -445,9 +446,11 @@ public class OfflineView extends ViewPart { */ @SuppressWarnings("unchecked") public void deleteSelectedOfflineReports() { - List<IBugzillaBug> selection = ((IStructuredSelection)viewer.getSelection()).toList(); + List<IBugzillaBug> selection = ((IStructuredSelection)viewer.getSelection()).toList(); closeOfflineReports(selection); - BugzillaPlugin.getDefault().getOfflineReports().remove(selection); + for (IBugzillaBug bug : selection) { + removeReport(bug); + } viewer.setInput(viewer.getInput()); } @@ -456,7 +459,10 @@ public class OfflineView extends ViewPart { */ public void deleteAllOfflineReports() { closeOfflineReports(BugzillaPlugin.getDefault().getOfflineReports().elements()); - BugzillaPlugin.getDefault().getOfflineReports().removeAll(); + List<IBugzillaBug> reports = new ArrayList<IBugzillaBug>(OfflineReportsFile.getOfflineBugs()); + for (IBugzillaBug bug : reports) { + removeReport(bug); + } viewer.setInput(viewer.getInput()); } @@ -466,28 +472,35 @@ public class OfflineView extends ViewPart { * * @param bug * The bug to add/update. + * @param saveChosen + * This is used to determine a refresh from a user save */ - public static void saveOffline(IBugzillaBug bug) { - OfflineReportsFile file = BugzillaPlugin.getDefault().getOfflineReports(); - // If there is already an offline report for this bug, update the file. - if (bug.isSavedOffline()) { - file.update(); - } - // If this bug has not been saved offline before, add it to the file. - else { - // If there is already an offline report with the same id, don't save this report. - int index = -1; - if ((index = file.find(bug.getId())) >= 0) { - removeReport(getOfflineBugs().get(index)); -// MessageDialog.openInformation(null, "Bug's Id is already used.", "There is already a bug saved offline with an identical id."); -// return; + public static void saveOffline(final IBugzillaBug bug, final boolean saveChosen) { + Display.getDefault().asyncExec(new Runnable(){ + public void run() { + + OfflineReportsFile file = BugzillaPlugin.getDefault().getOfflineReports(); + // If there is already an offline report for this bug, update the file. + if (bug.isSavedOffline()) { + file.update(); + } + // If this bug has not been saved offline before, add it to the file. + else { + // If there is already an offline report with the same id, don't save this report. + // int index = -1; + // if ((index = file.find(bug.getId())) >= 0) { + // removeReport(getOfflineBugs().get(index)); + // MessageDialog.openInformation(null, "Bug's Id is already used.", "There is already a bug saved offline with an identical id."); + // return; + // } + file.add(bug, saveChosen); + bug.setOfflineState(true); + // file.sort(OfflineReportsFile.lastSel); + } + OfflineView.checkWindow(); + OfflineView.refreshView(); } - file.add(bug); - bug.setOfflineState(true); - file.sort(OfflineReportsFile.lastSel); - } - OfflineView.checkWindow(); - OfflineView.refreshView(); + }); } public static List<IBugzillaBug> getOfflineBugs(){ @@ -502,6 +515,8 @@ public class OfflineView extends ViewPart { * The report to remove. */ public static void removeReport(IBugzillaBug bug) { + BugzillaPlugin.getDefault().fireOfflineStatusChanged(bug, BugzillaOfflineStaus.DELETED); + ArrayList<IBugzillaBug> bugList = new ArrayList<IBugzillaBug>(); bugList.add(bug); BugzillaPlugin.getDefault().getOfflineReports().remove(bugList); @@ -515,6 +530,15 @@ public class OfflineView extends ViewPart { } } + public static IBugzillaBug find(int bugId) { + int location = BugzillaPlugin.getDefault().getOfflineReports().find(bugId); + if(location != -1){ + return BugzillaPlugin.getDefault().getOfflineReports().elements().get(location); + } + return null; + } + + /** * @see SelectionListener#widgetSelected(SelectionEvent) */ diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/editor/AbstractBugEditor.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/editor/AbstractBugEditor.java index c783107ae..ccdc070da 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/editor/AbstractBugEditor.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/editor/AbstractBugEditor.java @@ -48,6 +48,7 @@ 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.core.IBugzillaReportSelection; +import org.eclipse.mylar.bugzilla.core.IOfflineBugListener.BugzillaOfflineStaus; import org.eclipse.mylar.bugzilla.ui.BugzillaUITools; import org.eclipse.mylar.bugzilla.ui.OfflineView; import org.eclipse.mylar.bugzilla.ui.outline.BugzillaOutlineNode; @@ -447,6 +448,7 @@ public abstract class AbstractBugEditor extends EditorPart implements Listener { infoArea.setLayout(infoLayout); infoArea.setBackground(background); if (getBug() == null) { + close(); MessageDialog.openError(infoArea.getShell(), "No such bug", "No bug exists with this id"); return null; @@ -1281,8 +1283,17 @@ public abstract class AbstractBugEditor extends EditorPart implements Listener { */ public void saveBug() { updateBug(); + + IBugzillaBug bug = getBug(); + + if(bug.hasChanges()){ + BugzillaPlugin.getDefault().fireOfflineStatusChanged(bug, BugzillaOfflineStaus.SAVED_WITH_OUTGOING_CHANGES); + } else { + BugzillaPlugin.getDefault().fireOfflineStatusChanged(bug, BugzillaOfflineStaus.SAVED); + } + changeDirtyStatus(false); - OfflineView.saveOffline(getBug()); + OfflineView.saveOffline(getBug(), true); OfflineView.checkWindow(); OfflineView.refreshView(); } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/editor/ExistingBugEditor.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/editor/ExistingBugEditor.java index 4f7d3f4b8..3c24c01e3 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/editor/ExistingBugEditor.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/editor/ExistingBugEditor.java @@ -693,17 +693,28 @@ public class ExistingBugEditor extends AbstractBugEditor // go through all of the attributes and update the main values to the new ones for (Iterator<Attribute> it = bug.getAttributes().iterator(); it.hasNext(); ) { Attribute a = it.next(); + if(a.getNewValue().compareTo(a.getValue()) != 0){ + bug.setHasChanged(true); + } a.setValue(a.getNewValue()); + } - + if(bug.getNewComment().compareTo(bug.getNewNewComment()) != 0){ + bug.setHasChanged(true); + } + // Update some other fields as well. bug.setNewComment(bug.getNewNewComment()); + } @Override protected void restoreBug() { + if(bug == null) + return; + // go through all of the attributes and restore the new values to the main ones for (Iterator<Attribute> it = bug.getAttributes().iterator(); it.hasNext(); ) { Attribute a = it.next(); diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTask.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTask.java index 5f24e0e9b..aaae8c5df 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTask.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTask.java @@ -14,9 +14,7 @@ package org.eclipse.mylar.bugzilla.ui.tasklist; import java.io.IOException; -import java.util.ArrayList; import java.util.Date; -import java.util.List; import javax.security.auth.login.LoginException; @@ -32,7 +30,6 @@ import org.eclipse.mylar.bugzilla.core.BugzillaPlugin; import org.eclipse.mylar.bugzilla.core.BugzillaRepository; import org.eclipse.mylar.bugzilla.core.IBugzillaBug; import org.eclipse.mylar.bugzilla.core.internal.HtmlStreamTokenizer; -import org.eclipse.mylar.bugzilla.core.offline.OfflineReportsFile; import org.eclipse.mylar.bugzilla.ui.BugzillaImages; import org.eclipse.mylar.bugzilla.ui.BugzillaUITools; import org.eclipse.mylar.bugzilla.ui.BugzillaUiPlugin; @@ -41,6 +38,7 @@ import org.eclipse.mylar.core.MylarPlugin; import org.eclipse.mylar.tasklist.MylarTasklistPlugin; import org.eclipse.mylar.tasklist.Task; import org.eclipse.mylar.tasklist.TaskListImages; +import org.eclipse.mylar.tasklist.ui.views.TaskListView; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; @@ -55,6 +53,10 @@ import org.eclipse.ui.internal.Workbench; */ public class BugzillaTask extends Task { + public enum BugReportSyncState { + OUTGOING, OK, INCOMMING, CONFLICT + + } /** * Comment for <code>serialVersionUID</code> */ @@ -318,9 +320,11 @@ public class BugzillaTask extends Task { if(!isBugDownloaded() && offline){ MessageDialog.openInformation(null, "Unable to open bug", "Unable to open the selected bugzilla task since you are currently offline"); return; - }else if(!isBugDownloaded()) { + }else if(!isBugDownloaded() && syncState != BugReportSyncState.OUTGOING) { input.getBugTask().downloadReport(); input.setOfflineBug(input.getBugTask().getBugReport()); + } else if(syncState == BugReportSyncState.OUTGOING){ + input.setOfflineBug(bugReport); } // get the active workbench page @@ -333,6 +337,25 @@ public class BugzillaTask extends Task { // try to open an editor on the input bug //page.openEditor(input, IBugzillaConstants.EXISTING_BUG_EDITOR_ID); page.openEditor(input, "org.eclipse.mylar.bugzilla.ui.tasklist.bugzillaTaskEditor"); + if(syncState == BugReportSyncState.INCOMMING){ + syncState = BugReportSyncState.OK; + Display.getDefault().asyncExec(new Runnable(){ + public void run() { + if(TaskListView.getDefault() != null && TaskListView.getDefault().getViewer() != null && !TaskListView.getDefault().getViewer().getControl().isDisposed()){ + TaskListView.getDefault().getViewer().refresh(); + } + } + }); + } else if(syncState == BugReportSyncState.CONFLICT){ + syncState = BugReportSyncState.OUTGOING; + Display.getDefault().asyncExec(new Runnable(){ + public void run() { + if(TaskListView.getDefault() != null && TaskListView.getDefault().getViewer() != null && !TaskListView.getDefault().getViewer().getControl().isDisposed()){ + TaskListView.getDefault().getViewer().refresh(); + } + } + }); + } } catch (Exception ex) { MylarPlugin.log(ex, "couldn't open bugzilla task"); @@ -365,15 +388,20 @@ public class BugzillaTask extends Task { @Override protected IStatus run(IProgressMonitor monitor) { - state = BugTaskState.DOWNLOADING; - notifyTaskDataChange(); - // Update time this bugtask was last downloaded. - lastRefresh = new Date(); - bugReport = downloadReport(); - state = BugTaskState.FREE; - updateTaskDetails(); - notifyTaskDataChange(); - saveBugReport(true); + try{ + state = BugTaskState.DOWNLOADING; + notifyTaskDataChange(); + // Update time this bugtask was last downloaded. + lastRefresh = new Date(); + bugReport = downloadReport(); + state = BugTaskState.FREE; + updateTaskDetails(); + notifyTaskDataChange(); + saveBugReport(true); + } catch (Exception e){ + e.printStackTrace(); + // ignore + } BugzillaUiPlugin.getDefault().getBugzillaRefreshManager().removeRefreshingTask(BugzillaTask.this); return new Status(IStatus.OK, MylarPlugin.IDENTIFIER, IStatus.OK, "", null); } @@ -382,7 +410,7 @@ public class BugzillaTask extends Task { public void updateTaskDetails() { try { if(bugReport == null) - downloadReport(); + bugReport = downloadReport(); if(bugReport == null) return; setPriority(bugReport.getAttribute("Priority").getValue()); @@ -410,7 +438,8 @@ public class BugzillaTask extends Task { @Override protected IStatus run(IProgressMonitor monitor) { try{ - final BugzillaTaskEditorInput input = new BugzillaTaskEditorInput(bugTask, offline); + boolean isLikeOffline = offline || syncState == BugReportSyncState.OUTGOING; + final BugzillaTaskEditorInput input = new BugzillaTaskEditorInput(bugTask, isLikeOffline); // state = BugTaskState.OPENING; // notifyTaskDataChange(); openTaskEditor(input, offline); @@ -453,12 +482,15 @@ public class BugzillaTask extends Task { public boolean readBugReport() { // XXX server name needs to be with the bug report - int location = BugzillaPlugin.getDefault().getOfflineReports().find(getBugId(getHandle())); - if(location == -1){ + IBugzillaBug tempBug = OfflineView.find(getBugId(getHandle())); + if(tempBug == null){ bugReport = null; return true; } - bugReport = (BugReport)BugzillaPlugin.getDefault().getOfflineReports().elements().get(location); + bugReport = (BugReport)tempBug; + + if(bugReport.hasChanges()) + syncState = BugReportSyncState.OUTGOING; return true; } @@ -467,16 +499,20 @@ public class BugzillaTask extends Task { return; // XXX use the server name for multiple repositories - OfflineReportsFile offlineReports = BugzillaPlugin.getDefault().getOfflineReports(); - int location = offlineReports.find(getBugId(getHandle())); - if(location != -1){ - IBugzillaBug tmpBugReport = offlineReports.elements().get(location); - List<IBugzillaBug> l = new ArrayList<IBugzillaBug>(1); - l.add(tmpBugReport); - offlineReports.remove(l); - } - offlineReports.add(bugReport); +// OfflineReportsFile offlineReports = BugzillaPlugin.getDefault().getOfflineReports(); +// IBugzillaBug tempBug = OfflineView.find(getBugId(getHandle())); +// OfflineView.re +// if(location != -1){ +// IBugzillaBug tmpBugReport = offlineReports.elements().get(location); +// List<IBugzillaBug> l = new ArrayList<IBugzillaBug>(1); +// l.add(tmpBugReport); +// offlineReports.remove(l); +// } +// OfflineView.removeReport(tempBug); + OfflineView.saveOffline(bugReport, false); + + final IWorkbench workbench = PlatformUI.getWorkbench(); if (refresh && !workbench.getDisplay().isDisposed()) { workbench.getDisplay().asyncExec(new Runnable() { @@ -490,14 +526,16 @@ public class BugzillaTask extends Task { public void removeReport() { // XXX do we really want to do this??? // XXX remove from registry too?? - OfflineReportsFile offlineReports = BugzillaPlugin.getDefault().getOfflineReports(); - int location = offlineReports.find(getBugId(getHandle())); - if(location != -1){ - IBugzillaBug tmpBugReport = offlineReports.elements().get(location); - List<IBugzillaBug> l = new ArrayList<IBugzillaBug>(1); - l.add(tmpBugReport); - offlineReports.remove(l); - } + IBugzillaBug tempBug = OfflineView.find(getBugId(getHandle())); + OfflineView.removeReport(tempBug); +// OfflineReportsFile offlineReports = BugzillaPlugin.getDefault().getOfflineReports(); +// int location = offlineReports.find(getBugId(getHandle())); +// if(location != -1){ +// IBugzillaBug tmpBugReport = offlineReports.elements().get(location); +// List<IBugzillaBug> l = new ArrayList<IBugzillaBug>(1); +// l.add(tmpBugReport); +// offlineReports.remove(l); +// } } public static String getServerName(String handle) { @@ -519,7 +557,18 @@ public class BugzillaTask extends Task { @Override public Image getIcon() { - return TaskListImages.getImage(BugzillaImages.TASK_BUGZILLA); + if(syncState == BugReportSyncState.OK){ + return TaskListImages.getImage(BugzillaImages.TASK_BUGZILLA); + }else if(syncState == BugReportSyncState.OUTGOING){ + return TaskListImages.getImage(BugzillaImages.TASK_BUGZILLA_OUTGOING); + } else if(syncState == BugReportSyncState.INCOMMING){ + return TaskListImages.getImage(BugzillaImages.TASK_BUGZILLA_INCOMMING); + } else if(syncState == BugReportSyncState.CONFLICT){ + return TaskListImages.getImage(BugzillaImages.TASK_BUGZILLA_CONFLICT); + } else { + return TaskListImages.getImage(BugzillaImages.TASK_BUGZILLA); + } + } public String getBugUrl() { @@ -565,6 +614,7 @@ public class BugzillaTask extends Task { public Job getRefreshJob() { if (isDirty() || (state != BugTaskState.FREE)) { + System.out.println("didn't get job for " + getHandle()); return null; } GetBugReportJob job = new GetBugReportJob("Refreshing with Bugzilla server..."); @@ -581,4 +631,19 @@ public class BugzillaTask extends Task { long timeDifference = (timeNow.getTime() - lastRefresh.getTime())/60000; return timeDifference; } + + private BugReportSyncState syncState = BugReportSyncState.OK; + + public void setSyncState(BugReportSyncState syncState) { + if((this.syncState != BugReportSyncState.INCOMMING && syncState != BugReportSyncState.OK)) + this.syncState = syncState; + } + + public static String getHandle(IBugzillaBug bug) { + return "Bugzilla-"+bug.getId(); + } + + public BugReportSyncState getSyncState() { + return syncState; + } } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskEditorInput.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskEditorInput.java index c56114904..ce561da5d 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskEditorInput.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskEditorInput.java @@ -20,6 +20,7 @@ import javax.security.auth.login.LoginException; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.mylar.bugzilla.core.BugReport; import org.eclipse.mylar.bugzilla.ui.editor.ExistingBugEditorInput; +import org.eclipse.mylar.bugzilla.ui.tasklist.BugzillaTask.BugReportSyncState; import org.eclipse.ui.IPersistableElement; @@ -100,7 +101,7 @@ public class BugzillaTaskEditorInput extends ExistingBugEditorInput { * Returns the offline bug for this input's Bugzilla task */ public BugReport getOfflineBug() { - if(offline) + if(offline || bugTask.getSyncState() == BugReportSyncState.OUTGOING) return offlineBug; else return super.getBug(); diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskExternalizer.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskExternalizer.java index 4c89f0cf2..81e5fffe7 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskExternalizer.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskExternalizer.java @@ -14,6 +14,7 @@ package org.eclipse.mylar.bugzilla.ui.tasklist; import java.util.Date; import org.eclipse.mylar.bugzilla.ui.BugzillaUiPlugin; +import org.eclipse.mylar.bugzilla.ui.tasklist.BugzillaTask.BugReportSyncState; import org.eclipse.mylar.bugzilla.ui.tasklist.BugzillaTask.BugTaskState; import org.eclipse.mylar.core.MylarPlugin; import org.eclipse.mylar.tasklist.ICategory; @@ -42,6 +43,7 @@ public class BugzillaTaskExternalizer extends DefaultTaskListExternalizer { private static final String BUGZILLA = "Bugzilla"; private static final String LAST_DATE = "LastDate"; private static final String DIRTY = "Dirty"; + private static final String SYNC_STATE = "offlineSyncState"; private static final String DESCRIPTION = "Description"; private static final String URL = "URL"; @@ -164,6 +166,8 @@ public class BugzillaTaskExternalizer extends DefaultTaskListExternalizer { node.setAttribute(LAST_DATE, new Long(new Date().getTime()).toString()); } + node.setAttribute(SYNC_STATE, bt.getSyncState().toString()); + if (bt.isDirty()) { node.setAttribute(DIRTY, TRUE); } else { @@ -199,6 +203,7 @@ public class BugzillaTaskExternalizer extends DefaultTaskListExternalizer { task.setState(BugTaskState.FREE); task.setLastRefresh(new Date(new Long(element.getAttribute("LastDate")) .longValue())); + if (element.getAttribute("Dirty").compareTo("true") == 0) { task.setDirty(true); } else { @@ -212,6 +217,19 @@ public class BugzillaTaskExternalizer extends DefaultTaskListExternalizer { MylarPlugin.log(e, "Failed to read bug report"); } + if (element.hasAttribute(SYNC_STATE)) { + String syncState = element.getAttribute(SYNC_STATE); + if(syncState.compareTo(BugReportSyncState.OK.toString()) == 0){ + task.setSyncState(BugReportSyncState.OK); + } else if(syncState.compareTo(BugReportSyncState.INCOMMING.toString()) == 0){ + task.setSyncState(BugReportSyncState.INCOMMING); + } else if(syncState.compareTo(BugReportSyncState.OUTGOING.toString()) == 0){ + task.setSyncState(BugReportSyncState.OUTGOING); + } else if(syncState.compareTo(BugReportSyncState.CONFLICT.toString()) == 0){ + task.setSyncState(BugReportSyncState.CONFLICT); + } + } + ITaskHandler taskHandler = MylarTasklistPlugin.getDefault().getTaskHandlerForElement(task); if(taskHandler != null){ ITask addedTask = taskHandler.taskAdded(task); diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskListManager.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskListManager.java index c5dbb45af..333a8a33c 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskListManager.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskListManager.java @@ -14,12 +14,18 @@ package org.eclipse.mylar.bugzilla.ui.tasklist; import java.util.HashMap; import java.util.Map; +import org.eclipse.mylar.bugzilla.core.IBugzillaBug; +import org.eclipse.mylar.bugzilla.core.IOfflineBugListener; +import org.eclipse.mylar.bugzilla.ui.tasklist.BugzillaTask.BugReportSyncState; +import org.eclipse.mylar.tasklist.ITask; +import org.eclipse.mylar.tasklist.MylarTasklistPlugin; import org.eclipse.mylar.tasklist.internal.TaskCategory; +import org.eclipse.mylar.tasklist.ui.views.TaskListView; /** * @author Mik Kersten and Ken Sueda */ -public class BugzillaTaskListManager { +public class BugzillaTaskListManager implements IOfflineBugListener { private Map<String, BugzillaTask> bugzillaTaskRegistry = new HashMap<String, BugzillaTask>(); @@ -47,5 +53,32 @@ public class BugzillaTaskListManager { public void setTaskRegistyCategory(TaskCategory cat) { this.cat = cat; } + + public void offlineStatusChange(IBugzillaBug bug, BugzillaOfflineStaus status) { + BugReportSyncState state = null; + if(status == BugzillaOfflineStaus.SAVED_WITH_OUTGOING_CHANGES){ + state = BugReportSyncState.OUTGOING; + } else if(status == BugzillaOfflineStaus.SAVED){ + state = BugReportSyncState.OK; + }else if(status == BugzillaOfflineStaus.SAVED_WITH_INCOMMING_CHANGES){ + state = BugReportSyncState.INCOMMING; + }else if(status == BugzillaOfflineStaus.CONFLICT){ + state = BugReportSyncState.CONFLICT; + } + if(state == null){ + // this means that we got a status that we didn't understand + return; + } + + String handle = BugzillaTask.getHandle(bug); + ITask task = MylarTasklistPlugin.getTaskListManager().getTaskForHandle(handle, true); + if(task != null && task instanceof BugzillaTask){ + BugzillaTask bugTask = (BugzillaTask) task; + bugTask.setSyncState(state); + if(TaskListView.getDefault() != null && TaskListView.getDefault().getViewer() != null && !TaskListView.getDefault().getViewer().getControl().isDisposed()){ + TaskListView.getDefault().getViewer().refresh(); + } + } + } } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/NewBugWizard.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/NewBugWizard.java index 2c16bf603..ee95abb13 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/NewBugWizard.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/NewBugWizard.java @@ -129,7 +129,7 @@ public class NewBugWizard extends AbstractBugWizard { protected void saveBugOffline() { // Since the bug report is new, it just needs to be added to the // existing list of reports in the offline file. - OfflineView.saveOffline(model); + OfflineView.saveOffline(model, true); } @Override diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/internal/TaskList.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/internal/TaskList.java index 53280fa31..42c65c952 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/internal/TaskList.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/internal/TaskList.java @@ -148,11 +148,11 @@ public class TaskList implements Serializable { private ITask findTaskHelper(List<? extends ITaskListElement> elements, String handle) { for (ITaskListElement element : elements) { if(element instanceof ITask){ - if(element.getHandle() == handle) + if(element.getHandle().compareTo(handle) == 0) return (ITask)element; } else if(element instanceof IQueryHit){ IQueryHit hit = (IQueryHit)element; - if (hit.getHandle() == handle && hit.hasCorrespondingActivatableTask()) { + if (hit.getHandle().compareTo(handle) == 0 && hit.hasCorrespondingActivatableTask()) { return hit.getOrCreateCorrespondingTask(); } } |