KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > wizards > repositorystep > 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.subversion.ui.wizards.repositorystep;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import java.net.MalformedURLException JavaDoc;
26 import javax.swing.JComponent JavaDoc;
27 import javax.swing.JPanel JavaDoc;
28 import org.netbeans.modules.subversion.RepositoryFile;
29 import org.netbeans.modules.subversion.Subversion;
30 import org.netbeans.modules.subversion.SvnModuleConfig;
31 import org.netbeans.modules.subversion.client.ExceptionHandler;
32 import org.netbeans.modules.subversion.client.SvnClient;
33 import org.netbeans.modules.subversion.client.WizardStepProgressSupport;
34 import org.netbeans.modules.subversion.ui.repository.Repository;
35 import org.netbeans.modules.subversion.ui.repository.RepositoryConnection;
36 import org.netbeans.modules.subversion.ui.wizards.AbstractStep;
37 import org.openide.ErrorManager;
38 import org.openide.WizardDescriptor;
39 import org.openide.util.HelpCtx;
40 import org.openide.util.NbBundle;
41 import org.tigris.subversion.svnclientadapter.ISVNInfo;
42 import org.tigris.subversion.svnclientadapter.SVNClientException;
43 import org.tigris.subversion.svnclientadapter.SVNRevision;
44 import org.tigris.subversion.svnclientadapter.SVNUrl;
45         
46 /**
47  *
48  *
49  *
50  * @author Tomas Stupka
51  */

