KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > copy > SwitchTo


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 package org.netbeans.modules.subversion.ui.copy;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.io.File JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25 import javax.swing.JButton JavaDoc;
26 import javax.swing.JTextField JavaDoc;
27 import javax.swing.text.JTextComponent JavaDoc;
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 /**
38  *
39  * @author Tomas Stupka
40  */

41 public class SwitchTo extends CopyDialog implements PropertyChangeListener JavaDoc {
42
43     private RepositoryPaths repositoryPaths;
44     private final File JavaDoc root;
45     private final RepositoryFile repositoryRoot;
46         
47     public SwitchTo(RepositoryFile repositoryRoot, File JavaDoc root, boolean localChanges) {
48         super(new SwitchToPanel(), NbBundle.getMessage(SwitchTo.class, "CTL_SwitchTo_Title", root.getName()), NbBundle.getMessage(SwitchTo.class, "CTL_SwitchTo_Action")); // NOI18N
49

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 JavaDoc) 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 JavaDoc browserPurposeMessage;
70         int browserMode;
71         if(root.isFile()) {
72             getSwitchToPanel().urlLabel.setText(NbBundle.getMessage(SwitchTo.class, "CTL_SwitchTo_RepositoryFile")); // NOI18N
73
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 JavaDoc ex) {
97             // should be already checked and
98
// not happen at this place anymore
99
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 JavaDoc evt) {
109         if( evt.getPropertyName().equals(RepositoryPaths.PROP_VALID) ) {
110             boolean valid = ((Boolean JavaDoc)evt.getNewValue()).booleanValue();
111             getOKButton().setEnabled(valid);
112         }
113     }
114 }
115
Popular Tags