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.ideaplugin.bean.ArchiveBean;
025: import org.apache.ideaplugin.bean.XmlFileFilter;
026:
027: import javax.swing.*;
028: import javax.swing.border.EmptyBorder;
029: import java.awt.*;
030: import java.awt.event.ActionListener;
031: import java.awt.event.ActionEvent;
032: import java.io.File;
033: import java.io.ByteArrayOutputStream;
034: import java.io.FileInputStream;
035: import java.io.IOException;
036:
037: /**
038: * Created by IntelliJ IDEA.
039: * User: shivantha
040: * Date: 17/07/2007
041: * Time: 09:45:03
042: * To change this template use File | Settings | File Templates.
043: */
044: public class ServiceXMLFileSelectionPage extends WizardPanel {
045: /**
046: * varialbales
047: */
048: private JLabel lblXmlLocation;
049: private JTextField txtServiceXml;
050: private JButton butSelect;
051: private JCheckBox chkBoxIncludeXml;
052: private JButton btnHint;
053: private JTextArea txaHint;
054: private boolean flag = false;
055: private String hint = "";
056: private final JFileChooser fileChooser = new JFileChooser();
057: private ArchiveBean archiveBean;
058: private String value;
059:
060: /**
061: * Constructor
062: * @param wizardComponents
063: */
064: public ServiceXMLFileSelectionPage(
065: WizardComponents wizardComponents, ArchiveBean archiveBean) {
066: super (wizardComponents,
067: "Axis2 Idea Plugin Service Archiver Creator Wizards");
068: setPanelTopTitle("Service Archiver");
069: setPanelBottomTitle("Select the service.xml file");
070: this .archiveBean = archiveBean;
071: init();
072: }
073:
074: /**
075: * initiate panel
076: */
077: private void init() {
078:
079: txaHint = new JTextArea();
080: txaHint.setBorder(null);
081: txaHint.setFocusable(false);
082: txaHint.setLineWrap(true);
083: txaHint.setWrapStyleWord(true);
084: txaHint.setOpaque(false);
085:
086: btnHint = new JButton("Hint >>");
087: btnHint.setBorder(new EmptyBorder(new Insets(0, 0, 0, 0)));
088: lblXmlLocation = new JLabel("set the Service XML file");
089: lblXmlLocation.setEnabled(false);
090: txtServiceXml = new JTextField();
091: txtServiceXml.setEnabled(false);
092: butSelect = new JButton("Browse..");
093: butSelect.setEnabled(false);
094: chkBoxIncludeXml = new JCheckBox(
095: "Generate service xml automatically", true);
096:
097: setBackButtonEnabled(true);
098: setNextButtonEnabled(false);
099: setFinishButtonEnabled(false);
100: setPageComplete(false);
101:
102: this .setLayout(new GridBagLayout());
103:
104: this .add(chkBoxIncludeXml, new GridBagConstraints(0, 0,
105: GridBagConstraints.REMAINDER, 1, 0.0, 0.0,
106: GridBagConstraints.CENTER,
107: GridBagConstraints.HORIZONTAL, new Insets(5, 1, 1, 1),
108: 0, 0));
109: chkBoxIncludeXml.addActionListener(new ActionListener() {
110: public void actionPerformed(ActionEvent e) {
111: setChangeEnabled();
112: update();
113: }
114: });
115: this
116: .add(lblXmlLocation, new GridBagConstraints(0, 1, 1, 1,
117: 0.1, 0.0, GridBagConstraints.WEST,
118: GridBagConstraints.NONE,
119: new Insets(5, 10, 0, 0), 0, 0));
120:
121: this .add(txtServiceXml, new GridBagConstraints(1, 1,
122: GridBagConstraints.RELATIVE, 1, 1.0, 0.0,
123: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
124: new Insets(5, 1, 0, 0), 0, 0));
125:
126: txtServiceXml.addActionListener(new ActionListener() {
127: public void actionPerformed(ActionEvent e) {
128: update();
129: }
130: });
131:
132: this
133: .add(butSelect, new GridBagConstraints(2, 1, 1, 1, 0.1,
134: 0.0, GridBagConstraints.CENTER,
135: GridBagConstraints.NONE,
136: new Insets(5, 0, 1, 10), 0, 0));
137:
138: butSelect.addActionListener(new ActionListener() {
139: public void actionPerformed(ActionEvent e) {
140: browseXmlFile();
141: setNextButtonEnabled(true);
142: setPageComplete(true);
143: update();
144: }
145: });
146: this .add(btnHint, new GridBagConstraints(0, 2,
147: GridBagConstraints.REMAINDER, 1, 0.1, 0.0,
148: GridBagConstraints.WEST, GridBagConstraints.NONE,
149: new Insets(5, 10, 0, 10), 0, 0));
150: btnHint.addActionListener(new ActionListener() {
151: public void actionPerformed(ActionEvent e) {
152: if (flag) {
153: btnHint.setText("Hint >>");
154: txaHint.setText("");
155: flag = false;
156: } else {
157: btnHint.setText("Hint <<");
158: txaHint.setText(hint);
159: flag = true;
160: }
161: update();
162: }
163: });
164:
165: this .add(txaHint, new GridBagConstraints(0, 3,
166: GridBagConstraints.REMAINDER, 1, 0.1, 1.0,
167: GridBagConstraints.CENTER, GridBagConstraints.BOTH,
168: new Insets(5, 10, 10, 10), 0, 0));
169:
170: }
171:
172: //next
173: public void next() {
174: if (!chkBoxIncludeXml.isSelected()) {
175: switchPanel(CodegenFrame.PANEL_LAST_C);
176: } else {
177: switchPanel(CodegenFrame.PANEL_LOAD_C);
178: }
179: setNextButtonEnabled(false);
180:
181: }
182:
183: //back
184: public void back() {
185: switchPanel(CodegenFrame.PANEL_THIRD_C);
186: }
187:
188: //update
189: public void update() {
190: fillBean();
191: setPageComplete(true);
192: setNextButtonEnabled(true);
193: }
194:
195: //get page type
196: public int getPageType() {
197: return WizardPanel.SERVICE_ARCHIVE_TYPE;
198: }
199:
200: private void browseXmlFile() {
201: fileChooser.setFileFilter(new XmlFileFilter());
202: fileChooser.setCurrentDirectory(archiveBean.getClassLoc());
203: int returnVal = fileChooser.showOpenDialog(butSelect);
204: if (returnVal == JFileChooser.APPROVE_OPTION) {
205: File xmlfile = fileChooser.getSelectedFile();
206: txtServiceXml.setText(xmlfile.getAbsolutePath());
207: byte[] buf = new byte[1024];
208: int read;
209: ByteArrayOutputStream out;
210: try {
211: FileInputStream in = new FileInputStream(xmlfile);
212:
213: out = new ByteArrayOutputStream();
214: while ((read = in.read(buf)) > 0) {
215: out.write(buf, 0, read);
216: }
217: in.close();
218: value = new String(out.toByteArray());
219: } catch (IOException e1) {
220: }
221:
222: } else {
223: txtServiceXml.setText("");
224: }
225: }
226:
227: private void setChangeEnabled() {
228: if (chkBoxIncludeXml.isSelected()) {
229: lblXmlLocation.setEnabled(false);
230: txtServiceXml.setEnabled(false);
231: butSelect.setEnabled(false);
232: } else {
233: lblXmlLocation.setEnabled(true);
234: txtServiceXml.setEnabled(true);
235: butSelect.setEnabled(true);
236: }
237: }
238:
239: private void fillBean() {
240: if (!chkBoxIncludeXml.isSelected()) {
241: if (value != null)
242: archiveBean.setServiceXML(value);
243: }
244:
245: }
246:
247: public boolean isIncludeXml() {
248: return this.chkBoxIncludeXml.isSelected();
249: }
250: }
|