2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.versioning.system.cvss.ui.actions.tag;
44
import org.netbeans.modules.versioning.system.cvss.CvsModuleConfig;
45
import org.netbeans.modules.versioning.system.cvss.util.Utils;
46
import org.netbeans.modules.versioning.system.cvss.ui.selectors.BranchSelector;
47
import org.netbeans.lib.cvsclient.CVSRoot;
48
import org.openide.DialogDescriptor;
50
import javax.swing.event.DocumentListener;
51
import javax.swing.event.DocumentEvent;
53
import java.io.IOException;
55
import org.openide.util.*;
58
* Settings panel for the Branch command.
60
* @author Maros Sandor
62
class BranchSettings extends javax.swing.JPanel {
64
private final File[] roots;
65
private boolean autoComputeBaseTagName = true;
67
public BranchSettings(File [] roots) {
70
cbTagBase.setSelected(CvsModuleConfig.getDefault().getPreferences().getBoolean("BranchSettings.tagBase", true)); // NOI18N
71
tfBaseTagName.setText(CvsModuleConfig.getDefault().getPreferences().get("BranchSettings.tagBaseName", NbBundle.getMessage(BranchSettings.class, "BK0001"))); // NOI18N
72
tfBaseTagName.getDocument().addDocumentListener(new DocumentListener() {
73
public void changedUpdate(DocumentEvent e) {
74
autoComputeBaseTagName = computeBaseTagName().equals(tfBaseTagName.getText());
75
onBranchNameChange(tfBaseTagName.getText());
78
public void insertUpdate(DocumentEvent e) {
79
autoComputeBaseTagName = computeBaseTagName().equals(tfBaseTagName.getText());
80
onBranchNameChange(tfBaseTagName.getText());
83
public void removeUpdate(DocumentEvent e) {
84
autoComputeBaseTagName = computeBaseTagName().equals(tfBaseTagName.getText());
85
onBranchNameChange(tfBaseTagName.getText());
89
cbCheckoutBranch.setSelected(CvsModuleConfig.getDefault().getPreferences().getBoolean("BranchSettings.checkout", true)); // NOI18N
90
tfName.setText(CvsModuleConfig.getDefault().getPreferences().get("BranchSettings.branchName", NbBundle.getMessage(BranchSettings.class, "BK0002"))); // NOI18N
92
tfName.getDocument().addDocumentListener(new DocumentListener() {
93
public void changedUpdate(DocumentEvent e) {
94
onBranchNameChange(tfName.getText());
98
public void insertUpdate(DocumentEvent e) {
99
onBranchNameChange(tfName.getText());
103
public void removeUpdate(DocumentEvent e) {
104
onBranchNameChange(tfName.getText());
111
void onBranchNameChange() {
112
onBranchNameChange(tfName.getText());
115
private void onBranchNameChange(String name) {
116
JButton dd = (JButton) getClientProperty("OKButton");
117
if (dd != null) dd.setEnabled(Utils.isTagValid(name));
120
public boolean isCheckingOutBranch() {
121
return cbCheckoutBranch.isSelected();
124
public boolean isTaggingBase() {
125
return cbTagBase.isSelected();
128
public String getBranchName() {
129
return tfName.getText();
132
public String getBaseTagName() {
133
return tfBaseTagName.getText();
136
public void saveSettings() {
137
CvsModuleConfig.getDefault().getPreferences().putBoolean("BranchSettings.tagBase", cbTagBase.isSelected()); // NOI18N
138
CvsModuleConfig.getDefault().getPreferences().putBoolean("BranchSettings.checkout", cbCheckoutBranch.isSelected()); // NOI18N
139
CvsModuleConfig.getDefault().getPreferences().put("BranchSettings.branchName", tfName.getText()); // NOI18N
142
private String computeBaseTagName() {
143
return NbBundle.getMessage(BranchSettings.class, "BK0003", tfName.getText()); // NOI18N
146
private void refreshComponents() {
147
jLabel1.setEnabled(cbTagBase.isSelected());
148
tfBaseTagName.setEnabled(cbTagBase.isSelected());
149
if (autoComputeBaseTagName && cbTagBase.isSelected()) {
150
tfBaseTagName.setText(computeBaseTagName());
152
DialogDescriptor dd = (DialogDescriptor) getClientProperty("org.openide.DialogDescriptor"); // NOI18N
154
dd.setValid(tfName.getText().trim().length() > 0);
158
/** This method is called from within the constructor to
159
* initialize the form.
160
* WARNING: Do NOT modify this code. The content of this method is
161
* always regenerated by the Form Editor.
163
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
164
private void initComponents() {
165
java.awt.GridBagConstraints gridBagConstraints;
167
cbTagBase = new javax.swing.JCheckBox();
168
cbCheckoutBranch = new javax.swing.JCheckBox();
169
nameLabel = new javax.swing.JLabel();
170
tfName = new javax.swing.JTextField();
171
jButton1 = new javax.swing.JButton();
172
jLabel1 = new javax.swing.JLabel();
173
tfBaseTagName = new javax.swing.JTextField();
175
setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
176
setLayout(new java.awt.GridBagLayout());
178
cbTagBase.setSelected(true);
179
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/actions/tag/Bundle"); // NOI18N
180
org.openide.awt.Mnemonics.setLocalizedText(cbTagBase, bundle.getString("CTL_BranchForm_TagBase")); // NOI18N
181
cbTagBase.setToolTipText(bundle.getString("TT_BranchForm_TagBase")); // NOI18N
182
cbTagBase.addActionListener(new java.awt.event.ActionListener() {
183
public void actionPerformed(java.awt.event.ActionEvent evt) {
184
cbTagBaseActionPerformed(evt);
187
gridBagConstraints = new java.awt.GridBagConstraints();
188
gridBagConstraints.gridx = 0;
189
gridBagConstraints.gridy = 1;
190
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
191
gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
192
gridBagConstraints.weightx = 1.0;
193
gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
194
add(cbTagBase, gridBagConstraints);
196
cbCheckoutBranch.setSelected(true);
197
org.openide.awt.Mnemonics.setLocalizedText(cbCheckoutBranch, bundle.getString("CTL_BranchForm_UpdateToBranch")); // NOI18N
198
cbCheckoutBranch.setToolTipText(bundle.getString("TT_BranchForm_UpdateToBranch")); // NOI18N
199
gridBagConstraints = new java.awt.GridBagConstraints();
200
gridBagConstraints.gridx = 0;
201
gridBagConstraints.gridy = 3;
202
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
203
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
204
gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
205
gridBagConstraints.weightx = 1.0;
206
gridBagConstraints.weighty = 1.0;
207
add(cbCheckoutBranch, gridBagConstraints);
209
nameLabel.setLabelFor(tfName);
210
org.openide.awt.Mnemonics.setLocalizedText(nameLabel, bundle.getString("CTL_BranchForm_BranchName")); // NOI18N
211
gridBagConstraints = new java.awt.GridBagConstraints();
212
gridBagConstraints.gridx = 0;
213
gridBagConstraints.gridy = 0;
214
gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
215
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
216
add(nameLabel, gridBagConstraints);
218
tfName.setColumns(20);
219
gridBagConstraints = new java.awt.GridBagConstraints();
220
gridBagConstraints.gridx = 1;
221
gridBagConstraints.gridy = 0;
222
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
223
gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
224
gridBagConstraints.weightx = 1.0;
225
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
226
add(tfName, gridBagConstraints);
227
tfName.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(BranchSettings.class, "ACSN_BranchForm_Name")); // NOI18N
228
tfName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(BranchSettings.class, "ACSD_BranchForm_Name")); // NOI18N
230
org.openide.awt.Mnemonics.setLocalizedText(jButton1, bundle.getString("CTL_BranchForm_BrowseBranch")); // NOI18N
231
jButton1.setToolTipText(bundle.getString("TT_BranchForm_Browse")); // NOI18N
232
jButton1.addActionListener(new java.awt.event.ActionListener() {
233
public void actionPerformed(java.awt.event.ActionEvent evt) {
237
gridBagConstraints = new java.awt.GridBagConstraints();
238
gridBagConstraints.gridx = 2;
239
gridBagConstraints.gridy = 0;
240
add(jButton1, gridBagConstraints);
242
jLabel1.setLabelFor(tfBaseTagName);
243
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, bundle.getString("CTL_BranchForm_BaseTagName")); // NOI18N
244
jLabel1.setToolTipText(bundle.getString("TT_BranchForm_BaseTagName")); // NOI18N
245
gridBagConstraints = new java.awt.GridBagConstraints();
246
gridBagConstraints.gridx = 0;
247
gridBagConstraints.gridy = 2;
248
gridBagConstraints.insets = new java.awt.Insets(0, 21, 0, 5);
249
add(jLabel1, gridBagConstraints);
250
gridBagConstraints = new java.awt.GridBagConstraints();
251
gridBagConstraints.gridx = 1;
252
gridBagConstraints.gridy = 2;
253
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
254
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
255
add(tfBaseTagName, gridBagConstraints);
256
tfBaseTagName.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(BranchSettings.class, "ACSN_BranchForm_TagName")); // NOI18N
257
tfBaseTagName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(BranchSettings.class, "ACSD_BranchForm_TagName")); // NOI18N
258
}// </editor-fold>//GEN-END:initComponents
260
private void browseBranches(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseBranches
261
for (int i = 0; i < roots.length; i++) {
263
CVSRoot.parse(Utils.getCVSRootFor(roots[i])); // raises exception
264
BranchSelector selector = new BranchSelector();
265
String tag = selector.selectTag(roots[i]);
270
} catch (IOException e) {
271
// no root for this file, try next
274
}//GEN-LAST:event_browseBranches
276
private void cbTagBaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTagBaseActionPerformed
278
}//GEN-LAST:event_cbTagBaseActionPerformed
281
// Variables declaration - do not modify//GEN-BEGIN:variables
282
private javax.swing.JCheckBox cbCheckoutBranch;
283
private javax.swing.JCheckBox cbTagBase;
284
private javax.swing.JButton jButton1;
285
private javax.swing.JLabel jLabel1;
286
private javax.swing.JLabel nameLabel;
287
private javax.swing.JTextField tfBaseTagName;
288
private javax.swing.JTextField tfName;
289
// End of variables declaration//GEN-END:variables