1 19 20 package org.netbeans.modules.web.project.ui.wizards; 21 22 import org.netbeans.api.java.platform.JavaPlatform; 23 import org.netbeans.api.java.platform.JavaPlatformManager; 24 import org.netbeans.api.java.platform.Specification; 25 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 26 import org.netbeans.modules.web.project.ui.FoldersListSettings; 27 import org.openide.modules.SpecificationVersion; 28 29 35 public final class J2eeVersionWarningPanel extends javax.swing.JPanel { 36 37 40 public final static String WARN_SET_JDK_14 = "warnSetJdk14"; 42 45 public final static String WARN_SET_JDK_15 = "warnSetJdk15"; 47 50 public final static String WARN_SET_SOURCE_LEVEL_14 = "warnSetSourceLevel14"; 52 55 public final static String WARN_SET_SOURCE_LEVEL_15 = "warnSetSourceLevel15"; 57 private String warningType; 58 private String javaPlatformName; 59 60 public J2eeVersionWarningPanel(String warningType) { 61 initComponents(); 62 setWarningType(warningType); 63 } 64 65 public String getWarningType() { 66 return warningType; 67 } 68 69 public void setWarningType(String warningType) { 70 this.warningType = warningType; 71 72 setJdk14Panel.setVisible(false); 73 setSourceLevel14Panel.setVisible(false); 74 setJdk15Panel.setVisible(false); 75 setSourceLevel15Panel.setVisible(false); 76 77 if (WARN_SET_JDK_14.equals(warningType)) { 78 setJdk14Panel.setVisible(true); 79 downgradeJdk14CheckBox.setSelected(FoldersListSettings.getDefault().isAgreedSetJdk14()); 80 } else if (WARN_SET_SOURCE_LEVEL_14.equals(warningType)) { 81 setSourceLevel14Panel.setVisible(true); 82 downgradeSourceLevel14CheckBox.setSelected(FoldersListSettings.getDefault().isAgreedSetSourceLevel14()); 83 } else if (WARN_SET_JDK_15.equals(warningType)) { 84 setJdk15Panel.setVisible(true); 85 downgradeJdk15CheckBox.setSelected(FoldersListSettings.getDefault().isAgreedSetJdk15()); 86 } else if (WARN_SET_SOURCE_LEVEL_15.equals(warningType)) { 87 setSourceLevel15Panel.setVisible(true); 88 downgradeSourceLevel15CheckBox.setSelected(FoldersListSettings.getDefault().isAgreedSetSourceLevel15()); 89 } 90 } 91 92 public boolean getDowngradeAllowed() { 93 if (WARN_SET_JDK_14.equals(warningType)) { 94 return downgradeJdk14CheckBox.isSelected(); 95 } else if (WARN_SET_SOURCE_LEVEL_14.equals(warningType)) { 96 return downgradeSourceLevel14CheckBox.isSelected(); 97 } else if (WARN_SET_JDK_15.equals(warningType)) { 98 return downgradeJdk15CheckBox.isSelected(); 99 } else if (WARN_SET_SOURCE_LEVEL_15.equals(warningType)) { 100 return downgradeSourceLevel15CheckBox.isSelected(); 101 } else return false; 102 } 103 104 public String getSuggestedJavaPlatformName() { 105 if (javaPlatformName == null && WARN_SET_JDK_14.equals(warningType) ) { 106 JavaPlatform[] java14Platforms = getJavaPlatforms("1.4"); 107 javaPlatformName = java14Platforms[0].getDisplayName(); 108 } 109 if (javaPlatformName == null && WARN_SET_JDK_15.equals(warningType) ) { 110 JavaPlatform[] java14Platforms = getJavaPlatforms("1.5"); 111 javaPlatformName = java14Platforms[0].getDisplayName(); 112 } 113 return javaPlatformName; 114 } 115 116 public static String findWarningType(String j2eeLevel) { 117 JavaPlatform defaultPlatform = JavaPlatformManager.getDefault().getDefaultPlatform(); 119 SpecificationVersion version = defaultPlatform.getSpecification().getVersion(); 120 String sourceLevel = version.toString(); 121 if (sourceLevel.equals("1.6") || sourceLevel.equals("1.7")) 123 sourceLevel = "1.5"; 124 126 if (new SpecificationVersion("1.4").equals(version) && j2eeLevel.equals(J2eeModule.J2EE_14)) return null; 129 130 if ("1.5".equals(sourceLevel) && j2eeLevel.equals(J2eeModule.JAVA_EE_5)) return null; 133 134 if (j2eeLevel.equals(J2eeModule.J2EE_14)) { 135 JavaPlatform[] java14Platforms = getJavaPlatforms("1.4"); if (java14Platforms.length > 0) { 137 return WARN_SET_JDK_14; 139 } else { 140 return WARN_SET_SOURCE_LEVEL_14; 142 } 143 } else if (j2eeLevel.equals(J2eeModule.JAVA_EE_5)) { 144 JavaPlatform[] java15Platforms = getJavaPlatforms("1.5"); if (java15Platforms.length > 0) { 146 return WARN_SET_JDK_15; 148 } else { 149 return WARN_SET_SOURCE_LEVEL_15; 151 } 152 } else { 153 return null; 155 } 156 } 157 158 private static JavaPlatform[] getJavaPlatforms(String level) { 159 return JavaPlatformManager.getDefault().getPlatforms(null, new Specification("J2SE", new SpecificationVersion(level))); } 161 162 167 private void initComponents() { 169 java.awt.GridBagConstraints gridBagConstraints; 170 171 setJdk14Panel = new javax.swing.JPanel (); 172 warningJdk14TextArea = new javax.swing.JTextArea (); 173 downgradeJdk14CheckBox = new javax.swing.JCheckBox (); 174 setSourceLevel15Panel = new javax.swing.JPanel (); 175 warningSourceLevel15TextArea = new javax.swing.JTextArea (); 176 downgradeSourceLevel15CheckBox = new javax.swing.JCheckBox (); 177 setJdk15Panel = new javax.swing.JPanel (); 178 warningJdk15TextArea = new javax.swing.JTextArea (); 179 downgradeJdk15CheckBox = new javax.swing.JCheckBox (); 180 setSourceLevel14Panel = new javax.swing.JPanel (); 181 warningSourceLevel14TextArea = new javax.swing.JTextArea (); 182 downgradeSourceLevel14CheckBox = new javax.swing.JCheckBox (); 183 184 setLayout(new java.awt.GridBagLayout ()); 185 186 setJdk14Panel.setLayout(new java.awt.GridBagLayout ()); 187 188 warningJdk14TextArea.setEditable(false); 189 warningJdk14TextArea.setLineWrap(true); 190 warningJdk14TextArea.setText(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("MSG_RecommendationSetJdk14")); 191 warningJdk14TextArea.setWrapStyleWord(true); 192 warningJdk14TextArea.setOpaque(false); 193 gridBagConstraints = new java.awt.GridBagConstraints (); 194 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 195 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 196 gridBagConstraints.weightx = 1.0; 197 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 198 setJdk14Panel.add(warningJdk14TextArea, gridBagConstraints); 199 200 downgradeJdk14CheckBox.setMnemonic(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "MNE_AgreeSetJdk14").charAt(0)); 201 downgradeJdk14CheckBox.setText(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "CTL_AgreeSetJdk14")); 202 downgradeJdk14CheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 203 downgradeJdk14CheckBox.addActionListener(new java.awt.event.ActionListener () { 204 public void actionPerformed(java.awt.event.ActionEvent evt) { 205 downgradeJdk14CheckBoxActionPerformed(evt); 206 } 207 }); 208 209 gridBagConstraints = new java.awt.GridBagConstraints (); 210 gridBagConstraints.gridx = 0; 211 gridBagConstraints.gridy = 1; 212 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 213 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 214 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 215 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 216 gridBagConstraints.weightx = 1.0; 217 gridBagConstraints.weighty = 1.0; 218 setJdk14Panel.add(downgradeJdk14CheckBox, gridBagConstraints); 219 downgradeJdk14CheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("ACS_AgreeSetJdk14")); 220 221 gridBagConstraints = new java.awt.GridBagConstraints (); 222 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 223 gridBagConstraints.weightx = 1.0; 224 gridBagConstraints.weighty = 1.0; 225 add(setJdk14Panel, gridBagConstraints); 226 227 setSourceLevel15Panel.setLayout(new java.awt.GridBagLayout ()); 228 229 warningSourceLevel15TextArea.setEditable(false); 230 warningSourceLevel15TextArea.setLineWrap(true); 231 warningSourceLevel15TextArea.setText(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("MSG_RecommendationSetSourceLevel15")); 232 warningSourceLevel15TextArea.setWrapStyleWord(true); 233 warningSourceLevel15TextArea.setOpaque(false); 234 gridBagConstraints = new java.awt.GridBagConstraints (); 235 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 236 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 237 gridBagConstraints.weightx = 1.0; 238 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 239 setSourceLevel15Panel.add(warningSourceLevel15TextArea, gridBagConstraints); 240 241 downgradeSourceLevel15CheckBox.setMnemonic(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "MNE_AgreeSetSourceLevel15").charAt(0)); 242 downgradeSourceLevel15CheckBox.setText(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "CTL_AgreeSetSourceLevel15")); 243 downgradeSourceLevel15CheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 244 downgradeSourceLevel15CheckBox.addActionListener(new java.awt.event.ActionListener () { 245 public void actionPerformed(java.awt.event.ActionEvent evt) { 246 downgradeSourceLevel15CheckBoxActionPerformed(evt); 247 } 248 }); 249 250 gridBagConstraints = new java.awt.GridBagConstraints (); 251 gridBagConstraints.gridx = 0; 252 gridBagConstraints.gridy = 1; 253 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 254 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 255 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 256 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 257 gridBagConstraints.weightx = 1.0; 258 gridBagConstraints.weighty = 1.0; 259 setSourceLevel15Panel.add(downgradeSourceLevel15CheckBox, gridBagConstraints); 260 downgradeSourceLevel15CheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("ACS_AgreeSetSourceLevel15")); 261 262 gridBagConstraints = new java.awt.GridBagConstraints (); 263 gridBagConstraints.gridx = 3; 264 gridBagConstraints.gridy = 0; 265 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 266 gridBagConstraints.weightx = 1.0; 267 gridBagConstraints.weighty = 1.0; 268 add(setSourceLevel15Panel, gridBagConstraints); 269 270 setJdk15Panel.setLayout(new java.awt.GridBagLayout ()); 271 272 warningJdk15TextArea.setEditable(false); 273 warningJdk15TextArea.setLineWrap(true); 274 warningJdk15TextArea.setText(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("MSG_RecommendationSetJdk15")); 275 warningJdk15TextArea.setWrapStyleWord(true); 276 warningJdk15TextArea.setOpaque(false); 277 gridBagConstraints = new java.awt.GridBagConstraints (); 278 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 279 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 280 gridBagConstraints.weightx = 1.0; 281 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 282 setJdk15Panel.add(warningJdk15TextArea, gridBagConstraints); 283 284 downgradeJdk15CheckBox.setMnemonic(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "MNE_AgreeSetJdk15").charAt(0)); 285 downgradeJdk15CheckBox.setText(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "CTL_AgreeSetJdk15")); 286 downgradeJdk15CheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 287 downgradeJdk15CheckBox.addActionListener(new java.awt.event.ActionListener () { 288 public void actionPerformed(java.awt.event.ActionEvent evt) { 289 downgradeJdk15CheckBoxActionPerformed(evt); 290 } 291 }); 292 293 gridBagConstraints = new java.awt.GridBagConstraints (); 294 gridBagConstraints.gridx = 0; 295 gridBagConstraints.gridy = 1; 296 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 297 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 298 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 299 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 300 gridBagConstraints.weightx = 1.0; 301 gridBagConstraints.weighty = 1.0; 302 setJdk15Panel.add(downgradeJdk15CheckBox, gridBagConstraints); 303 downgradeJdk15CheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("ACS_AgreeSetJdk15")); 304 305 gridBagConstraints = new java.awt.GridBagConstraints (); 306 gridBagConstraints.gridx = 2; 307 gridBagConstraints.gridy = 0; 308 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 309 gridBagConstraints.weightx = 1.0; 310 gridBagConstraints.weighty = 1.0; 311 add(setJdk15Panel, gridBagConstraints); 312 313 setSourceLevel14Panel.setLayout(new java.awt.GridBagLayout ()); 314 315 warningSourceLevel14TextArea.setEditable(false); 316 warningSourceLevel14TextArea.setLineWrap(true); 317 warningSourceLevel14TextArea.setText(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("MSG_RecommendationSetSourceLevel14")); 318 warningSourceLevel14TextArea.setWrapStyleWord(true); 319 warningSourceLevel14TextArea.setOpaque(false); 320 gridBagConstraints = new java.awt.GridBagConstraints (); 321 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 322 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 323 gridBagConstraints.weightx = 1.0; 324 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 325 setSourceLevel14Panel.add(warningSourceLevel14TextArea, gridBagConstraints); 326 327 downgradeSourceLevel14CheckBox.setMnemonic(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "MNE_AgreeSetSourceLevel14").charAt(0)); 328 downgradeSourceLevel14CheckBox.setText(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "CTL_AgreeSetSourceLevel14")); 329 downgradeSourceLevel14CheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 330 downgradeSourceLevel14CheckBox.addActionListener(new java.awt.event.ActionListener () { 331 public void actionPerformed(java.awt.event.ActionEvent evt) { 332 downgradeSourceLevel14CheckBoxActionPerformed(evt); 333 } 334 }); 335 336 gridBagConstraints = new java.awt.GridBagConstraints (); 337 gridBagConstraints.gridx = 0; 338 gridBagConstraints.gridy = 1; 339 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 340 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 341 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 342 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 343 gridBagConstraints.weightx = 1.0; 344 gridBagConstraints.weighty = 1.0; 345 setSourceLevel14Panel.add(downgradeSourceLevel14CheckBox, gridBagConstraints); 346 downgradeSourceLevel14CheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("ACS_AgreeSetSourceLevel14")); 347 348 gridBagConstraints = new java.awt.GridBagConstraints (); 349 gridBagConstraints.gridx = 1; 350 gridBagConstraints.gridy = 0; 351 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 352 gridBagConstraints.weightx = 1.0; 353 gridBagConstraints.weighty = 1.0; 354 add(setSourceLevel14Panel, gridBagConstraints); 355 356 } 358 private void downgradeSourceLevel15CheckBoxActionPerformed(java.awt.event.ActionEvent evt) { FoldersListSettings.getDefault().setAgreedSetSourceLevel15(downgradeSourceLevel15CheckBox.isSelected()); 360 } 362 private void downgradeJdk15CheckBoxActionPerformed(java.awt.event.ActionEvent evt) { FoldersListSettings.getDefault().setAgreedSetJdk15(downgradeJdk15CheckBox.isSelected()); 364 } 366 private void downgradeSourceLevel14CheckBoxActionPerformed(java.awt.event.ActionEvent evt) { FoldersListSettings.getDefault().setAgreedSetSourceLevel14(downgradeSourceLevel14CheckBox.isSelected()); 368 } 370 private void downgradeJdk14CheckBoxActionPerformed(java.awt.event.ActionEvent evt) { FoldersListSettings.getDefault().setAgreedSetJdk14(downgradeJdk14CheckBox.isSelected()); 372 } 374 private javax.swing.JCheckBox downgradeJdk14CheckBox; 376 private javax.swing.JCheckBox downgradeJdk15CheckBox; 377 private javax.swing.JCheckBox downgradeSourceLevel14CheckBox; 378 private javax.swing.JCheckBox downgradeSourceLevel15CheckBox; 379 private javax.swing.JPanel setJdk14Panel; 380 private javax.swing.JPanel setJdk15Panel; 381 private javax.swing.JPanel setSourceLevel14Panel; 382 private javax.swing.JPanel setSourceLevel15Panel; 383 private javax.swing.JTextArea warningJdk14TextArea; 384 private javax.swing.JTextArea warningJdk15TextArea; 385 private javax.swing.JTextArea warningSourceLevel14TextArea; 386 private javax.swing.JTextArea warningSourceLevel15TextArea; 387 389 } 390 391 | Popular Tags |