1 19 20 package org.netbeans.modules.j2ee.clientproject.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.clientproject.ui.FoldersListSettings; 26 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 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 { 144 assert j2eeLevel.equals(J2eeModule.JAVA_EE_5); 145 JavaPlatform[] java15Platforms = getJavaPlatforms("1.5"); if (java15Platforms.length > 0) { 147 return WARN_SET_JDK_15; 149 } else { 150 return WARN_SET_SOURCE_LEVEL_15; 152 } 153 } 154 } 155 156 private static JavaPlatform[] getJavaPlatforms(String level) { 157 return JavaPlatformManager.getDefault().getPlatforms(null, new Specification("J2SE", new SpecificationVersion(level))); } 159 160 165 private void initComponents() { 167 java.awt.GridBagConstraints gridBagConstraints; 168 169 setJdk14Panel = new javax.swing.JPanel (); 170 warningJdk14TextArea = new javax.swing.JTextArea (); 171 downgradeJdk14CheckBox = new javax.swing.JCheckBox (); 172 setSourceLevel15Panel = new javax.swing.JPanel (); 173 warningSourceLevel15TextArea = new javax.swing.JTextArea (); 174 downgradeSourceLevel15CheckBox = new javax.swing.JCheckBox (); 175 setJdk15Panel = new javax.swing.JPanel (); 176 warningJdk15TextArea = new javax.swing.JTextArea (); 177 downgradeJdk15CheckBox = new javax.swing.JCheckBox (); 178 setSourceLevel14Panel = new javax.swing.JPanel (); 179 warningSourceLevel14TextArea = new javax.swing.JTextArea (); 180 downgradeSourceLevel14CheckBox = new javax.swing.JCheckBox (); 181 182 setLayout(new java.awt.GridBagLayout ()); 183 184 setJdk14Panel.setLayout(new java.awt.GridBagLayout ()); 185 186 warningJdk14TextArea.setEditable(false); 187 warningJdk14TextArea.setLineWrap(true); 188 warningJdk14TextArea.setText(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("MSG_RecommendationSetJdk14")); 189 warningJdk14TextArea.setWrapStyleWord(true); 190 warningJdk14TextArea.setOpaque(false); 191 gridBagConstraints = new java.awt.GridBagConstraints (); 192 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 193 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 194 gridBagConstraints.weightx = 1.0; 195 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 196 setJdk14Panel.add(warningJdk14TextArea, gridBagConstraints); 197 198 downgradeJdk14CheckBox.setMnemonic(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "MNE_AgreeSetJdk14").charAt(0)); 199 downgradeJdk14CheckBox.setSelected(true); 200 downgradeJdk14CheckBox.setText(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "CTL_AgreeSetJdk14")); 201 downgradeJdk14CheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 202 downgradeJdk14CheckBox.addActionListener(new java.awt.event.ActionListener () { 203 public void actionPerformed(java.awt.event.ActionEvent evt) { 204 downgradeJdk14CheckBoxActionPerformed(evt); 205 } 206 }); 207 208 gridBagConstraints = new java.awt.GridBagConstraints (); 209 gridBagConstraints.gridx = 0; 210 gridBagConstraints.gridy = 1; 211 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 212 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 213 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 214 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 215 gridBagConstraints.weightx = 1.0; 216 gridBagConstraints.weighty = 1.0; 217 setJdk14Panel.add(downgradeJdk14CheckBox, gridBagConstraints); 218 downgradeJdk14CheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("ACS_AgreeSetJdk14")); 219 220 gridBagConstraints = new java.awt.GridBagConstraints (); 221 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 222 gridBagConstraints.weightx = 1.0; 223 gridBagConstraints.weighty = 1.0; 224 add(setJdk14Panel, gridBagConstraints); 225 226 setSourceLevel15Panel.setLayout(new java.awt.GridBagLayout ()); 227 228 warningSourceLevel15TextArea.setEditable(false); 229 warningSourceLevel15TextArea.setLineWrap(true); 230 warningSourceLevel15TextArea.setText(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("MSG_RecommendationSetSourceLevel15")); 231 warningSourceLevel15TextArea.setWrapStyleWord(true); 232 warningSourceLevel15TextArea.setOpaque(false); 233 gridBagConstraints = new java.awt.GridBagConstraints (); 234 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 235 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 236 gridBagConstraints.weightx = 1.0; 237 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 238 setSourceLevel15Panel.add(warningSourceLevel15TextArea, gridBagConstraints); 239 240 downgradeSourceLevel15CheckBox.setMnemonic(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "MNE_AgreeSetSourceLevel15").charAt(0)); 241 downgradeSourceLevel15CheckBox.setSelected(true); 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.setSelected(true); 286 downgradeJdk15CheckBox.setText(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "CTL_AgreeSetJdk15")); 287 downgradeJdk15CheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 288 downgradeJdk15CheckBox.addActionListener(new java.awt.event.ActionListener () { 289 public void actionPerformed(java.awt.event.ActionEvent evt) { 290 downgradeJdk15CheckBoxActionPerformed(evt); 291 } 292 }); 293 294 gridBagConstraints = new java.awt.GridBagConstraints (); 295 gridBagConstraints.gridx = 0; 296 gridBagConstraints.gridy = 1; 297 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 298 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 299 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 300 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 301 gridBagConstraints.weightx = 1.0; 302 gridBagConstraints.weighty = 1.0; 303 setJdk15Panel.add(downgradeJdk15CheckBox, gridBagConstraints); 304 downgradeJdk15CheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("ACS_AgreeSetJdk15")); 305 306 gridBagConstraints = new java.awt.GridBagConstraints (); 307 gridBagConstraints.gridx = 2; 308 gridBagConstraints.gridy = 0; 309 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 310 gridBagConstraints.weightx = 1.0; 311 gridBagConstraints.weighty = 1.0; 312 add(setJdk15Panel, gridBagConstraints); 313 314 setSourceLevel14Panel.setLayout(new java.awt.GridBagLayout ()); 315 316 warningSourceLevel14TextArea.setEditable(false); 317 warningSourceLevel14TextArea.setLineWrap(true); 318 warningSourceLevel14TextArea.setText(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("MSG_RecommendationSetSourceLevel14")); 319 warningSourceLevel14TextArea.setWrapStyleWord(true); 320 warningSourceLevel14TextArea.setOpaque(false); 321 gridBagConstraints = new java.awt.GridBagConstraints (); 322 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 323 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 324 gridBagConstraints.weightx = 1.0; 325 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 326 setSourceLevel14Panel.add(warningSourceLevel14TextArea, gridBagConstraints); 327 328 downgradeSourceLevel14CheckBox.setMnemonic(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "MNE_AgreeSetSourceLevel14").charAt(0)); 329 downgradeSourceLevel14CheckBox.setSelected(true); 330 downgradeSourceLevel14CheckBox.setText(org.openide.util.NbBundle.getMessage(J2eeVersionWarningPanel.class, "CTL_AgreeSetSourceLevel14")); 331 downgradeSourceLevel14CheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 332 downgradeSourceLevel14CheckBox.addActionListener(new java.awt.event.ActionListener () { 333 public void actionPerformed(java.awt.event.ActionEvent evt) { 334 downgradeSourceLevel14CheckBoxActionPerformed(evt); 335 } 336 }); 337 338 gridBagConstraints = new java.awt.GridBagConstraints (); 339 gridBagConstraints.gridx = 0; 340 gridBagConstraints.gridy = 1; 341 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 342 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 343 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 344 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 345 gridBagConstraints.weightx = 1.0; 346 gridBagConstraints.weighty = 1.0; 347 setSourceLevel14Panel.add(downgradeSourceLevel14CheckBox, gridBagConstraints); 348 downgradeSourceLevel14CheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2eeVersionWarningPanel.class).getString("ACS_AgreeSetSourceLevel14")); 349 350 gridBagConstraints = new java.awt.GridBagConstraints (); 351 gridBagConstraints.gridx = 1; 352 gridBagConstraints.gridy = 0; 353 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 354 gridBagConstraints.weightx = 1.0; 355 gridBagConstraints.weighty = 1.0; 356 add(setSourceLevel14Panel, gridBagConstraints); 357 358 } 360 private void downgradeSourceLevel15CheckBoxActionPerformed(java.awt.event.ActionEvent evt) { FoldersListSettings.getDefault().setAgreedSetSourceLevel15(downgradeSourceLevel15CheckBox.isSelected()); 362 } 364 private void downgradeJdk15CheckBoxActionPerformed(java.awt.event.ActionEvent evt) { FoldersListSettings.getDefault().setAgreedSetJdk15(downgradeJdk15CheckBox.isSelected()); 366 } 368 private void downgradeSourceLevel14CheckBoxActionPerformed(java.awt.event.ActionEvent evt) { FoldersListSettings.getDefault().setAgreedSetSourceLevel14(downgradeSourceLevel14CheckBox.isSelected()); 370 } 372 private void downgradeJdk14CheckBoxActionPerformed(java.awt.event.ActionEvent evt) { FoldersListSettings.getDefault().setAgreedSetJdk14(downgradeJdk14CheckBox.isSelected()); 374 } 376 private javax.swing.JCheckBox downgradeJdk14CheckBox; 378 private javax.swing.JCheckBox downgradeJdk15CheckBox; 379 private javax.swing.JCheckBox downgradeSourceLevel14CheckBox; 380 private javax.swing.JCheckBox downgradeSourceLevel15CheckBox; 381 private javax.swing.JPanel setJdk14Panel; 382 private javax.swing.JPanel setJdk15Panel; 383 private javax.swing.JPanel setSourceLevel14Panel; 384 private javax.swing.JPanel setSourceLevel15Panel; 385 private javax.swing.JTextArea warningJdk14TextArea; 386 private javax.swing.JTextArea warningJdk15TextArea; 387 private javax.swing.JTextArea warningSourceLevel14TextArea; 388 private javax.swing.JTextArea warningSourceLevel15TextArea; 389 391 } 392 393 | Popular Tags |