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-2007 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.clientproject.ui.wizards;
44
import org.netbeans.api.java.platform.JavaPlatform;
45
import org.netbeans.api.java.platform.JavaPlatformManager;
46
import org.netbeans.api.java.platform.Specification;
47
import org.netbeans.modules.j2ee.clientproject.ui.FoldersListSettings;
48
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
49
import org.openide.modules.SpecificationVersion;
52
* Displays a warning that the project's Java platform will be set to JDK 1.4 or
53
* the source level will be set to 1.4. Similarly for 1.5. See issue #55797.
55
* @author Andrei Badea
57
public final class J2eeVersionWarningPanel extends javax.swing.JPanel {
58
private static final long serialVersionUID = 1L;
61
* Display a warning that the target platform will be downgraded to JDK 1.4
63
public final static String WARN_SET_JDK_14 = "warnSetJdk14"; // NOI18N
66
* Display a warning that the target platform will be upgraded to JDK 1.5
68
public final static String WARN_SET_JDK_15 = "warnSetJdk15"; // NOI18N
71
* Display a warning that the source level will be downgraded to 1.4
73
public final static String WARN_SET_SOURCE_LEVEL_14 = "warnSetSourceLevel14"; // NOI18N
76
* Display a warning that the source level will be upgraded to 1.5
78
public final static String WARN_SET_SOURCE_LEVEL_15 = "warnSetSourceLevel15"; // NOI18N
80
private String warningType;
81
private String javaPlatformName;
83
public J2eeVersionWarningPanel(String warningType) {
85
setWarningType(warningType);
88
public String getWarningType() {
92
public void setWarningType(String warningType) {
93
this.warningType = warningType;
95
setJdk14Panel.setVisible(false);
96
setSourceLevel14Panel.setVisible(false);
97
setJdk15Panel.setVisible(false);
98
setSourceLevel15Panel.setVisible(false);
100
if (WARN_SET_JDK_14.equals(warningType)) {
101
setJdk14Panel.setVisible(true);
102
downgradeJdk14CheckBox.setSelected(FoldersListSettings.getDefault().isAgreedSetJdk14());
103
} else if (WARN_SET_SOURCE_LEVEL_14.equals(warningType)) {
104
setSourceLevel14Panel.setVisible(true);
105
downgradeSourceLevel14CheckBox.setSelected(FoldersListSettings.getDefault().isAgreedSetSourceLevel14());
106
} else if (WARN_SET_JDK_15.equals(warningType)) {
107
setJdk15Panel.setVisible(true);
108
downgradeJdk15CheckBox.setSelected(FoldersListSettings.getDefault().isAgreedSetJdk15());
109
} else if (WARN_SET_SOURCE_LEVEL_15.equals(warningType)) {
110
setSourceLevel15Panel.setVisible(true);
111
downgradeSourceLevel15CheckBox.setSelected(FoldersListSettings.getDefault().isAgreedSetSourceLevel15());
115
public boolean getDowngradeAllowed() {
116
if (WARN_SET_JDK_14.equals(warningType)) {
117
return downgradeJdk14CheckBox.isSelected();
118
} else if (WARN_SET_SOURCE_LEVEL_14.equals(warningType)) {
119
return downgradeSourceLevel14CheckBox.isSelected();
120
} else if (WARN_SET_JDK_15.equals(warningType)) {
121
return downgradeJdk15CheckBox.isSelected();
122
} else if (WARN_SET_SOURCE_LEVEL_15.equals(warningType)) {
123
return downgradeSourceLevel15CheckBox.isSelected();
127
public String getSuggestedJavaPlatformName() {
128
if (javaPlatformName == null && WARN_SET_JDK_14.equals(warningType) ) {
129
JavaPlatform[] java14Platforms = getJavaPlatforms("1.4");
130
javaPlatformName = java14Platforms[0].getDisplayName();
132
if (javaPlatformName == null && WARN_SET_JDK_15.equals(warningType) ) {
133
JavaPlatform[] java14Platforms = getJavaPlatforms("1.5");
134
javaPlatformName = java14Platforms[0].getDisplayName();
136
return javaPlatformName;
139
public static String findWarningType(String j2eeLevel) {
140
// System.out.println("findWarningType: j2eeLevel="+j2eeLevel);
141
JavaPlatform defaultPlatform = JavaPlatformManager.getDefault().getDefaultPlatform();
142
SpecificationVersion version = defaultPlatform.getSpecification().getVersion();
143
String sourceLevel = version.toString();
144
// #89131: these levels are not actually distinct from 1.5.
145
if (sourceLevel.equals("1.6") || sourceLevel.equals("1.7")) {
148
// System.out.println("default platform is "+version);
150
// no warning if 1.4 is the default for j2ee14
151
if (new SpecificationVersion("1.4").equals(version) && j2eeLevel.equals(J2eeModule.J2EE_14)) { // NOI18N
155
// no warning if 1.5, 1.6, 1.7 is the default for j2ee15
156
if ("1.5".equals(sourceLevel) && j2eeLevel.equals(J2eeModule.JAVA_EE_5)) { // NOI18N
160
if (j2eeLevel.equals(J2eeModule.J2EE_14)) {
161
JavaPlatform[] java14Platforms = getJavaPlatforms("1.4"); //NOI18N
162
if (java14Platforms.length > 0) {
163
// the user has JDK 1.4, so we warn we'll downgrade to 1.4
164
return WARN_SET_JDK_14;
166
// no JDK 1.4, the best we can do is downgrade the source level to 1.4
167
return WARN_SET_SOURCE_LEVEL_14;
170
assert j2eeLevel.equals(J2eeModule.JAVA_EE_5);
171
JavaPlatform[] java15Platforms = getJavaPlatforms("1.5"); //NOI18N
172
if (java15Platforms.length > 0) {
173
// the user has JDK 1.5, so we warn we'll downgrade to 1.5
174
return WARN_SET_JDK_15;
176
// no JDK 1.5, the best we can do is downgrade the source level to 1.5
177
return WARN_SET_SOURCE_LEVEL_15;
182
private static JavaPlatform[] getJavaPlatforms(String level) {
183
return JavaPlatformManager.getDefault().getPlatforms(null, new Specification("J2SE", new SpecificationVersion(level))); // NOI18N
186
/** This method is called from within the constructor to
187
* initialize the form.
188
* WARNING: Do NOT modify this code. The content of this method is
189
* always regenerated by the Form Editor.
191
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
192
private void initComponents() {
193
java.awt.GridBagConstraints gridBagConstraints;
195
setJdk14Panel = new javax.swing.JPanel();
196
warningJdk14TextArea = new javax.swing.JTextArea();
197
downgradeJdk14CheckBox = new javax.swing.JCheckBox();
198
setSourceLevel15Panel = new javax.swing.JPanel();
199
warningSourceLevel15TextArea = new javax.swing.JTextArea();
200
downgradeSourceLevel15CheckBox = new javax.swing.JCheckBox();
201
setJdk15Panel = new javax.swing.JPanel();
202
warningJdk15TextArea = new javax.swing.JTextArea();
203
downgradeJdk15CheckBox = new javax.swing.JCheckBox();
204
setSourceLevel14Panel = new javax.swing.JPanel();
205
warningSourceLevel14TextArea = new javax.swing.JTextArea();
206
downgradeSourceLevel14CheckBox = new javax.swing.JCheckBox();
208
setLayout(new java.awt.GridBagLayout());
210
setJdk14Panel.setLayout(new java.awt.GridBagLayout());
212
warningJdk14TextArea.setEditable(false);
213
warningJdk14TextArea.setLineWrap(true);
214
warningJdk14TextArea.setText(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("MSG_RecommendationSetJdk14"));
215
warningJdk14TextArea.setWrapStyleWord(true);
216
warningJdk14TextArea.setOpaque(false);
217
gridBagConstraints = new java.awt.GridBagConstraints();
218
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
219
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
220
gridBagConstraints.weightx = 1.0;
221
gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
222
setJdk14Panel.add(warningJdk14TextArea, gridBagConstraints);
224
downgradeJdk14CheckBox.setMnemonic(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "MNE_AgreeSetJdk14").charAt(0));
225
downgradeJdk14CheckBox.setSelected(true);
226
downgradeJdk14CheckBox.setText(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "CTL_AgreeSetJdk14"));
227
downgradeJdk14CheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
228
downgradeJdk14CheckBox.addActionListener(new java.awt.event.ActionListener() {
229
public void actionPerformed(java.awt.event.ActionEvent evt) {
230
downgradeJdk14CheckBoxActionPerformed(evt);
234
gridBagConstraints = new java.awt.GridBagConstraints();
235
gridBagConstraints.gridx = 0;
236
gridBagConstraints.gridy = 1;
237
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
238
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
239
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
240
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
241
gridBagConstraints.weightx = 1.0;
242
gridBagConstraints.weighty = 1.0;
243
setJdk14Panel.add(downgradeJdk14CheckBox, gridBagConstraints);
244
downgradeJdk14CheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("ACS_AgreeSetJdk14"));
246
gridBagConstraints = new java.awt.GridBagConstraints();
247
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
248
gridBagConstraints.weightx = 1.0;
249
gridBagConstraints.weighty = 1.0;
250
add(setJdk14Panel, gridBagConstraints);
252
setSourceLevel15Panel.setLayout(new java.awt.GridBagLayout());
254
warningSourceLevel15TextArea.setEditable(false);
255
warningSourceLevel15TextArea.setLineWrap(true);
256
warningSourceLevel15TextArea.setText(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("MSG_RecommendationSetSourceLevel15"));
257
warningSourceLevel15TextArea.setWrapStyleWord(true);
258
warningSourceLevel15TextArea.setOpaque(false);
259
gridBagConstraints = new java.awt.GridBagConstraints();
260
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
261
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
262
gridBagConstraints.weightx = 1.0;
263
gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
264
setSourceLevel15Panel.add(warningSourceLevel15TextArea, gridBagConstraints);
266
downgradeSourceLevel15CheckBox.setMnemonic(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "MNE_AgreeSetSourceLevel15").charAt(0));
267
downgradeSourceLevel15CheckBox.setSelected(true);
268
downgradeSourceLevel15CheckBox.setText(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "CTL_AgreeSetSourceLevel15"));
269
downgradeSourceLevel15CheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
270
downgradeSourceLevel15CheckBox.addActionListener(new java.awt.event.ActionListener() {
271
public void actionPerformed(java.awt.event.ActionEvent evt) {
272
downgradeSourceLevel15CheckBoxActionPerformed(evt);
276
gridBagConstraints = new java.awt.GridBagConstraints();
277
gridBagConstraints.gridx = 0;
278
gridBagConstraints.gridy = 1;
279
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
280
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
281
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
282
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
283
gridBagConstraints.weightx = 1.0;
284
gridBagConstraints.weighty = 1.0;
285
setSourceLevel15Panel.add(downgradeSourceLevel15CheckBox, gridBagConstraints);
286
downgradeSourceLevel15CheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("ACS_AgreeSetSourceLevel15"));
288
gridBagConstraints = new java.awt.GridBagConstraints();
289
gridBagConstraints.gridx = 3;
290
gridBagConstraints.gridy = 0;
291
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
292
gridBagConstraints.weightx = 1.0;
293
gridBagConstraints.weighty = 1.0;
294
add(setSourceLevel15Panel, gridBagConstraints);
296
setJdk15Panel.setLayout(new java.awt.GridBagLayout());
298
warningJdk15TextArea.setEditable(false);
299
warningJdk15TextArea.setLineWrap(true);
300
warningJdk15TextArea.setText(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("MSG_RecommendationSetJdk15"));
301
warningJdk15TextArea.setWrapStyleWord(true);
302
warningJdk15TextArea.setOpaque(false);
303
gridBagConstraints = new java.awt.GridBagConstraints();
304
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
305
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
306
gridBagConstraints.weightx = 1.0;
307
gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
308
setJdk15Panel.add(warningJdk15TextArea, gridBagConstraints);
310
downgradeJdk15CheckBox.setMnemonic(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "MNE_AgreeSetJdk15").charAt(0));
311
downgradeJdk15CheckBox.setSelected(true);
312
downgradeJdk15CheckBox.setText(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "CTL_AgreeSetJdk15"));
313
downgradeJdk15CheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
314
downgradeJdk15CheckBox.addActionListener(new java.awt.event.ActionListener() {
315
public void actionPerformed(java.awt.event.ActionEvent evt) {
316
downgradeJdk15CheckBoxActionPerformed(evt);
320
gridBagConstraints = new java.awt.GridBagConstraints();
321
gridBagConstraints.gridx = 0;
322
gridBagConstraints.gridy = 1;
323
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
324
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
325
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
326
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
327
gridBagConstraints.weightx = 1.0;
328
gridBagConstraints.weighty = 1.0;
329
setJdk15Panel.add(downgradeJdk15CheckBox, gridBagConstraints);
330
downgradeJdk15CheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("ACS_AgreeSetJdk15"));
332
gridBagConstraints = new java.awt.GridBagConstraints();
333
gridBagConstraints.gridx = 2;
334
gridBagConstraints.gridy = 0;
335
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
336
gridBagConstraints.weightx = 1.0;
337
gridBagConstraints.weighty = 1.0;
338
add(setJdk15Panel, gridBagConstraints);
340
setSourceLevel14Panel.setLayout(new java.awt.GridBagLayout());
342
warningSourceLevel14TextArea.setEditable(false);
343
warningSourceLevel14TextArea.setLineWrap(true);
344
warningSourceLevel14TextArea.setText(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("MSG_RecommendationSetSourceLevel14"));
345
warningSourceLevel14TextArea.setWrapStyleWord(true);
346
warningSourceLevel14TextArea.setOpaque(false);
347
gridBagConstraints = new java.awt.GridBagConstraints();
348
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
349
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
350
gridBagConstraints.weightx = 1.0;
351
gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
352
setSourceLevel14Panel.add(warningSourceLevel14TextArea, gridBagConstraints);
354
downgradeSourceLevel14CheckBox.setMnemonic(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "MNE_AgreeSetSourceLevel14").charAt(0));
355
downgradeSourceLevel14CheckBox.setSelected(true);
356
downgradeSourceLevel14CheckBox.setText(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "CTL_AgreeSetSourceLevel14"));
357
downgradeSourceLevel14CheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
358
downgradeSourceLevel14CheckBox.addActionListener(new java.awt.event.ActionListener() {
359
public void actionPerformed(java.awt.event.ActionEvent evt) {
360
downgradeSourceLevel14CheckBoxActionPerformed(evt);
364
gridBagConstraints = new java.awt.GridBagConstraints();
365
gridBagConstraints.gridx = 0;
366
gridBagConstraints.gridy = 1;
367
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
368
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
369
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
370
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
371
gridBagConstraints.weightx = 1.0;
372
gridBagConstraints.weighty = 1.0;
373
setSourceLevel14Panel.add(downgradeSourceLevel14CheckBox, gridBagConstraints);
374
downgradeSourceLevel14CheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("ACS_AgreeSetSourceLevel14"));
376
gridBagConstraints = new java.awt.GridBagConstraints();
377
gridBagConstraints.gridx = 1;
378
gridBagConstraints.gridy = 0;
379
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
380
gridBagConstraints.weightx = 1.0;
381
gridBagConstraints.weighty = 1.0;
382
add(setSourceLevel14Panel, gridBagConstraints);
384
}// </editor-fold>//GEN-END:initComponents
386
private void downgradeSourceLevel15CheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downgradeSourceLevel15CheckBoxActionPerformed
387
FoldersListSettings.getDefault().setAgreedSetSourceLevel15(downgradeSourceLevel15CheckBox.isSelected());
388
}//GEN-LAST:event_downgradeSourceLevel15CheckBoxActionPerformed
390
private void downgradeJdk15CheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downgradeJdk15CheckBoxActionPerformed
391
FoldersListSettings.getDefault().setAgreedSetJdk15(downgradeJdk15CheckBox.isSelected());
392
}//GEN-LAST:event_downgradeJdk15CheckBoxActionPerformed
394
private void downgradeSourceLevel14CheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downgradeSourceLevel14CheckBoxActionPerformed
395
FoldersListSettings.getDefault().setAgreedSetSourceLevel14(downgradeSourceLevel14CheckBox.isSelected());
396
}//GEN-LAST:event_downgradeSourceLevel14CheckBoxActionPerformed
398
private void downgradeJdk14CheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downgradeJdk14CheckBoxActionPerformed
399
FoldersListSettings.getDefault().setAgreedSetJdk14(downgradeJdk14CheckBox.isSelected());
400
}//GEN-LAST:event_downgradeJdk14CheckBoxActionPerformed
402
// Variables declaration - do not modify//GEN-BEGIN:variables
403
private javax.swing.JCheckBox downgradeJdk14CheckBox;
404
private javax.swing.JCheckBox downgradeJdk15CheckBox;
405
private javax.swing.JCheckBox downgradeSourceLevel14CheckBox;
406
private javax.swing.JCheckBox downgradeSourceLevel15CheckBox;
407
private javax.swing.JPanel setJdk14Panel;
408
private javax.swing.JPanel setJdk15Panel;
409
private javax.swing.JPanel setSourceLevel14Panel;
410
private javax.swing.JPanel setSourceLevel15Panel;
411
private javax.swing.JTextArea warningJdk14TextArea;
412
private javax.swing.JTextArea warningJdk15TextArea;
413
private javax.swing.JTextArea warningSourceLevel14TextArea;
414
private javax.swing.JTextArea warningSourceLevel15TextArea;
415
// End of variables declaration//GEN-END:variables