1 19 20 package org.netbeans.modules.subversion.ui.wizards.importstep; 21 22 import java.awt.event.FocusEvent ; 23 import java.io.File ; 24 import java.net.MalformedURLException ; 25 import javax.swing.JComponent ; 26 import javax.swing.JLabel ; 27 import javax.swing.JPanel ; 28 import javax.swing.event.DocumentEvent ; 29 import javax.swing.event.DocumentListener ; 30 import org.netbeans.modules.subversion.FileStatusCache; 31 import org.netbeans.modules.subversion.RepositoryFile; 32 import org.netbeans.modules.subversion.Subversion; 33 import org.netbeans.modules.subversion.client.ExceptionHandler; 34 import org.netbeans.modules.subversion.client.SvnClient; 35 import org.netbeans.modules.subversion.client.WizardStepProgressSupport; 36 import org.netbeans.modules.subversion.ui.browser.Browser; 37 import org.netbeans.modules.subversion.ui.wizards.AbstractStep; 38 import org.netbeans.modules.subversion.ui.browser.BrowserAction; 39 import org.netbeans.modules.subversion.ui.browser.RepositoryPaths; 40 import org.netbeans.modules.subversion.ui.checkout.CheckoutAction; 41 import org.netbeans.modules.subversion.util.FileUtils; 42 import org.netbeans.modules.subversion.util.SvnUtils; 43 import org.openide.ErrorManager; 44 import org.openide.WizardDescriptor; 45 import org.openide.util.HelpCtx; 46 import org.tigris.subversion.svnclientadapter.SVNClientException; 47 import org.tigris.subversion.svnclientadapter.SVNUrl; 48 49 52 public class ImportStep extends AbstractStep implements DocumentListener , WizardDescriptor.AsynchronousValidatingPanel, WizardDescriptor.FinishablePanel { 53 54 private ImportPanel importPanel; 55 56 private RepositoryPaths repositoryPaths; 57 private BrowserAction[] actions; 58 private File importDirectory; 59 private WizardStepProgressSupport support; 60 61 public ImportStep(BrowserAction[] actions, File importDirectory) { 62 this.actions = actions; 63 this.importDirectory = importDirectory; 64 } 65 66 public HelpCtx getHelp() { 67 return new HelpCtx(ImportStep.class); 68 } 69 70 protected JComponent createComponent() { 71 if (importPanel == null) { 72 importPanel = new ImportPanel(); 73 importPanel.messageTextArea.getDocument().addDocumentListener(this); 74 importPanel.repositoryPathTextField.getDocument().addDocumentListener(this); 75 } 76 return importPanel; 77 } 78 79 protected void validateBeforeNext() { 80 try { 81 if(support != null) { 82 support.performInCurrentThread(org.openide.util.NbBundle.getMessage(ImportStep.class, "CTL_Import_Progress")); } 84 } finally { 85 support = null; 86 } 87 } 88 89 public void prepareValidation() { 90 support = new ImportProgressSupport(importPanel.progressPanel, importPanel.progressLabel); 91 support.startProgress(); 92 } 93 94 public boolean validateUserInput() { 95 invalid(null); 96 97 String text = importPanel.repositoryPathTextField.getText().trim(); 98 if (text.length() == 0) { 99 invalid(org.openide.util.NbBundle.getMessage(ImportStep.class, "BK2014")); return false; 101 } 102 103 text = importPanel.messageTextArea.getText().trim(); 104 boolean valid = text.length() > 0; 105 if(valid) { 106 valid(); 107 } else { 108 invalid(org.openide.util.NbBundle.getMessage(ImportStep.class, "CTL_Import_MessageRequired")); } 110 111 return valid; 112 } 113 114 public void insertUpdate(DocumentEvent e) { 115 validateUserInput(); 116 } 117 118 public void removeUpdate(DocumentEvent e) { 119 validateUserInput(); 120 } 121 122 public void changedUpdate(DocumentEvent e) { 123 } 124 125 public void focusGained(FocusEvent e) { 126 127 } 128 129 public void focusLost(FocusEvent e) { 130 validateUserInput(); 131 } 132 133 public String getImportMessage() { 134 return importPanel.messageTextArea.getText(); 135 } 136 137 public void setup(RepositoryFile repositoryFile) { 138 if(importPanel.repositoryPathTextField.getText().trim().equals("")) { if(repositoryPaths == null) { 141 repositoryPaths = 142 new RepositoryPaths ( 143 repositoryFile, 144 importPanel.repositoryPathTextField, 145 importPanel.browseRepositoryButton, 146 null, 147 null 148 ); 149 String browserPurposeMessage = org.openide.util.NbBundle.getMessage(ImportStep.class, "LBL_BrowserMessage"); 150 int browserMode = Browser.BROWSER_SINGLE_SELECTION_ONLY; 151 repositoryPaths.setupBrowserBehavior(browserPurposeMessage, browserMode, actions); 152 } else { 153 repositoryPaths.setRepositoryFile(repositoryFile); 154 } 155 } 156 importPanel.repositoryPathTextField.setText(repositoryFile.getPath()); 157 validateUserInput(); 158 } 159 160 public RepositoryFile getRepositoryFile() { 161 try { 162 return repositoryPaths.getRepositoryFiles()[0]; } catch (MalformedURLException ex) { 164 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 165 } 166 return null; 167 } 168 169 public SVNUrl getRepositoryFolderUrl() { 170 return getRepositoryFile().getFileUrl(); 171 } 172 173 public void stop() { 174 if(support != null) { 175 support.cancel(); 176 } 177 } 178 179 public boolean isFinishPanel() { 180 return true; 181 } 182 183 private class ImportProgressSupport extends WizardStepProgressSupport { 184 public ImportProgressSupport(JPanel panel, JLabel label) { 185 super(panel); 186 } 187 public void perform() { 188 String invalidMsg = null; 189 try { 190 if(!validateUserInput()) { 191 return; 192 } 193 194 invalid(null); 195 196 SvnClient client; 197 try { 198 client = Subversion.getInstance().getClient(repositoryPaths.getRepositoryUrl(), this); 199 } catch (SVNClientException ex) { 200 ErrorManager.getDefault().notify(ex); 201 valid(ex.getLocalizedMessage()); 202 return; 203 } 204 205 try { 206 RepositoryFile repositoryFile = getRepositoryFile(); 207 SVNUrl repositoryUrl = repositoryFile.getRepositoryUrl(); 208 try { 209 FileUtils.deleteRecursively(new File (importDirectory.getAbsoluteFile() + "/" + ".svn")); FileUtils.deleteRecursively(new File (importDirectory.getAbsoluteFile() + "/" + "_svn")); File importDummyFolder = new File (System.getProperty("java.io.tmpdir") + "/svn_dummy/" + importDirectory.getName()); importDummyFolder.mkdirs(); 215 importDummyFolder.deleteOnExit(); 216 client.doImport(importDummyFolder, repositoryFile.getFileUrl(), getImportMessage(), false); 217 } catch (SVNClientException ex) { 218 if(ExceptionHandler.isFileAlreadyExists(ex.getMessage()) ) { 219 } else { 221 throw ex; 222 } 223 } 224 if(isCanceled()) { 225 return; 226 } 227 228 RepositoryFile[] repositoryFiles = new RepositoryFile[] { repositoryFile }; 229 CheckoutAction.checkout(client, repositoryUrl, repositoryFiles, importDirectory, true, this); 230 Subversion.getInstance().versionedFilesChanged(); 231 SvnUtils.refreshRecursively(importDirectory); 232 forceStatusRefresh(importDirectory); if(isCanceled()) { 235 FileUtils.deleteRecursively(new File (importDirectory.getAbsoluteFile() + "/" + ".svn")); FileUtils.deleteRecursively(new File (importDirectory.getAbsoluteFile() + "/" + "_svn")); return; 238 } 239 } catch (SVNClientException ex) { 240 annotate(ex); 241 invalidMsg = ExceptionHandler.parseExceptionMessage(ex); 242 } 243 244 } finally { 245 if(isCanceled()) { 246 valid(org.openide.util.NbBundle.getMessage(ImportStep.class, "MSG_Import_ActionCanceled")); } else if(invalidMsg != null) { 248 valid(invalidMsg); 249 } else { 250 valid(); 251 } 252 } 253 } 254 255 public void setEditable(boolean editable) { 256 importPanel.browseRepositoryButton.setEnabled(editable); 257 importPanel.messageTextArea.setEditable(editable); 258 importPanel.repositoryPathTextField.setEditable(editable); 259 } 260 261 private void deleteDirectory(File file) { 262 File [] files = file.listFiles(); 263 if(files !=null || files.length > 0) { 264 for (int i = 0; i < files.length; i++) { 265 if(files[i].isDirectory()) { 266 deleteDirectory(files[i]); 267 } else { 268 files[i].delete(); 269 } 270 } 271 } 272 file.delete(); 273 } 274 }; 275 276 private static void forceStatusRefresh(File file) { 277 Subversion.getInstance().getStatusCache().refresh(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN); 278 if(!file.isFile()) { 279 File [] files = file.listFiles(); 280 for (int i = 0; i < files.length; i++) { 281 forceStatusRefresh(files[i]); 282 } 283 } 284 } 285 286 } 287 288 | Popular Tags |