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

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

Introduction

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

Prototype

@NotNull
    public static IdeFocusManager getGlobalInstance() 

Source Link

Usage

From source file:automation.RobotControl.java

License:Apache License

@Nullable
public JTextField findJTextField(String textComponent) throws Exception {

    if (textComponent.equals("")) {
        ArrayList<Component> jTextFields = GuiUtil.findComponentsByType(JTextField.class,
                IdeFocusManager.getGlobalInstance().getFocusOwner());
        return (JTextField) jTextFields.get(0);
    }//www  . j  a v a2 s  . c  o  m

    Component cmpWithText = GuiUtil.findComponentByText(textComponent,
            IdeFocusManager.getGlobalInstance().getFocusOwner());
    Container parent = cmpWithText.getParent();
    Component[] components = parent.getComponents();
    for (Component component : components) {
        if (component instanceof JTextField
                && component.getLocationOnScreen().getY() <= cmpWithText.getLocationOnScreen().getY()
                && ((component.getLocationOnScreen().getY()
                        + component.getBounds().height) >= (cmpWithText.getLocationOnScreen().getY()
                                + cmpWithText.getBounds().height))) {
            return (JTextField) component;
        }
    }
    return null;
}

From source file:automation.RobotControl.java

License:Apache License

@Nullable
public void selectItemFromProjectWizardList(String itemName, Runnable runnable) throws Exception {
    ArrayList<Component> componentArrayList = GuiUtil.findComponentsByType(JBList.class,
            IdeFocusManager.getGlobalInstance().getFocusOwner());
    TemplatesGroup myGroup = null;/*from w  w  w .j  a  va 2  s  .  co  m*/
    int i0 = -1;
    int j0 = -1;
    for (int j = 0; j < componentArrayList.size(); j++) {
        ListModel model = ((JBList) componentArrayList.get(j)).getModel();
        for (int i = 0; i < model.getSize(); i++) {
            if (!(model.getElementAt(0) instanceof TemplatesGroup))
                break;
            TemplatesGroup tGroup = (TemplatesGroup) model.getElementAt(i);
            if (tGroup.getName().equals(itemName)) {
                myGroup = tGroup;
                i0 = i;
                j0 = j;
            }
        }
    }
    if (j0 >= 0 && i0 >= 0 && myGroup != null) {
        JBList jbList = (JBList) componentArrayList.get(j0);
        Point relativePoint = jbList.indexToLocation(i0);
        Rectangle cellBounds = jbList.getCellBounds(i0, 0);
        Point pointOnScreen = new Point(jbList.getLocationOnScreen().x + relativePoint.x + cellBounds.width / 2,
                jbList.getLocationOnScreen().y + relativePoint.y + cellBounds.height / 2);
        clickItemInListVerifyAndRun(pointOnScreen, jbList, i0, runnable);

    } else {
        throw new Exception("Unable to find item \"" + itemName + "\" or Project Wizard's JBList");
    }
}

From source file:automation.RobotControl.java

License:Apache License

@Nullable
public void selectItemFromPopupList(String itemName, Runnable runnable) throws Exception {
    ArrayList<Component> componentArrayList = GuiUtil.findComponentsByType(JBList.class,
            IdeFocusManager.getGlobalInstance().getFocusOwner());
    PopupFactoryImpl.ActionItem myActionItem = null;
    int i0 = -1;//from  ww  w  .  java 2s .  c om
    int j0 = -1;
    for (int j = 0; j < componentArrayList.size(); j++) {
        ListModel model = ((JBList) componentArrayList.get(j)).getModel();
        for (int i = 0; i < model.getSize(); i++) {
            if (!(model.getElementAt(0) instanceof PopupFactoryImpl.ActionItem))
                break;
            PopupFactoryImpl.ActionItem actionItem = (PopupFactoryImpl.ActionItem) model.getElementAt(i);
            if (actionItem.getText().equals(itemName)) {
                myActionItem = actionItem;
                i0 = i;
                j0 = j;
            }
        }
    }
    if (j0 >= 0 && i0 >= 0 && myActionItem != null) {
        JBList jbList = (JBList) componentArrayList.get(j0);
        Point relativePoint = jbList.indexToLocation(i0);
        Rectangle cellBounds = jbList.getCellBounds(i0, 0);
        Point pointOnScreen = new Point(jbList.getLocationOnScreen().x + relativePoint.x + cellBounds.width / 2,
                jbList.getLocationOnScreen().y + relativePoint.y + cellBounds.height / 2);
        clickItemInListVerifyAndRun(pointOnScreen, jbList, i0, runnable);

    } else {
        throw new Exception("Unable to find item \"" + itemName + "\" or popup list's JBList");
    }
}

From source file:automation.ScriptProcessor.java

License:Apache License

