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
.options
.Configurable
;
20 import com
.intellij
.openapi
.options
.ConfigurationException
;
21 import com
.intellij
.openapi
.project
.Project
;
22 import com
.intellij
.openapi
.project
.ProjectManager
;
23 import com
.intellij
.openapi
.util
.IconLoader
;
24 import com
.intellij
.openapi
.wm
.ex
.WindowManagerEx
;
25 import org
.jetbrains
.annotations
.NonNls
;
26 import org
.jetbrains
.annotations
.Nullable
;
32 * Provides UI for global {@link org.intellij.plugins.intelliLang.Configuration}. This is
33 * split into this and the SettingsUI class to avoid holding strong application-wide
34 * references on the UI objects.
36 * Even though this class is an application component, it determines the currently focused
37 * Project and passes it to the SettingsUI instance. This is kinda unconventional, but has
38 * the benefit of having a centralized IDE-wide configuration that doesn't need to be
39 * recreated and maintained for each project, and still being able to use class-choosers
40 * that will allow to browse the current project's classes.
42 public class Settings
implements Configurable
{
44 private final Configuration myConfiguration
;
46 Settings(Configuration configuration
) {
47 myConfiguration
= configuration
;
50 private SettingsUI mySettingsUI
;
52 public String
getDisplayName() {
53 return "Language Injection";
57 public Icon
getIcon() {
58 return IconLoader
.getIcon("icon.png");
63 public String
getHelpTopic() {
64 return "IntelliLang.Configuration";
67 public JComponent
createComponent() {
68 final ProjectManager projectManager
= ProjectManager
.getInstance();
69 final Project
[] projects
= projectManager
.getOpenProjects();
71 Project project
= null;
72 if (projects
.length
== 0) {
73 project
= projectManager
.getDefaultProject();
76 final WindowManagerEx windowManager
= WindowManagerEx
.getInstanceEx();
77 final Window focusedWindow
= windowManager
.getMostRecentFocusedWindow();
78 if (focusedWindow
!= null) {
79 for (Project p
: projects
) {
80 final Window w
= windowManager
.suggestParentWindow(p
);
81 if (w
== focusedWindow
|| w
.isAncestorOf(focusedWindow
) || focusedWindow
.isAncestorOf(w
)) {
87 if (project
== null) {
88 project
= projectManager
.getDefaultProject();
92 mySettingsUI
= new SettingsUI(project
, myConfiguration
);
94 return mySettingsUI
.createComponent();
97 public boolean isModified() {
98 return mySettingsUI
!= null && mySettingsUI
.isModified();
101 public void apply() throws ConfigurationException
{
102 mySettingsUI
.apply();
105 public void reset() {
106 mySettingsUI
.reset();
109 public void disposeUIResources() {