1 19 package org.netbeans.modules.subversion.ui.copy; 20 21 import java.awt.event.ActionEvent ; 22 import java.awt.event.ActionListener ; 23 import java.awt.event.FocusEvent ; 24 import java.awt.event.FocusListener ; 25 import java.beans.PropertyChangeEvent ; 26 import java.beans.PropertyChangeListener ; 27 import java.io.File ; 28 import java.net.MalformedURLException ; 29 import javax.swing.event.DocumentEvent ; 30 import javax.swing.event.DocumentListener ; 31 import javax.swing.text.JTextComponent ; 32 import org.netbeans.modules.subversion.RepositoryFile; 33 import org.netbeans.modules.subversion.ui.browser.Browser; 34 import org.netbeans.modules.subversion.ui.browser.BrowserAction; 35 import org.netbeans.modules.subversion.ui.browser.CreateFolderAction; 36 import org.netbeans.modules.subversion.ui.browser.RepositoryPaths; 37 import org.openide.ErrorManager; 38 import org.openide.util.NbBundle; 39 40 44 public class CreateCopy extends CopyDialog implements DocumentListener , FocusListener , ActionListener , PropertyChangeListener { 45 46 private final RepositoryPaths copyToRepositoryPaths; 47 private final RepositoryPaths copyFromRepositoryPaths; 48 49 private final File localeFile; 50 private final RepositoryFile repositoryFile; 51 private final boolean localChanges; 52 53 54 public CreateCopy(RepositoryFile repositoryFile, File localeFile, boolean localChanges) { 55 super(new CreateCopyPanel(), NbBundle.getMessage(CreateCopy.class, "CTL_CopyDialog_Prompt", localeFile.getName()), NbBundle.getMessage(CreateCopy.class, "CTL_CopyDialog_Title")); 57 this.localeFile = localeFile; 58 this.repositoryFile = repositoryFile; 59 this.localChanges = localChanges; 60 61 CreateCopyPanel panel = getCreateCopyPanel(); 62 63 panel.localRadioButton.addActionListener(this); 64 panel.remoteRadioButton.addActionListener(this); 65 panel.skipCheckBox.addActionListener(this); 66 67 panel.copyFromLocalTextField.setText(localeFile.getAbsolutePath()); 68 panel.copyFromRemoteTextField.setText(repositoryFile.getFileUrl().toString()); 69 70 copyFromRepositoryPaths = 71 new RepositoryPaths( 72 repositoryFile, 73 panel.copyFromRemoteTextField, 74 null, 75 panel.copyFromRevisionTextField, 76 panel.searchButton 77 ); 78 79 if(localeFile.isFile()) { 80 panel.localRadioButton.setText(org.openide.util.NbBundle.getMessage(CreateCopy.class, "CTL_CopyForm_fromLocalFile")); panel.remoteRadioButton.setText(org.openide.util.NbBundle.getMessage(CreateCopy.class, "CTL_CopyForm_fromRemoteFile")); panel.skipCheckBox.setEnabled(false); 83 } else { 84 panel.localRadioButton.setText(org.openide.util.NbBundle.getMessage(CreateCopy.class, "CTL_CopyForm_fromLocalFolder")); panel.remoteRadioButton.setText(org.openide.util.NbBundle.getMessage(CreateCopy.class, "CTL_CopyForm_fromRemoteFolder")); } 87 88 panel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CreateCopy.class, "CTL_CopyDialog_Title")); 90 copyToRepositoryPaths = 91 new RepositoryPaths( 92 repositoryFile, 93 (JTextComponent ) panel.urlComboBox.getEditor().getEditorComponent(), 94 panel.browseRepositoryButton, 95 null, 96 null 97 ); 98 99 String browserPurposeMessage = ""; 100 if(localeFile.isFile()) { 101 browserPurposeMessage = org.openide.util.NbBundle.getMessage(CreateCopy.class, "LBL_BrowserMessageCopyFile"); } else { 103 browserPurposeMessage = org.openide.util.NbBundle.getMessage(CreateCopy.class, "LBL_BrowserMessageCopyFolder"); } 105 106 String defaultFolderName = localeFile.isFile() ? "" : localeFile.getName(); 107 int browserMode = Browser.BROWSER_SINGLE_SELECTION_ONLY; 108 copyToRepositoryPaths.setupBrowserBehavior(browserPurposeMessage, browserMode, new BrowserAction[] { new CreateFolderAction(defaultFolderName)} ); 109 copyToRepositoryPaths.addPropertyChangeListener(this); 110 111 setupUrlComboBox(panel.urlComboBox, CreateCopy.class.getName()); 112 panel.messageTextArea.getDocument().addDocumentListener(this); 113 ((JTextComponent ) panel.urlComboBox.getEditor().getEditorComponent()).getDocument().addDocumentListener(this); 114 115 setFromLocal(); 116 validateUserInput(); 117 } 118 119 protected void validateUserInput() { 120 String text = getCreateCopyPanel().messageTextArea.getText(); 121 try { 122 RepositoryFile rf[] = copyToRepositoryPaths.getRepositoryFiles(); 123 if(rf == null || rf.length == 0) { 124 125 setErrorText(org.openide.util.NbBundle.getMessage(CreateCopy.class, "LBL_MISSING_REPOSITORY_FOLDER")); 126 127 getOKButton().setEnabled(false); 128 return; 129 } 130 } catch (NumberFormatException ex) { 131 setErrorText(ex.getLocalizedMessage()); getOKButton().setEnabled(false); 133 return; 134 } catch (MalformedURLException ex) { 135 setErrorText(ex.getLocalizedMessage()); getOKButton().setEnabled(false); 137 return; 138 } 139 if (text == null || text.length() == 0) { 140 141 setErrorText(org.openide.util.NbBundle.getMessage(CreateCopy.class, "LBL_MISSING_COPY_MESSAGE")); 142 143 getOKButton().setEnabled(false); 144 return; 145 } 146 resetErrorText(); 147 getOKButton().setEnabled(true); 148 } 149 150 private void setErrorText(String txt) { 151 CreateCopyPanel panel = getCreateCopyPanel(); 152 panel.invalidValuesLabel.setVisible(true); 153 panel.invalidValuesLabel.setText(txt); 154 } 155 156 private void resetErrorText() { 157 CreateCopyPanel panel = getCreateCopyPanel(); 158 panel.invalidValuesLabel.setVisible(false); 159 panel.invalidValuesLabel.setText(""); 160 } 161 162 CreateCopyPanel getCreateCopyPanel() { 163 return (CreateCopyPanel) getPanel(); 164 } 165 166 RepositoryFile getToRepositoryFile() { 167 try { 168 return getToRepositoryFileIntern(); 169 } catch (MalformedURLException ex) { 170 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); } catch (NumberFormatException ex) { 172 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); } 174 return null; 175 } 176 177 private RepositoryFile getToRepositoryFileIntern() throws NumberFormatException , MalformedURLException { 178 RepositoryFile[] toRepositoryFiles = copyToRepositoryPaths.getRepositoryFiles(); 179 if(toRepositoryFiles.length > 0) { 180 RepositoryFile toRepositoryFile = toRepositoryFiles[0]; 181 if(skipContents()) { 182 return toRepositoryFile; 183 } else { 184 if(isLocal()) { 185 return toRepositoryFile.appendPath(localeFile.getName()); 186 } else { 187 return toRepositoryFile.appendPath(repositoryFile.getFileUrl().getLastPathSegment()); 188 } 189 } 190 } else { 191 return null; 192 } 193 } 194 195 String getMessage() { 196 return getCreateCopyPanel().messageTextArea.getText(); 197 } 198 199 boolean isLocal() { 200 return getCreateCopyPanel().localRadioButton.isSelected(); 201 } 202 203 File getLocalFile() { 204 return localeFile; 205 } 206 207 RepositoryFile getFromRepositoryFile() { 208 try { 209 return copyFromRepositoryPaths.getRepositoryFiles()[0]; 210 } 211 catch (MalformedURLException ex) { 212 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); } catch (NumberFormatException ex) { 214 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); } 216 return null; 217 } 218 219 boolean switchTo() { 220 return getCreateCopyPanel().switchToCheckBox.isSelected(); 221 } 222 223 boolean skipContents() { 224 return getCreateCopyPanel().skipCheckBox.isSelected(); 225 } 226 227 public void insertUpdate(DocumentEvent e) { 228 validateUserInput(); 229 setPreview(); 230 } 231 232 public void removeUpdate(DocumentEvent e) { 233 validateUserInput(); 234 setPreview(); 235 } 236 237 public void changedUpdate(DocumentEvent e) { 238 validateUserInput(); 239 setPreview(); 240 } 241 242 public void focusGained(FocusEvent e) { 243 } 244 245 public void focusLost(FocusEvent e) { 246 validateUserInput(); 247 setPreview(); 248 } 249 250 public void propertyChange(PropertyChangeEvent evt) { 251 if( evt.getPropertyName().equals(RepositoryPaths.PROP_VALID) ) { 252 boolean valid = ((Boolean )evt.getNewValue()).booleanValue(); 253 if(valid) { 254 validateUserInput(); 256 } else { 257 getOKButton().setEnabled(valid); 258 } 259 } 260 } 261 262 public void actionPerformed(ActionEvent evt) { 263 if(evt.getSource() == getCreateCopyPanel().localRadioButton) { 264 setFromLocal(); 265 setPreview(); 266 } else if(evt.getSource() == getCreateCopyPanel().remoteRadioButton) { 267 selectFromRemote(); 268 setPreview(); 269 } else if(evt.getSource() == getCreateCopyPanel().skipCheckBox) { 270 setPreview(); 271 } 272 } 273 274 private void setFromLocal() { 275 CreateCopyPanel panel = getCreateCopyPanel(); 276 panel.copyFromLocalTextField.setEnabled(true); 277 panel.copyFromRemoteTextField.setEnabled(false); 278 panel.warningLabel.setVisible(localChanges); 279 } 280 281 private void selectFromRemote() { 282 CreateCopyPanel panel = getCreateCopyPanel(); 283 panel.copyFromLocalTextField.setEnabled(false); 284 panel.copyFromRemoteTextField.setEnabled(true); 285 panel.warningLabel.setVisible(false); 286 } 287 288 private void setPreview() { 289 try { 290 RepositoryFile repositoryFile = getToRepositoryFileIntern(); 291 if(repositoryFile!=null) { 292 getCreateCopyPanel().previewTextField.setText(repositoryFile.getFileUrl().toString()); 293 } else { 294 getCreateCopyPanel().previewTextField.setText(""); } 296 } 297 catch (NumberFormatException ex) { 298 getCreateCopyPanel().previewTextField.setText(""); } catch (MalformedURLException ex) { 301 getCreateCopyPanel().previewTextField.setText(""); }; 304 } 305 306 } 307 | Popular Tags |