KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > wizards > RepositoryStep


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.versioning.system.cvss.ui.wizards;
21
22 import org.openide.WizardDescriptor;
23 import org.openide.ErrorManager;
24 import org.openide.util.RequestProcessor;
25 import org.openide.util.NbBundle;
26 import org.openide.util.HelpCtx;
27 import org.netbeans.api.progress.ProgressHandle;
28 import org.netbeans.api.progress.ProgressHandleFactory;
29 import org.netbeans.api.options.OptionsDisplayer;
30 import org.netbeans.lib.cvsclient.connection.*;
31 import org.netbeans.lib.cvsclient.CVSRoot;
32 import org.netbeans.modules.versioning.system.cvss.CvsModuleConfig;
33 import org.netbeans.modules.versioning.system.cvss.SSHConnection;
34 import org.netbeans.modules.versioning.util.Utils;
35
36 import javax.swing.event.DocumentListener JavaDoc;
37 import javax.swing.event.DocumentEvent JavaDoc;
38 import javax.swing.*;
39 import javax.swing.text.JTextComponent JavaDoc;
40 import javax.net.SocketFactory;
41 import java.awt.event.ActionListener JavaDoc;
42 import java.awt.event.ActionEvent JavaDoc;
43 import java.awt.*;
44 import java.util.*;
45 import java.net.Socket JavaDoc;
46 import java.net.SocketAddress JavaDoc;
47 import java.net.InetSocketAddress JavaDoc;
48 import java.io.IOException JavaDoc;
49 import java.lang.reflect.InvocationTargetException JavaDoc;
50
51 /**
52  * UI for CvsRootSettings. After initialization data
53  * are taken directly from UI. These are propagated
54  * into CvsRootSettings on {@link #storeValidValues()}.
55  *
56  * @author Petr Kuzel
57  */

