2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.j2ee.earproject.ui.wizards.dd;
44
import java.awt.Component;
45
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionListener;
48
import javax.swing.DefaultListCellRenderer;
49
import javax.swing.JList;
50
import javax.swing.JPanel;
51
import org.netbeans.api.project.Project;
52
import org.netbeans.api.project.ProjectUtils;
53
import org.netbeans.modules.j2ee.earproject.ProjectEar;
54
import org.netbeans.modules.j2ee.spi.ejbjar.EarImplementation;
55
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileUtil;
57
import org.openide.util.NbBundle;
60
* Adopted from {@link org.netbeans.modules.j2ee.ejbcore.ejb.wizard.dd.EjbJarXmlVisualPanel1}.
61
* @author Martin Adamek
63
public final class ApplicationXmlVisualPanel1 extends JPanel {
64
private static final long serialVersionUID = 1L;
66
// generated by apisupport wizard
68
public ApplicationXmlVisualPanel1() {
72
void setProject(Project project) {
73
// initialize visual components
74
//#118047 avoid using the EarProject instance directly to allow for alternate implementations.
75
EarImplementation projectEar = project.getLookup().lookup(EarImplementation.class);
76
fileNameText.setText(ProjectEar.FILE_DD); // NOI18N
77
projectText.setText(ProjectUtils.getInformation(project).getDisplayName());
78
// a nasty fallback to getProjectDirectory if the metainf folder doesn't exist.
79
// not sure if there are ways of checking for the right location and creating it upon request.
80
FileObject docBase = projectEar != null ? projectEar.getMetaInf() : project.getProjectDirectory();
81
locationText.setText(FileUtil.getFileDisplayName(docBase));
83
locationText.addActionListener(new ActionListener() {
84
public void actionPerformed(ActionEvent actionEvent) {
90
FileObject getSelectedLocation() {
91
return FileUtil.toFileObject(new File(locationText.getText()));
94
File getCreatedFile() {
95
return new File(createdFileText.getText());
99
public String getName() {
100
return NbBundle.getMessage(ApplicationXmlVisualPanel1.class, "LBL_SelectLocation");
103
private void refreshLocation() {
104
FileObject fileObject = getSelectedLocation();
105
if (fileObject != null) {
106
createdFileText.setText(FileUtil.getFileDisplayName(fileObject) + File.separator + ProjectEar.FILE_DD);
108
firePropertyChange("", null, null);
111
private class FileObjectListCellRenderer extends DefaultListCellRenderer {
112
private static final long serialVersionUID = 1L;
114
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
115
if (value instanceof FileObject) {
116
FileObject fileObject = (FileObject) value;
117
setText(FileUtil.getFileDisplayName(fileObject));
123
/** This method is called from within the constructor to
124
* initialize the form.
125
* WARNING: Do NOT modify this code. The content of this method is
126
* always regenerated by the Form Editor.
128
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
129
private void initComponents() {
131
jLabel1 = new javax.swing.JLabel();
132
jLabel2 = new javax.swing.JLabel();
133
jLabel3 = new javax.swing.JLabel();
134
jLabel4 = new javax.swing.JLabel();
135
createdFileText = new javax.swing.JTextField();
136
projectText = new javax.swing.JTextField();
137
fileNameText = new javax.swing.JTextField();
138
locationText = new javax.swing.JTextField();
140
jLabel1.setLabelFor(fileNameText);
141
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(ApplicationXmlVisualPanel1.class, "LBL_Name")); // NOI18N
143
jLabel2.setLabelFor(projectText);
144
org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(ApplicationXmlVisualPanel1.class, "LBL_Project")); // NOI18N
146
jLabel3.setLabelFor(locationText);
147
org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(ApplicationXmlVisualPanel1.class, "LBL_Location")); // NOI18N
149
jLabel4.setLabelFor(createdFileText);
150
org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(ApplicationXmlVisualPanel1.class, "LBL_CreatedFile")); // NOI18N
152
createdFileText.setEditable(false);
154
projectText.setEditable(false);
156
fileNameText.setEditable(false);
158
locationText.setEditable(false);
160
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
161
this.setLayout(layout);
162
layout.setHorizontalGroup(
163
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
164
.add(layout.createSequentialGroup()
166
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
171
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
172
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
173
.add(projectText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
174
.add(createdFileText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
175
.add(fileNameText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
176
.add(locationText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE))
179
layout.setVerticalGroup(
180
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
181
.add(layout.createSequentialGroup()
183
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
185
.add(fileNameText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
186
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
187
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
189
.add(projectText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
190
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
191
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
193
.add(locationText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
194
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
195
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
197
.add(createdFileText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
198
.addContainerGap(194, Short.MAX_VALUE))
200
}// </editor-fold>//GEN-END:initComponents
203
// Variables declaration - do not modify//GEN-BEGIN:variables
204
private javax.swing.JTextField createdFileText;
205
private javax.swing.JTextField fileNameText;
206
private javax.swing.JLabel jLabel1;
207
private javax.swing.JLabel jLabel2;
208
private javax.swing.JLabel jLabel3;
209
private javax.swing.JLabel jLabel4;
210
private javax.swing.JTextField locationText;
211
private javax.swing.JTextField projectText;
212
// End of variables declaration//GEN-END:variables