1 package com.atlassian.theplugin.idea.ui.tree.clickaction; 2 3 import com.atlassian.theplugin.commons.crucible.api.model.CrucibleFileInfo; 4 import com.atlassian.theplugin.commons.crucible.api.model.ReviewAdapter; 5 import com.atlassian.theplugin.commons.crucible.api.model.VersionedComment; 6 import com.atlassian.theplugin.idea.crucible.CrucibleHelper; 7 import com.atlassian.theplugin.idea.ui.tree.AtlassianClickAction; 8 import com.atlassian.theplugin.idea.ui.tree.AtlassianTreeNode; 9 import com.atlassian.theplugin.idea.ui.tree.comment.VersionedCommentTreeNode; 10 import com.intellij.openapi.editor.Document; 11 import com.intellij.openapi.editor.Editor; 12 import com.intellij.openapi.fileEditor.FileDocumentManager; 13 import com.intellij.openapi.fileEditor.OpenFileDescriptor; 14 import com.intellij.openapi.project.Project; 15 import com.intellij.openapi.vfs.VirtualFile; 16 17 public class CrucibleVersionedCommentClickAction implements AtlassianClickAction { 18 private Project project; 19 20 public CrucibleVersionedCommentClickAction(Project project) { 21 this.project = project; 22 } 23 24 public void execute(final AtlassianTreeNode node, final int noOfClicks) { 25 VersionedCommentTreeNode anode = (VersionedCommentTreeNode) node; 26 27 ReviewAdapter review = anode.getReview(); 28 CrucibleFileInfo file = anode.getFile(); 29 Editor editor = CrucibleHelper.getEditorForCrucibleFile(review, file); 30 VersionedComment comment = anode.getComment(); 31 32 switch (noOfClicks) { 33 case 1: 34 if (editor != null) { 35 scrollFileToComment(editor, comment); 36 } 37 break; 38 case 2: 39 if (editor != null) { 40 scrollFileToComment(editor, comment); 41 } else { 42 CrucibleHelper.openFileOnComment(project, review, file, comment); 43 } 44 break; 45 default: 46 break; 47 } 48 } 49 50 private void scrollFileToComment(final Editor editor, final VersionedComment comment) { 51 Document document = editor.getDocument(); 52 VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document); 53 if (virtualFile != null) { 54 OpenFileDescriptor display = new OpenFileDescriptor(project, virtualFile, comment.getToStartLine() - 1, 55 0); 56 if (display.canNavigateToSource()) { 57 display.navigate(false); 58 } 59 } 60 } 61 }