KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > templates > SunDDVisualPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.j2ee.sun.share.configbean.templates;
20
21 import java.io.File JavaDoc;
22 import javax.swing.JPanel JavaDoc;
23
24 import org.openide.filesystems.FileObject;
25 import org.openide.filesystems.FileUtil;
26 import org.openide.util.Lookup;
27 import org.openide.util.NbBundle;
28
29 import org.netbeans.api.project.Project;
30 import org.netbeans.api.project.ProjectUtils;
31 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
32 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
33
34
35 /*
36  *
37  * @author Peter Williams
38  */

39 public final class SunDDVisualPanel extends JPanel JavaDoc {
40     
41     private Project project;
42     private String JavaDoc sunDDFileName;
43     private File JavaDoc sunDDFile;
44     private File JavaDoc sunDDLocation;
45
46     public SunDDVisualPanel() {
47         initComponents();
48     }
49
50     void setProject(final Project project) {
51         this.project = project;
52
53         // get j2ee module provider
54
// get list of config files for this module type
55
// figure out which ones exist already
56
//
57
Lookup lookup = project.getLookup();
58         J2eeModuleProvider provider = (J2eeModuleProvider) lookup.lookup(J2eeModuleProvider.class);
59         J2eeModule j2eeModule = provider.getJ2eeModule();
60         sunDDFileName = getConfigFileName(j2eeModule);
61
62         // Calculate location:
63
sunDDFile = (sunDDFileName != null) ? provider.getDeploymentConfigurationFile(sunDDFileName) : null;
64         sunDDLocation = (sunDDFile != null) ? sunDDFile.getParentFile() : null;
65         
66         // initialize visual components
67
textFileName.setText(sunDDFileName); // NOI18N
68
textProjectName.setText(ProjectUtils.getInformation(project).getDisplayName());
69
70         File JavaDoc projectFolder = FileUtil.toFile(project.getProjectDirectory());
71         textLocation.setText((sunDDLocation != null) ? getRelativePath(sunDDLocation, projectFolder) : null);
72         // only fill 'created file' in if location is valid.
73
textCreatedFile.setText((sunDDLocation != null) ? getRelativePath(sunDDFile, projectFolder) : null);
74     }
75     
76     String JavaDoc getFileName() {
77         return sunDDFileName;
78     }
79     
80     File JavaDoc getFile() {
81         return sunDDFile;
82     }
83     
84     File JavaDoc getSelectedLocation() {
85         return sunDDLocation;
86     }
87     
88     public String JavaDoc getName() {
89         return NbBundle.getMessage(SunDDVisualPanel.class, "LBL_CreateSunDeploymentDescriptor"); // NOI18N
90
}
91
92     /** This method is called from within the constructor to
93      * initialize the form.
94      * WARNING: Do NOT modify this code. The content of this method is
95      * always regenerated by the Form Editor.
96      */

97     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
98
private void initComponents() {
99         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
100
101         labelFileName = new javax.swing.JLabel JavaDoc();
102         textFileName = new javax.swing.JTextField JavaDoc();
103         labelProjectName = new javax.swing.JLabel JavaDoc();
104         textProjectName = new javax.swing.JTextField JavaDoc();
105         labelLocation = new javax.swing.JLabel JavaDoc();
106         textLocation = new javax.swing.JTextField JavaDoc();
107         labelCreatedFile = new javax.swing.JLabel JavaDoc();
108         textCreatedFile = new javax.swing.JTextField JavaDoc();
109         filler1 = new javax.swing.JLabel JavaDoc();
110
111         setLayout(new java.awt.GridBagLayout JavaDoc());
112
113         labelFileName.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "MNE_Name").charAt(0));
114         labelFileName.setLabelFor(textFileName);
115         org.openide.awt.Mnemonics.setLocalizedText(labelFileName, org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "LBL_Name"));
116         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
117         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
118         add(labelFileName, gridBagConstraints);
119
120         textFileName.setEditable(false);
121         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
122         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
123         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
124         gridBagConstraints.weightx = 1.0;
125         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
126         add(textFileName, gridBagConstraints);
127         textFileName.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCN_Name"));
128         textFileName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCD_Name"));
129
130         labelProjectName.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "MNE_Project").charAt(0));
131         labelProjectName.setLabelFor(textProjectName);
132         org.openide.awt.Mnemonics.setLocalizedText(labelProjectName, org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "LBL_Project"));
133         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
134         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
135         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
136         add(labelProjectName, gridBagConstraints);
137
138         textProjectName.setEditable(false);
139         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
140         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
141         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
142         gridBagConstraints.weightx = 1.0;
143         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
144         add(textProjectName, gridBagConstraints);
145         textProjectName.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCN_Project"));
146         textProjectName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCD_Project"));
147
148         labelLocation.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "MNE_Location").charAt(0));
149         labelLocation.setLabelFor(textLocation);
150         org.openide.awt.Mnemonics.setLocalizedText(labelLocation, org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "LBL_Location"));
151         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
152         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
153         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
154         add(labelLocation, gridBagConstraints);
155
156         textLocation.setEditable(false);
157         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
158         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
159         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
160         gridBagConstraints.weightx = 1.0;
161         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
162         add(textLocation, gridBagConstraints);
163         textLocation.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCN_Location"));
164         textLocation.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCD_Location"));
165
166         labelCreatedFile.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "MNE_CreatedFile").charAt(0));
167         labelCreatedFile.setLabelFor(textCreatedFile);
168         org.openide.awt.Mnemonics.setLocalizedText(labelCreatedFile, org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "LBL_CreatedFile"));
169         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
170         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
171         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 11, 0);
172         add(labelCreatedFile, gridBagConstraints);
173
174         textCreatedFile.setEditable(false);
175         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
176         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
177         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
178         gridBagConstraints.weightx = 1.0;
179         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 11, 0);
180         add(textCreatedFile, gridBagConstraints);
181         textCreatedFile.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCN_CreatedFile"));
182         textCreatedFile.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCD_CreatedFile"));
183
184         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
185         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
186         gridBagConstraints.weightx = 1.0;
187         gridBagConstraints.weighty = 1.0;
188         add(filler1, gridBagConstraints);
189
190     }// </editor-fold>//GEN-END:initComponents
191