52 public class RepositoryStep extends AbstractStep implements WizardDescriptor.AsynchronousValidatingPanel, PropertyChangeListener JavaDoc {
53     
54     private Repository repository;
55     private RepositoryStepPanel panel;
56     private RepositoryFile repositoryFile;
57     private int repositoryModeMask;
58     private WizardStepProgressSupport support;
59
60     public RepositoryStep() {
61         this.repositoryModeMask = 0;
62     }
63     
64     public RepositoryStep(int repositoryModeMask) {
65         this.repositoryModeMask = repositoryModeMask;
66     }
67
68     public HelpCtx getHelp() {
69         return new HelpCtx(RepositoryStep.class);
70     }
71
72     protected JComponent JavaDoc createComponent() {
73         if (repository == null) {
74             repositoryModeMask = repositoryModeMask | Repository.FLAG_URL_EDITABLE | Repository.FLAG_URL_ENABLED | Repository.FLAG_SHOW_HINTS;
75             String JavaDoc title = org.openide.util.NbBundle.getMessage(RepositoryStep.class, "CTL_Repository_Location"); // NOI18N
76
repository = new Repository(repositoryModeMask, title);
77             repository.addPropertyChangeListener(this);
78             panel = new RepositoryStepPanel();
79             panel.repositoryPanel.setLayout(new BorderLayout JavaDoc());
80             panel.repositoryPanel.add(repository.getPanel());
81             valid();
82         }
83         return panel;
84     }
85
86     protected void validateBeforeNext() {
87         try {
88             if(support != null) {
89                 support.performInCurrentThread(NbBundle.getMessage(RepositoryStep.class, "BK2012")); // NOI18N
90
}
91         } finally {
92             support = null;
93         }
94     }
95     
96     public void prepareValidation() {
97         support = new RepositoryStepProgressSupport(panel.progressPanel);
98         try {
99             SVNUrl url = getSelectedRepositoryConnection().getSvnUrl();
100             support.setRepositoryRoot(url);
101         } catch (MalformedURLException JavaDoc mue) {
102             // should not happen
103
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, mue); // should not happen
104
}
105         support.startProgress();
106     }
107
108     private void storeHistory() {
109         RepositoryConnection rc = getSelectedRepositoryConnection();
110         if(rc != null) {
111             SvnModuleConfig.getDefault().insertRecentUrl(rc);
112         }
113     }
114     
115     public RepositoryFile getRepositoryFile() {
116         return repositoryFile;
117     }
118     
119     private RepositoryConnection getSelectedRepositoryConnection() {
120         try {
121             return repository.getSelectedRC();
122         } catch (Exception JavaDoc ex) {
123             invalid(ex.getLocalizedMessage());
124             return null;
125         }
126     }
127
128     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
129         if(evt.getPropertyName().equals(Repository.PROP_VALID)) {
130             if(repository.isValid()) {
131                 valid(repository.getMessage());
132             } else {
133                 invalid(repository.getMessage());
134             }
135         }
136     }
137
138     public void stop() {
139         if(support != null) {
140             support.cancel();
141         }
142     }
143
144     private class RepositoryStepProgressSupport extends WizardStepProgressSupport {
145
146         public RepositoryStepProgressSupport(JPanel JavaDoc panel) {
147             super(panel);
148         }
149
150         public void perform() {
151             final RepositoryConnection rc = getSelectedRepositoryConnection();
152             if (rc == null) {
153                 return;
154             }
155             String JavaDoc invalidMsg = null;
156             try {
157                 invalid(null);
158
159                 SvnClient client;
160                 SVNUrl url = rc.getSvnUrl();
161                 try {
162                     int handledExceptions = ExceptionHandler.EX_DEFAULT_HANDLED_EXCEPTIONS ^ // the default without
163
(ExceptionHandler.EX_NO_HOST_CONNECTION | // host connection errors (misspeled host or proxy urls, ...)
164
ExceptionHandler.EX_AUTHENTICATION) ; // authentication errors
165
client = Subversion.getInstance().getClient(url, rc.getUsername(), rc.getPassword(), handledExceptions);
166                 } catch (SVNClientException ex) {
167                     ErrorManager.getDefault().notify(ex);
168                     invalidMsg = ex.getLocalizedMessage();
169                     return;
170                 }
171                     
172                 repositoryFile = null; // reset
173
ISVNInfo info = null;
174                 try {
175                     repository.storeConfigValues();
176                     info = client.getInfo(url);
177                 } catch (SVNClientException ex) {
178                     annotate(ex);
179                     invalidMsg = ExceptionHandler.parseExceptionMessage(ex);
180                 }
181                 if(isCanceled()) {
182                     return;
183                 }
184
185                 if(info != null) {
186                     // XXX convert to repositoryConnection
187

188                     SVNUrl repositoryUrl = info.getRepository();
189                     if(repositoryUrl==null) {
190                         // XXX see issue #72810 and #72921. workaround!
191
repositoryUrl = rc.getSvnUrl();
192                     }
193                     SVNRevision revision = rc.getSvnRevision();
194                     String JavaDoc[] repositorySegments = repositoryUrl.getPathSegments();
195                     String JavaDoc[] selectedSegments = rc.getSvnUrl().getPathSegments();
196                     String JavaDoc[] repositoryFolder = new String JavaDoc[selectedSegments.length - repositorySegments.length];
197                     System.arraycopy(selectedSegments, repositorySegments.length,
198                                      repositoryFolder, 0,
199                                      repositoryFolder.length);
200
201                     repositoryFile = new RepositoryFile(repositoryUrl, repositoryFolder, revision);
202                 } else {
203                     invalidMsg = org.openide.util.NbBundle.getMessage(RepositoryStep.class, "CTL_Repository_Invalid", rc.getUrl()); // NOI18N
204
return;
205                 }
206             } catch (MalformedURLException JavaDoc ex) {
207                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); // should not happen
208
} finally {
209                 if(isCanceled()) {
210                     valid(org.openide.util.NbBundle.getMessage(RepositoryStep.class, "CTL_Repository_Canceled")); // NOI18N
211
} else if(invalidMsg == null) {
212                   valid();
213                   storeHistory();
214                 } else {
215                   valid(invalidMsg);
216                 }
217             }
218         }
219
220         public void setEditable(boolean editable) {
221             repository.setEditable(editable);
222         }
223     };
224
225 }
226
227
Popular Tags