KickJava   Java API By Example, From Geeks To Geeks.

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


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.Descriptor;
29 import org.enhydra.tool.archive.JarPlan;
30 import org.enhydra.tool.archive.EjbPlan;
31
32 // JDK
33
import java.awt.*;
34 import java.io.File JavaDoc;
35 import javax.swing.*;
36 import java.lang.ref.WeakReference JavaDoc;
37 import java.beans.*;
38
39 //
40
public class EjbFilePanel extends ArchivePanel {
41     private FilePanel filePanel = null;
42     private JCheckBox checkCreateClient = null;
43     private GridBagLayout layoutMain = null;
44
45     public EjbFilePanel() {
46         try {
47             jbInit();
48             pmInit();
49         } catch (Exception JavaDoc ex) {
50             ex.printStackTrace();
51         }
52     }
53
54     public void readPlan(JarPlan plan) throws ArchiveException {
55         filePanel.setArchivePath(plan.getArchivePath());
56         if (plan instanceof EjbPlan) {
57             EjbPlan ep = (EjbPlan) plan;
58             Descriptor[] row = plan.getDescriptors();
59             filePanel.getDDTableModel().clear();
60             for (int i = 0 ; i < row.length ; i++ ) {
61               filePanel.getDDTableModel().addDescriptor(row[i]);
62             }
63             filePanel.getDDTable().setRowSelectionInterval(0, 0);
64             checkCreateClient.setSelected(ep.isCreateClient());
65         } else {
66             throw new ArchiveException("Unable to read plan: expecting type EjbPlan");
67         }
68     }
69
70     public void writePlan(JarPlan plan) throws ArchiveException {
71         validatePlan();
72         plan.setArchivePath(filePanel.getArchivePath());
73         if (plan instanceof EjbPlan) {
74             EjbPlan ep = (EjbPlan) plan;
75             int count = filePanel.getDDTableModel().getRowCount();
76
77             ep.setDescriptors(filePanel.getDDTableModel().getDescriptors());
78             ep.setCreateClient(checkCreateClient.isSelected());
79         }
80     }
81
82     public void validatePlan() throws ArchiveException {
83         filePanel.validatePlan();
84     }
85
86     public String JavaDoc getPageTitle() {
87         return "Enterprise JavaBean Archive";
88     }
89
90     public String JavaDoc getInstructions() {
91         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
92
93         buf.append("Enter details for the enterprise JavaBean archive.");
94         return buf.toString();
95     }
96
97     protected void preparePanel() {
98         String JavaDoc[] defaultDD = new String JavaDoc[1];
99         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
100
101         buf.append(getWorkingRoot());
102         buf.append(File.separator);
103         buf.append("src");
104         buf.append(File.separator);
105         buf.append("meta-inf");
106         buf.append(File.separator);
107         buf.append("ejb-jar.xml");
108         defaultDD[0] = buf.toString();
109         filePanel.setDefaultDD(defaultDD);
110         filePanel.preparePanel();
111     }
112
113     private void pmInit() {
114         filePanel.setExtension("jar");
115     }
116
117     // override ArchivePanel
118
protected void setWizard(ArchiveWizard wizard) {
119       super.setWizard(wizard);
120       filePanel.setWizard(wizard);
121     }
122
123     private void jbInit() throws Exception JavaDoc {
124         filePanel = (FilePanel) Beans.instantiate(getClass().getClassLoader(),
125                                                   FilePanel.class.getName());
126         checkCreateClient =
127             (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
128                                           JCheckBox.class.getName());
129         layoutMain =
130             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
131                                               GridBagLayout.class.getName());
132         checkCreateClient.setText("Create client jar");
133         this.setLayout(layoutMain);
134         this.add(filePanel,
135                  new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1,
136                                         GridBagConstraints.CENTER,
137                                         GridBagConstraints.BOTH,
138                                         new Insets(0, 0, 0, 0), 0, 0));
139         this.add(checkCreateClient,
140                  new GridBagConstraints(0, 1, 1, 1, 0.1, 0.0,
141                                         GridBagConstraints.WEST,
142                                         GridBagConstraints.HORIZONTAL,
143                                         new Insets(0, 10, 5, 5), 0, 0));
144     }
145
146 }
147
Popular Tags