1 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 ; 29 import javax.swing.event.DocumentEvent ; 30 import javax.swing.*; 31 import java.io.IOException ; 32 import java.io.File ; 33 import org.openide.util.*; 34 35 40 class BranchSettings extends javax.swing.JPanel { 41 42 private final File [] roots; 43 private boolean autoComputeBaseTagName = true; 44 45 public BranchSettings(File [] roots) { 46 this.roots = roots; 47 initComponents(); 48 cbTagBase.setSelected(CvsModuleConfig.getDefault().getPreferences().getBoolean("BranchSettings.tagBase", true)); tfBaseTagName.setText(CvsModuleConfig.getDefault().getPreferences().get("BranchSettings.tagBaseName", NbBundle.getMessage(BranchSettings.class, "BK0001"))); tfBaseTagName.getDocument().addDocumentListener(new DocumentListener () { 51 public void changedUpdate(DocumentEvent e) { 52 autoComputeBaseTagName = computeBaseTagName().equals(tfBaseTagName.getText()); 53 onBranchNameChange(tfBaseTagName.getText()); 54 } 55 56 public void insertUpdate(DocumentEvent e) { 57 autoComputeBaseTagName = computeBaseTagName().equals(tfBaseTagName.getText()); 58 onBranchNameChange(tfBaseTagName.getText()); 59 } 60 61 public void removeUpdate(DocumentEvent e) { 62 autoComputeBaseTagName = computeBaseTagName().equals(tfBaseTagName.getText()); 63 onBranchNameChange(tfBaseTagName.getText()); 64 } 65 }); 66 67 cbCheckoutBranch.setSelected(CvsModuleConfig.getDefault().getPreferences().getBoolean("BranchSettings.checkout", true)); tfName.setText(CvsModuleConfig.getDefault().getPreferences().get("BranchSettings.branchName", NbBundle.getMessage(BranchSettings.class, "BK0002"))); tfName.getDocument().addDocumentListener(new DocumentListener () { 70 public void changedUpdate(DocumentEvent e) { 71 onBranchNameChange(tfName.getText()); 72 refreshComponents(); 73 } 74 75 public void insertUpdate(DocumentEvent e) { 76 onBranchNameChange(tfName.getText()); 77 refreshComponents(); 78 } 79 80 public void removeUpdate(DocumentEvent 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 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 getBranchName() { 106 return tfName.getText(); 107 } 108 109 public String getBaseTagName() { 110 return tfBaseTagName.getText(); 111 } 112 113 public void saveSettings() { 114 CvsModuleConfig.getDefault().getPreferences().putBoolean("BranchSettings.tagBase", cbTagBase.isSelected()); CvsModuleConfig.getDefault().getPreferences().putBoolean("BranchSettings.checkout", cbCheckoutBranch.isSelected()); CvsModuleConfig.getDefault().getPreferences().put("BranchSettings.branchName", tfName.getText()); } 118 119 private String computeBaseTagName() { 120 return NbBundle.getMessage(BranchSettings.class, "BK0003", tfName.getText()); } 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"); if (dd != null) { 131 dd.setValid(tfName.getText().trim().length() > 0); 132 } 133 } 134 135 140 private void initComponents() { 142 java.awt.GridBagConstraints gridBagConstraints; 143 144 cbTagBase = new javax.swing.JCheckBox (); 145 cbCheckoutBranch = new javax.swing.JCheckBox (); 146 nameLabel = new javax.swing.JLabel (); 147 tfName = new javax.swing.JTextField (); 148 jButton1 = new javax.swing.JButton (); 149 jLabel1 = new javax.swing.JLabel (); 150 tfBaseTagName = new javax.swing.JTextField (); 151 152 setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)); 153 setLayout(new java.awt.GridBagLayout ()); 154 155 cbTagBase.setSelected(true); 156 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/actions/tag/Bundle"); org.openide.awt.Mnemonics.setLocalizedText(cbTagBase, bundle.getString("CTL_BranchForm_TagBase")); cbTagBase.setToolTipText(bundle.getString("TT_BranchForm_TagBase")); cbTagBase.addActionListener(new java.awt.event.ActionListener () { 160 public void actionPerformed(java.awt.event.ActionEvent evt) { 161 cbTagBaseActionPerformed(evt); 162 } 163 }); 164 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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")); cbCheckoutBranch.setToolTipText(bundle.getString("TT_BranchForm_UpdateToBranch")); gridBagConstraints = new java.awt.GridBagConstraints (); 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")); gridBagConstraints = new java.awt.GridBagConstraints (); 189 gridBagConstraints.gridx = 0; 190 gridBagConstraints.gridy = 0; 191 gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END; 192 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 5); 193 add(nameLabel, gridBagConstraints); 194 195 tfName.setColumns(20); 196 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 0, 0, 6); 203 add(tfName, gridBagConstraints); 204 205 org.openide.awt.Mnemonics.setLocalizedText(jButton1, bundle.getString("CTL_BranchForm_BrowseBranch")); jButton1.setToolTipText(bundle.getString("TT_BranchForm_Browse")); jButton1.addActionListener(new java.awt.event.ActionListener () { 208 public void actionPerformed(java.awt.event.ActionEvent evt) { 209 browseBranches(evt); 210 } 211 }); 212 gridBagConstraints = new java.awt.GridBagConstraints (); 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")); jLabel1.setToolTipText(bundle.getString("TT_BranchForm_BaseTagName")); gridBagConstraints = new java.awt.GridBagConstraints (); 221 gridBagConstraints.gridx = 0; 222 gridBagConstraints.gridy = 2; 223 gridBagConstraints.insets = new java.awt.Insets (0, 21, 0, 5); 224 add(jLabel1, gridBagConstraints); 225 gridBagConstraints = new java.awt.GridBagConstraints (); 226 gridBagConstraints.gridx = 1; 227 gridBagConstraints.gridy = 2; 228 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 229 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 6); 230 add(tfBaseTagName, gridBagConstraints); 231 } 233 private void browseBranches(java.awt.event.ActionEvent evt) { for (int i = 0; i < roots.length; i++) { 235 try { 236 CVSRoot.parse(Utils.getCVSRootFor(roots[i])); BranchSelector selector = new BranchSelector(); 238 String tag = selector.selectTag(roots[i]); 239 if (tag != null) { 240 tfName.setText(tag); 241 } 242 return; 243 } catch (IOException e) { 244 } 246 } 247 } 249 private void cbTagBaseActionPerformed(java.awt.event.ActionEvent evt) { refreshComponents(); 251 } 253 254 private javax.swing.JCheckBox cbCheckoutBranch; 256 private javax.swing.JCheckBox cbTagBase; 257 private javax.swing.JButton jButton1; 258 private javax.swing.JLabel jLabel1; 259 private javax.swing.JLabel nameLabel; 260 private javax.swing.JTextField tfBaseTagName; 261 private javax.swing.JTextField tfName; 262 } 264 | Popular Tags |