KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > history > 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.subversion.ui.history;
21
22 import org.netbeans.modules.subversion.ui.actions.ContextAction;
23 import org.netbeans.modules.subversion.FileInformation;
24 import org.netbeans.modules.subversion.util.Context;
25 import org.netbeans.modules.subversion.util.SvnUtils;
26 import org.netbeans.modules.versioning.util.Utils;
27 import org.netbeans.api.project.Project;
28 import org.netbeans.api.project.ui.OpenProjects;
29 import org.openide.nodes.Node;
30 import org.openide.util.NbBundle;
31 import org.tigris.subversion.svnclientadapter.SVNUrl;
32
33 import javax.swing.*;
34 import java.io.File JavaDoc;
35 import java.util.*;
36
37 /**
38  * Opens Search History Component.
39  *
40  * @author Maros Sandor
41  */

42 public class SearchHistoryAction extends ContextAction {
43
44     protected String JavaDoc getBaseName(Node [] activatedNodes) {
45         return "CTL_MenuItem_SearchHistory"; // NOI18N
46
}
47
48     protected int getFileEnabledStatus() {
49         return FileInformation.STATUS_IN_REPOSITORY;
50     }
51
52     protected int getDirectoryEnabledStatus() {
53         return FileInformation.STATUS_MANAGED & ~FileInformation.STATUS_NOTVERSIONED_EXCLUDED & ~FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY;
54     }
55
56     protected boolean asynchronous() {
57         return false;
58     }
59
60     protected void performContextAction(Node[] nodes) {
61         String JavaDoc title = NbBundle.getMessage(SearchHistoryAction.class, "CTL_SearchHistory_Title", getContextDisplayName(nodes)); // NOI18N
62
openHistory(getContext(nodes), title);
63     }
64
65     private void openHistory(final Context context, final String JavaDoc title) {
66         SwingUtilities.invokeLater(new Runnable JavaDoc() {
67             public void run() {
68                 SearchHistoryTopComponent tc = new SearchHistoryTopComponent(context);
69                 tc.setDisplayName(title);
70                 tc.open();
71                 tc.requestActive();
72                 File JavaDoc [] files = context.getFiles();
73                 if (Utils.shareCommonDataObject(files)) {
74                     tc.search();
75                 }
76             }
77         });
78     }
79
80     /**
81      * Opens the Seach History panel with given pre-filled values. The search is executed in default context
82      * (all open projects).
83      *
84      * @param title title of the search
85      * @param commitMessage commit message to search for
86      * @param username user name to search for
87      * @param date date of the change in question
88      */

89     public static void openSearch(String JavaDoc title, String JavaDoc commitMessage, String JavaDoc username, Date date) {
90         openSearch(getDefaultContext(), title, commitMessage, username, date);
91     }
92
93     public static void openSearch(Context context, String JavaDoc title, String JavaDoc commitMessage, String JavaDoc username, Date date) {
94         Calendar c = Calendar.getInstance();
95         c.setTime(date);
96         // annotations do not include time information, we must search whole day
97
c.add(Calendar.DATE, 1);
98         Date to = c.getTime();
99         c.setTime(date);
100         c.add(Calendar.DATE, -1);
101         Date from = c.getTime();
102         
103         if (commitMessage != null && commitMessage.indexOf('\n') != -1) {
104             commitMessage = commitMessage.substring(0, commitMessage.indexOf('\n'));
105         }
106         SearchHistoryTopComponent tc = new SearchHistoryTopComponent(context, commitMessage, username, from, to);
107         String JavaDoc tcTitle = NbBundle.getMessage(SearchHistoryAction.class, "CTL_SearchHistory_Title", title); // NOI18N
108
tc.setDisplayName(tcTitle);
109         tc.open();
110         tc.requestActive();
111         tc.search();
112     }
113
114     private static Context getDefaultContext() {
115         Project [] projects = OpenProjects.getDefault().getOpenProjects();
116         return SvnUtils.getProjectsContext(projects);
117     }
118
119     /**
120      * Opens search panel in the context of the given repository URL.
121      *
122      * @param repositoryUrl URL to search
123      * @param localRoot local working copy root that corresponds to the repository URL
124      * @param revision revision to search for
125      */

126     public static void openSearch(SVNUrl repositoryUrl, File JavaDoc localRoot, long revision) {
127         SearchHistoryTopComponent tc = new SearchHistoryTopComponent(repositoryUrl, localRoot, revision);
128         String JavaDoc tcTitle = NbBundle.getMessage(SearchHistoryAction.class, "CTL_SearchHistory_Title", repositoryUrl); // NOI18N
129
tc.setDisplayName(tcTitle);
130         tc.open();
131         tc.requestActive();
132         tc.search();
133     }
134 }
135
Popular Tags