Problem 17716. another Throwable: PsiImplUtil.getParameterIndex
[fedora-idea.git] / plugins / IntelliLang / src / org / intellij / plugins / intelliLang / AdvancedSettingsUI.java
blob4f817124c435660cf155c86b6db492d1ab0d8106
1 /*
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 org.intellij.plugins.intelliLang;
19 import com.intellij.ide.util.TreeClassChooser;
20 import com.intellij.ide.util.TreeClassChooserFactory;
21 import com.intellij.openapi.editor.Document;
22 import com.intellij.openapi.options.Configurable;
23 import com.intellij.openapi.options.ConfigurationException;
24 import com.intellij.openapi.project.Project;
25 import com.intellij.psi.JavaPsiFacade;
26 import com.intellij.psi.PsiClass;
27 import com.intellij.psi.search.GlobalSearchScope;
28 import com.intellij.ui.ReferenceEditorWithBrowseButton;
29 import com.intellij.util.Function;
30 import org.intellij.plugins.intelliLang.util.PsiUtilEx;
31 import org.intellij.plugins.intelliLang.util.ShiftTabAction;
32 import org.jetbrains.annotations.Nls;
33 import org.jetbrains.annotations.NotNull;
35 import javax.swing.*;
36 import java.awt.*;
37 import java.awt.event.ActionEvent;
38 import java.awt.event.ActionListener;
39 import java.util.Arrays;
41 /**
42 * @author Gregory.Shrago
44 public class AdvancedSettingsUI implements Configurable {
45 private final Configuration myConfiguration;
47 @SuppressWarnings({"UnusedDeclaration", "FieldCanBeLocal"})
48 private JPanel myRoot;
50 private JRadioButton myNoInstrumentation;
51 private JRadioButton myAssertInstrumentation;
52 private JRadioButton myExceptionInstrumentation;
53 private JPanel myLanguageAnnotationPanel;
54 private JPanel myPatternAnnotationPanel;
55 private JPanel mySubstAnnotationPanel;
57 private final ReferenceEditorWithBrowseButton myAnnotationField;
58 private final ReferenceEditorWithBrowseButton myPatternField;
59 private final ReferenceEditorWithBrowseButton mySubstField;
61 public AdvancedSettingsUI(@NotNull final Project project, Configuration configuration) {
62 myConfiguration = configuration;
64 myAnnotationField = new ReferenceEditorWithBrowseButton(null, project, new Function<String, Document>() {
65 public Document fun(String s) {
66 return PsiUtilEx.createDocument(s, project);
68 }, myConfiguration.getLanguageAnnotationClass());
69 myAnnotationField.addActionListener(new BrowseClassListener(project, myAnnotationField));
70 myAnnotationField.setEnabled(!project.isDefault());
71 ShiftTabAction.attachTo(myAnnotationField.getEditorTextField());
72 addField(myLanguageAnnotationPanel, myAnnotationField);
74 myPatternField = new ReferenceEditorWithBrowseButton(null, project, new Function<String, Document>() {
75 public Document fun(String s) {
76 return PsiUtilEx.createDocument(s, project);
78 }, myConfiguration.getPatternAnnotationClass());
79 myPatternField.addActionListener(new BrowseClassListener(project, myPatternField));
80 myPatternField.setEnabled(!project.isDefault());
81 ShiftTabAction.attachTo(myPatternField.getEditorTextField());
82 addField(myPatternAnnotationPanel, myPatternField);
84 mySubstField = new ReferenceEditorWithBrowseButton(null, project, new Function<String, Document>() {
85 public Document fun(String s) {
86 return PsiUtilEx.createDocument(s, project);
88 }, myConfiguration.getPatternAnnotationClass());
89 mySubstField.addActionListener(new BrowseClassListener(project, mySubstField));
90 mySubstField.setEnabled(!project.isDefault());
91 ShiftTabAction.attachTo(mySubstField.getEditorTextField());
92 addField(mySubstAnnotationPanel, mySubstField);
95 /**
96 * Adds textfield into placeholder panel and assigns a directly preceding label
98 private static void addField(JPanel panel, ReferenceEditorWithBrowseButton field) {
99 panel.add(field, BorderLayout.CENTER);
101 final Component[] components = panel.getParent().getComponents();
102 final int index = Arrays.asList(components).indexOf(panel);
103 if (index > 0) {
104 final Component component = components[index - 1];
105 if (component instanceof JLabel) {
106 ((JLabel)component).setLabelFor(field);
111 public JComponent createComponent() {
112 return myRoot;
115 @SuppressWarnings({"SimplifiableIfStatement"})
116 public boolean isModified() {
117 if (getInstrumentation() != myConfiguration.getInstrumentation()) {
118 return true;
120 if (!myAnnotationField.getText().equals(myConfiguration.getLanguageAnnotationClass())) {
121 return true;
123 if (!myPatternField.getText().equals(myConfiguration.getPatternAnnotationClass())) {
124 return true;
126 if (!mySubstField.getText().equals(myConfiguration.getSubstAnnotationClass())) {
127 return true;
129 return false;
132 @NotNull
133 private Configuration.InstrumentationType getInstrumentation() {
134 if (myNoInstrumentation.isSelected()) return Configuration.InstrumentationType.NONE;
135 if (myAssertInstrumentation.isSelected()) return Configuration.InstrumentationType.ASSERT;
136 if (myExceptionInstrumentation.isSelected()) return Configuration.InstrumentationType.EXCEPTION;
138 assert false;
139 return null;
142 public void apply() throws ConfigurationException {
143 myConfiguration.setInstrumentationType(getInstrumentation());
144 myConfiguration.setLanguageAnnotation(myAnnotationField.getText());
145 myConfiguration.setPatternAnnotation(myPatternField.getText());
146 myConfiguration.setSubstAnnotation(mySubstField.getText());
149 public void reset() {
150 myAnnotationField.setText(myConfiguration.getLanguageAnnotationClass());
151 myPatternField.setText(myConfiguration.getPatternAnnotationClass());
152 mySubstField.setText(myConfiguration.getSubstAnnotationClass());
154 myNoInstrumentation.setSelected(myConfiguration.getInstrumentation() == Configuration.InstrumentationType.NONE);
155 myAssertInstrumentation.setSelected(myConfiguration.getInstrumentation() == Configuration.InstrumentationType.ASSERT);
156 myExceptionInstrumentation.setSelected(myConfiguration.getInstrumentation() == Configuration.InstrumentationType.EXCEPTION);
159 public void disposeUIResources() {
162 @Nls
163 public String getDisplayName() {
164 return "Advanced";
167 public Icon getIcon() {
168 return null;
171 public String getHelpTopic() {
172 return "reference.settings.injection.advanced";
175 private static class BrowseClassListener implements ActionListener {
176 private final Project myProject;
177 private final ReferenceEditorWithBrowseButton myField;
179 private BrowseClassListener(Project project, ReferenceEditorWithBrowseButton annotationField) {
180 myProject = project;
181 myField = annotationField;
184 public void actionPerformed(ActionEvent e) {
185 final TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(myProject);
187 final GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
188 final PsiClass aClass = JavaPsiFacade.getInstance(myProject).findClass(myField.getText(), scope);
189 final TreeClassChooser chooser =
190 factory.createNoInnerClassesScopeChooser("Select Annotation Class", scope, new TreeClassChooser.ClassFilter() {
191 public boolean isAccepted(PsiClass aClass) {
192 return aClass.isAnnotationType();
194 }, aClass);
196 chooser.showDialog();
197 final PsiClass psiClass = chooser.getSelectedClass();
198 if (psiClass != null) {
199 myField.setText(psiClass.getQualifiedName());