public static void process() throws Exception {
    final String SMOKE_TEST_CONFIG_PROJ = "plugin.smoke-test.project";
    String projName = System.getProperty(SMOKE_TEST_CONFIG_PROJ);
    System.out.println(SMOKE_TEST_CONFIG_PROJ + "=" + projName);
    projName = "smoke-test-" + (new SimpleDateFormat("dd-MMM-yy-HH-mm")).format(new Date());

    Map<String, String> mapping = new HashMap<>();
    mapping.put("$PROJECT_NAME", projName);

    //    Queue<Command> script = new Queue<>(8);
    //    script.addLast(new StartCommand());
    //    script.addLast(new NavigateAndClickCommand(new Parameters("Create New Project")));
    //    script.addLast(new WaitDialogCommand(new Parameters("New Project")));
    //    script.addLast(new SelectInListCommand(new Parameters("Java")));
    //    script.addLast(new NavigateAndClickCommand(new Parameters("New...")));
    //    script.addLast(new SelectInJdkListCommand(new Parameters("JDK")));
    //    script.addLast(new WaitDialogCommand(new Parameters("Select Home Directory for JDK")));
    //    script.addLast(new TypeInTextFieldCommand(new Parameters("", null, "/Library/Java/JavaVirtualMachines/jdk1.8.0_71.jdk/Contents/Home")));
    //    //the tree is sticking here
    //    script.addLast(new WaitCommand(new Parameters(1000)));
    //    script.addLast(new NavigateAndClickCommand(new Parameters("OK")));
    //    script.addLast(new WaitCommand(new Parameters(500)));
    //    script.addLast(new NavigateAndClickCommand(new Parameters("Next")));
    //    script.addLast(new WaitUiCommand(new Parameters("Create project from template")));
    //    script.addLast(new NavigateAndClickCommand(new Parameters("Next")));
    //    script.addLast(new WaitUiCommand(new Parameters("Project name:")));
    //    script.addLast(new TypeInTextFieldCommand(new Parameters("Project name:", null, projName)));
    //    script.addLast(new WaitCommand(new Parameters(1000)));
    //    script.addLast(new NavigateAndClickCommand(new Parameters("Finish")));
    //    script.addLast(new WaitProjectOpeningCommand(new Parameters()));
    //    script.addLast(new RunnableCommand(() -> {
    //      System.out.println("Idea is ready");
    //    }));/* w w w. j av  a2  s. c om*/
    //    script.pullFirst().process(script);

    //    Component target = IdeFocusManager.getGlobalInstance().getFocusOwner();
    //    JRootPane rootPane = target == null ? null : SwingUtilities.getRootPane(target);
    //    JComponent glassPane = rootPane == null ? null : (JComponent)rootPane.getGlassPane();
    //    rootPane.addMouseListener(new MouseAdapter() {
    //      @Override
    //      public void mouseClicked(MouseEvent e) {
    //        System.out.println("mouseClicked();");
    //        RobotControlManager.getInstance().getRobotControl().mouseClick();
    //        e.consume();
    //      }
    //    });

    final DataContext dataContext = DataManager.getInstance()
            .getDataContext(IdeFocusManager.getGlobalInstance().getFocusOwner());
    AnActionEvent e = AnActionEvent.createFromDataContext(ActionPlaces.WELCOME_SCREEN, null, dataContext);

    //    (new UpdateScripts()).actionPerformed(e);
    Script start2 = new Script("start2", mapping);
    start2.actionPerformed(e);

}

From source file:com.android.tools.idea.configurations.ThemeSelectionPanel.java

License:Apache License

public void focus() {
    final Project project = myConfiguration.getModule().getProject();
    final IdeFocusManager focusManager = project.isDefault() ? IdeFocusManager.getGlobalInstance()
            : IdeFocusManager.getInstance(project);
    focusManager.doWhenFocusSettlesDown(new Runnable() {
        @Override/*from  www  . java 2 s  .  co m*/
        public void run() {
            focusManager.requestFocus(myThemeList, true);
        }
    });
}

From source file:com.android.tools.idea.editors.hprof.views.ClassesTreeView.java

License:Apache License

public void requestFocus() {
    IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
        IdeFocusManager.getGlobalInstance().requestFocus(myTree, true);
    });
}

From source file:com.android.tools.idea.editors.hprof.views.InstancesTreeView.java

License:Apache License

public void requestFocus() {
    IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
        IdeFocusManager.getGlobalInstance().requestFocus(myDebuggerTree, true);
    });
}

From source file:com.android.tools.idea.gradle.editor.ui.GradleEditorComboBoxEditor.java

License:Apache License

@Override
public void selectAll() {
    myField.selectAll();/*from w  ww  .j ava 2s .  c  o m*/
    IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
        IdeFocusManager.getGlobalInstance().requestFocus(myField, true);
    });
}

From source file:com.android.tools.idea.tests.gui.framework.fixture.CreateResourceFileDialogFixture.java

License:Apache License

@NotNull
public CreateResourceFileDialogFixture setFileName(@NotNull final String newName) {
    final Component field = robot().finder().findByLabel(getDialogWrapper().getContentPane(), "File name:");
    execute(new GuiTask() {
        @Override/*from  w  w w . jav a 2  s .c  o m*/
        protected void executeInEDT() throws Throwable {
            IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                IdeFocusManager.getGlobalInstance().requestFocus(field, true);
            });
        }
    });
    robot().pressAndReleaseKey(KeyEvent.VK_BACK_SPACE); // to make sure we don't append to existing item on Linux
    robot().enterText(newName);
    return this;
}

From source file:com.android.tools.idea.tests.gui.framework.fixture.RenameRefactoringDialogFixture.java

License:Apache License

@NotNull
public RenameRefactoringDialogFixture setNewName(@NotNull final String newName) {
    final EditorTextField field = robot().finder().findByType(target(), EditorTextField.class);
    GuiActionRunner.execute(new GuiTask() {
        @Override//  w ww . ja v a 2s.  co  m
        protected void executeInEDT() throws Throwable {
            IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                IdeFocusManager.getGlobalInstance().requestFocus(field, true);
            });
        }
    });
    robot().pressAndReleaseKey(KeyEvent.VK_BACK_SPACE); // to make sure we don't append to existing item on Linux
    robot().enterText(newName);
    Wait.seconds(1).expecting("EditorTextField to show new name").until(() -> newName.equals(field.getText()));
    return this;
}