update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / actions / ShowJavadocAction.java
blob0fe6e2e0ba30e726caf7aaa3f7be716b5a65c1f8
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.actions;
18 import com.intellij.codeInsight.documentation.DocumentationComponent;
19 import com.intellij.codeInsight.documentation.DocumentationManager;
20 import com.intellij.openapi.actionSystem.AnAction;
21 import com.intellij.openapi.actionSystem.AnActionEvent;
22 import com.intellij.openapi.diagnostic.Logger;
23 import com.intellij.openapi.ui.popup.JBPopup;
24 import com.intellij.openapi.ui.popup.JBPopupFactory;
25 import com.intellij.openapi.util.Disposer;
26 import com.intellij.psi.PsiClass;
27 import com.intellij.psi.PsiMethod;
28 import com.intellij.psi.util.PropertyUtil;
29 import com.intellij.ui.TabbedPaneWrapper;
30 import com.intellij.ui.awt.RelativePoint;
31 import com.intellij.uiDesigner.UIDesignerBundle;
32 import com.intellij.uiDesigner.propertyInspector.IntrospectedProperty;
33 import com.intellij.uiDesigner.propertyInspector.PropertyInspectorTable;
35 import java.awt.*;
37 /**
38 * @author Anton Katilin
39 * @author Vladimir Kondratyev
41 public final class ShowJavadocAction extends AnAction {
42 private static final Logger LOG = Logger.getInstance("#com.intellij.uiDesigner.actions.ShowJavadocAction");
44 public void actionPerformed(final AnActionEvent e) {
45 final PropertyInspectorTable inspector = (PropertyInspectorTable)e.getDataContext().getData(PropertyInspectorTable.class.getName());
46 final IntrospectedProperty introspectedProperty = inspector.getSelectedIntrospectedProperty();
47 final PsiClass aClass = inspector.getComponentClass();
49 final PsiMethod getter = PropertyUtil.findPropertyGetter(aClass, introspectedProperty.getName(), false, true);
50 LOG.assertTrue(getter != null);
52 final PsiMethod setter = PropertyUtil.findPropertySetter(aClass, introspectedProperty.getName(), false, true);
53 LOG.assertTrue(setter != null);
55 final DocumentationManager documentationManager = DocumentationManager.getInstance(aClass.getProject());
57 final DocumentationComponent component1 = new DocumentationComponent(documentationManager);
58 final DocumentationComponent component2 = new DocumentationComponent(documentationManager);
60 final TabbedPaneWrapper tabbedPane = new TabbedPaneWrapper();
62 tabbedPane.addTab(UIDesignerBundle.message("tab.getter"), component1);
63 tabbedPane.addTab(UIDesignerBundle.message("tab.setter"), component2);
65 documentationManager.fetchDocInfo(getter, component1);
66 documentationManager.queueFetchDocInfo(setter, component2).doWhenProcessed(new Runnable() {
67 public void run() {
68 final JBPopup hint =
69 JBPopupFactory.getInstance().createComponentPopupBuilder(tabbedPane.getComponent(), component1)
70 .setDimensionServiceKey(aClass.getProject(), DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false)
71 .setResizable(true)
72 .setMovable(true)
73 .setRequestFocus(true)
74 .setTitle(UIDesignerBundle.message("property.javadoc.title", introspectedProperty.getName()))
75 .createPopup();
76 component1.setHint(hint);
77 component2.setHint(hint);
78 Disposer.register(hint, component1);
79 Disposer.register(hint, component2);
80 hint.show(new RelativePoint(inspector, new Point(0,0)));
81 //component1.requestFocus();
83 });
86 public void update(final AnActionEvent e) {
87 final PropertyInspectorTable inspector = (PropertyInspectorTable)e.getDataContext().getData(PropertyInspectorTable.class.getName());
88 e.getPresentation().setEnabled(inspector != null &&
89 inspector.getSelectedIntrospectedProperty() != null &&
90 inspector.getComponentClass() != null);