2 * Copyright 2000-2014 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.
16 package com.intellij.openapi.roots.ui.configuration;
18 import com.intellij.openapi.Disposable;
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.roots.ui.configuration.projectRoot.StructureConfigurableContext;
23 import com.intellij.openapi.util.Disposer;
24 import com.intellij.ui.ScrollPaneFactory;
25 import com.intellij.util.Alarm;
26 import com.intellij.util.ui.UIUtil;
27 import org.jetbrains.annotations.Nls;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
33 import java.util.ArrayList;
36 * @author Konstantin Bulenkov
38 public class ErrorPaneConfigurable extends JPanel implements Configurable, Disposable, ConfigurationErrors {
39 private final Project myProject;
40 private final StructureConfigurableContext myContext;
41 private final Alarm myAlarm;
42 private final ArrayList<ConfigurationError> myErrors = new ArrayList<ConfigurationError>();
43 private final JTextPane myContent = new JTextPane();
45 public ErrorPaneConfigurable(Project project, StructureConfigurableContext context) {
46 super(new BorderLayout());
47 myContent.setEditorKit(UIUtil.getHTMLEditorKit());
48 myContent.setEditable(false);
49 myContent.setBackground(UIUtil.getListBackground());
50 final JScrollPane pane = ScrollPaneFactory.createScrollPane(myContent, true);
51 pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
55 myAlarm = new Alarm(this);
56 project.getMessageBus().connect(this).subscribe(ConfigurationErrors.TOPIC, this);
61 public void refresh() {
62 myAlarm.cancelAllRequests();
63 myAlarm.addRequest(new Runnable() {
66 String html = "<html>" +
67 "<header><style type='text/css'>" +
70 " font-family: '" + UIUtil.getLabelFont().getName() + "';" +
71 " font-size: " + UIUtil.getLabelFont().getSize() + ";" +
74 " margin-bottom: 3;" +
79 " text-decoration: none;" +
86 for (ConfigurationError error : myErrors) {
88 String description = error.getDescription();
89 if (description.startsWith("<html>") && description.endsWith("</html>")) {
90 description = description.substring(6, description.length() - 7);
92 if (description.startsWith("Module '")) {
94 final int end = description.indexOf("'", 9);
95 final String moduleName = description.substring(start, end);
96 description = "Module <a href='module://" + moduleName + "'>" + moduleName + "</a> " + description.substring(end + 1);
98 if (error.canBeFixed()) {
99 description += " <a href='fix://" + i + "'>Fix</a>";
101 html+= "<li>" + description + "</li>";
103 html += "</ol></body></html>";
104 myContent.setText(html);
111 public String getDisplayName() {
117 public String getHelpTopic() {
123 public JComponent createComponent() {
128 public boolean isModified() {
133 public void apply() throws ConfigurationException {
138 public void reset() {
143 public void disposeUIResources() {
144 Disposer.dispose(this);
148 public void dispose() {
152 public void addError(@NotNull ConfigurationError error) {
158 public void removeError(@NotNull ConfigurationError error) {
159 myErrors.remove(error);