Example #1
0
  /**
   * Waits for specified time period for a shell matching specified matcher.
   *
   * @param matcher matcher to match shell
   * @param timePeriod time period to wait for
   * @return shell matching specified matcher
   */
  public Shell getShell(final Matcher<String> matcher, TimePeriod timePeriod) {
    if (!timePeriod.equals(TimePeriod.NONE)) {
      new WaitUntil(new ShellMatchingMatcherIsAvailable(matcher), timePeriod, false);
    }

    Shell[] shells =
        Display.syncExec(
            new ResultRunnable<Shell[]>() {

              @Override
              public Shell[] run() {
                return Display.getDisplay().getShells();
              }
            });

    for (final Shell s : shells) {
      if (matcher.matches(s)) {
        Shell visibleShell =
            Display.syncExec(
                new ResultRunnable<Shell>() {
                  @Override
                  public Shell run() {
                    if (!s.isDisposed() && s.isVisible()) {
                      return s;
                    }
                    return null;
                  }
                });
        if (visibleShell != null) {
          return visibleShell;
        }
      }
    }
    return null;
  }
Example #2
0
  /**
   * Return child shells.
   *
   * @param shell the shell
   * @return the shells
   */
  public Shell[] getShells(final Shell shell) {
    return Display.syncExec(
        new ResultRunnable<Shell[]>() {

          @Override
          public Shell[] run() {
            return shell.getShells();
          }
        });
  }
Example #3
0
 private Shell getLastVisibleShell() {
   return Display.syncExec(
       new ResultRunnable<Shell>() {
         @Override
         public Shell run() {
           Shell[] shells = Display.getDisplay().getShells();
           for (int i = shells.length - 1; i >= 0; i--) {
             if (shells[i].isVisible()) return shells[i];
           }
           return null;
         }
       });
 }
Example #4
0
  /**
   * Gets currently Active Shell without waiting for shell to become active.
   *
   * @return active shell or null if there is no active shell
   */
  public Shell getCurrentActiveShell() {
    return Display.syncExec(
        new ResultRunnable<Shell>() {

          @Override
          public Shell run() {
            Shell s = Display.getDisplay().getActiveShell();
            if (s != null && s.isVisible()) {
              return s;
            }
            return null;
          }
        });
  }
Example #5
0
  /**
   * Gets currently focused and visible shell.
   *
   * @return focused shell or null if there is no focused shell
   */
  public Shell getCurrentFocusShell() {
    return Display.syncExec(
        new ResultRunnable<Shell>() {

          @Override
          public Shell run() {
            Shell[] ss = Display.getDisplay().getShells();
            for (Shell shell : ss) {
              if (shell.isFocusControl() && shell.isVisible()) {
                return shell;
              }
            }
            return null;
          }
        });
  }
Example #6
0
  /**
   * Gets all visible shells.
   *
   * @return array of all visible shells
   */
  public Shell[] getShells() {

    return Display.syncExec(
        new ResultRunnable<Shell[]>() {

          @Override
          public Shell[] run() {
            List<Shell> visibleShells = new ArrayList<Shell>();
            Shell[] shells = Display.getDisplay().getShells();
            for (Shell s : shells) {
              if (!s.isDisposed() && s.isVisible()) {
                visibleShells.add(s);
              }
            }
            return visibleShells.toArray(new Shell[visibleShells.size()]);
          }
        });
  }