1 19 package org.netbeans.modules.subversion.ui.copy; 20 21 import java.beans.PropertyChangeEvent ; 22 import java.beans.PropertyChangeListener ; 23 import java.io.File ; 24 import java.net.MalformedURLException ; 25 import javax.swing.JButton ; 26 import javax.swing.JTextField ; 27 import javax.swing.text.JTextComponent ; 28 import org.netbeans.modules.subversion.RepositoryFile; 29 import org.netbeans.modules.subversion.ui.browser.Browser; 30 import org.netbeans.modules.subversion.ui.browser.RepositoryPaths; 31 import org.netbeans.modules.subversion.util.SvnUtils; 32 import org.openide.ErrorManager; 33 import org.openide.util.NbBundle; 34 import org.tigris.subversion.svnclientadapter.SVNRevision; 35 import org.tigris.subversion.svnclientadapter.SVNUrl; 36 37 41 public class SwitchTo extends CopyDialog implements PropertyChangeListener { 42 43 private RepositoryPaths repositoryPaths; 44 private final File root; 45 private final RepositoryFile repositoryRoot; 46 47 public SwitchTo(RepositoryFile repositoryRoot, File root, boolean localChanges) { 48 super(new SwitchToPanel(), NbBundle.getMessage(SwitchTo.class, "CTL_SwitchTo_Title", root.getName()), NbBundle.getMessage(SwitchTo.class, "CTL_SwitchTo_Action")); 50 this.root = root; 51 this.repositoryRoot = repositoryRoot; 52 53 SwitchToPanel panel = getSwitchToPanel(); 54 panel.warningLabel.setVisible(localChanges); 55 56 setupUrlComboBox(panel.urlComboBox, SwitchTo.class.getName()); 57 58 repositoryPaths = 59 new RepositoryPaths( 60 repositoryRoot, 61 (JTextField ) panel.urlComboBox.getEditor().getEditorComponent(), 62 panel.browseRepositoryButton, 63 panel.revisionTextField, 64 panel.searchRevisionButton 65 ); 66 repositoryPaths.addPropertyChangeListener(this); 67 getSwitchToPanel().getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(SwitchTo.class, "CTL_SwitchTo_RepositoryFile")); 68 69 String browserPurposeMessage; 70 int browserMode; 71 if(root.isFile()) { 72 getSwitchToPanel().urlLabel.setText(NbBundle.getMessage(SwitchTo.class, "CTL_SwitchTo_RepositoryFile")); browserPurposeMessage = org.openide.util.NbBundle.getMessage(CreateCopy.class, "LBL_BrowserMessageSwitchFile"); 74 browserMode = Browser.BROWSER_SINGLE_SELECTION_ONLY | Browser.BROWSER_SHOW_FILES | Browser.BROWSER_FILES_SELECTION_ONLY; 75 } else { 76 browserPurposeMessage = org.openide.util.NbBundle.getMessage(CreateCopy.class, "LBL_BrowserMessageSwitchFolder"); 77 browserMode = Browser.BROWSER_SINGLE_SELECTION_ONLY; 78 } 79 repositoryPaths.setupBrowserBehavior(browserPurposeMessage, browserMode, null); 80 } 81 82 RepositoryFile getRepositoryFile() { 83 try { 84 RepositoryFile[] repositoryFiles = repositoryPaths.getRepositoryFiles(); 85 if(repositoryFiles.length > 0) { 86 return repositoryFiles[0]; 87 } else { 88 SVNRevision revision = repositoryPaths.getRevision(); 89 if(revision == null) { 90 return null; 91 } 92 SVNUrl url = SvnUtils.getRepositoryUrl(root); 93 RepositoryFile rf = new RepositoryFile(repositoryRoot.getRepositoryUrl(), url, revision); 94 return rf; 95 } 96 } catch (MalformedURLException ex) { 97 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 100 } 101 return null; 102 } 103 104 private SwitchToPanel getSwitchToPanel() { 105 return (SwitchToPanel) getPanel(); 106 } 107 108 public void propertyChange(PropertyChangeEvent evt) { 109 if( evt.getPropertyName().equals(RepositoryPaths.PROP_VALID) ) { 110 boolean valid = ((Boolean )evt.getNewValue()).booleanValue(); 111 getOKButton().setEnabled(valid); 112 } 113 } 114 } 115 | Popular Tags |