Example usage for com.intellij.openapi.wm IdeFocusManager getInstance

List of usage examples for com.intellij.openapi.wm IdeFocusManager getInstance

Introduction

In this page you can find the example usage for com.intellij.openapi.wm IdeFocusManager getInstance.

Prototype

public static IdeFocusManager getInstance(@Nullable Project project) 

Source Link

Usage

From source file:org.cordovastudio.editors.designer.actions.DesignerActionPanel.java

License:Apache License

@Override
public Object getData(@NonNls String dataId) {
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId) || PlatformDataKeys.CUT_PROVIDER.is(dataId)
            || PlatformDataKeys.COPY_PROVIDER.is(dataId) || PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        JTable table = CordovaDesignerToolWindowManager.getInstance(myDesigner).getPropertyTable();
        Component focusOwner = IdeFocusManager.getInstance(myDesigner.getProject()).getFocusOwner();
        if (!UIUtil.isAncestor(table, focusOwner)) {
            return myCommonEditActionsProvider;
        }//w w  w  . j a  v  a 2  s . c  om
    }
    return null;
}

From source file:org.cordovastudio.editors.designer.LightToolWindow.java

License:Apache License

public LightToolWindow(LightToolWindowContent content, String title, Icon icon, JComponent component,
        JComponent focusedComponent, ThreeComponentsSplitter contentSplitter, ToolWindowAnchor anchor,
        AbstractToolWindowManager manager, Project project, PropertiesComponent propertiesComponent, String key,
        int defaultWidth, AnAction[] actions) {
    super(new BorderLayout());
    myContent = content;//from ww w. j a  v a 2s .  c  o  m
    myFocusedComponent = focusedComponent;
    myContentSplitter = contentSplitter;
    myAnchor = anchor;
    myProject = project;
    myManager = manager;
    myPropertiesComponent = propertiesComponent;

    myShowStateKey = AbstractToolWindowManager.EDITOR_MODE + key + ".SHOW";
    myWidthKey = AbstractToolWindowManager.EDITOR_MODE + key + ".WIDTH";

    HeaderPanel header = new HeaderPanel();
    header.setLayout(new BorderLayout());
    add(header, BorderLayout.NORTH);

    JLabel titleLabel = new JLabel(title);
    titleLabel.setBorder(IdeBorderFactory.createEmptyBorder(2, 5, 2, 10));
    titleLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
    header.add(titleLabel, BorderLayout.CENTER);

    JPanel actionPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
    actionPanel.setBorder(IdeBorderFactory.createEmptyBorder(3, 0, 2, 0));
    actionPanel.setOpaque(false);
    header.add(actionPanel, BorderLayout.EAST);

    if (actions != null) {
        for (AnAction action : actions) {
            addAction(actionPanel, action);
        }

        actionPanel.add(new JLabel(AllIcons.General.Divider));
    }

    addAction(actionPanel, new GearAction());
    addAction(actionPanel, new HideAction());

    JPanel contentWrapper = new JPanel(new BorderLayout());
    contentWrapper.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
    contentWrapper.add(component, BorderLayout.CENTER);

    add(contentWrapper, BorderLayout.CENTER);

    addMouseListener(new MouseAdapter() {
        public void mouseReleased(final MouseEvent e) {
            IdeFocusManager.getInstance(myProject).requestFocus(myFocusedComponent, true);
        }
    });

    addMouseListener(new PopupHandler() {
        public void invokePopup(Component component, int x, int y) {
            showGearPopup(component, x, y);
        }
    });

    myMinimizeButton = new AnchoredButton(title, icon) {
        @Override
        public void updateUI() {
            setUI(StripeButtonUI.createUI(this));
            setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
        }

        @Override
        public int getMnemonic2() {
            return 0;
        }

        @Override
        public ToolWindowAnchor getAnchor() {
            return myAnchor;
        }
    };
    myMinimizeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            myMinimizeButton.setSelected(false);
            updateContent(true, true);
        }
    });
    myMinimizeButton.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
    myMinimizeButton.setFocusable(false);

    myMinimizeButton.setRolloverEnabled(true);
    myMinimizeButton.setOpaque(false);

    myMinimizeComponent = new JPanel() {
        @Override
        public void doLayout() {
            Dimension size = myMinimizeButton.getPreferredSize();
            myMinimizeButton.setBounds(0, 0, getWidth(), size.height);
        }
    };
    myMinimizeComponent.add(myMinimizeButton);

    configureBorder();
    configureWidth(defaultWidth);
    updateContent(myPropertiesComponent.getBoolean(myShowStateKey, true), false);
}

