1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.wizards; 21 22 import java.awt.Dialog ; 23 import java.awt.event.ActionListener ; 24 import javax.swing.event.ChangeListener ; 25 import javax.swing.*; 26 import javax.swing.event.DocumentListener ; 27 import org.netbeans.lib.cvsclient.CVSRoot; 28 import org.openide.DialogDescriptor; 29 import org.openide.DialogDisplayer; 30 import org.openide.util.HelpCtx; 31 32 40 public final class RootWizard implements ActionListener , DocumentListener { 41 42 private final RepositoryStep repositoryStep; 43 private final CvsRootPanel rootPanel; 44 private DialogDescriptor dd; 45 46 private RootWizard(RepositoryStep step) { 47 this.repositoryStep = step; 48 rootPanel = null; 49 } 50 51 private RootWizard(CvsRootPanel rootPanel) { 52 repositoryStep = null; 53 this.rootPanel = rootPanel; 54 } 55 56 63 public static RootWizard configureRoot(String root) { 64 RepositoryStep step = new RepositoryStep(root); 65 step.applyStandaloneLayout(); 66 67 return new RootWizard(step); 68 } 69 70 75 public static String editCvsRoot(String root) { 76 CvsRootPanel rootPanel = new CvsRootPanel(); 77 RootWizard wizard = new RootWizard(rootPanel); 78 return wizard.customizeRoot(root); 79 } 80 81 private String customizeRoot(String root) { 82 String access = "pserver"; String host = ""; String port = ""; String user = System.getProperty("user.name"); String repository = ""; try { 88 CVSRoot cvsRoot = CVSRoot.parse(root); 89 access = cvsRoot.getMethod(); 90 host = cvsRoot.getHostName(); 91 int portG = cvsRoot.getPort(); 92 if (portG > 0) { 93 port = "" + portG; } 95 user = cvsRoot.getUserName(); 96 repository = cvsRoot.getRepository(); 97 } catch (IllegalArgumentException ex) { 98 } 100 rootPanel.accessComboBox.setSelectedItem(access); 101 rootPanel.hostTextField.setText(host); 102 rootPanel.portTextField.setText(port); 103 rootPanel.userTextField.setText(user); 104 rootPanel.repositoryTextField.setText(repository); 105 106 rootPanel.accessComboBox.addActionListener(this); 107 rootPanel.userTextField.getDocument().addDocumentListener(this); 108 rootPanel.hostTextField.getDocument().addDocumentListener(this); 109 rootPanel.userTextField.getDocument().addDocumentListener(this); 110 rootPanel.portTextField.getDocument().addDocumentListener(this); 111 rootPanel.repositoryTextField.getDocument().addDocumentListener(this); 112 113 rootPanel.setBorder(BorderFactory.createEmptyBorder(6,6,6,6)); 115 dd = new DialogDescriptor(rootPanel, org.openide.util.NbBundle.getMessage(RootWizard.class, "BK2024")); 116 dd.setHelpCtx(new HelpCtx(CvsRootPanel.class)); 117 dd.setModal(true); 118 rootPanel.setPreferredSize(rootPanel.getPreferredSize()); 120 updateVisibility(); 121 checkInput(); 122 123 Dialog d = DialogDisplayer.getDefault().createDialog(dd); 124 d.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(RootWizard.class, "ACSD_CvsRootPanel")); 125 d.setVisible(true); 126 127 if (DialogDescriptor.OK_OPTION.equals(dd.getValue())) { 128 try { 129 String ret = collectRoot(); 130 CVSRoot cvsRoot = CVSRoot.parse(ret); 131 return ret; 132 } catch (IllegalArgumentException ex) { 133 } 135 } 136 137 return null; 138 } 139 140 private void updateVisibility() { 141 String access = (String ) rootPanel.accessComboBox.getSelectedItem(); 142 boolean hostVisible = ("pserver".equals(access) || "ext".equals(access)); rootPanel.userLabel.setVisible(hostVisible); 144 rootPanel.userTextField.setVisible(hostVisible); 145 rootPanel.hostLabel.setVisible(hostVisible); 146 rootPanel.hostTextField.setVisible(hostVisible); 147 rootPanel.portLabel.setVisible(hostVisible); 148 rootPanel.portTextField.setVisible(hostVisible); 149 } 150 151 private String collectRoot() throws IllegalArgumentException { 152 String method = (String ) rootPanel.accessComboBox.getSelectedItem(); 153 boolean hasHost = ("pserver".equals(method) || "ext".equals(method)); 155 StringBuffer sb = new StringBuffer (":"); sb.append(method); 157 sb.append(":"); if (hasHost) { 159 String s = rootPanel.userTextField.getText(); 160 if ("".equals(s.trim())) throw new IllegalArgumentException (); sb.append(s); 162 sb.append("@"); s = rootPanel.hostTextField.getText(); 164 if ("".equals(s.trim())) throw new IllegalArgumentException (); sb.append(s); 166 sb.append(":"); String portS = rootPanel.portTextField.getText(); 168 if ("".equals(portS.trim()) == false) { int portp = Integer.parseInt(portS); if (portp > 0) { 171 sb.append(portS); 172 } 173 } 174 } 175 String s = rootPanel.repositoryTextField.getText(); 176 if ("".equals(s.trim())) throw new IllegalArgumentException (); sb.append(s); 178 179 return sb.toString(); 180 } 181 182 private void checkInput() { 183 try { 184 String ret = collectRoot(); 185 CVSRoot cvsRoot = CVSRoot.parse(ret); 186 dd.setValid(true); 187 } catch (IllegalArgumentException ex) { 188 dd.setValid(false); 189 } 190 191 } 192 193 196 public JPanel getPanel() { 197 RepositoryPanel repositoryPanel = (RepositoryPanel) repositoryStep.getComponent(); 198 return repositoryPanel; 199 } 200 201 208 public String commit(boolean validate) { 209 if (validate) { 210 repositoryStep.prepareValidation(); 211 repositoryStep.validateBeforeNext(); 212 if (repositoryStep.isValid() == false) { 213 return repositoryStep.getErrorMessage(); 214 } 215 } 216 repositoryStep.storeValidValues(); 217 return null; 218 219 } 220 221 222 public boolean isValid() { 223 return repositoryStep.isValid(); 224 } 225 226 227 public void addChangeListener(ChangeListener l) { 228 repositoryStep.addChangeListener(l); 229 } 230 231 public void removeChangeListener(ChangeListener l) { 232 repositoryStep.removeChangeListener(l); 233 } 234 235 public void actionPerformed(java.awt.event.ActionEvent actionEvent) { 236 updateVisibility(); 237 checkInput(); 238 } 239 240 public void changedUpdate(javax.swing.event.DocumentEvent documentEvent) { 241 } 242 243 public void insertUpdate(javax.swing.event.DocumentEvent documentEvent) { 244 checkInput(); 245 } 246 247 public void removeUpdate(javax.swing.event.DocumentEvent documentEvent) { 248 checkInput(); 249 } 250 } 251 | Popular Tags |