1 package org.apache.axis.tool.service.swing.ui; 2 3 import java.awt.HeadlessException ; 4 import java.awt.event.ActionEvent ; 5 import java.awt.event.ActionListener ; 6 import java.awt.event.KeyEvent ; 7 import java.awt.event.KeyListener ; 8 import java.util.ArrayList ; 9 10 import javax.swing.ButtonGroup ; 11 import javax.swing.JButton ; 12 import javax.swing.JCheckBox ; 13 import javax.swing.JDialog ; 14 import javax.swing.JFrame ; 15 import javax.swing.JLabel ; 16 import javax.swing.JPanel ; 17 import javax.swing.JRadioButton ; 18 import javax.swing.JTextField ; 19 20 import org.apache.axis.tool.service.bean.Page2Bean; 21 import org.apache.axis.tool.service.bean.WizardBean; 22 import org.apache.axis.tool.service.control.Controller; 23 import org.apache.axis.tool.service.control.ProcessException; 24 import org.apache.axis.tool.util.Constants; 25 26 41 public class WizardPane2 extends WizardPane { 42 43 private WizardBean parentBean; 44 private Page2Bean myBean; 45 46 private JRadioButton selectManualFileRadioButton; 47 private JRadioButton createAutomaticFileRadioButton; 48 private JPanel selectionPanel; 49 50 51 public WizardPane2(WizardBean wizardBean, JFrame ownerFrame) { 52 super(ownerFrame); 53 54 init(); 55 56 parentBean = wizardBean; 57 58 if (wizardBean.getPage2bean()!=null){ 59 myBean = wizardBean.getPage2bean(); 60 setBeanValues(); 62 63 }else{ 64 myBean = new Page2Bean(); 65 wizardBean.setPage2bean(myBean); 66 setDefaultValues(); 67 } 68 69 } 70 71 public void setBeanValues(){ 72 if (myBean.isManual()){ 73 this.selectManualFileRadioButton.setSelected(true); 74 loadScreen(new ManualSelectionPanel(true)); 75 }else{ 76 this.createAutomaticFileRadioButton.setSelected(true); 77 loadScreen(new AutomaticSelectionPanel(true)); 78 } 79 } 80 81 82 public boolean validateValues() { 83 String text = ""; 84 String text2=""; 85 boolean returnValue = false; 86 if (myBean.isManual()){ 87 text = myBean.getManualFileName(); 88 returnValue = (text!=null && text.trim().length()>0); 89 }else{ 90 text = myBean.getAutomaticClassName(); 91 text2 = myBean.getProviderClassName(); 92 returnValue = (text!=null && text.trim().length()>0) && 93 (text2!=null && text2.trim().length()>0) ; 94 } 95 96 return returnValue; 97 } 98 99 private void init(){ 100 this.setLayout(null); 101 this.setSize(width,height); 102 103 initDescription("\n Select either the service xml file or the class that you want to \n " + 104 " expose as the service to auto generate a service.xml. \n " + 105 " Only the class files that are in the previously selected location can\n" + 106 " be laded from here"); 107 108 ButtonGroup group = new ButtonGroup (); 109 110 this.selectManualFileRadioButton = new JRadioButton ("Select a file manually"); 111 this.selectManualFileRadioButton.setBounds(hgap,descHeight,Constants.UIConstants.RADIO_BUTTON_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT); 112 this.add(this.selectManualFileRadioButton); 113 group.add(selectManualFileRadioButton); 114 this.selectManualFileRadioButton.addActionListener(new ActionListener (){ 115 public void actionPerformed(ActionEvent e) { 116 changeSelectionScreen(); 117 } 118 }); 119 this.createAutomaticFileRadioButton = new JRadioButton ("Create a file automatically"); 120 this.createAutomaticFileRadioButton.setBounds(hgap,descHeight+vgap +Constants.UIConstants.GENERAL_COMP_HEIGHT ,Constants.UIConstants.RADIO_BUTTON_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT); 121 this.add(this.createAutomaticFileRadioButton); 122 group.add(createAutomaticFileRadioButton); 123 this.createAutomaticFileRadioButton.addActionListener(new ActionListener (){ 124 public void actionPerformed(ActionEvent e) { 125 changeSelectionScreen(); 126 } 127 }); 128 129 this.selectionPanel = new JPanel (); 130 this.selectionPanel.setLayout(null); 131 this.selectionPanel.setBounds(0,descHeight + 2*Constants.UIConstants.GENERAL_COMP_HEIGHT +2*vgap,width,100); 132 this.add(this.selectionPanel); 133 134 136 137 138 } 139 private void setDefaultValues(){ 140 this.selectManualFileRadioButton.setSelected(true); 141 loadScreen(new ManualSelectionPanel()); 142 updateBeanFlags(true); 143 } 144 private void changeSelectionScreen(){ 145 if (selectManualFileRadioButton.isSelected()){ 146 loadScreen(new ManualSelectionPanel(true)); 147 updateBeanFlags(true); 148 } else{ 149 loadScreen(new AutomaticSelectionPanel(true)); 150 updateBeanFlags(false); 151 } 152 } 153 private void updateBeanFlags(boolean flag){ 154 myBean.setManual(flag);myBean.setAutomatic(!flag); 155 } 156 157 private void loadScreen(JPanel panel){ 158 this.selectionPanel.removeAll(); 159 this.selectionPanel.add(panel); 160 this.repaint(); 161 } 162 163 164 165 private class ManualSelectionPanel extends JPanel { 166 167 private JLabel serverXMLFileLocationLabel; 168 private JTextField serverXMLFileLocationTextBox; 169 private JButton browseButton; 170 171 public ManualSelectionPanel() { 172 init(); 173 } 174 175 public ManualSelectionPanel(boolean loadVals) { 176 init(); 177 if (loadVals){ 178 this.serverXMLFileLocationTextBox.setText(myBean.getManualFileName()); 179 } 180 } 181 182 private void init(){ 183 this.setLayout(null); 184 this.setSize(width,100); 185 186 this.serverXMLFileLocationLabel = new JLabel ("Service File"); 187 this.add(this.serverXMLFileLocationLabel); 188 this.serverXMLFileLocationLabel.setBounds(hgap,vgap,Constants.UIConstants.LABEL_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT); 189 190 this.serverXMLFileLocationTextBox = new JTextField (); 191 this.add(this.serverXMLFileLocationTextBox); 192 this.serverXMLFileLocationTextBox.setBounds(Constants.UIConstants.LABEL_WIDTH + 2*hgap ,vgap,Constants.UIConstants.TEXT_BOX_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT); 193 this.serverXMLFileLocationTextBox.addActionListener(new ActionListener (){ 194 public void actionPerformed(ActionEvent e) { 195 setOutFileName(); 196 } 197 }); 198 this.serverXMLFileLocationTextBox.addKeyListener(new KeyListener (){ 199 public void keyTyped(KeyEvent e) { } 200 public void keyPressed(KeyEvent e) {} 201 public void keyReleased(KeyEvent e) { setOutFileName();} 202 }); 203 204 this.browseButton = new JButton ("."); 205 this.add(this.browseButton); 206 this.browseButton.setBounds(Constants.UIConstants.LABEL_WIDTH + 2*hgap +Constants.UIConstants.TEXT_BOX_WIDTH,vgap,Constants.UIConstants.BROWSE_BUTTON_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT); 207 this.browseButton.addActionListener(new ActionListener (){ 208 public void actionPerformed(ActionEvent e) { 209 serverXMLFileLocationTextBox.setText(browseForAFile("xml")); 210 setOutFileName(); 211 } 212 }); 213 214 } 215 216 private void setOutFileName(){ 217 myBean.setManualFileName(serverXMLFileLocationTextBox.getText()); 218 } 219 } 220 221 private class AutomaticSelectionPanel extends JPanel { 222 223 private JLabel classFileListLable; 224 private JLabel providerClassLable; 225 private JTextField classFileNameTextBox; 226 private JTextField providerClassNameTextBox; 227 private JButton loadButton; 228 private JButton advancedButton; 229 230 public AutomaticSelectionPanel() { 231 init(); 232 } 233 234 public AutomaticSelectionPanel(boolean loadVals) { 235 init(); 236 if (loadVals){ 237 this.classFileNameTextBox.setText(myBean.getAutomaticClassName()); 238 this.providerClassNameTextBox.setText(myBean.getProviderClassName()); 239 } 240 } 241 private void init(){ 242 this.setLayout(null); 243 this.setSize(width,100); 244 245 this.classFileListLable = new JLabel ("Class Name"); 246 this.add(this.classFileListLable); 247 this.classFileListLable.setBounds(hgap,vgap,Constants.UIConstants.LABEL_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT); 248 249 this.classFileNameTextBox = new JTextField (); 250 this.add(this.classFileNameTextBox); 251 this.classFileNameTextBox.setBounds(Constants.UIConstants.LABEL_WIDTH + 2*hgap ,vgap,Constants.UIConstants.TEXT_BOX_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT); 252 this.classFileNameTextBox.addActionListener(new ActionListener (){ 253 public void actionPerformed(ActionEvent e) { 254 setClassName(); 255 } 256 }); 257 this.classFileNameTextBox.addKeyListener(new KeyListener (){ 258 public void keyTyped(KeyEvent e) {} 259 public void keyPressed(KeyEvent e) {} 260 public void keyReleased(KeyEvent e) {setClassName();} 261 }); 262 263 this.providerClassLable = new JLabel ("Provider Class Name"); 264 this.add(this.providerClassLable); 265 this.providerClassLable.setBounds(hgap,(Constants.UIConstants.GENERAL_COMP_HEIGHT+vgap),Constants.UIConstants.LABEL_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT); 266 267 this.providerClassNameTextBox = new JTextField (); 268 this.add(this.providerClassNameTextBox); 269 this.providerClassNameTextBox.setBounds(Constants.UIConstants.LABEL_WIDTH + 2*hgap ,(Constants.UIConstants.GENERAL_COMP_HEIGHT+vgap*2),Constants.UIConstants.TEXT_BOX_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT); 270 this.providerClassNameTextBox.addActionListener(new ActionListener (){ 271 public void actionPerformed(ActionEvent e) { 272 setProviderClassName(); 273 } 274 }); 275 this.providerClassNameTextBox.addKeyListener(new KeyListener (){ 276 public void keyTyped(KeyEvent e) {} 277 public void keyPressed(KeyEvent e) {} 278 public void keyReleased(KeyEvent e) {setProviderClassName();} 279 }); 280 281 this.loadButton = new JButton ("Load"); 282 this.add(this.loadButton); 283 this.loadButton.setBounds(hgap,(Constants.UIConstants.GENERAL_COMP_HEIGHT+vgap)*2 + vgap, 284 Constants.UIConstants.GENERAL_BUTTON_WIDTH, 285 Constants.UIConstants.GENERAL_COMP_HEIGHT); 286 this.loadButton.addActionListener(new ActionListener (){ 287 public void actionPerformed(ActionEvent e) { 288 loadAllMethods(); 289 } 290 }); 291 loadButton.setEnabled(false); 292 293 this.advancedButton = new JButton ("Advanced"); 294 this.add(this.advancedButton); 295 this.advancedButton.setBounds(2*hgap +Constants.UIConstants.GENERAL_BUTTON_WIDTH 296 ,(Constants.UIConstants.GENERAL_COMP_HEIGHT+vgap)*2 + vgap, 297 Constants.UIConstants.GENERAL_BUTTON_WIDTH, 298 Constants.UIConstants.GENERAL_COMP_HEIGHT); 299 this.advancedButton.addActionListener(new ActionListener (){ 300 public void actionPerformed(ActionEvent e) { 301 openDialog(); 302 } 303 }); 304 this.advancedButton.setEnabled(false); 305 } 306 307 private void loadAllMethods(){ 308 try { 309 ArrayList methodList = new Controller().getMethodList(parentBean); 310 myBean.setSelectedMethodNames(methodList); 311 loadButton.setEnabled(false); 312 advancedButton.setEnabled(true); 313 } catch (ProcessException e) { 314 showErrorMessage(e.getMessage()); 315 } 316 } 317 318 private void openDialog(){ 319 try { 320 new AdvancedSelectionDialog().show(); 321 } catch (ProcessException e) { 322 showErrorMessage(e.getMessage()); 323 } 324 } 325 private void setClassName(){ 326 loadButton.setEnabled(true); 327 advancedButton.setEnabled(false); 328 myBean.setAutomaticClassName(classFileNameTextBox.getText()); 329 } 330 331 private void setProviderClassName(){ 332 myBean.setProviderClassName(providerClassNameTextBox.getText()); 335 } 336 337 338 339 } 340 341 342 private class AdvancedSelectionDialog extends JDialog { 343 344 private JPanel lablePanel; 345 private JButton okButton; 346 private JButton cancelButton; 347 private boolean[] selectedValues; 348 private ArrayList completeMethodList; 349 350 351 public AdvancedSelectionDialog() throws HeadlessException ,ProcessException { 352 super(); 353 super.setModal(true); 354 super.setTitle("Select Methods"); 355 this.getContentPane().setLayout(null); 356 init(); 357 } 358 359 private void init() throws ProcessException{ 360 this.completeMethodList = new Controller().getMethodList(parentBean); 362 int methodCount = this.completeMethodList.size(); 363 int panelHeight = methodCount*(Constants.UIConstants.GENERAL_COMP_HEIGHT + vgap); 364 365 this.lablePanel = new JPanel (); 366 this.lablePanel.setLayout(null); 367 this.lablePanel.setBounds(0,0,width,panelHeight); 368 this.getContentPane().add(this.lablePanel); 369 370 ArrayList currentSelectedList = myBean.getSelectedMethodNames(); 371 JCheckBox tempCheckBox; 373 boolean currentSelection; 374 this.selectedValues = new boolean[methodCount]; 375 376 for (int i = 0; i < methodCount; i++) { 377 tempCheckBox = new JCheckBox (this.completeMethodList.get(i).toString()); 378 currentSelection = currentSelectedList.contains(this.completeMethodList.get(i)); 379 tempCheckBox.setSelected(currentSelection); 380 selectedValues[i] = currentSelection; 381 tempCheckBox.setBounds(hgap,vgap + (Constants.UIConstants.GENERAL_COMP_HEIGHT+vgap)*i, 382 Constants.UIConstants.LABEL_WIDTH*3, 383 Constants.UIConstants.GENERAL_COMP_HEIGHT); 384 tempCheckBox.addActionListener(new CheckBoxActionListner(tempCheckBox,i)); 385 this.lablePanel.add(tempCheckBox); 386 387 } 388 389 okButton = new JButton ("OK"); 390 this.getContentPane().add (this.okButton); 391 this.okButton.setBounds(hgap,panelHeight+vgap, 392 Constants.UIConstants.GENERAL_BUTTON_WIDTH, 393 Constants.UIConstants.GENERAL_COMP_HEIGHT); 394 this.okButton.addActionListener(new ActionListener (){ 395 public void actionPerformed(ActionEvent e) { 396 loadValuesToBean(); 397 closeMe(); 398 } 399 }); 400 401 cancelButton = new JButton ("Cancel"); 402 this.getContentPane().add (this.cancelButton); 403 this.cancelButton.setBounds(hgap*2 +Constants.UIConstants.GENERAL_BUTTON_WIDTH ,panelHeight+vgap, 404 Constants.UIConstants.GENERAL_BUTTON_WIDTH, 405 Constants.UIConstants.GENERAL_COMP_HEIGHT); 406 this.cancelButton.addActionListener(new ActionListener (){ 407 public void actionPerformed(ActionEvent e) { 408 closeMe(); 409 } 410 }); 411 412 this.setSize(width,panelHeight+2*Constants.UIConstants.GENERAL_COMP_HEIGHT + 30); 413 this.setResizable(false); 414 } 415 416 private void updateSelection(JCheckBox checkBox,int index){ 417 if (checkBox.isSelected()){ 418 selectedValues[index] = true; 419 }else{ 420 selectedValues[index] = false; 421 } 422 423 } 424 425 private void loadValuesToBean(){ 426 ArrayList modifiedMethodList = new ArrayList (); 427 for (int i = 0; i < selectedValues.length; i++) { 428 if( selectedValues[i]) 429 modifiedMethodList.add(completeMethodList.get(i)); 430 } 431 432 myBean.setSelectedMethodNames(modifiedMethodList); 433 } 434 private void closeMe(){ 435 this.dispose(); 436 } 437 438 private class CheckBoxActionListner implements ActionListener { 439 private JCheckBox checkBox; 440 private int index; 441 442 public CheckBoxActionListner(JCheckBox checkBox,int index) { 443 this.index = index; 444 this.checkBox = checkBox; 445 } 446 447 public void actionPerformed(ActionEvent e) { 448 updateSelection(checkBox,index); 449 } 450 451 } 452 } 453 454 455 } 456 | Popular Tags |