1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.actions.log; 21 22 import org.netbeans.modules.versioning.system.cvss.ui.actions.AbstractSystemAction; 23 import org.netbeans.modules.versioning.system.cvss.ui.history.SearchHistoryTopComponent; 24 import org.netbeans.modules.versioning.system.cvss.FileInformation; 25 import org.netbeans.modules.versioning.system.cvss.util.Utils; 26 import org.netbeans.modules.versioning.system.cvss.util.Context; 27 import org.netbeans.api.project.Project; 28 import org.netbeans.api.project.ui.OpenProjects; 29 import org.openide.util.NbBundle; 30 import org.openide.nodes.Node; 31 32 import javax.swing.*; 33 import java.util.*; 34 import java.io.File ; 35 36 41 public class SearchHistoryAction extends AbstractSystemAction { 42 43 protected String getBaseName(Node [] activatedNodes) { 44 return "CTL_MenuItem_SearchHistory"; } 46 47 protected int getFileEnabledStatus() { 48 return FileInformation.STATUS_IN_REPOSITORY; 49 } 50 51 protected int getDirectoryEnabledStatus() { 52 return FileInformation.STATUS_MANAGED & ~FileInformation.STATUS_NOTVERSIONED_EXCLUDED & ~FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY; 53 } 54 55 protected boolean asynchronous() { 56 return false; 57 } 58 59 public void performCvsAction(Node[] nodes) { 60 String title = NbBundle.getMessage(SearchHistoryAction.class, "CTL_SearchHistory_Title", getContextDisplayName(nodes)); 61 openHistory(getContext(nodes), title); 62 } 63 64 private void openHistory(final Context context, final String title) { 65 SwingUtilities.invokeLater(new Runnable () { 66 public void run() { 67 SearchHistoryTopComponent tc = new SearchHistoryTopComponent(context); 68 tc.setDisplayName(title); 69 tc.open(); 70 tc.requestActive(); 71 File [] files = context.getFiles(); 72 if (files.length == 1 && files[0].isFile() || files.length > 1 && org.netbeans.modules.versioning.util.Utils.shareCommonDataObject(files)) { 73 tc.search(); 74 } 75 } 76 }); 77 } 78 79 88 public static void openSearch(String title, String commitMessage, String username, Date date) { 89 openSearch(getDefaultContext(), title, commitMessage, username, date); 90 } 91 92 public static void openSearch(Context context, String title, String commitMessage, String username, Date date) { 93 Calendar c = Calendar.getInstance(); 94 c.setTime(date); 95 c.add(Calendar.DATE, 1); 97 Date to = c.getTime(); 98 c.setTime(date); 99 c.add(Calendar.DATE, -1); 100 Date from = c.getTime(); 101 102 if (commitMessage != null && commitMessage.indexOf('\n') != -1) { 103 commitMessage = commitMessage.substring(0, commitMessage.indexOf('\n')); 104 } 105 SearchHistoryTopComponent tc = new SearchHistoryTopComponent(context, commitMessage, username, from, to); 106 String tcTitle = NbBundle.getMessage(SearchHistoryAction.class, "CTL_SearchHistory_Title", title); 107 tc.setDisplayName(tcTitle); 108 tc.open(); 109 tc.requestActive(); 110 tc.search(); 111 } 112 113 private static Context getDefaultContext() { 114 Project [] projects = OpenProjects.getDefault().getOpenProjects(); 115 return Utils.getProjectsContext(projects); 116 } 117 } 118 | Popular Tags |