KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > actions > log > SearchHistoryAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 JavaDoc;
35
36 /**
37  * Search History action.
38  *
39  * @author Maros Sandor
40  */

41 public class SearchHistoryAction extends AbstractSystemAction {
42
43     protected String JavaDoc getBaseName(Node [] activatedNodes) {
44         return "CTL_MenuItem_SearchHistory"; // NOI18N
45
}
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 JavaDoc 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 JavaDoc title) {
65         SwingUtilities.invokeLater(new Runnable JavaDoc() {
66             public void run() {
67                 SearchHistoryTopComponent tc = new SearchHistoryTopComponent(context);
68                 tc.setDisplayName(title);
69                 tc.open();
70                 tc.requestActive();
71                 File JavaDoc [] 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     /**
80      * Opens the Seach History panel with given pre-filled values. The search is executed in default context
81      * (all open projects).
82      *
83      * @param title title of the search
84      * @param commitMessage commit message to search for
85      * @param username user name to search for
86      * @param date date of the change in question
87      */

88     public static void openSearch(String JavaDoc title, String JavaDoc commitMessage, String JavaDoc username, Date date) {
89         openSearch(getDefaultContext(), title, commitMessage, username, date);
90     }
91
92     public static void openSearch(Context context, String JavaDoc title, String JavaDoc commitMessage, String JavaDoc username, Date date) {
93         Calendar c = Calendar.getInstance();
94         c.setTime(date);
95         // annotations do not include time information, we must search whole day
96
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 JavaDoc 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