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.ParameterObj;
026: import org.apache.ideaplugin.bean.ValidateXMLFile;
027:
028: import javax.swing.*;
029: import java.awt.*;
030: import java.awt.event.ActionListener;
031: import java.awt.event.ActionEvent;
032: import java.awt.event.MouseEvent;
033: import java.awt.event.MouseListener;
034:
035: public class ServiceXMLEditPage extends WizardPanel {
036: protected JTextArea desArea;
037: protected JButton addpara;
038: protected JButton addModuleRef;
039: protected JButton validateXML;
040: private JButton reGenerate;
041: protected JScrollPane sp;
042: private JLabel lblerror;
043: private ArchiveBean archiveBean;
044:
045: public ServiceXMLEditPage(WizardComponents wizardComponents,
046: ArchiveBean archiveBean) {
047: super (wizardComponents,
048: "Axis2 Idea Plugin Service Archiver Creator Wizards");
049: setPanelTopTitle("Service Archiver");
050: setPanelBottomTitle("Edit the generated service.xml");
051: this .archiveBean = archiveBean;
052: init();
053: }
054:
055: public void init() {
056: ParameterDialog.initialize(addpara, "Parameter Dialog");
057: addpara = new JButton("+Parameter ");
058: addpara.setEnabled(false);
059: addModuleRef = new JButton("+ModuleRef ");
060: addModuleRef.setEnabled(false);
061: validateXML = new JButton("Validate XML");
062: reGenerate = new JButton("ReGenerate XML");
063: lblerror = new JLabel();
064: desArea = new JTextArea("");
065: sp = new JScrollPane(desArea);
066: sp.setAutoscrolls(true);
067: this .setLayout(new GridBagLayout());
068: setDefaultEnabled();
069:
070: this .add(addpara, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0,
071: GridBagConstraints.CENTER, GridBagConstraints.NONE,
072: new Insets(5, 1, 0, 10), 0, 0));
073:
074: addpara.addActionListener(new ActionListener() {
075: public void actionPerformed(ActionEvent e) {
076: ParameterObj selectedName = ParameterDialog
077: .showDialog("Parameter Dialog");
078: setParameter(selectedName);
079: setEnabledToNotValidate();
080: update();
081: }
082: });
083:
084: this .add(addModuleRef,
085: new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0,
086: GridBagConstraints.CENTER,
087: GridBagConstraints.NONE, new Insets(5, 10, 1,
088: 10), 0, 0));
089:
090: addModuleRef.addActionListener(new ActionListener() {
091: public void actionPerformed(ActionEvent e) {
092: String moduleName = (String) JOptionPane
093: .showInputDialog(addModuleRef, "Module Name",
094: "Module Dialog",
095: JOptionPane.PLAIN_MESSAGE);
096: setModule(moduleName);
097: setEnabledToNotValidate();
098: update();
099: }
100: });
101: this .add(validateXML,
102: new GridBagConstraints(2, 0, 1, 1, 1.0, 0.0,
103: GridBagConstraints.CENTER,
104: GridBagConstraints.NONE, new Insets(5, 10, 1,
105: 10), 0, 0));
106:
107: validateXML.addActionListener(new ActionListener() {
108: public void actionPerformed(ActionEvent e) {
109: if (new ValidateXMLFile()
110: .Validate("<?xml version=\"1.0\"?>\n"
111: + desArea.getText())) {
112: setEnabledToValidate();
113: lblerror
114: .setText("Service XML file validation successfully");
115: } else {
116: setEnabledToNotValidate();
117: lblerror
118: .setText("Error! Service XML file validation Error");
119: }
120: update();
121: }
122: });
123: this .add(reGenerate,
124: new GridBagConstraints(3, 0, 1, 1, 1.0, 0.0,
125: GridBagConstraints.CENTER,
126: GridBagConstraints.NONE, new Insets(5, 10, 1,
127: 10), 0, 0));
128:
129: reGenerate.addActionListener(new ActionListener() {
130: public void actionPerformed(ActionEvent e) {
131: desArea.setText("");
132: desArea.setText(archiveBean.getServiceXML());
133: update();
134: }
135: });
136: this .add(sp, new GridBagConstraints(0, 1,
137: GridBagConstraints.REMAINDER, 1, 1.0, 1.0,
138: GridBagConstraints.WEST, GridBagConstraints.BOTH,
139: new Insets(5, 10, 10, 10), 0, 0));
140: desArea.addMouseListener(new MouseListener() {
141: public void mouseClicked(MouseEvent e) {
142: addpara.setEnabled(true);
143: addModuleRef.setEnabled(true);
144: }
145:
146: public void mousePressed(MouseEvent e) {
147: }
148:
149: public void mouseReleased(MouseEvent e) {
150: }
151:
152: public void mouseEntered(MouseEvent e) {
153: }
154:
155: public void mouseExited(MouseEvent e) {
156: }
157: });
158: this .add(lblerror, new GridBagConstraints(0, 2,
159: GridBagConstraints.REMAINDER, 1, 1.0, 0.0,
160: GridBagConstraints.WEST, GridBagConstraints.NONE,
161: new Insets(5, 20, 10, 10), 0, 0));
162:
163: }
164:
165: //next
166: public void next() {
167: if (!archiveBean.getServiceXML().equals("")) {
168: archiveBean.setServiceXML(desArea.getText());
169: }
170: switchPanel(CodegenFrame.PANEL_LAST_C);
171:
172: }
173:
174: //back
175: public void back() {
176: switchPanel(CodegenFrame.PANEL_LOAD_C);
177: }
178:
179: //update
180: public void update() {
181:
182: }
183:
184: //get page type
185: public int getPageType() {
186: return WizardPanel.SERVICE_ARCHIVE_TYPE;
187: }
188:
189: public void setDescription(String descrip) {
190: this .desArea.setText(descrip);
191: update();
192: }
193:
194: private void setEnabledToValidate() {
195: setNextButtonEnabled(true);
196: reGenerate.setEnabled(false);
197: addpara.setEnabled(false);
198: addModuleRef.setEnabled(false);
199: setPageComplete(true);
200: }
201:
202: private void setEnabledToNotValidate() {
203: reGenerate.setEnabled(true);
204: setNextButtonEnabled(false);
205: setPageComplete(false);
206: addpara.setEnabled(false);
207: addModuleRef.setEnabled(false);
208: }
209:
210: public void setDefaultEnabled() {
211: lblerror.setText("");
212: addpara.setEnabled(false);
213: addModuleRef.setEnabled(false);
214: validateXML.setEnabled(true);
215: reGenerate.setEnabled(false);
216: setNextButtonEnabled(false);
217: }
218:
219: private void setParameter(ParameterObj obj) {
220: int position = desArea.getCaretPosition();
221: System.out.println(desArea.getLineCount());
222: System.out.println(desArea.getCaretPosition());
223: String str = " <parameter name=\"" + obj.getName()
224: + "\" locked=\"false\">" + obj.getValue()
225: + "</parameter>\n";
226: desArea.insert(str, position + 1);
227: }
228:
229: private void setModule(String module) {
230: int position = desArea.getCaretPosition();
231: String str = " <module ref=\"" + module + "\" />\n";
232: desArea.insert(str, position + 1);
233: }
234: }
|