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.java2wsdl.JarFileFilter;
025: import org.apache.ideaplugin.bean.ArchiveBean;
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.util.ArrayList;
033: import java.net.URL;
034: import java.net.URLClassLoader;
035: import java.io.File;
036:
037: public class LibraryAddingPage extends WizardPanel {
038:
039: private JTextField txtJarLocation;
040: private JButton butSelect;
041: private JButton butAdd;
042: private JButton butRemove;
043: private JList listPathDisply;
044: private DefaultListModel listModel;
045: private JButton btnHint;
046: private JTextArea txaHint;
047: private boolean flag = false;
048: private String hint = "";
049: private ArchiveBean archiveBean;
050: private final JFileChooser fileChooser = new JFileChooser();
051:
052: public LibraryAddingPage(WizardComponents wizardComponents,
053: ArchiveBean archiveBean) {
054: super (wizardComponents,
055: "Axis2 Idea Plugin Service Archiver Creator Wizards");
056: setPanelTopTitle("Service Archiver");
057: setPanelBottomTitle("Add any external Jar");
058: this .archiveBean = archiveBean;
059: init();
060: }
061:
062: private void init() {
063: txaHint = new JTextArea();
064: txaHint.setBorder(null);
065: txaHint.setFocusable(false);
066: txaHint.setLineWrap(true);
067: txaHint.setWrapStyleWord(true);
068: txaHint.setOpaque(false);
069:
070: btnHint = new JButton("Hint >>");
071: btnHint.setBorder(new EmptyBorder(new Insets(0, 0, 0, 0)));
072: txtJarLocation = new JTextField();
073: butSelect = new JButton("Browse..");
074: butAdd = new JButton("Add ->");
075: butRemove = new JButton("Remove <-");
076: listModel = new DefaultListModel();
077: listPathDisply = new JList(listModel);
078: listPathDisply.setAutoscrolls(true);
079: listPathDisply.setOpaque(false);
080: listPathDisply.setBorder(BorderFactory.createBevelBorder(1));
081: listPathDisply.setFocusable(false);
082:
083: setBackButtonEnabled(true);
084: setNextButtonEnabled(true);
085: setFinishButtonEnabled(false);
086: setPageComplete(false);
087:
088: this .setLayout(new GridBagLayout());
089:
090: this .add(new JLabel("Jar file location"),
091: new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0,
092: GridBagConstraints.WEST,
093: GridBagConstraints.NONE, new Insets(5, 10, 0,
094: 10), 0, 0));
095:
096: this .add(txtJarLocation, new GridBagConstraints(1, 0,
097: GridBagConstraints.RELATIVE, 1, 1.0, 0.0,
098: GridBagConstraints.CENTER,
099: GridBagConstraints.HORIZONTAL, new Insets(5, 1, 0, 10),
100: 0, 0));
101:
102: txtJarLocation.addActionListener(new ActionListener() {
103: public void actionPerformed(ActionEvent e) {
104: update();
105: }
106: });
107:
108: this .add(butSelect,
109: new GridBagConstraints(2, 0, 1, 1, 0.1, 0.0,
110: GridBagConstraints.CENTER,
111: GridBagConstraints.NONE, new Insets(5, 10, 1,
112: 10), 0, 0));
113:
114: butSelect.addActionListener(new ActionListener() {
115: public void actionPerformed(ActionEvent e) {
116: broswseJarFile();
117: update();
118: }
119: });
120:
121: this .add(butAdd, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.0,
122: GridBagConstraints.CENTER,
123: GridBagConstraints.HORIZONTAL, new Insets(5, 10, 1, 1),
124: 0, 0));
125: butAdd.addActionListener(new ActionListener() {
126: public void actionPerformed(ActionEvent e) {
127: listModel.addElement(txtJarLocation.getText());
128: txtJarLocation.setText("");
129: update();
130: }
131: });
132:
133: this .add(butRemove, new GridBagConstraints(1, 1, 1, 1, 1.0,
134: 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
135: new Insets(5, 1, 1, 1), 2, 0));
136: butRemove.addActionListener(new ActionListener() {
137: public void actionPerformed(ActionEvent e) {
138: handleRemove();
139: update();
140: }
141: });
142:
143: this .add(new JScrollPane(listPathDisply),
144: new GridBagConstraints(0, 2,
145: GridBagConstraints.REMAINDER, 1, 1.0, 0.0,
146: GridBagConstraints.CENTER,
147: GridBagConstraints.HORIZONTAL, new Insets(5,
148: 10, 1, 10), 0, 0));
149:
150: this .add(btnHint, new GridBagConstraints(0, 3, 1, 1, 0.1, 0.0,
151: GridBagConstraints.WEST, GridBagConstraints.NONE,
152: new Insets(5, 10, 0, 10), 0, 0));
153: btnHint.addActionListener(new ActionListener() {
154: public void actionPerformed(ActionEvent e) {
155: if (flag) {
156: btnHint.setText("Hint >>");
157: txaHint.setText("");
158: flag = false;
159: } else {
160: btnHint.setText("Hint <<");
161: txaHint.setText(hint);
162: flag = true;
163: }
164: update();
165: }
166: });
167:
168: this .add(txaHint, new GridBagConstraints(0, 4,
169: GridBagConstraints.REMAINDER, 1, 0.1, 1.0,
170: GridBagConstraints.CENTER, GridBagConstraints.BOTH,
171: new Insets(5, 10, 10, 10), 0, 0));
172:
173: }
174:
175: //next
176: public void next() {
177: switchPanel(CodegenFrame.PANEL_FOURTH_C);
178:
179: }
180:
181: //back
182: public void back() {
183: switchPanel(CodegenFrame.PANEL_SECOND_C);
184: }
185:
186: //update
187: public void update() {
188: fillBean();
189: setPageComplete(true);
190: setNextButtonEnabled(true);
191: }
192:
193: //get page type
194: public int getPageType() {
195: return WizardPanel.SERVICE_ARCHIVE_TYPE;
196: }
197:
198: private void broswseJarFile() {
199: fileChooser.setFileFilter(new JarFileFilter());
200: int returnVal = fileChooser.showOpenDialog(butAdd);
201: if (returnVal == JFileChooser.APPROVE_OPTION) {
202: File file = fileChooser.getSelectedFile();
203: txtJarLocation.setText(file.getAbsolutePath());
204: }
205: }
206:
207: private void handleRemove() {
208: int[] selectionIndices = listPathDisply.getSelectedIndices();
209: for (int i = 0; i < selectionIndices.length; i++) {
210: listModel.remove(selectionIndices[i]);
211: }
212: }
213:
214: private void fillBean() {
215: ArrayList tempList = archiveBean.getLibs();
216: tempList.addAll(getJarPathlist());
217: archiveBean.addLibs(tempList);
218: URL urllist[] = new URL[listModel.size() + 1];
219: ClassLoader cls = new URLClassLoader(urllist,
220: LibraryAddingPage.class.getClassLoader());
221: archiveBean.setClassLoader(cls);
222: }
223:
224: //get class path list
225: public ArrayList getJarPathlist() {
226: Object[] listObject = listModel.toArray();
227: ArrayList listString = new ArrayList();
228: for (int i = 0; i < listObject.length; i++) {
229: listString.add(listObject[i].toString());
230: }
231: return listString;
232: }
233: }
|