KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > actions > tag > BranchSettings


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
20 package org.netbeans.modules.versioning.system.cvss.ui.actions.tag;
21
22 import org.netbeans.modules.versioning.system.cvss.CvsModuleConfig;
23 import org.netbeans.modules.versioning.system.cvss.util.Utils;
24 import org.netbeans.modules.versioning.system.cvss.ui.selectors.BranchSelector;
25 import org.netbeans.lib.cvsclient.CVSRoot;
26 import org.openide.DialogDescriptor;
27
28 import javax.swing.event.DocumentListener JavaDoc;
29 import javax.swing.event.DocumentEvent JavaDoc;
30 import javax.swing.*;
31 import java.io.IOException JavaDoc;
32 import java.io.File JavaDoc;
33 import org.openide.util.*;
34
35 /**
36  * Settings panel for the Branch command.
37  *
38  * @author Maros Sandor
39  */

40 class BranchSettings extends javax.swing.JPanel JavaDoc {
41     
42     private final File JavaDoc[] roots;
43     private boolean autoComputeBaseTagName = true;
44
45     public BranchSettings(File JavaDoc [] roots) {
46         this.roots = roots;
47         initComponents();
48         cbTagBase.setSelected(CvsModuleConfig.getDefault().getPreferences().getBoolean("BranchSettings.tagBase", true)); // NOI18N
49
tfBaseTagName.setText(CvsModuleConfig.getDefault().getPreferences().get("BranchSettings.tagBaseName", NbBundle.getMessage(BranchSettings.class, "BK0001"))); // NOI18N
50
tfBaseTagName.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
51             public void changedUpdate(DocumentEvent JavaDoc e) {
52                 autoComputeBaseTagName = computeBaseTagName().equals(tfBaseTagName.getText());
53                 onBranchNameChange(tfBaseTagName.getText());
54             }
55
56             public void insertUpdate(DocumentEvent JavaDoc e) {
57                 autoComputeBaseTagName = computeBaseTagName().equals(tfBaseTagName.getText());
58                 onBranchNameChange(tfBaseTagName.getText());
59             }
60
61             public void removeUpdate(DocumentEvent JavaDoc e) {
62                 autoComputeBaseTagName = computeBaseTagName().equals(tfBaseTagName.getText());
63                 onBranchNameChange(tfBaseTagName.getText());
64             }
65         });
66         
67         cbCheckoutBranch.setSelected(CvsModuleConfig.getDefault().getPreferences().getBoolean("BranchSettings.checkout", true)); // NOI18N
68
tfName.setText(CvsModuleConfig.getDefault().getPreferences().get("BranchSettings.branchName", NbBundle.getMessage(BranchSettings.class, "BK0002"))); // NOI18N
69
tfName.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
70             public void changedUpdate(DocumentEvent JavaDoc e) {
71                 onBranchNameChange(tfName.getText());
72                 refreshComponents();
73             }
74
75             public void insertUpdate(DocumentEvent JavaDoc e) {
76                 onBranchNameChange(tfName.getText());
77                 refreshComponents();
78             }
79
80             public void removeUpdate(DocumentEvent JavaDoc e) {
81                 onBranchNameChange(tfName.getText());
82                 refreshComponents();
83             }
84         });
85         refreshComponents();
86     }
87
88     void onBranchNameChange() {
89         onBranchNameChange(tfName.getText());
90     }
91     
92     private void onBranchNameChange(String JavaDoc name) {
93         JButton dd = (JButton) getClientProperty("OKButton");
94         if (dd != null) dd.setEnabled(Utils.isTagValid(name));
95     }
96     
97     public boolean isCheckingOutBranch() {
98         return cbCheckoutBranch.isSelected();
99     }
100
101     public boolean isTaggingBase() {
102         return cbTagBase.isSelected();
103     }
104
105     public String JavaDoc getBranchName() {
106         return tfName.getText();
107     }
108
109     public String JavaDoc getBaseTagName() {
110         return tfBaseTagName.getText();
111     }
112     
113     public void saveSettings() {
114         CvsModuleConfig.getDefault().getPreferences().putBoolean("BranchSettings.tagBase", cbTagBase.isSelected()); // NOI18N
115
CvsModuleConfig.getDefault().getPreferences().putBoolean("BranchSettings.checkout", cbCheckoutBranch.isSelected()); // NOI18N
116
CvsModuleConfig.getDefault().getPreferences().put("BranchSettings.branchName", tfName.getText()); // NOI18N
117
}
118
119     private String JavaDoc computeBaseTagName() {
120         return NbBundle.getMessage(BranchSettings.class, "BK0003", tfName.getText()); // NOI18N
121
}
122     
123     private void refreshComponents() {
124         jLabel1.setEnabled(cbTagBase.isSelected());
125         tfBaseTagName.setEnabled(cbTagBase.isSelected());
126         if (autoComputeBaseTagName && cbTagBase.isSelected()) {
127             tfBaseTagName.setText(computeBaseTagName());
128         }
129         DialogDescriptor dd = (DialogDescriptor) getClientProperty("org.openide.DialogDescriptor"); // NOI18N
130
if (dd != null) {
131             dd.setValid(tfName.getText().trim().length() > 0);
132         }
133     }
134     
135     /** This method is called from within the constructor to
136      * initialize the form.
137      * WARNING: Do NOT modify this code. The content of this method is
138      * always regenerated by the Form Editor.
139      */

