1 19 package org.netbeans.modules.versioning.system.cvss.ui.history; 20 21 import org.openide.util.NbBundle; 22 import org.netbeans.modules.versioning.spi.VCSContext; 23 import org.netbeans.modules.versioning.system.cvss.CvsModuleConfig; 24 import org.netbeans.modules.versioning.system.cvss.ui.selectors.BranchSelector; 25 import org.netbeans.modules.versioning.system.cvss.util.Utils; 26 import org.netbeans.lib.cvsclient.CVSRoot; 27 28 import java.io.IOException ; 29 import java.io.File ; 30 import java.util.*; 31 32 37 class ViewRevisionPanel extends javax.swing.JPanel { 38 39 private final String VIEW_TRUNK_HEAD = "ViewRevisionPanel.ViewTrunkHEAD"; private final String VIEW_BRANCH = "ViewRevisionPanel.ViewBranch"; private final String VIEW_BRANCH_NAME = "ViewRevisionPanel.ViewBranchName"; 43 private final VCSContext ctx; 44 45 public ViewRevisionPanel(VCSContext ctx) { 46 this.ctx = ctx; 47 initComponents(); 48 rbBranch.setSelected(CvsModuleConfig.getDefault().getPreferences().getBoolean(VIEW_BRANCH, true)); 49 rbTrunk.setSelected(CvsModuleConfig.getDefault().getPreferences().getBoolean(VIEW_TRUNK_HEAD, false)); 50 tfTagName.setText(CvsModuleConfig.getDefault().getPreferences().get(VIEW_BRANCH_NAME, "")); 51 refreshComponents(); 52 } 53 54 String getRevision() { 55 return rbTrunk.isSelected() ? "HEAD" : tfTagName.getText(); } 57 58 void saveSettings() { 59 CvsModuleConfig.getDefault().getPreferences().putBoolean(VIEW_TRUNK_HEAD, rbTrunk.isSelected()); 60 CvsModuleConfig.getDefault().getPreferences().putBoolean(VIEW_BRANCH, rbBranch.isSelected()); 61 CvsModuleConfig.getDefault().getPreferences().put(VIEW_BRANCH_NAME, tfTagName.getText()); 62 } 63 64 void refreshComponents() { 65 tfTagName.setEnabled(rbBranch.isSelected()); 66 bBrowse.setEnabled(rbBranch.isSelected()); 67 } 68 69 private String browseBranches() { 70 Set<File > roots = ctx.getRootFiles(); 71 for (File root : roots) { 72 try { 73 CVSRoot.parse(Utils.getCVSRootFor(root)); BranchSelector selector = new BranchSelector(); 75 return selector.selectTag(root); 76 } catch (IOException e) { 77 } 79 } 80 return null; 81 } 82 83 88 private void initComponents() { 90 91 buttonGroup1 = new javax.swing.ButtonGroup (); 92 rbTrunk = new javax.swing.JRadioButton (); 93 rbBranch = new javax.swing.JRadioButton (); 94 tfTagName = new javax.swing.JTextField (); 95 bBrowse = new javax.swing.JButton (); 96 97 buttonGroup1.add(rbTrunk); 98 org.openide.awt.Mnemonics.setLocalizedText(rbTrunk, NbBundle.getMessage(ViewRevisionPanel.class, "ViewRevisionPanel.rbTrunk.text")); rbTrunk.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 100 rbTrunk.setMargin(new java.awt.Insets (0, 0, 0, 0)); 101 rbTrunk.addActionListener(new java.awt.event.ActionListener () { 102 public void actionPerformed(java.awt.event.ActionEvent evt) { 103 rbTrunkActionPerformed(evt); 104 } 105 }); 106 107 buttonGroup1.add(rbBranch); 108 org.openide.awt.Mnemonics.setLocalizedText(rbBranch, NbBundle.getMessage(ViewRevisionPanel.class, "ViewRevisionPanel.rbBranch.text")); rbBranch.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 110 rbBranch.setMargin(new java.awt.Insets (0, 0, 0, 0)); 111 rbBranch.addActionListener(new java.awt.event.ActionListener () { 112 public void actionPerformed(java.awt.event.ActionEvent evt) { 113 rbBranchActionPerformed(evt); 114 } 115 }); 116 117 tfTagName.setText(NbBundle.getMessage(ViewRevisionPanel.class, "ViewRevisionPanel.tfTagName.text")); 119 org.openide.awt.Mnemonics.setLocalizedText(bBrowse, NbBundle.getMessage(ViewRevisionPanel.class, "ViewRevisionPanel.bBrowse.text")); bBrowse.addActionListener(new java.awt.event.ActionListener () { 121 public void actionPerformed(java.awt.event.ActionEvent evt) { 122 bBrowseActionPerformed(evt); 123 } 124 }); 125 126 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 127 this.setLayout(layout); 128 layout.setHorizontalGroup( 129 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 130 .add(layout.createSequentialGroup() 131 .addContainerGap() 132 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 133 .add(layout.createSequentialGroup() 134 .add(rbBranch) 135 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 136 .add(tfTagName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE) 137 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 138 .add(bBrowse)) 139 .add(rbTrunk)) 140 .addContainerGap()) 141 ); 142 layout.setVerticalGroup( 143 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 144 .add(layout.createSequentialGroup() 145 .addContainerGap() 146 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 147 .add(rbBranch) 148 .add(bBrowse) 149 .add(tfTagName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 150 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 151 .add(rbTrunk) 152 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 153 ); 154 } 156 private void rbBranchActionPerformed(java.awt.event.ActionEvent evt) { refreshComponents(); 158 } 160 private void rbTrunkActionPerformed(java.awt.event.ActionEvent evt) { refreshComponents(); 162 } 164 private void bBrowseActionPerformed(java.awt.event.ActionEvent evt) { String tag = browseBranches(); 166 if (tag != null) { 167 tfTagName.setText(tag); 168 } 169 } 171 172 private javax.swing.JButton bBrowse; 174 private javax.swing.ButtonGroup buttonGroup1; 175 private javax.swing.JRadioButton rbBranch; 176 private javax.swing.JRadioButton rbTrunk; 177 private javax.swing.JTextField tfTagName; 178 180 } 181 | Popular Tags |