Java Code Examples for org.eclipse.swt.widgets.Display#getActiveShell()

The following examples show how to use org.eclipse.swt.widgets.Display#getActiveShell() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CreateAccountHandler.java    From offspring with MIT License 6 votes vote down vote up
@Execute
public void execute(Display display, IWallet wallet, INxtService nxt,
    IUserService userService, UISynchronize sync) {

  AddAccountDialog dialog = new AddAccountDialog(display.getActiveShell(),
      wallet, nxt);
  if (dialog.open() == Window.OK) {
    try {
      boolean select = userService.getActiveUser() == null;
      for (IWalletAccount walletAccount : wallet.getAccounts()) {
        if (walletAccount instanceof INXTWalletAccount) {
          userService.createUser(walletAccount.getLabel(),
              ((INXTWalletAccount) walletAccount).getPrivateKey(),
              ((INXTWalletAccount) walletAccount).getAccountNumber());
        }
      }
      if (select && userService.getUsers().size() > 0)
        userService.setActiveUser(userService.getUsers().get(0));
    }
    catch (WalletNotInitializedException e) {
      logger.error("Wallet not initialized", e);
    }
  }
}
 
Example 2
Source File: AbstractPopup.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
private Monitor selectMonitor(Display display) {
  Shell activeShell = display.getActiveShell();
  if (activeShell != null && activeShell.getMonitor() != null) {
    return activeShell.getMonitor();
  }

  // Fall-back
  Monitor[] monitors = display.getMonitors();
  if (monitors.length > 0) {
    return monitors[0];
  }

  // Worst case. What? Can this happen?
  return null;
}
 
Example 3
Source File: SelectExamplePage.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected Monitor getMonitor() {
	Shell shell = getShell();
	Display display = shell.getDisplay();
	Shell displayShell = display.getActiveShell();
	return (displayShell != null ? displayShell : shell).getMonitor();
}
 
Example 4
Source File: JaretTable.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Handle mouse move. This is mostly: modifying the appearance of the cursor.
 * 
 * @param x x coordinate of pointer
 * @param y y coordinate of pointer
 * @param stateMask keyStatemask
 */
private void mouseMoved(int x, int y, int stateMask) {
    Display display = Display.getCurrent();
    Shell activeShell = display != null ? display.getActiveShell() : null;

    // check for location over drag marker
    if (_dragMarkerRect != null && _dragMarkerRect.contains(x, y)) {
        if (activeShell != null) {
            // MAYBE other cursor for differentiation?
            activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZEALL));
        }
        return;
    }

    // check for location over lower border of row
    IRow row = rowByBottomBorder(y);
    if (row != null
            && _rowResizeAllowed
            && (_tvs.getRowHeigthMode(row) == RowHeightMode.VARIABLE || _tvs.getRowHeigthMode(row) == RowHeightMode.OPTANDVAR)
            && (!_resizeRestriction || Math.abs(x - _tableRect.x) <= SELDELTA || (_fixedColRect != null && _fixedColRect
                    .contains(x, y)))) {
        if (activeShell != null) {
            activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENS));
        }
        return;
    } else {
        IColumn col = colByRightBorder(x);
        if (col != null && _columnResizeAllowed && _tvs.columnResizingAllowed(col)
                && (!_resizeRestriction || _headerRect == null || _headerRect.contains(x, y))) {
            if (activeShell != null) {
                activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZEW));
            }
            return;
        }
    }
    // check header drag symboling
    if (_headerRect != null && _headerResizeAllowed && Math.abs(_headerRect.y + _headerRect.height - y) <= SELDELTA) {
        if (activeShell != null) {
            activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENS));
        }
        return;
    }

    if (Display.getCurrent().getActiveShell() != null) {
        Display.getCurrent().getActiveShell().setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_ARROW));
    }

}
 
Example 5
Source File: JaretTable.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Handle mouse move. This is mostly: modifying the appearance of the cursor.
 * 
 * @param x x coordinate of pointer
 * @param y y coordinate of pointer
 * @param stateMask keyStatemask
 */
private void mouseMoved(int x, int y, int stateMask) {
    Display display = Display.getCurrent();
    Shell activeShell = display != null ? display.getActiveShell() : null;

    // check for location over drag marker
    if (_dragMarkerRect != null && _dragMarkerRect.contains(x, y)) {
        if (activeShell != null) {
            // MAYBE other cursor for differentiation?
            activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZEALL));
        }
        return;
    }

    // check for location over lower border of row
    IRow row = rowByBottomBorder(y);
    if (row != null
            && _rowResizeAllowed
            && (_tvs.getRowHeigthMode(row) == RowHeightMode.VARIABLE || _tvs.getRowHeigthMode(row) == RowHeightMode.OPTANDVAR)
            && (!_resizeRestriction || Math.abs(x - _tableRect.x) <= SELDELTA || (_fixedColRect != null && _fixedColRect
                    .contains(x, y)))) {
        if (activeShell != null) {
            activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENS));
        }
        return;
    } else {
        IColumn col = colByRightBorder(x);
        if (col != null && _columnResizeAllowed && _tvs.columnResizingAllowed(col)
                && (!_resizeRestriction || _headerRect == null || _headerRect.contains(x, y))) {
            if (activeShell != null) {
                activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZEW));
            }
            return;
        }
    }
    // check header drag symboling
    if (_headerRect != null && _headerResizeAllowed && Math.abs(_headerRect.y + _headerRect.height - y) <= SELDELTA) {
        if (activeShell != null) {
            activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENS));
        }
        return;
    }

    if (Display.getCurrent().getActiveShell() != null) {
        Display.getCurrent().getActiveShell().setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_ARROW));
    }

}
 
Example 6
Source File: SWTUtils.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tries to get a {@linkplain Shell shell} that is centered on the shells of the current Eclipse
 * application.
 *
 * <p>Should be used instead of {@link Display#getActiveShell()}.
 *
 * @return a shell centered on top of the current application or <code>null</code> if no such
 *     shell exists or the default display is disposed
 */
public static Shell getShell() {

  final Display display = getDisplay();

  if (display.isDisposed()) return null;

  final IWorkbench workbench = PlatformUI.getWorkbench();

  final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();

  if (activeWorkbenchWindow != null && !activeWorkbenchWindow.getShell().isDisposed())
    return activeWorkbenchWindow.getShell();

  final IWorkbenchWindow[] workbenchWindows = workbench.getWorkbenchWindows();

  if (workbenchWindows.length > 0 && !workbenchWindows[0].getShell().isDisposed())
    return workbenchWindows[0].getShell();

  return display.getActiveShell();
}
 
Example 7
Source File: UIUtils.java    From n4js with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns with the active {@link Shell shell} from the {@link #getDisplay() display}. May return with {@code null}
 * if called from non-UI thread.
 *
 * @return the active shell, or {@code null} if invoked from non-UI thread.
 */
public static Shell getShell() {
	final Display display = getDisplay();
	return null == display ? null : display.getActiveShell();
}