From source file:org.cordovastudio.editors.designer.propertyTable.PropertyTablePanel.java

License:Apache License

public PropertyTablePanel(final Project project) {
    myPropertyTable = new RadPropertyTable(project) {
        protected void updateEditActions() {
            updateActions();/*  ww w.j a v  a  2s .c om*/
        }
    };

    setLayout(new GridBagLayout());

    int gridX = 0;

    myTitleLabel = new JLabel(CordovaDesignerBundle.message("designer.properties.title"));
    myTitleLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
    add(myTitleLabel, new GridBagConstraints(gridX++, 0, 1, 1, 0, 0, GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL, new Insets(2, 5, 2, 10), 0, 0));

    ActionManager actionManager = ActionManager.getInstance();
    DefaultActionGroup actionGroup = new DefaultActionGroup();

    //TODO: remove JavaDoc as it's not needed for Cordova projects!
    ShowJavadoc showJavadoc = new ShowJavadoc(myPropertyTable);
    showJavadoc.registerCustomShortcutSet(
            actionManager.getAction(IdeActions.ACTION_QUICK_JAVADOC).getShortcutSet(), myPropertyTable);
    actionGroup.add(showJavadoc);

    actionGroup.addSeparator();

    RestoreDefault restoreDefault = new RestoreDefault(myPropertyTable);
    // Don't register ACTION_DELETE on Mac; on Mac, the default delete key is VK_DELETE rather than VK_BACK_SPACE
    // which means users end up accidentally restoring to default when trying to edit inside property editors.
    if (!SystemInfo.isMac) {
        restoreDefault.registerCustomShortcutSet(
                actionManager.getAction(IdeActions.ACTION_DELETE).getShortcutSet(), myPropertyTable);
    }
    actionGroup.add(restoreDefault);

    actionGroup.add(new ShowExpert(myPropertyTable));

    myTabPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
    add(myTabPanel, new GridBagConstraints(gridX++, 0, 1, 1, 1, 0, GridBagConstraints.LINE_START,
            GridBagConstraints.NONE, new Insets(2, 0, 2, 0), 0, 0));

    myActionPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
    add(myActionPanel, new GridBagConstraints(gridX++, 0, 1, 1, 0, 0, GridBagConstraints.CENTER,
            GridBagConstraints.NONE, new Insets(2, 0, 2, 2), 0, 0));

    myActions = actionGroup.getChildren(null);
    for (AnAction action : myActions) {
        if (action instanceof Separator) {
            continue;
        }

        Presentation presentation = action.getTemplatePresentation();
        ActionButton button = new ActionButton(action, presentation, ActionPlaces.UNKNOWN,
                ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE);
        myActionPanel.add(button);
        presentation.putClientProperty(BUTTON_KEY, button);
    }

    actionGroup.add(new ShowColumns(myPropertyTable));

    PopupHandler.installPopupHandler(myPropertyTable, actionGroup,
            ActionPlaces.GUI_DESIGNER_PROPERTY_INSPECTOR_POPUP, actionManager);

    myPropertyTable.getSelectionModel().addListSelectionListener(this);
    valueChanged(null);

    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myPropertyTable);
    scrollPane.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
    myPropertyTable.initQuickFixManager(scrollPane.getViewport());
    add(scrollPane, new GridBagConstraints(0, 1, gridX, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

    myPropertyTable.setPropertyTablePanel(this);

    addMouseListener(new MouseAdapter() {
        public void mouseReleased(final MouseEvent e) {
            IdeFocusManager.getInstance(project).requestFocus(myPropertyTable, true);
        }
    });
}

From source file:org.eclipse.xtext.idea.trace.TraceBasedGeneratedSourcesFilter.java

License:Open Source License

@Override
public List<? extends PsiElement> getOriginalElements(final PsiElement element) {
    Application _application = ApplicationManager.getApplication();
    boolean _isDispatchThread = _application.isDispatchThread();
    if (_isDispatchThread) {
        Project _project = element.getProject();
        IdeFocusManager _instance = IdeFocusManager.getInstance(_project);
        final Component focusOwner = _instance.getFocusOwner();
        if (((!Objects.equal(focusOwner, null))
                && focusOwner.getClass().getName().startsWith(ProjectViewPane.class.getName()))) {
            return CollectionLiterals.<PsiElement>emptyList();
        }// w w  w. j a v  a 2  s.  com
    }
    return this.traceProvider.getOriginalElements(element);
}

From source file:org.jetbrains.idea.devkit.dom.generator.DomGenPanel.java

License:Apache License

public boolean validate() {
    if (!new File(mySchemaLocation.getText()).exists()) {
        Messages.showErrorDialog(myProject, "Schema location doesn't exist", "Error");
        IdeFocusManager.getInstance(myProject).requestFocus(mySchemaLocation, true);
        return false;
    }//w  ww  .  ja v  a  2 s  .com

    if (!new File(myOutputDir.getText()).exists()) {
        Messages.showErrorDialog(myProject, "Output dir doesn't exist", "Error");
        IdeFocusManager.getInstance(myProject).requestFocus(myOutputDir, true);
        return false;
    }

    return true;
}

From source file:org.jetbrains.idea.svn.actions.ShowSvnMapAction.java

License:Apache License

public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        return;//  ww  w  .j a v  a2 s. c o m
    }

    final CopiesPanel copiesPanel = new CopiesPanel(project);
    ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.VCS);
    final ContentManager contentManager = toolWindow.getContentManager();

    Content content = ContentFactory.SERVICE.getInstance().createContent(copiesPanel.getComponent(),
            SvnBundle.message("dialog.show.svn.map.title"), true);
    ContentsUtil.addOrReplaceContent(contentManager, content, true);
    toolWindow.activate(new Runnable() {
        public void run() {
            IdeFocusManager.getInstance(project).requestFocus(copiesPanel.getPreferredFocusedComponent(), true);
        }
    });
    /*SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        IdeFocusManager.getInstance(project).requestFocus(copiesPanel.getPrefferedFocusComponent(), true);
      }
    });*/
}

