1 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 ; 39 import java.beans.PropertyChangeListener ; 40 import java.beans.PropertyChangeEvent ; 41 import java.awt.Dialog ; 42 import java.text.DateFormat ; 43 import java.text.ParseException ; 44 import java.text.SimpleDateFormat ; 45 import java.util.Date ; 46 47 52 class SearchCriteriaPanel extends javax.swing.JPanel { 53 54 private final File[] roots; 55 private final SVNUrl url; 56 57 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 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 s = tfTo.getText().trim(); 80 if(s.length() == 0) { 81 return SVNRevision.HEAD; 82 } 83 return toRevision(s); 84 } 85 86 private Date parseDate(String s) { 87 if (s == null) return null; 88 for (int i = 0; i < SearchExecutor.dateFormats.length; i++) { 89 DateFormat dateformat = SearchExecutor.dateFormats[i]; 90 try { 91 return dateformat.parse(s); 92 } catch (ParseException e) { 93 } 95 } 96 return null; 97 } 98 99 private SVNRevision toRevision(String s) { 100 Date date = parseDate(s); 101 if (date != null) { 102 return new SVNRevision.DateSpec(date); 103 } else { 104 if ("BASE".equals(s)) { return SVNRevision.BASE; 106 } else if ("HEAD".equals(s)) { return SVNRevision.HEAD; 108 } else { 109 try { 110 return new SVNRevision.Number(Long.parseLong(s)); 111 } catch (NumberFormatException ex) { 112 } 114 } 115 } 116 return null; 117 } 118 119 public String getCommitMessage() { 120 String s = tfCommitMessage.getText().trim(); 121 return s.length() > 0 ? s : null; 122 } 123 124 public String getUsername() { 125 String s = tfUsername.getText().trim(); 126 return s.length() > 0 ? s : null; 127 } 128 129 public void setFrom(String from) { 130 if (from == null) from = ""; tfFrom.setText(from); 132 } 133 134 public void setTo(String to) { 135 if (to == null) to = ""; tfTo.setText(to); 137 } 138 139 public void setCommitMessage(String message) { 140 if (message == null) message = ""; tfCommitMessage.setText(message); 142 } 143 144 public void setUsername(String username) { 145 if (username == null) username = ""; tfUsername.setText(username); 147 } 148 149 public void addNotify() { 150 super.addNotify(); 151 SwingUtilities.invokeLater(new Runnable () { 152 public void run() { 153 tfCommitMessage.requestFocusInWindow(); 154 } 155 }); 156 } 157 158 163 private void initComponents() { 165 java.awt.GridBagConstraints gridBagConstraints; 166 167 jLabel1 = new javax.swing.JLabel (); 168 tfCommitMessage = new javax.swing.JTextField (); 169 jLabel2 = new javax.swing.JLabel (); 170 tfUsername = new javax.swing.JTextField (); 171 jLabel3 = new javax.swing.JLabel (); 172 jLabel5 = new javax.swing.JLabel (); 173 bBrowseFrom = new javax.swing.JButton (); 174 jLabel4 = new javax.swing.JLabel (); 175 jLabel6 = new javax.swing.JLabel (); 176 bBrowseTo = new javax.swing.JButton (); 177 178 setLayout(new java.awt.GridBagLayout ()); 179 180 setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 12, 0, 11)); 181 jLabel1.setLabelFor(tfCommitMessage); 182 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/subversion/ui/history/Bundle"); org.openide.awt.Mnemonics.setLocalizedText(jLabel1, bundle.getString("CTL_UseCommitMessage")); jLabel1.setToolTipText(bundle.getString("TT_CommitMessage")); gridBagConstraints = new java.awt.GridBagConstraints (); 186 gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; 187 add(jLabel1, gridBagConstraints); 188 189 tfCommitMessage.setColumns(20); 190 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 4, 0, 0); 197 add(tfCommitMessage, gridBagConstraints); 198 199 jLabel2.setLabelFor(tfUsername); 200 org.openide.awt.Mnemonics.setLocalizedText(jLabel2, bundle.getString("CTL_UseUsername")); jLabel2.setToolTipText(bundle.getString("TT_Username")); gridBagConstraints = new java.awt.GridBagConstraints (); 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 (); 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 (0, 4, 0, 0); 215 add(tfUsername, gridBagConstraints); 216 217 jLabel3.setLabelFor(tfFrom); 218 org.openide.awt.Mnemonics.setLocalizedText(jLabel3, bundle.getString("CTL_UseFrom")); jLabel3.setToolTipText(bundle.getString("TT_From")); gridBagConstraints = new java.awt.GridBagConstraints (); 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 (); 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 (0, 4, 0, 4); 232 add(tfFrom, gridBagConstraints); 233 234 org.openide.awt.Mnemonics.setLocalizedText(jLabel5, bundle.getString("CTL_FromToHint")); gridBagConstraints = new java.awt.GridBagConstraints (); 236 gridBagConstraints.gridx = 2; 237 gridBagConstraints.gridy = 2; 238 gridBagConstraints.insets = new java.awt.Insets (0, 2, 0, 4); 239 add(jLabel5, gridBagConstraints); 240 241 org.openide.awt.Mnemonics.setLocalizedText(bBrowseFrom, bundle.getString("CTL_BrowseFrom")); bBrowseFrom.setToolTipText(bundle.getString("TT_BrowseFrom")); bBrowseFrom.addActionListener(new java.awt.event.ActionListener () { 244 public void actionPerformed(java.awt.event.ActionEvent evt) { 245 onFromBrowse(evt); 246 } 247 }); 248 249 gridBagConstraints = new java.awt.GridBagConstraints (); 250 gridBagConstraints.gridx = 3; 251 gridBagConstraints.gridy = 2; 252 gridBagConstraints.insets = new java.awt.Insets (0, 4, 0, 0); 253 add(bBrowseFrom, gridBagConstraints); 254 255 jLabel4.setLabelFor(tfTo); 256 org.openide.awt.Mnemonics.setLocalizedText(jLabel4, bundle.getString("CTL_UseTo")); jLabel4.setToolTipText(bundle.getString("TT_To")); gridBagConstraints = new java.awt.GridBagConstraints (); 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 (3, 0, 0, 0); 263 add(jLabel4, gridBagConstraints); 264 265 tfTo.setColumns(20); 266 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 4, 0, 4); 275 add(tfTo, gridBagConstraints); 276 277 org.openide.awt.Mnemonics.setLocalizedText(jLabel6, bundle.getString("CTL_FromToHint")); gridBagConstraints = new java.awt.GridBagConstraints (); 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 (3, 2, 0, 4); 284 add(jLabel6, gridBagConstraints); 285 286 org.openide.awt.Mnemonics.setLocalizedText(bBrowseTo, bundle.getString("CTL_BrowseTo")); bBrowseTo.setToolTipText(bundle.getString("TT_BrowseTo")); bBrowseTo.addActionListener(new java.awt.event.ActionListener () { 289 public void actionPerformed(java.awt.event.ActionEvent evt) { 290 onToBrowse(evt); 291 } 292 }); 293 294 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 4, 0, 0); 301 add(bBrowseTo, gridBagConstraints); 302 303 } 305 private void onToBrowse(java.awt.event.ActionEvent evt) { onBrowse(tfTo); 307 } 309 private void onFromBrowse(java.awt.event.ActionEvent evt) { onBrowse(tfFrom); 311 } 313 private void onBrowse(final JTextField destination) { 314 final SVNUrl repositoryUrl = url != null ? url : SvnUtils.getRepositoryRootUrl(roots[0]); 315 316 String title = destination == tfFrom ? NbBundle.getMessage(SearchCriteriaPanel.class, "CTL_BrowseTag_StartTag") : NbBundle.getMessage(SearchCriteriaPanel.class, "CTL_BrowseTag_EndTag"); 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")); dialogDescriptor.setModal(true); 329 dialogDescriptor.setHelpCtx(new HelpCtx(Browser.class)); 330 dialogDescriptor.setValid(false); 331 332 browser.addPropertyChangeListener(new PropertyChangeListener () { 333 public void propertyChange(PropertyChangeEvent evt) { 334 if( ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName()) ) { 335 dialogDescriptor.setValid(browser.getSelectedNodes().length > 0); 336 } 337 } 338 }); 339 340 Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor); 341 dialog.setVisible(true); 342 343 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")); 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")); } 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 () { 378 public void run() { 379 destination.setText(Long.toString(revision.getNumber())); 380 } 381 }); 382 } 383 384 private javax.swing.JButton bBrowseFrom; 386 private javax.swing.JButton bBrowseTo; 387 private javax.swing.JLabel jLabel1; 388 private javax.swing.JLabel jLabel2; 389 private javax.swing.JLabel jLabel3; 390 private javax.swing.JLabel jLabel4; 391 private javax.swing.JLabel jLabel5; 392 private javax.swing.JLabel jLabel6; 393 private javax.swing.JTextField tfCommitMessage; 394 final javax.swing.JTextField tfFrom = new javax.swing.JTextField (); 395 final javax.swing.JTextField tfTo = new javax.swing.JTextField (); 396 private javax.swing.JTextField tfUsername; 397 399 } 400 | Popular Tags |