Problem 17716. another Throwable: PsiImplUtil.getParameterIndex
[fedora-idea.git] / plugins / IntelliLang / src / org / intellij / plugins / intelliLang / SettingsUI.java
blob84d0f0dc8be85e5b727cfe350cce3adca20b50e4
1 /*
2 * Copyright 2006 Sascha Weinreuter
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 org.intellij.plugins.intelliLang;
19 import com.intellij.openapi.extensions.Extensions;
20 import com.intellij.openapi.options.Configurable;
21 import com.intellij.openapi.options.ConfigurationException;
22 import com.intellij.openapi.project.Project;
23 import com.intellij.openapi.util.Comparing;
24 import org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport;
25 import org.jetbrains.annotations.NotNull;
26 import org.jetbrains.annotations.Nullable;
28 import javax.swing.*;
29 import java.awt.*;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.Collections;
33 import java.util.Comparator;
35 /**
36 * Provides user interface for editing configuration settings.
38 class SettingsUI {
40 private Configurable[] myConfigurables;
42 private final JPanel myRoot = new JPanel(new BorderLayout());
43 private final JTabbedPane myTabbedPane;
46 SettingsUI(@NotNull final Project project, Configuration configuration) {
47 myTabbedPane = new JTabbedPane(JTabbedPane.TOP);
48 myRoot.add(myTabbedPane);
50 final ArrayList<Configurable> configurables = new ArrayList<Configurable>();
51 for (LanguageInjectionSupport support : Extensions.getExtensions(LanguageInjectionSupport.EP_NAME)) {
52 configurables.addAll(Arrays.asList(support.createSettings(project, configuration)));
54 Collections.sort(configurables, new Comparator<Configurable>() {
55 public int compare(final Configurable o1, final Configurable o2) {
56 return Comparing.compare(o1.getDisplayName(), o2.getDisplayName());
58 });
59 configurables.add(0, new InjectionsSettingsUI(project, configuration));
60 myConfigurables = configurables.toArray(new Configurable[configurables.size()]);
61 for (Configurable configurable : configurables) {
62 myTabbedPane.addTab(configurable.getDisplayName(), configurable.createComponent());
66 public JComponent createComponent() {
67 return myRoot;
70 @Nullable
71 public Configurable getSelectedChild() {
72 final int index = myTabbedPane.getSelectedIndex();
73 if (index >= 0) return myConfigurables[index];
74 return null;
77 public boolean isModified() {
78 for (Configurable configurable : myConfigurables) {
79 if (configurable.isModified()) return true;
81 return false;
84 public void apply() throws ConfigurationException {
85 for (Configurable configurable : myConfigurables) {
86 configurable.apply();
90 public void reset() {
91 for (Configurable configurable : myConfigurables) {
92 configurable.reset();