KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > history > SearchCriteriaPanel


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.tigris.subversion.svnclientadapter.*;
23 import org.netbeans.modules.subversion.ui.browser.Browser;
24 import org.netbeans.modules.subversion.RepositoryFile;
25 import org.netbeans.modules.subversion.Subversion;
26 import org.netbeans.modules.subversion.client.SvnClient;
27 import org.netbeans.modules.subversion.client.SvnProgressSupport;
28 import org.netbeans.modules.subversion.util.SvnUtils;
29 import org.openide.DialogDescriptor;
30 import org.openide.DialogDisplayer;
31 import org.openide.ErrorManager;
32 import org.openide.explorer.ExplorerManager;
33 import org.openide.util.HelpCtx;
34 import org.openide.util.RequestProcessor;
35 import org.openide.util.NbBundle;
36
37 import javax.swing.*;
38 import java.io.File JavaDoc;
39 import java.beans.PropertyChangeListener JavaDoc;
40 import java.beans.PropertyChangeEvent JavaDoc;
41 import java.awt.Dialog JavaDoc;
42 import java.text.DateFormat JavaDoc;
43 import java.text.ParseException JavaDoc;
44 import java.text.SimpleDateFormat JavaDoc;
45 import java.util.Date JavaDoc;
46
47 /**
48  * Packages search criteria in Search History panel.
49  *
50  * @author Maros Sandor
51  */