192     
193     // Variables declaration - do not modify//GEN-BEGIN:variables
194
private javax.swing.JLabel JavaDoc filler1;
195     private javax.swing.JLabel JavaDoc labelCreatedFile;
196     private javax.swing.JLabel JavaDoc labelFileName;
197     private javax.swing.JLabel JavaDoc labelLocation;
198     private javax.swing.JLabel JavaDoc labelProjectName;
199     private javax.swing.JTextField JavaDoc textCreatedFile;
200     private javax.swing.JTextField JavaDoc textFileName;
201     private javax.swing.JTextField JavaDoc textLocation;
202     private javax.swing.JTextField JavaDoc textProjectName;
203     // End of variables declaration//GEN-END:variables
204

205
206     private String JavaDoc getConfigFileName(J2eeModule j2eeModule) {
207         String JavaDoc result = null;
208         Object JavaDoc moduleType = j2eeModule.getModuleType();
209         if(J2eeModule.WAR.equals(moduleType)) {
210             result = "sun-web.xml"; // NOI18N
211
} else if(J2eeModule.EJB.equals(moduleType)) {
212             result = "sun-ejb-jar.xml"; // NOI18N
213
} else if(J2eeModule.EAR.equals(moduleType)) {
214             result = "sun-application.xml"; // NOI18N
215
} else if(J2eeModule.CLIENT.equals(moduleType)) {
216             result = "sun-application-client.xml"; // NOI18N
217
}
218         return result;
219     }
220     
221     private static String JavaDoc getRelativePath(File JavaDoc file, File JavaDoc base) {
222         String JavaDoc basePath = base.getAbsolutePath();
223         String JavaDoc filePath = file.getAbsolutePath();
224         
225         if(filePath.startsWith(basePath)) {
226             String JavaDoc prefix = "";
227             int baseIndex = basePath.lastIndexOf(File.separatorChar);
228             if(baseIndex < 0 || baseIndex >= filePath.length()) {
229                 baseIndex = 0;
230             } else {
231                 prefix = "..."; // only apply prefix if we're calculating a true substring.
232
}
233             return prefix + filePath.substring(baseIndex);
234         }
235         return filePath;
236     }
237     
238 }
239
Popular Tags