140     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
141
private void initComponents() {
142         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
143
144         cbTagBase = new javax.swing.JCheckBox JavaDoc();
145         cbCheckoutBranch = new javax.swing.JCheckBox JavaDoc();
146         nameLabel = new javax.swing.JLabel JavaDoc();
147         tfName = new javax.swing.JTextField JavaDoc();
148         jButton1 = new javax.swing.JButton JavaDoc();
149         jLabel1 = new javax.swing.JLabel JavaDoc();
150         tfBaseTagName = new javax.swing.JTextField JavaDoc();
151
152         setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
153         setLayout(new java.awt.GridBagLayout JavaDoc());
154
155         cbTagBase.setSelected(true);
156         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/actions/tag/Bundle"); // NOI18N
157
org.openide.awt.Mnemonics.setLocalizedText(cbTagBase, bundle.getString("CTL_BranchForm_TagBase")); // NOI18N
158
cbTagBase.setToolTipText(bundle.getString("TT_BranchForm_TagBase")); // NOI18N
159
cbTagBase.addActionListener(new java.awt.event.ActionListener JavaDoc() {
160             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
161                 cbTagBaseActionPerformed(evt);
162             }
163         });
164         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
165         gridBagConstraints.gridx = 0;
166         gridBagConstraints.gridy = 1;
167         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
168         gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
169         gridBagConstraints.weightx = 1.0;
170         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
171         add(cbTagBase, gridBagConstraints);
172
173         cbCheckoutBranch.setSelected(true);
174         org.openide.awt.Mnemonics.setLocalizedText(cbCheckoutBranch, bundle.getString("CTL_BranchForm_UpdateToBranch")); // NOI18N
175
cbCheckoutBranch.setToolTipText(bundle.getString("TT_BranchForm_UpdateToBranch")); // NOI18N
176
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
177         gridBagConstraints.gridx = 0;
178         gridBagConstraints.gridy = 3;
179         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
180         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
181         gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
182         gridBagConstraints.weightx = 1.0;
183         gridBagConstraints.weighty = 1.0;
184         add(cbCheckoutBranch, gridBagConstraints);
185
186         nameLabel.setLabelFor(tfName);
187         org.openide.awt.Mnemonics.setLocalizedText(nameLabel, bundle.getString("CTL_BranchForm_BranchName")); // NOI18N
188
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
189         gridBagConstraints.gridx = 0;
190         gridBagConstraints.gridy = 0;
191         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
192         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 5);
193         add(nameLabel, gridBagConstraints);
194
195         tfName.setColumns(20);
196         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
197         gridBagConstraints.gridx = 1;
198         gridBagConstraints.gridy = 0;
199         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
200         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
201         gridBagConstraints.weightx = 1.0;
202         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 6);
203         add(tfName, gridBagConstraints);
204
205         org.openide.awt.Mnemonics.setLocalizedText(jButton1, bundle.getString("CTL_BranchForm_BrowseBranch")); // NOI18N
206
jButton1.setToolTipText(bundle.getString("TT_BranchForm_Browse")); // NOI18N
207
jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
208             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
209                 browseBranches(evt);
210             }
211         });
212         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
213         gridBagConstraints.gridx = 2;
214         gridBagConstraints.gridy = 0;
215         add(jButton1, gridBagConstraints);
216
217         jLabel1.setLabelFor(tfBaseTagName);
218         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, bundle.getString("CTL_BranchForm_BaseTagName")); // NOI18N
219
jLabel1.setToolTipText(bundle.getString("TT_BranchForm_BaseTagName")); // NOI18N
220
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
221         gridBagConstraints.gridx = 0;
222         gridBagConstraints.gridy = 2;
223         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 21, 0, 5);
224         add(jLabel1, gridBagConstraints);
225         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
226         gridBagConstraints.gridx = 1;
227         gridBagConstraints.gridy = 2;
228         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
229         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 6);
230         add(tfBaseTagName, gridBagConstraints);
231     }// </editor-fold>//GEN-END:initComponents
232

233     private void browseBranches(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseBranches
234
for (int i = 0; i < roots.length; i++) {
235             try {
236                 CVSRoot.parse(Utils.getCVSRootFor(roots[i])); // raises exception
237
BranchSelector selector = new BranchSelector();
238                 String JavaDoc tag = selector.selectTag(roots[i]);
239                 if (tag != null) {
240                     tfName.setText(tag);
241                 }
242                 return;
243             } catch (IOException JavaDoc e) {
244                 // no root for this file, try next
245
}
246         }
247     }//GEN-LAST:event_browseBranches
248

249     private void cbTagBaseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_cbTagBaseActionPerformed
250
refreshComponents();
251     }//GEN-LAST:event_cbTagBaseActionPerformed
252

253     
254     // Variables declaration - do not modify//GEN-BEGIN:variables
255
private javax.swing.JCheckBox JavaDoc cbCheckoutBranch;
256     private javax.swing.JCheckBox JavaDoc cbTagBase;
257     private javax.swing.JButton JavaDoc jButton1;
258     private javax.swing.JLabel JavaDoc jLabel1;
259     private javax.swing.JLabel JavaDoc nameLabel;
260     private javax.swing.JTextField JavaDoc tfBaseTagName;
261     private javax.swing.JTextField JavaDoc tfName;
262     // End of variables declaration//GEN-END:variables
263
}
264
Popular Tags