52 class SearchCriteriaPanel extends javax.swing.JPanel JavaDoc {
53     
54     private final File[] roots;
55     private final SVNUrl url;
56     
57     /** Creates new form SearchCriteriaPanel */
58     public SearchCriteriaPanel(File [] roots) {
59         this.roots = roots;
60         this.url = null;
61         initComponents();
62     }
63
64     public SearchCriteriaPanel(SVNUrl url) {
65         this.url = url;
66         this.roots = null;
67         initComponents();
68     }
69     
70     public SVNRevision getFrom() {
71         String JavaDoc s = tfFrom.getText().trim();
72         if(s.length() == 0) {
73             return new SVNRevision.Number(1);
74         }
75         return toRevision(s);
76     }
77
78     public SVNRevision getTo() {
79         String JavaDoc s = tfTo.getText().trim();
80         if(s.length() == 0) {
81             return SVNRevision.HEAD;
82         }
83         return toRevision(s);
84     }
85     
86     private Date JavaDoc parseDate(String JavaDoc s) {
87         if (s == null) return null;
88         for (int i = 0; i < SearchExecutor.dateFormats.length; i++) {
89             DateFormat JavaDoc dateformat = SearchExecutor.dateFormats[i];
90             try {
91                 return dateformat.parse(s);
92             } catch (ParseException JavaDoc e) {
93                 // try the next one
94
}
95         }
96         return null;
97     }
98
99     private SVNRevision toRevision(String JavaDoc s) {
100         Date JavaDoc date = parseDate(s);
101         if (date != null) {
102             return new SVNRevision.DateSpec(date);
103         } else {
104             if ("BASE".equals(s)) { // NOI18N
105
return SVNRevision.BASE;
106             } else if ("HEAD".equals(s)) { // NOI18N
107
return SVNRevision.HEAD;
108             } else {
109                 try {
110                     return new SVNRevision.Number(Long.parseLong(s));
111                 } catch (NumberFormatException JavaDoc ex) {
112                     // do nothing
113
}
114             }
115         }
116         return null;
117     }
118     
119     public String JavaDoc getCommitMessage() {
120         String JavaDoc s = tfCommitMessage.getText().trim();
121         return s.length() > 0 ? s : null;
122     }
123
124     public String JavaDoc getUsername() {
125         String JavaDoc s = tfUsername.getText().trim();
126         return s.length() > 0 ? s : null;
127     }
128
129     public void setFrom(String JavaDoc from) {
130         if (from == null) from = ""; // NOI18N
131
tfFrom.setText(from);
132     }
133
134     public void setTo(String JavaDoc to) {
135         if (to == null) to = ""; // NOI18N
136
tfTo.setText(to);
137     }
138     
139     public void setCommitMessage(String JavaDoc message) {
140         if (message == null) message = ""; // NOI18N
141
tfCommitMessage.setText(message);
142     }
143
144     public void setUsername(String JavaDoc username) {
145         if (username == null) username = ""; // NOI18N
146
tfUsername.setText(username);
147     }
148     
149     public void addNotify() {
150         super.addNotify();
151         SwingUtilities.invokeLater(new Runnable JavaDoc() {
152             public void run() {
153                 tfCommitMessage.requestFocusInWindow();
154             }
155         });
156     }
157
158     /** This method is called from within the constructor to
159      * initialize the form.
160      * WARNING: Do NOT modify this code. The content of this method is
161      * always regenerated by the Form Editor.
162      */

163     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
164
private void initComponents() {
165         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
166
167         jLabel1 = new javax.swing.JLabel JavaDoc();
168         tfCommitMessage = new javax.swing.JTextField JavaDoc();
169         jLabel2 = new javax.swing.JLabel JavaDoc();
170         tfUsername = new javax.swing.JTextField JavaDoc();
171         jLabel3 = new javax.swing.JLabel JavaDoc();
172         jLabel5 = new javax.swing.JLabel JavaDoc();
173         bBrowseFrom = new javax.swing.JButton JavaDoc();
174         jLabel4 = new javax.swing.JLabel JavaDoc();
175         jLabel6 = new javax.swing.JLabel JavaDoc();
176         bBrowseTo = new javax.swing.JButton JavaDoc();
177
178         setLayout(new java.awt.GridBagLayout JavaDoc());
179
180         setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 12, 0, 11));
181         jLabel1.setLabelFor(tfCommitMessage);
182         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/subversion/ui/history/Bundle"); // NOI18N
183
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, bundle.getString("CTL_UseCommitMessage")); // NOI18N
184
jLabel1.setToolTipText(bundle.getString("TT_CommitMessage")); // NOI18N
185
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
186         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
187         add(jLabel1, gridBagConstraints);
188
189         tfCommitMessage.setColumns(20);
190         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
191         gridBagConstraints.gridx = 1;
192         gridBagConstraints.gridy = 0;
193         gridBagConstraints.gridwidth = 2;
194         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
195         gridBagConstraints.weightx = 1.0;
196         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 0, 0);
197         add(tfCommitMessage, gridBagConstraints);
198
199         jLabel2.setLabelFor(tfUsername);
200         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, bundle.getString("CTL_UseUsername")); // NOI18N
201
jLabel2.setToolTipText(bundle.getString("TT_Username")); // NOI18N
202
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
203         gridBagConstraints.gridy = 1;
204         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
205         add(jLabel2, gridBagConstraints);
206
207         tfUsername.setColumns(20);
208         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
209         gridBagConstraints.gridx = 1;
210         gridBagConstraints.gridy = 1;
211         gridBagConstraints.gridwidth = 2;
212         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
213         gridBagConstraints.weightx = 1.0;
214         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 0, 0);
215         add(tfUsername, gridBagConstraints);
216
217         jLabel3.setLabelFor(tfFrom);
218         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, bundle.getString("CTL_UseFrom")); // NOI18N
219
jLabel3.setToolTipText(bundle.getString("TT_From")); // NOI18N
220
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
221         gridBagConstraints.gridy = 2;
222         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
223         add(jLabel3, gridBagConstraints);
224
225         tfFrom.setColumns(20);
226         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
227         gridBagConstraints.gridx = 1;
228         gridBagConstraints.gridy = 2;
229         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
230         gridBagConstraints.weightx = 1.0;
231         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 0, 4);
232         add(tfFrom, gridBagConstraints);
233
234         org.openide.awt.Mnemonics.setLocalizedText(jLabel5, bundle.getString("CTL_FromToHint")); // NOI18N
235
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
236         gridBagConstraints.gridx = 2;
237         gridBagConstraints.gridy = 2;
238         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 2, 0, 4);
239         add(jLabel5, gridBagConstraints);
240
241         org.openide.awt.Mnemonics.setLocalizedText(bBrowseFrom, bundle.getString("CTL_BrowseFrom")); // NOI18N
242
bBrowseFrom.setToolTipText(bundle.getString("TT_BrowseFrom")); // NOI18N
243
bBrowseFrom.addActionListener(new java.awt.event.ActionListener JavaDoc() {
244             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
245                 onFromBrowse(evt);
246             }
247         });
248
249         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
250         gridBagConstraints.gridx = 3;
251         gridBagConstraints.gridy = 2;
252         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 0, 0);
253         add(bBrowseFrom, gridBagConstraints);
254
255         jLabel4.setLabelFor(tfTo);
256         org.openide.awt.Mnemonics.setLocalizedText(jLabel4, bundle.getString("CTL_UseTo")); // NOI18N
257
jLabel4.setToolTipText(bundle.getString("TT_To")); // NOI18N
258
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
259         gridBagConstraints.gridy = 3;
260         gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
261         gridBagConstraints.weighty = 1.0;
262         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 0, 0, 0);
263         add(jLabel4, gridBagConstraints);
264
265         tfTo.setColumns(20);
266         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
267         gridBagConstraints.gridx = 1;
268         gridBagConstraints.gridy = 3;
269         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
270         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
271         gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
272         gridBagConstraints.weightx = 1.0;
273         gridBagConstraints.weighty = 1.0;
274         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 0, 4);
275         add(tfTo, gridBagConstraints);
276
277         org.openide.awt.Mnemonics.setLocalizedText(jLabel6, bundle.getString("CTL_FromToHint")); // NOI18N
278
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
279         gridBagConstraints.gridx = 2;
280         gridBagConstraints.gridy = 3;
281         gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_START;
282         gridBagConstraints.weighty = 1.0;
283         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 2, 0, 4);
284         add(jLabel6, gridBagConstraints);
285
286         org.openide.awt.Mnemonics.setLocalizedText(bBrowseTo, bundle.getString("CTL_BrowseTo")); // NOI18N
287
bBrowseTo.setToolTipText(bundle.getString("TT_BrowseTo")); // NOI18N
288
bBrowseTo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
289             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
290                 onToBrowse(evt);
291             }
292         });
293
294         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
295         gridBagConstraints.gridx = 3;
296         gridBagConstraints.gridy = 3;
297         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
298         gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
299         gridBagConstraints.weighty = 1.0;
300         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 0, 0);
301         add(bBrowseTo, gridBagConstraints);
302
303     }// </editor-fold>//GEN-END:initComponents
304

