2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.openapi
.roots
.ui
.configuration
;
19 import com
.intellij
.openapi
.options
.ConfigurationException
;
20 import com
.intellij
.openapi
.options
.UnnamedConfigurable
;
21 import com
.intellij
.openapi
.project
.ProjectBundle
;
22 import com
.intellij
.openapi
.roots
.LanguageLevelModuleExtension
;
23 import com
.intellij
.openapi
.roots
.ModifiableRootModel
;
24 import com
.intellij
.pom
.java
.LanguageLevel
;
28 import java
.awt
.event
.ActionEvent
;
29 import java
.awt
.event
.ActionListener
;
35 public class LanguageLevelConfigurable
implements UnnamedConfigurable
{
36 private LanguageLevelCombo myLanguageLevelCombo
;
37 private JPanel myPanel
= new JPanel(new GridBagLayout());
38 public LanguageLevelModuleExtension myLanguageLevelExtension
;
40 public LanguageLevelConfigurable(ModifiableRootModel rootModule
) {
41 myLanguageLevelExtension
= rootModule
.getModuleExtension(LanguageLevelModuleExtension
.class);
42 myLanguageLevelCombo
= new LanguageLevelCombo();
43 myLanguageLevelCombo
.addActionListener(new ActionListener() {
44 public void actionPerformed(final ActionEvent e
) {
45 final Object languageLevel
= myLanguageLevelCombo
.getSelectedItem();
46 myLanguageLevelExtension
.setLanguageLevel(languageLevel
instanceof LanguageLevel ?
(LanguageLevel
)languageLevel
: null);
49 myLanguageLevelCombo
.insertItemAt(LanguageLevelCombo
.USE_PROJECT_LANGUAGE_LEVEL
, 0);
50 myPanel
.add(new JLabel(ProjectBundle
.message("module.module.language.level")), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints
.NORTHWEST
, GridBagConstraints
.NONE
, new Insets(8, 6, 6, 0), 0, 0));
51 myPanel
.add(myLanguageLevelCombo
, new GridBagConstraints(1, 0, 1, 1, 1.0, 0, GridBagConstraints
.NORTHWEST
, GridBagConstraints
.NONE
, new Insets(6, 6, 6, 0), 0, 0));
54 public JComponent
createComponent() {
58 public boolean isModified() {
59 return myLanguageLevelExtension
.isChanged();
62 public void apply() throws ConfigurationException
{
63 myLanguageLevelExtension
.commit();
67 myLanguageLevelCombo
.setSelectedItem(myLanguageLevelExtension
.getLanguageLevel());
70 public void disposeUIResources() {
72 myLanguageLevelCombo
= null;
73 myLanguageLevelExtension
= null;