001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.ideaplugin.frames;
020:
021: import org.apache.axis2.tools.component.WizardPanel;
022: import org.apache.axis2.tools.component.WizardComponents;
023: import org.apache.axis2.tools.wizardframe.CodegenFrame;
024: import org.apache.axis2.tools.idea.WSDLFileFilter;
025: import org.apache.ideaplugin.bean.ArchiveBean;
026:
027: import javax.swing.*;
028: import javax.swing.border.EmptyBorder;
029: import javax.wsdl.xml.WSDLReader;
030: import javax.wsdl.factory.WSDLFactory;
031: import javax.wsdl.WSDLException;
032: import java.awt.*;
033: import java.awt.event.ActionListener;
034: import java.awt.event.ActionEvent;
035: import java.io.File;
036:
037: /**
038: * Created by IntelliJ IDEA.
039: * User: shivantha
040: * Date: 16/07/2007
041: * Time: 11:20:00
042: * To change this template use File | Settings | File Templates.
043: */
044: public class WSDLFileSelectionPage extends WizardPanel {
045:
046: private JLabel lblWSDL;
047: private JCheckBox chkBoxSkip;
048: private JCheckBox chkBoxSelect;
049: private JTextField txtWSDL;
050: private JButton btnBrowse;
051: private JButton btnHint;
052: private JTextArea txaHint;
053: private boolean flag = false;
054: private String hint = "";
055: private final JFileChooser fileChooser = new JFileChooser();
056: private ArchiveBean archiveBean;
057:
058: /**
059: * Constructor
060: * @param wizardComponents
061: */
062: public WSDLFileSelectionPage(WizardComponents wizardComponents,
063: ArchiveBean archiveBean) {
064: super (wizardComponents,
065: "Axis2 Idea Plugin Service Archiver Creator Wizards");
066: setPanelTopTitle("Service Archiver");
067: setPanelBottomTitle("Add the WSDL file");
068: this .archiveBean = archiveBean;
069: init();
070: }
071:
072: private void init() {
073: txaHint = new JTextArea();
074: txaHint.setBorder(null);
075: txaHint.setFocusable(false);
076: txaHint.setLineWrap(true);
077: txaHint.setWrapStyleWord(true);
078: txaHint.setOpaque(false);
079:
080: btnHint = new JButton("Hint >>");
081: btnHint.setBorder(new EmptyBorder(new Insets(0, 0, 0, 0)));
082:
083: lblWSDL = new JLabel("Select a WSDL file");
084:
085: chkBoxSkip = new JCheckBox("Skip WSDL", true);
086:
087: chkBoxSelect = new JCheckBox("Select WSDL", false);
088:
089: ButtonGroup buttonGroup = new ButtonGroup();
090: buttonGroup.add(chkBoxSkip);
091: buttonGroup.add(chkBoxSelect);
092:
093: txtWSDL = new JTextField();
094:
095: btnBrowse = new JButton("Browse..");
096:
097: setBackButtonEnabled(true);
098: setNextButtonEnabled(true);
099: setFinishButtonEnabled(false);
100: this .setLayout(new GridBagLayout());
101:
102: this .add(chkBoxSkip, new GridBagConstraints(0, 0,
103: GridBagConstraints.REMAINDER, 1, 0.0, 0.0,
104: GridBagConstraints.WEST, GridBagConstraints.NONE,
105: new Insets(5, 10, 0, 10), 0, 0));
106: chkBoxSkip.addActionListener(new ActionListener() {
107: public void actionPerformed(ActionEvent e) {
108: update();
109: }
110: });
111:
112: this .add(chkBoxSelect, new GridBagConstraints(0, 1,
113: GridBagConstraints.REMAINDER, 1, 0.0, 0.0,
114: GridBagConstraints.WEST, GridBagConstraints.NONE,
115: new Insets(5, 10, 0, 0), 0, 0));
116: chkBoxSelect.addActionListener(new ActionListener() {
117: public void actionPerformed(ActionEvent e) {
118: update();
119: }
120: });
121: this .add(lblWSDL, new GridBagConstraints(0, 2, 1, 1, 0.1, 0.0,
122: GridBagConstraints.WEST, GridBagConstraints.NONE,
123: new Insets(5, 10, 0, 0), 0, 0));
124:
125: this .add(txtWSDL, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0,
126: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
127: new Insets(5, 10, 0, 0), 0, 0));
128:
129: this .add(btnBrowse,
130: new GridBagConstraints(2, 2, 1, 1, 0.1, 0.0,
131: GridBagConstraints.CENTER,
132: GridBagConstraints.NONE, new Insets(5, 10, 0,
133: 10), 0, 0));
134:
135: btnBrowse.addActionListener(new ActionListener() {
136: public void actionPerformed(ActionEvent e) {
137: browseWSDLFile();
138: checkWSDLFile();
139: update();
140: }
141: });
142:
143: this .add(btnHint, new GridBagConstraints(0, 3, 1, 1, 0.1, 0.0,
144: GridBagConstraints.WEST, GridBagConstraints.NONE,
145: new Insets(5, 10, 0, 10), 0, 0));
146: btnHint.addActionListener(new ActionListener() {
147: public void actionPerformed(ActionEvent e) {
148: if (flag) {
149: btnHint.setText("Hint >>");
150: txaHint.setText("");
151: flag = false;
152: } else {
153: btnHint.setText("Hint <<");
154: txaHint.setText(hint);
155: flag = true;
156: }
157: update();
158: }
159: });
160:
161: this .add(txaHint, new GridBagConstraints(0, 4,
162: GridBagConstraints.REMAINDER, 1, 0.1, 1.0,
163: GridBagConstraints.CENTER, GridBagConstraints.BOTH,
164: new Insets(5, 10, 10, 10), 0, 0));
165:
166: }
167:
168: public void back() {
169: switchPanel(CodegenFrame.PANEL_FIRST_C);
170: }
171:
172: public void next() {
173: switchPanel(CodegenFrame.PANEL_THIRD_C);
174: }
175:
176: public void update() {
177: setChangeEnabled();
178: fillBean();
179: setPageComplete(true);
180: setBackButtonEnabled(true);
181: setNextButtonEnabled(true);
182: }
183:
184: public int getPageType() {
185: return WizardPanel.SERVICE_ARCHIVE_TYPE;
186: }
187:
188: private void setChangeEnabled() {
189: if (chkBoxSkip.isSelected()) {
190: lblWSDL.setEnabled(false);
191: txtWSDL.setEnabled(false);
192: btnBrowse.setEnabled(false);
193: } else {
194: lblWSDL.setEnabled(true);
195: txtWSDL.setEnabled(true);
196: btnBrowse.setEnabled(true);
197: }
198: }
199:
200: private void fillBean() {
201: if (chkBoxSelect.isSelected()) {
202: if (!txtWSDL.getText().equals(""))
203: archiveBean.addWsdls(new File(txtWSDL.getText()));
204: }
205: }
206:
207: private void checkWSDLFile() {
208: if (txtWSDL.getText().equals("")) {
209: try {
210: WSDLReader reader = WSDLFactory.newInstance()
211: .newWSDLReader();
212: reader.readWSDL(txtWSDL.getText().trim());
213: } catch (WSDLException e1) {
214: txtWSDL.setText("");
215: JOptionPane.showMessageDialog(btnBrowse,
216: "The file selected is not a valid WSDLfile",
217: "Axis2 ServiceArchieve creation",
218: JOptionPane.ERROR_MESSAGE);
219: }
220: }
221: }
222:
223: private void browseWSDLFile() {
224: fileChooser.setFileFilter(new WSDLFileFilter());
225: fileChooser.setCurrentDirectory(archiveBean.getClassLoc());
226: int returnVal = fileChooser.showOpenDialog(btnBrowse);
227: if (returnVal == JFileChooser.APPROVE_OPTION) {
228: File file = fileChooser.getSelectedFile();
229: txtWSDL.setText(file.getAbsolutePath());
230: }
231: }
232: }
|