1 package com
.intellij
.openapi
.wm
.impl
.welcomeScreen
;
3 import com
.intellij
.openapi
.actionSystem
.*;
4 import com
.intellij
.openapi
.project
.Project
;
5 import com
.intellij
.openapi
.ui
.popup
.JBPopupFactory
;
6 import com
.intellij
.openapi
.ui
.popup
.ListPopup
;
7 import com
.intellij
.openapi
.wm
.ex
.WindowManagerEx
;
11 import java
.awt
.event
.InputEvent
;
14 * @author Vladislav.Kaznacheev
16 public abstract class WelcomePopupAction
{
18 protected abstract void fillActions(DefaultActionGroup group
);
20 protected abstract String
getTextForEmpty();
22 protected abstract String
getCaption();
24 public void showPopup(Component contextComponent
, final InputEvent e
) {
25 final DefaultActionGroup group
= new DefaultActionGroup();
28 if (group
.getChildrenCount() == 0) {
29 group
.add(new AnAction(getTextForEmpty()) {
30 public void actionPerformed(AnActionEvent e
) {
31 group
.setPopup(false);
36 final ListPopup popup
= JBPopupFactory
.getInstance()
37 .createActionGroupPopup(getCaption(),
39 createDataContext(contextComponent
),
40 JBPopupFactory
.ActionSelectionAid
.NUMBERING
,
44 Component focusedComponent
= e
.getComponent();
45 if (focusedComponent
!= null) {
46 popup
.showUnderneathOf(focusedComponent
);
52 focusedComponent
= WindowManagerEx
.getInstanceEx().getFocusedComponent((Project
)null);
53 r
= WindowManagerEx
.getInstanceEx().getScreenBounds();
54 x
= r
.x
+ r
.width
/ 2;
55 y
= r
.y
+ r
.height
/ 2;
56 Point point
= new Point(x
, y
);
57 SwingUtilities
.convertPointToScreen(point
, focusedComponent
.getParent());
59 popup
.showInScreenCoordinates(focusedComponent
.getParent(), point
);
63 private static DataContext
createDataContext(final Component contextComponent
) {
64 return new DataContext() {
65 public Object
getData(String dataId
) {
66 if (DataConstants
.PROJECT
.equals(dataId
)) {
69 return contextComponent
;