Adding Git source, NetBeans project files, GPL v2 LICENSE, ant build file.
[nbgit.git] / src / org / netbeans / modules / git / ui / log / SearchHistoryTopComponent.java
blobe6466e5e12f3c86dc996d85b543f1251b0c57363
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.netbeans.modules.git.ui.log;
44 import java.util.Date;
45 import org.netbeans.modules.git.ui.diff.DiffSetupSource;
46 import org.netbeans.modules.versioning.spi.VCSContext;
47 import org.openide.util.NbBundle;
49 /**
50 * @author Maros Sandor
52 public class SearchHistoryTopComponent extends TopComponent implements DiffSetupSource {
54 private SearchHistoryPanel shp;
55 private SearchCriteriaPanel scp;
57 public SearchHistoryTopComponent() {
58 getAccessibleContext().setAccessibleName(NbBundle.getMessage(SearchHistoryTopComponent.class, "ACSN_SearchHistoryT_Top_Component")); // NOI18N
59 getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(SearchHistoryTopComponent.class, "ACSD_SearchHistoryT_Top_Component")); // NOI18N
62 public SearchHistoryTopComponent(VCSContext context) {
63 this(context, null, null, null, null);
66 public SearchHistoryTopComponent(VCSContext context, String commitMessage, String username, Date from, Date to) {
67 this();
68 File[] roots = context.getRootFiles().toArray(new File[0]);
69 initComponents(roots, commitMessage, username, from, to);
72 public SearchHistoryTopComponent(String repositoryUrl, File localRoot, long revision) {
73 this();
74 initComponents(repositoryUrl, localRoot, revision);
77 public void search() {
78 shp.executeSearch();
79 shp.setSearchCriteria(false);
82 public void searchOut() {
83 shp.setOutSearch();
84 shp.executeSearch();
85 shp.setSearchCriteria(false);
86 scp.setFrom("");
87 scp.setTo("");
90 public void searchIncoming() {
91 shp.setIncomingSearch();
92 scp.setFrom("");
93 scp.setTo("");
96 private void initComponents(String repositoryUrl, File localRoot, long revision) {
97 setLayout(new BorderLayout());
98 scp = new SearchCriteriaPanel(repositoryUrl);
99 scp.setFrom(Long.toString(revision));
100 scp.setTo(Long.toString(revision));
101 shp = new SearchHistoryPanel(repositoryUrl, localRoot, scp);
102 add(shp);
105 private void initComponents(File[] roots, String commitMessage, String username, Date from, Date to) {
106 setLayout(new BorderLayout());
107 scp = new SearchCriteriaPanel(roots);
108 scp.setCommitMessage(commitMessage);
109 scp.setUsername(username);
110 if (from != null){
111 scp.setFrom(SearchExecutor.simpleDateFormat.format(from));
112 }else{
113 scp.setFrom(HgUtils.getLastWeeksDateStr());
115 if (to != null){
116 scp.setTo(SearchExecutor.simpleDateFormat.format(to));
117 }else{
118 scp.setTo(HgUtils.getTodaysDateStr());
120 shp = new SearchHistoryPanel(roots, scp);
121 add(shp);
124 public int getPersistenceType(){
125 return TopComponent.PERSISTENCE_NEVER;
128 protected void componentClosed() {
129 //((DiffMainPanel) getComponent(0)).componentClosed();
130 super.componentClosed();
133 protected String preferredID(){
134 if (shp.isIncomingSearch()) {
135 return "Hg.IncomingSearchHistoryTopComponent"; // NOI18N
136 } else if (shp.isOutSearch()) {
137 return "Hg.OutSearchHistoryTopComponent"; // NOI18N
139 return "Hg.SearchHistoryTopComponent"; // NOI18N
142 public HelpCtx getHelpCtx() {
143 return new HelpCtx(getClass());
146 public Collection getSetups() {
147 return shp.getSetups();
150 public String getSetupDisplayName() {
151 return getDisplayName();