1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.actions.log; 21 22 import org.openide.filesystems.FileObject; 23 import org.openide.filesystems.FileUtil; 24 import org.openide.loaders.DataObject; 25 import org.openide.ErrorManager; 26 import org.openide.util.Cancellable; 27 import org.openide.nodes.Node; 28 import org.openide.util.NbBundle; 29 import org.openide.windows.WindowManager; 30 import org.openide.cookies.EditorCookie; 31 import org.netbeans.modules.versioning.system.cvss.ui.actions.AbstractSystemAction; 32 import org.netbeans.modules.versioning.system.cvss.ui.actions.annotate.AnnotationBarManager; 33 import org.netbeans.modules.versioning.system.cvss.FileInformation; 34 import org.netbeans.modules.versioning.system.cvss.CvsVersioningSystem; 35 import org.netbeans.modules.versioning.system.cvss.ExecutorGroup; 36 import org.netbeans.lib.cvsclient.command.annotate.AnnotateCommand; 37 import org.netbeans.lib.cvsclient.command.log.LogCommand; 38 import org.netbeans.lib.cvsclient.admin.Entry; 39 import org.netbeans.lib.cvsclient.admin.AdminHandler; 40 41 import javax.swing.*; 42 import java.awt.event.ActionEvent ; 43 import java.io.File ; 44 import java.io.IOException ; 45 46 52 public class AnnotationsAction extends AbstractSystemAction { 53 54 protected String getBaseName(Node [] activatedNodes) { 55 if (visible(activatedNodes)) { 56 return "CTL_MenuItem_HideAnnotations"; } else { 58 return "CTL_MenuItem_Annotations"; } 60 } 61 62 public boolean enable(Node[] nodes) { 63 return super.enable(nodes) && activatedEditorCookie(nodes) != null; 64 } 65 66 protected int getFileEnabledStatus() { 67 return FileInformation.STATUS_IN_REPOSITORY; 68 } 69 70 protected int getDirectoryEnabledStatus() { 71 return 0; 72 } 73 74 protected boolean asynchronous() { 75 return false; 76 } 77 78 public void performCvsAction(Node[] nodes) { 79 if (visible(nodes)) { 80 JEditorPane pane = activatedEditorPane(nodes); 81 AnnotationBarManager.hideAnnotationBar(pane); 82 } else { 83 EditorCookie ec = activatedEditorCookie(nodes); 84 if (ec != null) { 85 File file = activatedFile(nodes); 86 CvsVersioningSystem cvss = CvsVersioningSystem.getInstance(); 87 AdminHandler entries = cvss.getAdminHandler(); 88 89 JEditorPane[] panes = ec.getOpenedPanes(); 90 if (panes == null) { 91 ec.open(); 92 } 93 panes = ec.getOpenedPanes(); 94 if (panes == null) { 95 return; 96 } 97 final JEditorPane currentPane = panes[0]; 98 LogOutputListener ab = AnnotationBarManager.showAnnotationBar(currentPane); 99 100 AnnotateCommand annotate = new AnnotateCommand(); 101 102 try { 103 Entry entry = entries.getEntry(file); 104 if (entry == null) { 105 return; 106 } 107 String revision = entry.getRevision(); 108 annotate.setAnnotateByRevision(revision); 109 File [] cmdFiles = new File [] {file}; 110 annotate.setFiles(cmdFiles); 111 112 ExecutorGroup group = new ExecutorGroup(NbBundle.getMessage(AnnotationsAction.class, "BK0001")); 113 114 AnnotationsExecutor executor = new AnnotationsExecutor(cvss, annotate); 115 executor.addLogOutputListener(ab); 116 group.addExecutor(executor); 117 118 120 LogCommand log = new LogCommand(); 121 log.setFiles(cmdFiles); 122 log.setNoTags(true); 123 124 LogExecutor lexecutor = new LogExecutor(cvss, log); 125 lexecutor.addLogOutputListener(ab); 126 group.addExecutor(lexecutor); 127 128 group.addCancellable(new Cancellable(){ 129 public boolean cancel() { 130 AnnotationBarManager.hideAnnotationBar(currentPane); 131 return true; 132 } 133 }); 134 135 group.execute(); 136 } catch (IOException e) { 137 ErrorManager err = ErrorManager.getDefault(); 138 err.annotate(e, NbBundle.getMessage(AnnotationsAction.class, "BK0002", file)); 139 err.notify(e); 140 } 141 } 142 } 143 } 144 145 148 public boolean visible(Node[] nodes) { 149 JEditorPane currentPane = activatedEditorPane(nodes); 150 return AnnotationBarManager.annotationBarVisible(currentPane); 151 } 152 153 157 private JEditorPane activatedEditorPane(Node[] nodes) { 158 EditorCookie ec = activatedEditorCookie(nodes); 159 if (ec != null) { 160 JEditorPane[] panes = ec.getOpenedPanes(); 161 if (panes != null && panes.length > 0) { 162 return panes[0]; 163 } 164 } 165 return null; 166 } 167 168 private EditorCookie activatedEditorCookie(Node[] nodes) { 169 if (nodes == null) { 170 nodes = WindowManager.getDefault().getRegistry().getActivatedNodes(); 171 } 172 if (nodes.length == 1) { 173 Node node = nodes[0]; 174 return (EditorCookie) node.getCookie(EditorCookie.class); 175 } 176 return null; 177 } 178 179 private File activatedFile(Node[] nodes) { 180 if (nodes.length == 1) { 181 Node node = nodes[0]; 182 DataObject dobj = (DataObject) node.getCookie(DataObject.class); 183 if (dobj != null) { 184 FileObject fo = dobj.getPrimaryFile(); 185 return FileUtil.toFile(fo); 186 } 187 } 188 return null; 189 190 } 191 } 192 | Popular Tags |