Generalized Import actions
[fedora-idea.git] / ui / impl / com / intellij / openapi / wm / impl / welcomeScreen / WelcomePopupAction.java
blob9859538f7752d43d9faa215926553b87aef8a1ec
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;
9 import javax.swing.*;
10 import java.awt.*;
11 import java.awt.event.InputEvent;
13 /**
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();
26 fillActions(group);
28 if (group.getChildrenCount() == 0) {
29 group.add(new AnAction(getTextForEmpty()) {
30 public void actionPerformed(AnActionEvent e) {
31 group.setPopup(false);
33 } );
36 final ListPopup popup = JBPopupFactory.getInstance()
37 .createActionGroupPopup(getCaption(),
38 group,
39 createDataContext(contextComponent),
40 JBPopupFactory.ActionSelectionAid.NUMBERING,
41 true);
44 Component focusedComponent = e.getComponent();
45 if (focusedComponent != null) {
46 popup.showUnderneathOf(focusedComponent);
48 else {
49 Rectangle r;
50 int x;
51 int y;
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)) {
67 return null;
69 return contextComponent;