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