58 public final class RepositoryStep extends AbstractStep implements WizardDescriptor.AsynchronousValidatingPanel, ActionListener JavaDoc, DocumentListener JavaDoc {
59
60     private static final String JavaDoc USE_INTERNAL_SSH = "repositoryStep.useInternalSSH";
61     private static final String JavaDoc EXT_COMMAND = "repositoryStep.extCommand";
62     private static final String JavaDoc RECENT_ROOTS = "repositoryStep.recentRoots";
63
64     private RequestProcessor.Task updatePasswordTask;
65     private volatile boolean passwordExpected;
66
67     private ProgressHandle progress;
68     private JComponent progressComponent;
69     private JLabel progressLabel;
70
71     private volatile boolean internalDocumentChange;
72     private Thread JavaDoc backgroundValidationThread;
73     private RepositoryPanel repositoryPanel;
74     private String JavaDoc scrambledPassword;
75     private final String JavaDoc initialCvsRoot;
76     private String JavaDoc preferedCvsRoot;
77
78
79     /**
80      * Creates multiple roots customizer.
81      */

82     public RepositoryStep() {
83         initialCvsRoot = null;
84     }
85
86     /**
87      * Creates single root customizer
88      */

89     public RepositoryStep(String JavaDoc root) {
90         initialCvsRoot = root;
91     }
92
93     public HelpCtx getHelp() {
94         return new HelpCtx(RepositoryStep.class);
95     }
96     
97     /**
98      * Preselected cvs root (first in list).
99      */

100     public void initPreferedCvsRoot(String JavaDoc root) {
101         preferedCvsRoot = root;
102     }
103
104     protected JComponent createComponent() {
105         repositoryPanel = new RepositoryPanel();
106
107         // password field, features automatic fill from ~/.cvspass
108

109         repositoryPanel.extSshRadioButton.addActionListener(this);
110         repositoryPanel.internalSshRadioButton.addActionListener(this);
111         repositoryPanel.extCommandTextField.getDocument().addDocumentListener(this);
112         repositoryPanel.extPasswordField.getDocument().addDocumentListener(this);
113         repositoryPanel.passwordTextField.getDocument().addDocumentListener(this);
114         RequestProcessor requestProcessor = new RequestProcessor();
115         updatePasswordTask = requestProcessor.create(new Runnable JavaDoc() {
116             public void run() {
117                 String JavaDoc cvsRoot = selectedCvsRoot();
118                 String JavaDoc password = PasswordsFile.findPassword(cvsRoot);
119                 if (password != null && passwordExpected) {
120                     String JavaDoc fakePasswordWithProperLen = new String JavaDoc(password).substring(1);
121                     scrambledPassword = password;
122                     internalDocumentChange = true;
123                     repositoryPanel.passwordTextField.setText(fakePasswordWithProperLen);
124                     internalDocumentChange = false;
125                     cancelPasswordUpdate();
126                 }
127             }
128         });
129
130         // roots combo setup, keeping history
131

132         Set recentRoots = new LinkedHashSet();
133         if (preferedCvsRoot != null) {
134             recentRoots.add(preferedCvsRoot);
135         }
136         recentRoots.addAll(Utils.getStringList(CvsModuleConfig.getDefault().getPreferences(), RECENT_ROOTS));
137         if (initialCvsRoot != null) {
138             // it's first => initially selected
139
recentRoots.add(initialCvsRoot);
140         }
141         Iterator cvsPassRoots = PasswordsFile.listRoots(":pserver:").iterator(); // NOI18N
142
while (cvsPassRoots.hasNext()) {
143             String JavaDoc next = (String JavaDoc) cvsPassRoots.next();
144             if (recentRoots.contains(next) == false) {
145                 recentRoots.add(next);
146             }
147         }
148         // templates for supported connection methods
149
String JavaDoc user = System.getProperty("user.name", ""); // NOI18N
150
if (user.length() > 0) user += "@"; // NOI18N
151
recentRoots.add(":pserver:" + user); // NOI18N
152
recentRoots.add(":ext:" + user); // NOI18N
153
recentRoots.add(":fork:"); // NOI18N
154
recentRoots.add(":local:"); // NOI18N
155

156         ComboBoxModel rootsModel = new DefaultComboBoxModel(new Vector(recentRoots));
157         repositoryPanel.rootComboBox.setModel(rootsModel);
158         repositoryPanel.rootComboBox.addActionListener(this);
159         Component JavaDoc editor = repositoryPanel.rootComboBox.getEditor().getEditorComponent();
160         JTextComponent JavaDoc textEditor = (JTextComponent JavaDoc) editor;
161         if (recentRoots.size() == 0) {
162             textEditor.setText(":pserver:" + user); // NOI18N
163
} else {
164             validateCvsRoot();
165             CVSRoot root = getCVSRoot();
166             schedulePasswordUpdate();
167         }
168         textEditor.selectAll();
169         textEditor.getDocument().addDocumentListener(this);
170
171         boolean useInternalSsh = CvsModuleConfig.getDefault().getPreferences().getBoolean(USE_INTERNAL_SSH, true);
172         repositoryPanel.internalSshRadioButton.setSelected(useInternalSsh);
173         repositoryPanel.extSshRadioButton.setSelected(!useInternalSsh);
174         
175         String JavaDoc extCommand = CvsModuleConfig.getDefault().getPreferences().get(EXT_COMMAND, "");
176         repositoryPanel.extCommandTextField.setText(extCommand);
177
178         repositoryPanel.proxyConfigurationButton.addActionListener(this);
179         repositoryPanel.editButton.addActionListener(this);
180
181         valid();
182         onCvsRootChange();
183
184         if (initialCvsRoot != null) {
185             boolean chooserVisible = false;
186             repositoryPanel.headerLabel.setVisible(chooserVisible);
187             repositoryPanel.rootsLabel.setVisible(chooserVisible);
188             repositoryPanel.rootComboBox.setVisible(chooserVisible);
189             repositoryPanel.descLabel.setVisible(chooserVisible);
190             repositoryPanel.editButton.setVisible(chooserVisible);
191         }
192
193         return repositoryPanel;
194     }
195
196     /**
197      * Heavy validation over network.
198      * Sets wizard as invalid to disable next button
199      * and starts. It's invoked in background validation thread.
200      */

201     protected void validateBeforeNext() {
202
203         if (validateCvsRoot() == false) {
204             return;
205         }
206         final CVSRoot root = getCVSRoot();
207
208         backgroundValidationThread = Thread.currentThread();
209
210         final String JavaDoc invalidMsg[] = new String JavaDoc[1]; // ret value
211
Runnable JavaDoc worker = new Runnable JavaDoc() {
212
213             private void fail(String JavaDoc msg) {
214                 invalidMsg[0] = msg;
215             }
216
217             public void run() {
218
219                 String JavaDoc host = root.getHostName();
220                 String JavaDoc userName = root.getUserName();
221                 int port = root.getPort();
222                 Socket JavaDoc sock = null;
223                 Connection connection = null;
224
225                 try {
226                     if (root.isLocal()) {
227                         LocalConnection lconnection = new LocalConnection();
228                         lconnection.setRepository(root.getRepository());
229                         lconnection.verify();
230                     } else {
231                         invalid(null);
232                         progress(NbBundle.getMessage(CheckoutWizard.class, "BK2011"));
233                         SocketFactory factory = SocketFactory.getDefault();
234
235                         // check raw network reachability
236

237                         if (CVSRoot.METHOD_PSERVER.equals(root.getMethod())) {
238                             port = port == 0 ? 2401 : port; // default port
239

240                             SocketAddress JavaDoc target = new InetSocketAddress JavaDoc(host, port);
241                             sock = factory.createSocket();
242                             sock.connect(target, 5000);
243                             sock.close();
244
245                             // try to login
246
progress(NbBundle.getMessage(CheckoutWizard.class, "BK2010"));
247                             PServerConnection pconnection = new PServerConnection(root, factory);
248                             String JavaDoc password = getScrambledPassword();
249                             pconnection.setEncodedPassword(password);
250                             pconnection.verify();
251                         } else if (CVSRoot.METHOD_EXT.equals(root.getMethod())) {
252                             if (repositoryPanel.internalSshRadioButton.isSelected()) {
253                                 port = port == 0 ? 22 : port; // default port
254
String JavaDoc password = repositoryPanel.extPasswordField.getText();
255                                 SSHConnection sshConnection = new SSHConnection(factory, host, port, userName, password);
256                                 sshConnection.setRepository(root.getRepository());
257                                 sshConnection.verify();
258                             } else {
259                                 String JavaDoc command = repositoryPanel.extCommandTextField.getText();
260                                 String JavaDoc userOption = ""; // NOI18N
261
if ( userName != null) {
262                                     userOption = " -l " + userName; // NOI18N
263
}
264                                 String JavaDoc cvs_server = System.getenv("CVS_SERVER") != null?
265                                     System.getenv("CVS_SERVER") + " server": "cvs server"; // NOI18N
266
command += " " + host + userOption + " " + cvs_server; // NOI18N
267
ExtConnection econnection = new ExtConnection(command);
268                                 econnection.setRepository(root.getRepository());
269                                 econnection.verify();
270                             }
271                         } else {
272                             assert false : "Login check implemented only for pserver"; // NOI18N
273
}
274                     }
275
276                 } catch (IOException JavaDoc e) {
277                     ErrorManager err = ErrorManager.getDefault();
278                     err.annotate(e, org.openide.util.NbBundle.getMessage(RepositoryStep.class, "BK2019")); // NOi18N
279
err.notify(ErrorManager.INFORMATIONAL, e);
280                     String JavaDoc msg = NbBundle.getMessage(CheckoutWizard.class, "BK1001", host);
281                     fail(msg);
282                 } catch (AuthenticationException e) {
283                     ErrorManager err = ErrorManager.getDefault();
284                     err.annotate(e, "Connection authentification verification failed."); // NOI18N
285
err.notify(ErrorManager.INFORMATIONAL, e);
286
287                     // enhanced contact, if getLocalizedMessage strts with "<" it contains our approved texts
288
String JavaDoc msg;
289                     if (e.getLocalizedMessage() != null && e.getLocalizedMessage().startsWith("<")) { // NOI18N
290
msg = e.getLocalizedMessage();
291                     } else {
292                         if (root.isLocal()) {
293                             msg = NbBundle.getMessage(CheckoutWizard.class, "BK1004");
294                         } else {
295                             msg = NbBundle.getMessage(CheckoutWizard.class, "BK1002");
296                         }
297                     }
298                     fail(msg);
299                 } finally {
300                     if (sock != null) {
301                         try {
302                             sock.close();
303                         } catch (IOException JavaDoc e) {
304                             // already closed
305
}
306                     }
307                     if (connection != null) {
308                         try {
309                             connection.close();
310                         } catch (IOException JavaDoc e) {
311                             // already closed
312
}
313                     }
314                 }
315             }
316         };
317
318         Thread JavaDoc workerThread = new Thread JavaDoc(worker, "CVS I/O Probe "); // NOI18N
319
workerThread.start();
320         try {
321             workerThread.join();
322             if (invalidMsg[0] == null) {
323                 valid();
324                 storeValidValues();
325             } else {
326                 valid(invalidMsg[0]);
327             }
328         } catch (InterruptedException JavaDoc e) {
329             invalid(org.openide.util.NbBundle.getMessage(RepositoryStep.class, "BK2023"));
330             ErrorManager err = ErrorManager.getDefault();
331             err.annotate(e, "Passing interrupt to possibly uninterruptible nested thread: " + workerThread); // NOI18N
332
workerThread.interrupt();
333             err.notify(ErrorManager.INFORMATIONAL, e);
334         } finally {
335             backgroundValidationThread = null;
336             SwingUtilities.invokeLater(new Runnable JavaDoc() {
337                 public void run() {
338                     validationDone();
339                 }
340             });
341         }
342
343     }
344
345     private void progress(String JavaDoc message) {
346         if (progressLabel != null) {
347             progressLabel.setText(message);
348         }
349     }
350
351     private void validationDone() {
352         progress.finish();
353         repositoryPanel.jPanel1.remove(progressComponent);
354         repositoryPanel.jPanel1.revalidate();
355         repositoryPanel.jPanel1.repaint();
356         editable(true);
357     }
358
359     private void editable(boolean editable) {
360         repositoryPanel.rootComboBox.setEditable(editable);
361         repositoryPanel.passwordTextField.setEditable(editable);
362         repositoryPanel.extCommandTextField.setEditable(editable);
363         repositoryPanel.extPasswordField.setEditable(editable);
364
365         repositoryPanel.proxyConfigurationButton.setEnabled(editable);
366         repositoryPanel.extREmemberPasswordCheckBox.setEnabled(editable);
367         repositoryPanel.internalSshRadioButton.setEnabled(editable);
368         repositoryPanel.extSshRadioButton.setEnabled(editable);
369     }
370
371
372     void storeValidValues() {
373         String JavaDoc root = selectedCvsRoot();
374         CVSRoot cvsRoot = CVSRoot.parse(root);
375         if (root.startsWith(":pserver:")) { // NOI18N
376
try {
377                 // CVSclient library reads password directly from .cvspass file
378
// store it here into the file. It's potentionally necessary for
379
// next step branch and module browsers
380

381                 PasswordsFile.storePassword(root, getScrambledPassword());
382             } catch (IOException JavaDoc e) {
383                 ErrorManager err = ErrorManager.getDefault();
384                 err.annotate(e, org.openide.util.NbBundle.getMessage(RepositoryStep.class, "BK2020"));
385                 err.notify(e);
386             }
387         } else if (root.startsWith(":ext:")) { // NOI18N
388
boolean internalSsh = repositoryPanel.internalSshRadioButton.isSelected();
389             CvsModuleConfig.ExtSettings extSettings = new CvsModuleConfig.ExtSettings();
390             extSettings.extUseInternalSsh = internalSsh;
391             extSettings.extPassword = repositoryPanel.extPasswordField.getText();
392             extSettings.extRememberPassword = repositoryPanel.extREmemberPasswordCheckBox.isSelected();
393             extSettings.extCommand = repositoryPanel.extCommandTextField.getText();
394             CvsModuleConfig.getDefault().getPreferences().putBoolean(USE_INTERNAL_SSH, internalSsh);
395             CvsModuleConfig.getDefault().getPreferences().put(EXT_COMMAND, extSettings.extCommand);
396             CvsModuleConfig.getDefault().setExtSettingsFor(cvsRoot, extSettings);
397         }
398
399         Utils.insert(CvsModuleConfig.getDefault().getPreferences(), RECENT_ROOTS, root, 8);
400     }
401
402     /**
403      * Fast root syntax check. It can invalidate whole step
404      * but neder set it as valid.
405      */

406     private boolean validateCvsRoot() {
407         String JavaDoc cvsRoot = selectedCvsRoot();
408         String JavaDoc errorMessage = null;
409         boolean supportedMethod = false;
410         if (cvsRoot != null) {
411             supportedMethod |= cvsRoot.startsWith(":pserver:"); // NOI18N
412
supportedMethod |= cvsRoot.startsWith(":local:"); // NOI18N
413
supportedMethod |= cvsRoot.startsWith(":fork:"); // NOI18N
414
supportedMethod |= cvsRoot.startsWith(":ext:"); // NOI18N
415
}
416         if (supportedMethod == false ) {
417             errorMessage = NbBundle.getMessage(CheckoutWizard.class, "BK1000");
418         } else {
419             try {
420                 CVSRoot.parse(cvsRoot);
421             } catch (IllegalArgumentException JavaDoc ex) {
422                 errorMessage = org.openide.util.NbBundle.getMessage(RepositoryStep.class, "BK2021") + ex.getLocalizedMessage();
423             }
424         }
425         if (errorMessage != null) {
426             invalid(errorMessage);
427         }
428         return errorMessage == null;
429     }
430
431     /**
432      * On valid CVS root loads UI fields from CvsRootSettings.
433      * Always updates UI fields visibility.
434      */

435     private void onCvsRootChange() {
436         if (validateCvsRoot()) {
437             valid();
438             CVSRoot root = getCVSRoot();
439             if (CVSRoot.METHOD_EXT.equals(root.getMethod())) {
440                 if (CvsModuleConfig.getDefault().hasExtSettingsFor(root)) {
441                     CvsModuleConfig.ExtSettings extSettings = CvsModuleConfig.getDefault().getExtSettingsFor(root);
442                     repositoryPanel.internalSshRadioButton.setSelected(extSettings.extUseInternalSsh);
443                     repositoryPanel.extPasswordField.setText(extSettings.extPassword);
444                     repositoryPanel.extREmemberPasswordCheckBox.setSelected(extSettings.extRememberPassword);
445                     repositoryPanel.extCommandTextField.setText(extSettings.extCommand);
446                 }
447             }
448             repositoryPanel.extPasswordField.setEditable(root.getPassword() == null);
449             repositoryPanel.passwordTextField.setEditable(root.getPassword() == null);
450             if (root.getPassword() != null) {
451                 if (CVSRoot.METHOD_EXT.equals(root.getMethod())) {
452                     repositoryPanel.extPasswordField.setText(root.getPassword());
453                 } else if (CVSRoot.METHOD_PSERVER.equals(root.getMethod())) {
454                     repositoryPanel.passwordTextField.setText(root.getPassword());
455                 }
456             } else {
457                 schedulePasswordUpdate();
458             }
459         }
460         updateVisibility();
461         updateLabel();
462     }
463
464     private void updateLabel() {
465         String JavaDoc cvsRoot = selectedCvsRoot();
466         if (cvsRoot.startsWith(":pserver:")) { // NOI18N
467
repositoryPanel.descLabel.setText("(:pserver:username@hostname:/repository_path)"); // NOI18N
468
} else if (cvsRoot.startsWith(":local:")) { // NOI18N
469
repositoryPanel.descLabel.setText("(:local:/repository_path)"); // NOI18N
470
} else if (cvsRoot.startsWith(":fork:")) { // NOI18N
471
repositoryPanel.descLabel.setText("(:fork:/repository_path)"); // NOI18N
472
} else if (cvsRoot.startsWith(":ext:")) { // NOI18N
473
repositoryPanel.descLabel.setText("(:ext:username@hostname:/repository_path)"); // NOI18N
474
} else {
475             repositoryPanel.descLabel.setText(NbBundle.getMessage(CheckoutWizard.class, "BK1014"));
476         }
477
478     }
479
480     /** Shows proper fields depending on CVS root connection method. */
481     private void updateVisibility() {
482         String JavaDoc root = selectedCvsRoot();
483         boolean showPserverFields = root.startsWith(":pserver:"); // NOI18N
484
boolean showExtFields = root.startsWith(":ext:"); // NOI18N
485

486         repositoryPanel.passwordTextField.setVisible(showPserverFields);
487         repositoryPanel.pPaswordLabel.setVisible(showPserverFields);
488
489         repositoryPanel.internalSshRadioButton.setVisible(showExtFields);
490         repositoryPanel.extSshRadioButton.setVisible(showExtFields);
491
492         repositoryPanel.extPasswordLabel5.setVisible(showExtFields);
493         repositoryPanel.extPasswordField.setVisible(showExtFields);
494         repositoryPanel.extPasswordField.setEnabled(repositoryPanel.internalSshRadioButton.isSelected());
495         repositoryPanel.extREmemberPasswordCheckBox.setVisible(showExtFields);
496         repositoryPanel.extREmemberPasswordCheckBox.setEnabled(repositoryPanel.internalSshRadioButton.isSelected());
497
498         repositoryPanel.extCommandLabel.setVisible(showExtFields);
499         repositoryPanel.extCommandTextField.setVisible(showExtFields);
500         repositoryPanel.extCommandTextField.setEnabled(repositoryPanel.extSshRadioButton.isSelected());
501
502         repositoryPanel.proxyConfigurationButton.setVisible(showPserverFields || showExtFields);
503         repositoryPanel.proxyConfigurationButton.setEnabled(!repositoryPanel.extSshRadioButton.isSelected());
504         repositoryPanel.browseButton.setVisible(showExtFields);
505         repositoryPanel.browseButton.setEnabled(repositoryPanel.extSshRadioButton.isSelected());
506     }
507
508     /**
509      * Load selected root from Swing structures (from arbitrary thread).
510      * @return null on failure
511      */

512     private String JavaDoc selectedCvsRoot() {
513         if (initialCvsRoot != null) {
514             return initialCvsRoot;
515         }
516         final String JavaDoc cvsRoot[] = new String JavaDoc[1];
517         try {
518             Runnable JavaDoc awt = new Runnable JavaDoc() {
519                 public void run() {
520                     cvsRoot[0] = (String JavaDoc) repositoryPanel.rootComboBox.getEditor().getItem();
521                 }
522             };
523             if (SwingUtilities.isEventDispatchThread()) {
524                 awt.run();
525             } else {
526                 SwingUtilities.invokeAndWait(awt);
527             }
528             String JavaDoc root = cvsRoot[0].trim();
529             try {
530                 return CVSRoot.parse(root).toString();
531             } catch (Exception JavaDoc e) {
532                 return root;
533             }
534         } catch (InterruptedException JavaDoc e) {
535             ErrorManager err = ErrorManager.getDefault();
536             err.notify(e);
537         } catch (InvocationTargetException JavaDoc e) {
538             ErrorManager err = ErrorManager.getDefault();
539             err.notify(e);
540         }
541         return null;
542     }
543
544     private CVSRoot getCVSRoot() {
545         try {
546             String JavaDoc root = selectedCvsRoot();
547             return CVSRoot.parse(root);
548         } catch (IllegalArgumentException JavaDoc e) {
549             // expected, it means invalid root
550
}
551         return null;
552     }
553
554     /**
555      * Visually notifies user about password length
556      */

557     private void schedulePasswordUpdate() {
558         String JavaDoc root = selectedCvsRoot();
559         if (root.startsWith(":pserver:")) { // NOI18N
560
passwordExpected = true;
561             updatePasswordTask.schedule(10);
562         }
563     }
564
565     private void cancelPasswordUpdate() {
566         passwordExpected = false;
567     }
568
569     private void onPasswordChange() {
570         cancelPasswordUpdate();
571         scrambledPassword = null;
572         if (validateCvsRoot()) {
573             valid();
574         }
575     }
576     
577     private void setValid() {
578         valid();
579     }
580     
581     private void onProxyConfiguration() {
582         OptionsDisplayer.getDefault().open("General");
583         if (validateCvsRoot()) {
584             valid();
585         }
586     }
587     
588     private void editRoot() {
589         String JavaDoc root = selectedCvsRoot();
590         root = RootWizard.editCvsRoot(root);
591         if (root != null) {
592             repositoryPanel.rootComboBox.setSelectedItem(root);
593         }
594     }
595
596     // hooks
597

598     public void actionPerformed(ActionEvent JavaDoc e) {
599         if (repositoryPanel.proxyConfigurationButton == e.getSource()) {
600             onProxyConfiguration();
601         } else if (repositoryPanel.rootComboBox == e.getSource()) {
602             onCvsRootChange();
603         } else if (repositoryPanel.editButton == e.getSource()) {
604             editRoot();
605         } else if (repositoryPanel.extSshRadioButton == e.getSource()) {
606             setValid();
607             validateCvsRoot();
608             updateVisibility();
609         } else if (repositoryPanel.internalSshRadioButton == e.getSource()) {
610             setValid();
611             validateCvsRoot();
612             updateVisibility();
613         } else {
614             assert false : "Unexpected event source: " + e.getSource(); // NOI18N
615
}
616     }
617
618     public void changedUpdate(DocumentEvent JavaDoc e) {
619     }
620
621     public void insertUpdate(DocumentEvent JavaDoc e) {
622         textChanged(e);
623     }
624
625     public void removeUpdate(DocumentEvent JavaDoc e) {
626         textChanged(e);
627     }
628
629     private void textChanged(final DocumentEvent JavaDoc e) {
630         // repost later to AWT otherwise it can deadlock because
631
// the document is locked while firing event and we try
632
// synchronously access its content from selectedCvsRoot
633
if (internalDocumentChange) return;
634         Runnable JavaDoc awt = new Runnable JavaDoc() {
635             public void run() {
636                 if (e.getDocument() == repositoryPanel.passwordTextField.getDocument()) {
637                     onPasswordChange();
638                 } else if (e.getDocument() == ((JTextComponent JavaDoc) repositoryPanel.rootComboBox.getEditor().getEditorComponent()).getDocument()) {
639                     onCvsRootChange();
640                 } else if (e.getDocument() == repositoryPanel.extPasswordField.getDocument()) {
641                     setValid();
642                     validateCvsRoot();
643                 } else if (e.getDocument() == repositoryPanel.extCommandTextField.getDocument()) {
644                     setValid();
645                     validateCvsRoot();
646                 }
647             }
648         };
649         SwingUtilities.invokeLater(awt);
650     }
651
652     public void prepareValidation() {
653         progress = ProgressHandleFactory.createHandle(NbBundle.getMessage(CheckoutWizard.class, "BK2012"));
654         JComponent bar = ProgressHandleFactory.createProgressComponent(progress);
655         JButton stopButton = new JButton(org.openide.util.NbBundle.getMessage(RepositoryStep.class, "BK2022"));
656         stopButton.addActionListener(new ActionListener JavaDoc() {
657             public void actionPerformed(ActionEvent JavaDoc e) {
658                 if (backgroundValidationThread != null) {
659                     backgroundValidationThread.interrupt();
660                 }
661             }
662         });
663         progressComponent = new JPanel();
664         progressComponent.setLayout(new BorderLayout(6, 0));
665         progressLabel = new JLabel();
666         progressComponent.add(progressLabel, BorderLayout.NORTH);
667         progressComponent.add(bar, BorderLayout.CENTER);
668         progressComponent.add(stopButton, BorderLayout.LINE_END);
669         progress.start(/*2, 5*/);
670         repositoryPanel.jPanel1.setLayout(new BorderLayout());
671         repositoryPanel.jPanel1.add(progressComponent, BorderLayout.SOUTH);
672         repositoryPanel.jPanel1.revalidate();
673
674         editable(false);
675     }
676
677     private String JavaDoc getPassword() {
678         return new String JavaDoc(repositoryPanel.passwordTextField.getPassword());
679     }
680
681     public String JavaDoc getCvsRoot() {
682         return selectedCvsRoot();
683     }
684
685     public String JavaDoc getScrambledPassword() {
686         if (scrambledPassword == null) {
687             String JavaDoc plainPassword = getPassword();
688             scrambledPassword = StandardScrambler.getInstance().scramble(plainPassword);
689         }
690         return scrambledPassword;
691     }
692 }
693
Popular Tags