KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > options > SvnOptionsController


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.options;
20
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.awt.event.ActionListener JavaDoc;
23 import java.io.File JavaDoc;
24 import javax.swing.JFileChooser JavaDoc;
25 import javax.swing.filechooser.FileFilter JavaDoc;
26 import org.netbeans.modules.subversion.Subversion;
27 import org.netbeans.modules.subversion.SvnModuleConfig;
28 import org.netbeans.modules.subversion.ui.repository.Repository;
29 import org.netbeans.modules.versioning.util.AccessibleJFileChooser;
30 import org.netbeans.spi.options.OptionsPanelController;
31 import org.openide.filesystems.FileUtil;
32 import org.openide.util.HelpCtx;
33 import org.openide.util.NbBundle;
34
35 /**
36  *
37  * @author Tomas Stupka
38  */

39 public final class SvnOptionsController extends OptionsPanelController implements ActionListener JavaDoc {
40     
41     private final SvnOptionsPanel panel;
42     private final Repository repository;
43     private final AnnotationSettings annotationSettings;
44     
45     public SvnOptionsController() {
46         panel = new SvnOptionsPanel();
47         
48         int repositoryModeMask = Repository.FLAG_URL_ENABLED | Repository.FLAG_SHOW_REMOVE;
49         String JavaDoc title = org.openide.util.NbBundle.getMessage(SvnOptionsController.class, "CTL_Repository_Location");
50         repository = new Repository(repositoryModeMask, title); // NOI18N
51

52         annotationSettings = new AnnotationSettings();
53         
54         panel.browseButton.addActionListener(this);
55         panel.manageConnSettingsButton.addActionListener(this);
56         panel.manageLabelsButton.addActionListener(this);
57         
58     }
59     
60     public void update() {
61         
62         panel.executablePathTextField.setText(SvnModuleConfig.getDefault().getExecutableBinaryPath());
63         
64         annotationSettings.update();
65         repository.refreshUrlHistory();
66         
67     }
68     
69     public void applyChanges() {
70         
71         // executable
72
SvnModuleConfig.getDefault().setExecutableBinaryPath(panel.executablePathTextField.getText());
73         // XXX only if value changed?
74
// Subversion.setupSvnClientFactory(); this won't work anyway because the svnclientadapter doesn't allow more setups per client!
75

76         // labels
77
annotationSettings.applyChanges();
78         Subversion.getInstance().getAnnotator().refresh();
79         Subversion.getInstance().refreshAllAnnotations();
80         
81         // connection
82
repository.storeRecentUrls();
83     }
84     
85     public void cancel() {
86         repository.refreshUrlHistory();
87     }
88     
89     public boolean isValid() {
90         return true;
91     }
92     
93     public boolean isChanged() {
94         return false; // NOI18N // XXX
95
}
96     
97     public org.openide.util.HelpCtx getHelpCtx() {
98         return new org.openide.util.HelpCtx("netbeans.optionsDialog.advanced.subversion");
99     }
100     
101     public javax.swing.JComponent JavaDoc getComponent(org.openide.util.Lookup masterLookup) {
102         return panel;
103     }
104     
105     public void addPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc l) {
106         
107     }
108     
109     public void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc l) {
110         
111     }
112     
113     public void actionPerformed(ActionEvent JavaDoc evt) {
114         if(evt.getSource() == panel.browseButton) {
115             onBrowseClick();
116         } else if(evt.getSource() == panel.manageConnSettingsButton) {
117             onManageConnClick();
118         } else if(evt.getSource() == panel.manageLabelsButton) {
119             onManageLabelsClick();
120         }
121     }
122     
123     private File JavaDoc getExecutableFile() {
124         String JavaDoc execPath = panel.executablePathTextField.getText();
125         return FileUtil.normalizeFile(new File JavaDoc(execPath));
126     }
127     
128     private void onBrowseClick() {
129         File JavaDoc oldFile = getExecutableFile();
130         JFileChooser JavaDoc fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(SvnOptionsController.class, "ACSD_BrowseFolder"), oldFile); // NOI18N
131
fileChooser.setDialogTitle(NbBundle.getMessage(SvnOptionsController.class, "Browse_title")); // NOI18N
132
fileChooser.setMultiSelectionEnabled(false);
133         FileFilter JavaDoc[] old = fileChooser.getChoosableFileFilters();
134         for (int i = 0; i < old.length; i++) {
135             FileFilter JavaDoc fileFilter = old[i];
136             fileChooser.removeChoosableFileFilter(fileFilter);
137             
138         }
139         fileChooser.addChoosableFileFilter(new FileFilter JavaDoc() {
140             public boolean accept(File JavaDoc f) {
141                 return f.isDirectory();
142             }
143             public String JavaDoc getDescription() {
144                 return NbBundle.getMessage(SvnOptionsController.class, "SVNExec");// NOI18N
145
}
146         });
147         fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
148         fileChooser.showDialog(panel, NbBundle.getMessage(SvnOptionsController.class, "OK_Button")); // NOI18N
149
File JavaDoc f = fileChooser.getSelectedFile();
150         if (f != null) {
151             panel.executablePathTextField.setText(f.getAbsolutePath());
152         }
153     }
154     
155     private void onManageConnClick() {
156         boolean ok = repository.show(NbBundle.getMessage(SvnOptionsController.class, "CTL_ManageConnections"), new HelpCtx(Repository.class));
157         if(!ok) {
158             repository.refreshUrlHistory();
159         }
160     }
161     
162     private void onManageLabelsClick() {
163         annotationSettings.show();
164     }
165 }
166
Popular Tags