From source file:org.jetbrains.idea.svn.dialogs.CopiesPanel.java

License:Apache License

public CopiesPanel(final Project project) {
    myProject = project;//  w w  w .j  a va 2s  .c  om
    myConnection = myProject.getMessageBus().connect(myProject);
    myVcs = SvnVcs.getInstance(myProject);
    myCurrentInfoList = null;

    final Runnable focus = new Runnable() {
        @Override
        public void run() {
            IdeFocusManager.getInstance(myProject).requestFocus(myRefreshLabel, true);
        }
    };
    final Runnable refreshView = new Runnable() {
        @Override
        public void run() {
            final List<WCInfo> infoList = myVcs.getWcInfosWithErrors();
            final boolean hasErrors = !myVcs.getSvnFileUrlMapping().getErrorRoots().isEmpty();
            final List<WorkingCopyFormat> supportedFormats = getSupportedFormats();
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    if (myCurrentInfoList != null) {
                        final List<OverrideEqualsWrapper<WCInfo>> newList = ObjectsConvertor.convert(infoList,
                                new Convertor<WCInfo, OverrideEqualsWrapper<WCInfo>>() {
                                    @Override
                                    public OverrideEqualsWrapper<WCInfo> convert(WCInfo o) {
                                        return new OverrideEqualsWrapper<WCInfo>(
                                                InfoEqualityPolicy.getInstance(), o);
                                    }
                                }, ObjectsConvertor.NOT_NULL);

                        if (Comparing.haveEqualElements(newList, myCurrentInfoList)) {
                            myRefreshLabel.setEnabled(true);
                            return;
                        }
                        myCurrentInfoList = newList;
                    }
                    Collections.sort(infoList, WCComparator.getInstance());
                    updateList(infoList, supportedFormats);
                    myRefreshLabel.setEnabled(true);
                    showErrorNotification(hasErrors);
                    SwingUtilities.invokeLater(focus);
                }
            };
            ApplicationManager.getApplication().invokeLater(runnable, ModalityState.NON_MODAL);
        }
    };
    final Consumer<Boolean> refreshOnPooled = new Consumer<Boolean>() {
        @Override
        public void consume(Boolean somethingNew) {
            if (Boolean.TRUE.equals(somethingNew)) {
                if (ApplicationManager.getApplication().isUnitTestMode()) {
                    refreshView.run();
                } else {
                    ApplicationManager.getApplication().executeOnPooledThread(refreshView);
                }
            } else {
                ApplicationManager.getApplication().invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        myRefreshLabel.setEnabled(true);
                    }
                }, ModalityState.NON_MODAL);
            }
        }
    };
    myConnection.subscribe(SvnVcs.ROOTS_RELOADED, refreshOnPooled);

    final JPanel holderPanel = new JPanel(new BorderLayout());
    FontMetrics fm = holderPanel.getFontMetrics(holderPanel.getFont());
    myTextHeight = (int) (fm.getHeight() * 1.3);
    myPanel = new JPanel(new GridBagLayout());
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(myPanel, BorderLayout.NORTH);
    holderPanel.add(panel, BorderLayout.WEST);
    myRefreshLabel = new MyLinkLabel(myTextHeight, "Refresh", new LinkListener() {
        @Override
        public void linkSelected(LinkLabel aSource, Object aLinkData) {
            if (myRefreshLabel.isEnabled()) {
                myVcs.invokeRefreshSvnRoots();
                myRefreshLabel.setEnabled(false);
            }
        }
    });
    final JScrollPane pane = ScrollPaneFactory.createScrollPane(holderPanel);
    myHolder = pane;
    final JScrollBar vBar = pane.getVerticalScrollBar();
    vBar.setBlockIncrement(vBar.getBlockIncrement() * 5);
    vBar.setUnitIncrement(vBar.getUnitIncrement() * 5);
    myHolder.setBorder(null);
    setFocusableForLinks(myRefreshLabel);
    refreshOnPooled.consume(true);
    initView();
}

