2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28 * Microsystems, Inc. All Rights Reserved.
29 * Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
31 * If you wish your version of this file to be governed by only the CDDL
32 * or only the GPL Version 2, indicate your decision by adding
33 * "[Contributor] elects to include this software in this distribution
34 * under the [CDDL or GPL Version 2] license." If you do not indicate a
35 * single choice of license, a recipient has the option to distribute
36 * your version of this file under either the CDDL, the GPL Version 2 or
37 * to extend the choice of license to its licensees as provided above.
38 * However, if you add GPL Version 2 code and therefore, elected the GPL
39 * Version 2 license, then the option applies only if the new code is
40 * made subject to such option by the copyright holder.
42 package org
.netbeans
.modules
.git
.ui
.log
;
44 import java
.awt
.event
.ActionEvent
;
46 import java
.util
.Calendar
;
47 import java
.util
.Date
;
48 import javax
.swing
.Action
;
49 import javax
.swing
.SwingUtilities
;
50 import org
.netbeans
.modules
.git
.FileInformation
;
51 import org
.netbeans
.modules
.git
.OutputLogger
;
52 import org
.netbeans
.modules
.git
.ui
.actions
.ContextAction
;
53 import org
.netbeans
.modules
.git
.util
.GitUtils
;
54 import org
.netbeans
.modules
.versioning
.spi
.VCSContext
;
55 import org
.netbeans
.modules
.versioning
.util
.Utils
;
56 import org
.openide
.nodes
.Node
;
57 import org
.openide
.util
.NbBundle
;
58 import org
.openide
.windows
.TopComponent
;
62 * Opens Search History Component.
64 * @author Maros Sandor
66 public class SearchHistoryAction
extends ContextAction
{
68 private final VCSContext context
;
69 static final int DIRECTORY_ENABLED_STATUS
= FileInformation
.STATUS_MANAGED
& ~FileInformation
.STATUS_NOTVERSIONED_EXCLUDED
& ~FileInformation
.STATUS_NOTVERSIONED_NEWLOCALLY
;
70 static final int FILE_ENABLED_STATUS
= FileInformation
.STATUS_MANAGED
& ~FileInformation
.STATUS_NOTVERSIONED_EXCLUDED
& ~FileInformation
.STATUS_NOTVERSIONED_NEWLOCALLY
;
72 public SearchHistoryAction(String name
, VCSContext context
) {
73 this.context
= context
;
74 putValue(Action
.NAME
, name
);
77 protected String
getBaseName(Node
[] activatedNodes
) {
78 return "CTL_MenuItem_SearchHistory"; // NOI18N
81 protected int getFileEnabledStatus() {
82 return FILE_ENABLED_STATUS
;
85 protected int getDirectoryEnabledStatus() {
86 return DIRECTORY_ENABLED_STATUS
;
89 protected boolean asynchronous() {
93 public void performAction(ActionEvent e
) {
94 String title
= NbBundle
.getMessage(SearchHistoryAction
.class, "CTL_SearchHistory_Title", Utils
.getContextDisplayName(context
)); // NOI18N
95 openHistory(context
, title
);
98 public static void openHistory(final VCSContext context
, final String title
) {
99 SwingUtilities
.invokeLater(new Runnable() {
101 if (context
== null) return;
102 outputSearchContextTab(context
, "MSG_Log_Title");
103 SearchHistoryTopComponent tc
= new SearchHistoryTopComponent(context
);
104 tc
.setDisplayName(title
);
111 private static void outputSearchContextTab(VCSContext context
, String title
) {
112 File root
= GitUtils
.getRootFile(context
);
113 OutputLogger logger
= OutputLogger
.getLogger(root
.getAbsolutePath());
115 NbBundle
.getMessage(SearchHistoryAction
.class,
118 NbBundle
.getMessage(SearchHistoryAction
.class,
119 "MSG_Log_Title_Sep")); // NOI18N
120 File
[] files
= context
.getFiles().toArray(new File
[0]);
122 NbBundle
.getMessage(SearchHistoryAction
.class,
123 "MSG_LOG_CONTEXT_SEP")); // NOI18N
124 for (File f
: files
) {
125 logger
.output(f
.getAbsolutePath());
127 logger
.outputInRed(""); // NOI18N
132 * Opens the Seach History panel to view Mercurial Incoming Changesets that will be sent on next Pull from remote repo
133 * using: hg incoming - to get the data
135 * @param title title of the search
136 * @param commitMessage commit message to search for
137 * @param username user name to search for
138 * @param date date of the change in question
140 public static void openIncoming(final VCSContext context
, final String title
) {
141 SwingUtilities
.invokeLater(new Runnable() {
143 if (context
== null) return;
144 outputSearchContextTab(context
, "MSG_LogIncoming_Title");
145 SearchHistoryTopComponent tc
= new SearchHistoryTopComponent(context
);
146 tc
.setDisplayName(title
);
154 * Opens the Seach History panel to view Mercurial Out Changesets that will be sent on next Push to remote repo
155 * using: hg out - to get the data
157 * @param title title of the search
158 * @param commitMessage commit message to search for
159 * @param username user name to search for
160 * @param date date of the change in question
162 public static void openOut(final VCSContext context
, final String title
) {
163 SwingUtilities
.invokeLater(new Runnable() {
165 if (context
== null) return;
166 outputSearchContextTab(context
, "MSG_LogOut_Title");
167 SearchHistoryTopComponent tc
= new SearchHistoryTopComponent(context
);
168 tc
.setDisplayName(title
);
177 * Opens the Seach History panel with given pre-filled values. The search is executed in default context
178 * (all open projects).
180 * @param title title of the search
181 * @param commitMessage commit message to search for
182 * @param username user name to search for
183 * @param date date of the change in question
185 public static void openSearch(String title
, String commitMessage
, String username
, Date date
) {
186 openSearch(getDefaultContext(), title
, commitMessage
, username
, date
);
189 public static void openSearch(VCSContext context
, String title
, String commitMessage
, String username
, Date date
) {
190 Calendar c
= Calendar
.getInstance();
192 // annotations do not include time information, we must search whole day
193 c
.add(Calendar
.DATE
, 1);
194 Date to
= c
.getTime();
196 c
.add(Calendar
.DATE
, -1);
197 Date from
= c
.getTime();
199 if (commitMessage
!= null && commitMessage
.indexOf('\n') != -1) {
200 commitMessage
= commitMessage
.substring(0, commitMessage
.indexOf('\n'));
202 SearchHistoryTopComponent tc
= new SearchHistoryTopComponent(context
, commitMessage
, username
, from
, to
);
203 String tcTitle
= NbBundle
.getMessage(SearchHistoryAction
.class, "CTL_SearchHistory_Title", title
); // NOI18N
204 tc
.setDisplayName(tcTitle
);
210 private static VCSContext
getDefaultContext() {
211 Node
[] nodes
= TopComponent
.getRegistry().getActivatedNodes();
213 return nodes
!= null ? VCSContext
.forNodes(nodes
): VCSContext
.EMPTY
;
217 * Opens search panel in the context of the given repository URL.
219 * @param repositoryUrl URL to search
220 * @param localRoot local working copy root that corresponds to the repository URL
221 * @param revision revision to search for
223 public static void openSearch(String repositoryUrl
, File localRoot
, long revision
) {
224 SearchHistoryTopComponent tc
= new SearchHistoryTopComponent(repositoryUrl
, localRoot
, revision
);
225 String tcTitle
= NbBundle
.getMessage(SearchHistoryAction
.class, "CTL_SearchHistory_Title", repositoryUrl
); // NOI18N
226 tc
.setDisplayName(tcTitle
);