305     private void onToBrowse(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_onToBrowse
306
onBrowse(tfTo);
307     }//GEN-LAST:event_onToBrowse
308

309     private void onFromBrowse(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_onFromBrowse
310
onBrowse(tfFrom);
311     }//GEN-LAST:event_onFromBrowse
312

313     private void onBrowse(final JTextField destination) {
314         final SVNUrl repositoryUrl = url != null ? url : SvnUtils.getRepositoryRootUrl(roots[0]);
315
316         String JavaDoc title = destination == tfFrom ? NbBundle.getMessage(SearchCriteriaPanel.class, "CTL_BrowseTag_StartTag") : NbBundle.getMessage(SearchCriteriaPanel.class, "CTL_BrowseTag_EndTag"); // NOI18N
317
final Browser browser;
318         RepositoryFile repoFile = new RepositoryFile(repositoryUrl, SVNRevision.HEAD);
319         int browserMode;
320         if(roots[0].isFile()) {
321             browserMode = Browser.BROWSER_SINGLE_SELECTION_ONLY | Browser.BROWSER_SHOW_FILES | Browser.BROWSER_FOLDERS_SELECTION_ONLY;
322         } else {
323             browserMode = Browser.BROWSER_SHOW_FILES;
324         }
325         browser = new Browser(title, browserMode, repoFile, null, null);
326         final DialogDescriptor dialogDescriptor =
327                 new DialogDescriptor(browser.getBrowserPanel(), NbBundle.getMessage(SearchCriteriaPanel.class, "LBL_Search_BrowseRepository")); // NOI18N
328
dialogDescriptor.setModal(true);
329         dialogDescriptor.setHelpCtx(new HelpCtx(Browser.class));
330         dialogDescriptor.setValid(false);
331         
332         browser.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
333             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
334                 if( ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName()) ) {
335                     dialogDescriptor.setValid(browser.getSelectedNodes().length > 0);
336                 }
337             }
338         });
339         
340         Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
341         dialog.setVisible(true);
342
343         // handle results
344
if (!DialogDescriptor.OK_OPTION.equals(dialogDescriptor.getValue())) {
345             browser.cancel();
346             return;
347         }
348
349         final SVNUrl tagURL = browser.getSelectedFiles()[0].getFileUrl();
350         destination.setText(NbBundle.getMessage(SearchCriteriaPanel.class, "MSG_Search_PleaseWait")); // NOI18N
351

