KickJava   Java API By Example, From Geeks To Geeks.

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


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.EarPlan;
31
32 // JDK
33
import java.awt.*;
34 import java.beans.Beans JavaDoc;
35 import java.io.File JavaDoc;
36 import java.util.ArrayList JavaDoc;
37 import javax.swing.*;
38
39 //
40
public class MetaPanel extends ArchivePanel {
41     private BorderLayout layoutMain = null;
42     private OneColumnFileSelector selectorPanel = null;
43
44     public MetaPanel() {
45         try {
46             jbInit();
47             pmInit();
48         } catch (Exception JavaDoc ex) {
49             ex.printStackTrace();
50         }
51     }
52
53     public void readPlan(JarPlan plan) throws ArchiveException {
54         selectorPanel.setSelections(plan.getLibFiles());
55         Descriptor[] dd = new Descriptor[0];
56         String JavaDoc[] paths = new String JavaDoc[0];
57         ArrayList JavaDoc list = new ArrayList JavaDoc();
58
59         if (plan instanceof EarPlan) {
60             EarPlan ep = (EarPlan) plan;
61             dd = ep.getDescriptors();
62             for (int i = 0 ; i < dd.length ; i++) {
63               list.add(dd[i].getPath());
64             }
65             list.trimToSize();
66             paths = new String JavaDoc[list.size()];
67             paths = (String JavaDoc[]) list.toArray(paths);
68             selectorPanel.setSelections(paths);
69         }
70     }
71
72     public void writePlan(JarPlan plan) throws ArchiveException {
73         if (plan instanceof EarPlan) {
74             EarPlan ep = (EarPlan) plan;
75             Descriptor[] dd = new Descriptor[0];
76             String JavaDoc[] paths = new String JavaDoc[0];
77             paths = selectorPanel.getSelections();
78             dd = new Descriptor[paths.length];
79             for (int i = 0 ; i < dd.length ; i++) {
80               dd[i] = new Descriptor(paths[i]);
81             }
82             ep.setDescriptors(dd);
83         }
84     }
85
86     public void validatePlan() throws ArchiveException {
87         // always valid
88
}
89
90     public String JavaDoc getPageTitle() {
91         return "Deployment Descriptors";
92     }
93
94     public String JavaDoc getInstructions() {
95         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
96
97         buf.append("Select the deployment descriptors ");
98         buf.append("to include in this archive.");
99         return buf.toString();
100     }
101
102     // override ArchivePanel
103
protected void setWizard(ArchiveWizard wizard) {
104         super.setWizard(wizard);
105         selectorPanel.setWizard(wizard);
106     }
107
108     private void pmInit() {
109         String JavaDoc[] exts = {
110             "xml", "mf"
111         };
112
113         selectorPanel.setExtensions(exts);
114         selectorPanel.setTitle("meta-inf");
115     }
116
117     private void jbInit() throws Exception JavaDoc {
118         layoutMain =
119             (BorderLayout) Beans.instantiate(getClass().getClassLoader(),
120                                              BorderLayout.class.getName());
121         selectorPanel =
122             (OneColumnFileSelector) Beans.instantiate(getClass().getClassLoader(),
123                 OneColumnFileSelector.class.getName());
124         this.setLayout(layoutMain);
125         this.add(selectorPanel, BorderLayout.CENTER);
126     }
127
128 }
129
Popular Tags