コード例 #1
0
  /**
   * Install a copy popup menu on the specified control and activate the copy handler for the
   * control when the control has focus. The handler will be deactivated when the control is
   * disposed.
   *
   * @param copyable the copyable that will perform the copy
   * @param control the control on which to install the menu and handler
   */
  public static void activateCopy(ICopyable copyable, final Control control) {
    IFocusService fs = PlatformUI.getWorkbench().getService(IFocusService.class);
    final IHandlerService hs = PlatformUI.getWorkbench().getService(IHandlerService.class);
    new CopyPopup(copyable, control);
    if (fs != null && hs != null) {
      fs.addFocusTracker(control, CONTROL_ID);
      final IHandlerActivation handlerActivation =
          hs.activateHandler(
              CopyHandler.ID,
              new CopyHandler(copyable),
              new Expression() {
                public EvaluationResult evaluate(IEvaluationContext context) {
                  return context.getVariable(ISources.ACTIVE_FOCUS_CONTROL_NAME) == control
                      ? EvaluationResult.TRUE
                      : EvaluationResult.FALSE;
                }

                public void collectExpressionInfo(final ExpressionInfo info) {
                  info.addVariableNameAccess(ISources.ACTIVE_FOCUS_CONTROL_NAME);
                }
              });
      control.addDisposeListener(
          new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
              hs.deactivateHandler(handlerActivation);
            }
          });
    }
  }
コード例 #2
0
ファイル: UIUtils.java プロジェクト: ralic/dbeaver
 public static void addFocusTracker(
     IServiceLocator serviceLocator, String controlID, Control control) {
   final IFocusService focusService = serviceLocator.getService(IFocusService.class);
   if (focusService != null) {
     focusService.addFocusTracker(control, controlID);
   } else {
     log.debug("Focus service not found in " + serviceLocator);
   }
 }
コード例 #3
0
ファイル: UIUtils.java プロジェクト: ralic/dbeaver
 public static void removeFocusTracker(IServiceLocator serviceLocator, Control control) {
   if (PlatformUI.getWorkbench().isClosing()) {
     // TODO: it is a bug in eclipse. During workbench shutdown disposed service returned.
     return;
   }
   final IFocusService focusService = serviceLocator.getService(IFocusService.class);
   if (focusService != null) {
     focusService.removeFocusTracker(control);
   } else {
     log.debug("Focus service not found in " + serviceLocator);
   }
 }