From source file:org.jetbrains.idea.svn.dialogs.IntersectingLocalChangesPanel.java

License:Apache License

public static void showInVersionControlToolWindow(final Project project, final String title,
        final List<FilePath> filesToShow, final String prompt) {
    final IntersectingLocalChangesPanel component = new IntersectingLocalChangesPanel(project, filesToShow,
            prompt);//from www.  ja v a2  s.  c o m

    ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.VCS);
    final ContentManager contentManager = toolWindow.getContentManager();

    Content content = ContentFactory.SERVICE.getInstance().createContent(component.getPanel(), title, true);
    ContentsUtil.addContent(contentManager, content, true);
    toolWindow.activate(new Runnable() {
        public void run() {
            IdeFocusManager.getInstance(project).requestFocus(component.getPrefferedFocusComponent(), true);
        }
    });

}

From source file:org.jetbrains.jet.plugin.codeInsight.ktSignature.EditSignatureBalloon.java

License:Apache License

public void show(@Nullable Point point, @NotNull final Editor mainEditor,
        @NotNull PsiElement psiElementInEditor) {
    int lineY = getLineY(mainEditor, psiElementInEditor);
    EditorGutterComponentEx gutter = (EditorGutterComponentEx) mainEditor.getGutter();
    Point adjustedPoint;/*from w  ww. j  a v  a  2 s. c o m*/
    if (point == null) {
        adjustedPoint = new Point(gutter.getIconsAreaWidth() + gutter.getLineMarkerAreaOffset(), lineY);
    } else {
        adjustedPoint = new Point(point.x, Math.min(lineY, point.y));
    }
    balloon.show(new RelativePoint(gutter, adjustedPoint), Balloon.Position.above);
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            IdeFocusManager.getInstance(mainEditor.getProject()).requestFocus(editor.getContentComponent(),
                    false);
        }
    });
}

From source file:org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicToolWindowWrapper.java

License:Apache License

public void setSelectedNode(DefaultMutableTreeNode node) {
    JTree tree = myTreeTable.getTree();
    TreePath path = new TreePath(node.getPath());
    tree.expandPath(path.getParentPath());
    int row = tree.getRowForPath(path);
    myTreeTable.getSelectionModel().setSelectionInterval(row, row);
    myTreeTable.scrollRectToVisible(myTreeTable.getCellRect(row, 0, true));
    IdeFocusManager.getInstance(myProject).requestFocus(myTreeTable, true);
}