diff options
author | Guy Perron | 2014-06-11 19:08:30 +0000 |
---|---|---|
committer | Sam Davis | 2014-07-30 21:28:18 +0000 |
commit | c0e11f3f3fceedd5e917203560f9ddd486757609 (patch) | |
tree | 5291a35e78a4c12d2d88ce465c170a0344559822 /org.eclipse.mylyn.gerrit.ui/src/org/eclipse/mylyn/internal | |
parent | bfa12d80327edac1ecf7e5a29b194cadea96740e (diff) | |
download | org.eclipse.mylyn.reviews-c0e11f3f3fceedd5e917203560f9ddd486757609.tar.gz org.eclipse.mylyn.reviews-c0e11f3f3fceedd5e917203560f9ddd486757609.tar.xz org.eclipse.mylyn.reviews-c0e11f3f3fceedd5e917203560f9ddd486757609.zip |
423242: Add ability to edit comment from compare navigator popup
Change-Id: Icf07632123a7f0dc87680a402719b4fca8642832
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=423242
Signed-off-by: Guy Perron <guy.perron@ericsson.com>
Diffstat (limited to 'org.eclipse.mylyn.gerrit.ui/src/org/eclipse/mylyn/internal')
-rw-r--r-- | org.eclipse.mylyn.gerrit.ui/src/org/eclipse/mylyn/internal/gerrit/ui/GerritReviewBehavior.java | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/org.eclipse.mylyn.gerrit.ui/src/org/eclipse/mylyn/internal/gerrit/ui/GerritReviewBehavior.java b/org.eclipse.mylyn.gerrit.ui/src/org/eclipse/mylyn/internal/gerrit/ui/GerritReviewBehavior.java index 8a36b1533..4b53955b3 100644 --- a/org.eclipse.mylyn.gerrit.ui/src/org/eclipse/mylyn/internal/gerrit/ui/GerritReviewBehavior.java +++ b/org.eclipse.mylyn.gerrit.ui/src/org/eclipse/mylyn/internal/gerrit/ui/GerritReviewBehavior.java @@ -8,6 +8,7 @@ * Contributors: * Tasktop Technologies - initial API and implementation * Sebastien Dubois (Ericsson) - Improvements for bug 400266 + * Guy Perron 423242: Add ability to edit comment from compare navigator popup *******************************************************************************/ package org.eclipse.mylyn.internal.gerrit.ui; @@ -15,7 +16,10 @@ package org.eclipse.mylyn.internal.gerrit.ui; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.util.StringUtils; import org.eclipse.mylyn.internal.gerrit.core.GerritOperationFactory; +import org.eclipse.mylyn.internal.gerrit.core.Messages; +import org.eclipse.mylyn.internal.gerrit.core.operations.DiscardDraftRequest; import org.eclipse.mylyn.internal.gerrit.core.operations.GerritOperation; import org.eclipse.mylyn.internal.gerrit.core.operations.SaveDraftRequest; import org.eclipse.mylyn.internal.gerrit.ui.egit.GitFileRevisionUtils; @@ -26,18 +30,27 @@ import org.eclipse.mylyn.reviews.core.model.ILocation; import org.eclipse.mylyn.reviews.core.model.IReviewItem; import org.eclipse.mylyn.reviews.ui.ReviewBehavior; import org.eclipse.mylyn.tasks.core.ITask; +import org.eclipse.osgi.util.NLS; import org.eclipse.team.core.history.IFileRevision; import com.google.gerrit.reviewdb.Patch; import com.google.gerrit.reviewdb.PatchLineComment; +import com.google.gwtjsonrpc.client.VoidResult; /** * @author Steffen Pingel + * @author Guy Perron */ public class GerritReviewBehavior extends ReviewBehavior { private Repository repository = null; + private final short LEFT_SIDE = 0; + + private final short RIGHT_SIDE = 1; + + private final String BASE = "base-"; //$NON-NLS-1$ + public GerritReviewBehavior(ITask task) { super(task); } @@ -53,12 +66,12 @@ public class GerritReviewBehavior extends ReviewBehavior { @Override public IStatus addComment(IReviewItem item, IComment comment, IProgressMonitor monitor) { - short side = 1; + short side = RIGHT_SIDE; String id = item.getId(); - if (id.startsWith("base-")) { //$NON-NLS-1$ + if (id.startsWith(BASE)) { // base revision - id = id.substring(5); - side = 0; + id = id.substring(BASE.length()); + side = LEFT_SIDE; } Patch.Key key = Patch.Key.parse(id); for (ILocation location : comment.getLocations()) { @@ -66,14 +79,48 @@ public class GerritReviewBehavior extends ReviewBehavior { ILineLocation lineLocation = (ILineLocation) location; SaveDraftRequest request = new SaveDraftRequest(key, lineLocation.getRangeMin(), side); request.setMessage(comment.getDescription()); + if (!StringUtils.isEmptyOrNull(comment.getId())) { + request.setUuid(comment.getId()); + } GerritOperation<PatchLineComment> operation = getOperationFactory().createSaveDraftOperation(getTask(), request); - return operation.run(monitor); + IStatus status = operation.run(monitor); + PatchLineComment patchLineComment = operation.getOperationResult(); + // save the value of uuid, and keep it with the comment + if (patchLineComment != null && patchLineComment.getKey() != null) { + comment.setId(patchLineComment.getKey().get()); + } + return status; } } //We'll only get here if there is something really broken in calling code or model. Gerrit has one and only one comment per location. - throw new RuntimeException("Internal Exception. No line location for comment. Comment: " + comment.getId()); //$NON-NLS-1$ + throw new RuntimeException(NLS.bind(Messages.GerritReviewBehavior_Internal_Exception, comment.getId())); + } + + @Override + public IStatus discardComment(IReviewItem item, IComment comment, IProgressMonitor monitor) { + short side = RIGHT_SIDE; + String id = item.getId(); + if (id.startsWith(BASE)) { + // base revision + id = id.substring(BASE.length()); + side = LEFT_SIDE; + } + Patch.Key key = Patch.Key.parse(id); + for (ILocation location : comment.getLocations()) { + if (location instanceof ILineLocation) { + ILineLocation lineLocation = (ILineLocation) location; + DiscardDraftRequest request = new DiscardDraftRequest(key, lineLocation.getRangeMin(), side, + comment.getId()); + request.setMessage(comment.getDescription()); + + GerritOperation<VoidResult> operation = getOperationFactory().createDiscardDraftOperation(getTask(), + request); + return operation.run(monitor); + } + } + throw new RuntimeException(Messages.GerritReviewBehavior_Internal_Exception + comment.getId()); } @Override |