1 19 20 package org.netbeans.modules.subversion.ui.wizards.repositorystep; 21 22 import java.awt.BorderLayout ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.net.MalformedURLException ; 26 import javax.swing.JComponent ; 27 import javax.swing.JPanel ; 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 52 public class RepositoryStep extends AbstractStep implements WizardDescriptor.AsynchronousValidatingPanel, PropertyChangeListener { 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 createComponent() { 73 if (repository == null) { 74 repositoryModeMask = repositoryModeMask | Repository.FLAG_URL_EDITABLE | Repository.FLAG_URL_ENABLED | Repository.FLAG_SHOW_HINTS; 75 String title = org.openide.util.NbBundle.getMessage(RepositoryStep.class, "CTL_Repository_Location"); repository = new Repository(repositoryModeMask, title); 77 repository.addPropertyChangeListener(this); 78 panel = new RepositoryStepPanel(); 79 panel.repositoryPanel.setLayout(new BorderLayout ()); 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")); } 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 mue) { 102 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, mue); } 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 ex) { 123 invalid(ex.getLocalizedMessage()); 124 return null; 125 } 126 } 127 128 public void propertyChange(PropertyChangeEvent 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 panel) { 147 super(panel); 148 } 149 150 public void perform() { 151 final RepositoryConnection rc = getSelectedRepositoryConnection(); 152 if (rc == null) { 153 return; 154 } 155 String 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 ^ (ExceptionHandler.EX_NO_HOST_CONNECTION | ExceptionHandler.EX_AUTHENTICATION) ; 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; 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 188 SVNUrl repositoryUrl = info.getRepository(); 189 if(repositoryUrl==null) { 190 repositoryUrl = rc.getSvnUrl(); 192 } 193 SVNRevision revision = rc.getSvnRevision(); 194 String [] repositorySegments = repositoryUrl.getPathSegments(); 195 String [] selectedSegments = rc.getSvnUrl().getPathSegments(); 196 String [] repositoryFolder = new String [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()); return; 205 } 206 } catch (MalformedURLException ex) { 207 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); } finally { 209 if(isCanceled()) { 210 valid(org.openide.util.NbBundle.getMessage(RepositoryStep.class, "CTL_Repository_Canceled")); } 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 |