update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / componentTree / QuickFixManagerImpl.java
blob1c41388f5685759f5bd19fa4de992bf8e68a2a8c
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.
16 package com.intellij.uiDesigner.componentTree;
18 import com.intellij.openapi.diagnostic.Logger;
19 import com.intellij.openapi.wm.StatusBar;
20 import com.intellij.openapi.wm.WindowManager;
21 import com.intellij.uiDesigner.ErrorAnalyzer;
22 import com.intellij.uiDesigner.ErrorInfo;
23 import com.intellij.uiDesigner.radComponents.RadComponent;
24 import com.intellij.uiDesigner.designSurface.GuiEditor;
25 import com.intellij.uiDesigner.quickFixes.QuickFixManager;
26 import org.jetbrains.annotations.NotNull;
28 import javax.swing.event.TreeSelectionEvent;
29 import javax.swing.event.TreeSelectionListener;
30 import javax.swing.tree.TreePath;
31 import javax.swing.*;
32 import java.awt.*;
34 /**
35 * @author Anton Katilin
36 * @author Vladimir Kondratyev
38 public final class QuickFixManagerImpl extends QuickFixManager<ComponentTree>{
39 private static final Logger LOG = Logger.getInstance("#com.intellij.uiDesigner.componentTree.QuickFixManagerImpl");
41 public QuickFixManagerImpl(final GuiEditor editor, @NotNull final ComponentTree componentTree, final JViewport viewPort) {
42 super(editor, componentTree, viewPort);
43 myComponent.addTreeSelectionListener(new MyTreeSelectionListener());
46 @NotNull
47 protected ErrorInfo[] getErrorInfos() {
48 final RadComponent component = myComponent.getSelectedComponent();
49 if(component == null){
50 return ErrorInfo.EMPTY_ARRAY;
52 return ErrorAnalyzer.getAllErrorsForComponent(component);
55 public Rectangle getErrorBounds() {
56 final TreePath selectionPath = myComponent.getSelectionPath();
57 LOG.assertTrue(selectionPath != null);
58 return myComponent.getPathBounds(selectionPath);
61 private final class MyTreeSelectionListener implements TreeSelectionListener{
62 public void valueChanged(final TreeSelectionEvent e) {
63 hideIntentionHint();
64 updateIntentionHintVisibility();
66 ErrorInfo[] errorInfos = getErrorInfos();
67 final StatusBar statusBar = WindowManager.getInstance().getStatusBar(myComponent.getProject());
68 if (errorInfos.length > 0 && errorInfos [0].myDescription != null) {
69 statusBar.setInfo(errorInfos [0].myDescription);
71 else {
72 statusBar.setInfo("");