352         RequestProcessor rp = Subversion.getInstance().getRequestProcessor(repositoryUrl);
353         SvnProgressSupport support = new SvnProgressSupport() {
354             public void perform() {
355                 processTagSelection(destination, repositoryUrl, tagURL, this);
356             }
357         };
358         support.start(rp, repositoryUrl, NbBundle.getMessage(SearchCriteriaPanel.class, "MSG_Search_ResolvingTagProgress")); // NOI18N
359
}
360
361     private void processTagSelection(final JTextField destination, SVNUrl repositoryURL, final SVNUrl tagURL, SvnProgressSupport progress) {
362         SvnClient client;
363         try {
364             client = Subversion.getInstance().getClient(repositoryURL, progress);
365         } catch (SVNClientException ex) {
366             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
367             return;
368         }
369         ISVNLogMessage[] log = new org.tigris.subversion.svnclientadapter.ISVNLogMessage[0];
370         try {
371             log = client.getLogMessages(tagURL, null, new SVNRevision.Number(1), SVNRevision.HEAD, true, false, 1);
372         } catch (SVNClientException e) {
373             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
374             return;
375         }
376         final SVNRevision.Number revision = log[0].getRevision();
377         SwingUtilities.invokeLater(new Runnable JavaDoc() {
378             public void run() {
379                 destination.setText(Long.toString(revision.getNumber()));
380             }
381         });
382     }
383     
384     // Variables declaration - do not modify//GEN-BEGIN:variables
385
private javax.swing.JButton JavaDoc bBrowseFrom;
386     private javax.swing.JButton JavaDoc bBrowseTo;
387     private javax.swing.JLabel JavaDoc jLabel1;
388     private javax.swing.JLabel JavaDoc jLabel2;
389     private javax.swing.JLabel JavaDoc jLabel3;
390     private javax.swing.JLabel JavaDoc jLabel4;
391     private javax.swing.JLabel JavaDoc jLabel5;
392     private javax.swing.JLabel JavaDoc jLabel6;
393     private javax.swing.JTextField JavaDoc tfCommitMessage;
394     final javax.swing.JTextField JavaDoc tfFrom = new javax.swing.JTextField JavaDoc();
395     final javax.swing.JTextField JavaDoc tfTo = new javax.swing.JTextField JavaDoc();
396     private javax.swing.JTextField JavaDoc tfUsername;
397     // End of variables declaration//GEN-END:variables
398

399 }
400
Popular Tags