KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > archive > wizard > EarFilePanel


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  * Paul Mahar
22  *
23  */

24 package org.enhydra.tool.archive.wizard;
25
26 // ToolBox
27
import org.enhydra.tool.archive.ArchiveException;
28 import org.enhydra.tool.archive.JarPlan;
29 import org.enhydra.tool.archive.EarPlan;
30
31 // JDK
32
import java.awt.*;
33 import java.io.File JavaDoc;
34 import javax.swing.*;
35 import java.beans.*;
36 import javax.swing.border.*;
37
38 //
39
public class EarFilePanel extends ArchivePanel {
40     private FilePanel filePanel = null;
41     private GridBagLayout layoutMain = null;
42     private JPanel panelApp = null;
43     private GridBagLayout layoutApp = null;
44     private JLabel labelAppName = null;
45     private JTextField textAppName = null;
46     private JLabel labelAppDesc = null;
47     private JScrollPane scroll = null;
48     private JTextArea textAppDesc = null;
49     private JCheckBox checkAlt = null;
50     private JCheckBox checkCopyClient = null;
51     private JPanel panellFiller = null;
52
53     public EarFilePanel() {
54         try {
55             jbInit();
56             pmInit();
57         } catch (Exception JavaDoc ex) {
58             ex.printStackTrace();
59         }
60     }
61
62     // override ArchivePanel
63
protected void setWizard(ArchiveWizard wizard) {
64         super.setWizard(wizard);
65         filePanel.setWizard(wizard);
66     }
67
68     public void readPlan(JarPlan plan) throws ArchiveException {
69         filePanel.setWizard(getWizard());
70         filePanel.setArchivePath(plan.getArchivePath());
71         filePanel.getDDTableModel().clear();
72         filePanel.getDDTable().setVisible(false);
73         if (plan instanceof EarPlan) {
74             EarPlan ep = (EarPlan) plan;
75
76             checkCopyClient.setSelected(ep.isCopyClient());
77             checkAlt.setSelected(ep.isAlt());
78             textAppName.setText(ep.getAppName());
79             textAppDesc.setText(ep.getDescription());
80         } else {
81             throw new ArchiveException("Unable to read plan: expecting type EarPlan");
82         }
83     }
84
85     public void writePlan(JarPlan plan) throws ArchiveException {
86         validatePlan();
87         plan.setArchivePath(filePanel.getArchivePath());
88         if (plan instanceof EarPlan) {
89             EarPlan ep = (EarPlan) plan;
90
91             ep.setCopyClient(checkCopyClient.isSelected());
92             ep.setAlt(checkAlt.isSelected());
93             ep.setAppName(textAppName.getText());
94             ep.setDescription(textAppDesc.getText());
95         } else {
96             throw new ArchiveException("Unable to write plan: expecting type EarPlan");
97         }
98     }
99
100     public void validatePlan() throws ArchiveException {
101         filePanel.validatePlan();
102         if (textAppName.getText().trim().length() == 0) {
103             throw new ArchiveException("Application name cannot be left blank.");
104         }
105     }
106
107     public String JavaDoc getPageTitle() {
108         return "Enterprise Application Archive";
109     }
110
111     public String JavaDoc getInstructions() {
112         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
113
114         buf.append("Enter details for the enterprise application archive file.");
115         return buf.toString();
116     }
117
118     protected void preparePanel() {
119         String JavaDoc[] defaultDD = new String JavaDoc[1];
120         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
121
122         buf.append(getWorkingRoot());
123         buf.append(File.separator);
124         buf.append("src");
125         buf.append(File.separator);
126         buf.append("meta-inf");
127         buf.append(File.separator);
128         buf.append("application.xml");
129         defaultDD[0] = buf.toString();
130         filePanel.setDefaultDD(defaultDD);
131         filePanel.preparePanel();
132     }
133
134     private void pmInit() {
135         filePanel.setExtension("ear");
136         checkAlt.setEnabled(false);
137         checkAlt.setSelected(false);
138     }
139
140     private void jbInit() throws Exception JavaDoc {
141         filePanel = (FilePanel) Beans.instantiate(getClass().getClassLoader(),
142                                                   FilePanel.class.getName());
143         layoutMain =
144             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
145                                               GridBagLayout.class.getName());
146         panelApp = (JPanel) Beans.instantiate(getClass().getClassLoader(),
147                                               JPanel.class.getName());
148         layoutApp =
149             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
150                                               GridBagLayout.class.getName());
151         labelAppName = (JLabel) Beans.instantiate(getClass().getClassLoader(),
152                                                   JLabel.class.getName());
153         textAppName =
154             (JTextField) Beans.instantiate(getClass().getClassLoader(),
155                                            JTextField.class.getName());
156         labelAppDesc = (JLabel) Beans.instantiate(getClass().getClassLoader(),
157                                                   JLabel.class.getName());
158         scroll = (JScrollPane) Beans.instantiate(getClass().getClassLoader(),
159                                                  JScrollPane.class.getName());
160         textAppDesc =
161             (JTextArea) Beans.instantiate(getClass().getClassLoader(),
162                                           JTextArea.class.getName());
163         checkAlt = (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
164                                                  JCheckBox.class.getName());
165         checkCopyClient =
166             (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
167                                           JCheckBox.class.getName());
168         panellFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(),
169                                                   JPanel.class.getName());
170         panelApp.setLayout(layoutApp);
171         panelApp.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(new Color(187, 218, 252), new Color(91, 107, 123)),
172                                             "Application"));
173         labelAppName.setText("Name:");
174         textAppName.setText("APPLICATION NAME");
175         labelAppDesc.setText("Description:");
176         textAppDesc.setText("Application description");
177         checkAlt.setText("Create alternate descriptors");
178         checkCopyClient.setEnabled(true);
179         checkCopyClient.setSelected(true);
180         checkCopyClient.setText("Copy EJB clients to web archives");
181         panelApp.add(labelAppName,
182                      new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1,
183                                             GridBagConstraints.WEST,
184                                             GridBagConstraints.HORIZONTAL,
185                                             new Insets(5, 10, 0, 5), 0, 0));
186         panelApp.add(textAppName,
187                      new GridBagConstraints(1, 0, 1, 1, 0.1, 0.1,
188                                             GridBagConstraints.WEST,
189                                             GridBagConstraints.HORIZONTAL,
190                                             new Insets(5, 5, 0, 10), 0, 0));
191         panelApp.add(labelAppDesc,
192                      new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1,
193                                             GridBagConstraints.WEST,
194                                             GridBagConstraints.HORIZONTAL,
195                                             new Insets(5, 10, 5, 5), 0, 0));
196         panelApp.add(scroll,
197                      new GridBagConstraints(1, 1, 1, 3, 0.4, 0.6,
198                                             GridBagConstraints.CENTER,
199                                             GridBagConstraints.BOTH,
200                                             new Insets(5, 5, 5, 10), 0, 50));
201         panelApp.add(checkAlt,
202                      new GridBagConstraints(0, 4, 2, 1, 0.1, 0.1,
203                                             GridBagConstraints.WEST,
204                                             GridBagConstraints.HORIZONTAL,
205                                             new Insets(2, 5, 2, 5), 0, 0));
206         panelApp.add(checkCopyClient,
207                      new GridBagConstraints(0, 5, 2, 1, 0.0, 0.0,
208                                             GridBagConstraints.CENTER,
209                                             GridBagConstraints.HORIZONTAL,
210                                             new Insets(2, 5, 2, 5), 0, 0));
211         panelApp.add(panellFiller,
212                      new GridBagConstraints(0, 2, 1, 1, 0.1, 0.1,
213                                             GridBagConstraints.CENTER,
214                                             GridBagConstraints.NONE,
215                                             new Insets(0, 0, 0, 0), 5, 5));
216         scroll.getViewport().add(textAppDesc, null);
217         this.setLayout(layoutMain);
218         this.add(filePanel,
219                  new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1,
220                                         GridBagConstraints.CENTER,
221                                         GridBagConstraints.BOTH,
222                                         new Insets(0, 0, 0, 0), 0, 0));
223         this.add(panelApp,
224                  new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1,
225                                         GridBagConstraints.CENTER,
226                                         GridBagConstraints.BOTH,
227                                         new Insets(2, 5, 5, 5), 0, 0));
228     }
229
230 }
231
Popular Tags