/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.axis2.tool.service.swing.ui;
import org.apache.axis2.tool.service.bean.Page2Bean;
import org.apache.axis2.tool.service.bean.WizardBean;
import org.apache.axis2.tool.service.control.Controller;
import org.apache.axis2.tool.service.control.ProcessException;
import org.apache.axis2.tool.util.Constants;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
public class WizardPane2 extends WizardPane {
private WizardBean parentBean;
private Page2Bean myBean;
private JRadioButton selectManualFileRadioButton;
private JRadioButton createAutomaticFileRadioButton;
private JPanel selectionPanel;
public WizardPane2(WizardBean wizardBean, JFrame ownerFrame) {
super(ownerFrame);
init();
parentBean = wizardBean;
if (wizardBean.getPage2bean() != null) {
myBean = wizardBean.getPage2bean();
//set the initial settings from the bean
setBeanValues();
} else {
myBean = new Page2Bean();
wizardBean.setPage2bean(myBean);
setDefaultValues();
}
}
public void setBeanValues() {
if (myBean.isManual()) {
this.selectManualFileRadioButton.setSelected(true);
loadScreen(new ManualSelectionPanel(true));
} else {
this.createAutomaticFileRadioButton.setSelected(true);
loadScreen(new AutomaticSelectionPanel(true));
}
}
public boolean validateValues() {
String text = "";
String text2 = "";
boolean returnValue = false;
if (myBean.isManual()) {
text = myBean.getManualFileName();
returnValue = (text != null && text.trim().length() > 0);
} else {
text = myBean.getAutomaticClassName();
text2 = myBean.getProviderClassName();
returnValue = (text != null && text.trim().length() > 0) &&
(text2 != null && text2.trim().length() > 0);
}
return returnValue;
}
private void init() {
this.setLayout(null);
this.setSize(width, height);
initDescription("\n Select either the service xml file or the class that you want to \n " +
" expose as the service to auto generate a service.xml. \n " +
" Only the class files that are in the previously selected location can\n" +
" be laded from here");
ButtonGroup group = new ButtonGroup();
this.selectManualFileRadioButton =
new JRadioButton("Select a file manually");
this.selectManualFileRadioButton.setBounds(hgap,
descHeight,
Constants.UIConstants.RADIO_BUTTON_WIDTH,
Constants.UIConstants.GENERAL_COMP_HEIGHT);
this.add(this.selectManualFileRadioButton);
group.add(selectManualFileRadioButton);
this.selectManualFileRadioButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeSelectionScreen();
}
});
this.createAutomaticFileRadioButton =
new JRadioButton("Create a file automatically");
this.createAutomaticFileRadioButton.setBounds(hgap,
descHeight + vgap + Constants.UIConstants.GENERAL_COMP_HEIGHT,
Constants.UIConstants.RADIO_BUTTON_WIDTH,
Constants.UIConstants.GENERAL_COMP_HEIGHT);
this.add(this.createAutomaticFileRadioButton);
group.add(createAutomaticFileRadioButton);
this.createAutomaticFileRadioButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeSelectionScreen();
}
});
this.selectionPanel = new JPanel();
this.selectionPanel.setLayout(null);
this.selectionPanel.setBounds(0,
descHeight + 2 * Constants.UIConstants.GENERAL_COMP_HEIGHT +
2 * vgap,
width,
100);
this.add(this.selectionPanel);
//select manual option by default
}
private void setDefaultValues() {
this.selectManualFileRadioButton.setSelected(true);
loadScreen(new ManualSelectionPanel());
updateBeanFlags(true);
}
private void changeSelectionScreen() {
if (selectManualFileRadioButton.isSelected()) {
loadScreen(new ManualSelectionPanel(true));
updateBeanFlags(true);
} else {
loadScreen(new AutomaticSelectionPanel(true));
updateBeanFlags(false);
}
}
private void updateBeanFlags(boolean flag) {
myBean.setManual(flag);
myBean.setAutomatic(!flag);
}
private void loadScreen(JPanel panel) {
this.selectionPanel.removeAll();
this.selectionPanel.add(panel);
this.repaint();
}
private class ManualSelectionPanel extends JPanel {
private JLabel serverXMLFileLocationLabel;
private JTextField serverXMLFileLocationTextBox;
private JButton browseButton;
public ManualSelectionPanel() {
init();
}
public ManualSelectionPanel(boolean loadVals) {
init();
if (loadVals) {
this.serverXMLFileLocationTextBox.setText(
myBean.getManualFileName());
}
}
private void init() {
this.setLayout(null);
this.setSize(width, 100);
this.serverXMLFileLocationLabel = new JLabel("Service File");
this.add(this.serverXMLFileLocationLabel);
this.serverXMLFileLocationLabel.setBounds(hgap,
vgap,
Constants.UIConstants.LABEL_WIDTH,
Constants.UIConstants.GENERAL_COMP_HEIGHT);
this.serverXMLFileLocationTextBox = new JTextField();
this.add(this.serverXMLFileLocationTextBox);
this.serverXMLFileLocationTextBox.setBounds(
Constants.UIConstants.LABEL_WIDTH + 2 * hgap,
vgap,
Constants.UIConstants.TEXT_BOX_WIDTH,
Constants.UIConstants.GENERAL_COMP_HEIGHT);
this.serverXMLFileLocationTextBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setOutFileName();
}
});
this.serverXMLFileLocationTextBox.add