Cleanup code whitespace
[nbgit.git] / src / org / nbgit / ui / log / SearchHistoryAction.java
blob2401bd1526c72a59be6570b09ddb2b62ff4b6271
1 /*
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]"
24 * Contributor(s):
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.nbgit.ui.log;
44 import java.awt.event.ActionEvent;
45 import java.io.File;
46 import javax.swing.SwingUtilities;
47 import org.nbgit.StatusInfo;
48 import org.nbgit.ui.ContextAction;
49 import org.netbeans.modules.versioning.spi.VCSContext;
50 import org.netbeans.modules.versioning.util.Utils;
51 import org.openide.nodes.Node;
52 import org.openide.util.NbBundle;
53 import org.openide.windows.TopComponent;
55 /**
56 * Opens Search History Component.
58 * @author Maros Sandor
60 public class SearchHistoryAction extends ContextAction {
62 static final int DIRECTORY_ENABLED_STATUS = StatusInfo.STATUS_MANAGED & ~StatusInfo.STATUS_NOTVERSIONED_EXCLUDED & ~StatusInfo.STATUS_NOTVERSIONED_NEWLOCALLY;
63 static final int FILE_ENABLED_STATUS = StatusInfo.STATUS_MANAGED & ~StatusInfo.STATUS_NOTVERSIONED_EXCLUDED & ~StatusInfo.STATUS_NOTVERSIONED_NEWLOCALLY;
65 public SearchHistoryAction(String name, VCSContext context)
67 super(name, context);
70 protected String getBaseName(Node[] activatedNodes)
72 return "CTL_MenuItem_SearchHistory"; // NOI18N
75 protected int getFileEnabledStatus()
77 return FILE_ENABLED_STATUS;
80 protected int getDirectoryEnabledStatus()
82 return DIRECTORY_ENABLED_STATUS;
85 protected boolean asynchronous()
87 return false;
90 public void performAction(ActionEvent e)
92 String title = NbBundle.getMessage(SearchHistoryAction.class, "CTL_SearchHistory_Title", Utils.getContextDisplayName(context)); // NOI18N
93 openHistory(context, title);
96 public static void openHistory(final VCSContext context, final String title)
98 SwingUtilities.invokeLater(new Runnable() {
100 public void run()
102 if (context == null)
103 return;
104 SearchHistoryTopComponent tc = new SearchHistoryTopComponent(context);
105 tc.setDisplayName(title);
106 tc.open();
107 tc.requestActive();
108 tc.search(true);
115 * Opens the Search History panel to view Git Changesets that will be sent on next Pull from remote repo
116 * using: git incoming - to get the data
118 * @param title title of the search
119 * @param commitMessage commit message to search for
120 * @param username user name to search for
121 * @param date date of the change in question
123 public static void openIncoming(final VCSContext context, final String title)
125 SwingUtilities.invokeLater(new Runnable() {
127 public void run()
129 if (context == null)
130 return;
131 SearchHistoryTopComponent tc = new SearchHistoryTopComponent(context);
132 tc.setDisplayName(title);
133 tc.open();
134 tc.requestActive();
135 tc.searchIncoming();
142 * Opens the Search History panel to view Git Out Changesets that will be sent on next Push to remote repo
143 * using: git out - to get the data
145 * @param title title of the search
146 * @param commitMessage commit message to search for
147 * @param username user name to search for
148 * @param date date of the change in question
150 public static void openOut(final VCSContext context, final String title)
152 SwingUtilities.invokeLater(new Runnable() {
154 public void run()
156 if (context == null)
157 return;
158 SearchHistoryTopComponent tc = new SearchHistoryTopComponent(context);
159 tc.setDisplayName(title);
160 tc.open();
161 tc.requestActive();
162 tc.searchOut();
169 * Opens the Search History panel with given pre-filled values. The search is executed in default context
170 * (all open projects).
172 * @param title title of the search
173 * @param commitMessage commit message to search for
174 * @param username user name to search for
175 * @param rev the revision of the change in question
177 public static void openSearch(String title, String commitMessage, String username, String rev)
179 openSearch(getDefaultContext(), title, commitMessage, username, rev);
182 public static void openSearch(VCSContext context, String title, String commitMessage, String username, String from)
184 String to = from + "~20";
186 if (commitMessage != null && commitMessage.indexOf('\n') != -1)
187 commitMessage = commitMessage.substring(0, commitMessage.indexOf('\n'));
188 SearchHistoryTopComponent tc = new SearchHistoryTopComponent(context, commitMessage, username, from, to);
189 String tcTitle = NbBundle.getMessage(SearchHistoryAction.class, "CTL_SearchHistory_Title", title); // NOI18N
190 tc.setDisplayName(tcTitle);
191 tc.open();
192 tc.requestActive();
193 tc.search(false);
196 private static VCSContext getDefaultContext()
198 Node[] nodes = TopComponent.getRegistry().getActivatedNodes();
200 return nodes != null ? VCSContext.forNodes(nodes) : VCSContext.EMPTY;
204 * Opens search panel in the context of the given repository URL.
206 * @param repositoryUrl URL to search
207 * @param localRoot local working copy root that corresponds to the repository URL
208 * @param revision revision to search for
210 public static void openSearch(String repositoryUrl, File localRoot, String revision)
212 SearchHistoryTopComponent tc = new SearchHistoryTopComponent(repositoryUrl, localRoot, revision);
213 String tcTitle = NbBundle.getMessage(SearchHistoryAction.class, "CTL_SearchHistory_Title", repositoryUrl); // NOI18N
214 tc.setDisplayName(tcTitle);
215 tc.open();
216 tc.requestActive();
217 tc.search(false);