Exemple #1
0
  public synchronized void sendFocus(Widget widget) {
    if (widget.isDisposed()) {
      return;
    }
    if (!(widget instanceof Control)) {
      return;
    }
    Control ctrl = (Control) widget;

    boolean sendUnfocus = TeslaCellEditorManager.getInstance().getEditors().length > 0;

    if (sendUnfocus) {
      if (ctrl != lastFocusControl) {
        // new focus control
        // send focusOut for real last focused control
        if (ctrl == lastFocusControl) {
          return;
        }
        if (lastFocusControl != null && !lastFocusControl.isDisposed()) {
          if (lastFocusControl.isFocusControl()) {
            sendEvent(lastFocusControl, SWT.FocusOut);
            if (!lastFocusControl.isDisposed()) {
              sendEvent(lastFocusControl, SWT.Deactivate);
            }
            if (!lastFocusControl.isDisposed()) {
              sendEvent(lastFocusControl, SWT.MouseExit);
            }
          }
        }
        lastFocusControl = ctrl;
        if (!ctrl.isFocusControl()) {
          ctrl.setFocus();
          sendEvent(lastFocusControl, SWT.MouseEnter);
          sendEvent(lastFocusControl, SWT.MouseMove);
          sendEvent(lastFocusControl, SWT.Activate);
          sendEvent(lastFocusControl, SWT.FocusIn);
        }
      }
    } else {
      // ctrl.getShell().forceActive();
      if (!ctrl.isFocusControl()) {
        try {
          ShellUtilsProvider.getShellUtils().forceActive(ctrl.getShell());
        } catch (CoreException e) {
          throw new RuntimeException(e);
        }
        ctrl.setFocus();
        ctrl.forceFocus();
        sendEvent(ctrl, SWT.MouseEnter);
        sendEvent(ctrl, SWT.MouseMove);
        sendEvent(ctrl, SWT.Activate);
        sendEvent(ctrl, SWT.FocusIn);
      }
      lastFocusControl = ctrl;
    }
  }
Exemple #2
0
  public synchronized void sendUnfocus(Widget widget) {
    if (widget.isDisposed()) {
      return;
    }
    if (!(widget instanceof Control)) {
      return;
    }
    Control ctrl = (Control) widget;
    boolean sendUnfocus = TeslaCellEditorManager.getInstance().getEditors().length > 0;

    if (!sendUnfocus) {
      if (ctrl.isFocusControl() || widget == lastFocusControl) {
        if (!ctrl.isDisposed()) {
          sendEvent(ctrl, SWT.FocusOut);
        }
        if (!ctrl.isDisposed()) {
          sendEvent(ctrl, SWT.Deactivate);
        }
        if (!ctrl.isDisposed()) {
          sendEvent(ctrl, SWT.MouseMove);
        }
        if (!ctrl.isDisposed()) {
          sendEvent(ctrl, SWT.MouseExit);
        }
      }
      lastFocusControl = null;
      TeslaEventManager.getManager().setForceFocusControl(null);
    }
  }
    private FocusHandler(Navigable navigable) {
      fIterator = new JavaWordIterator();
      fNavigable = navigable;

      Control control = navigable.getControl();
      control.addFocusListener(this);
      if (control.isFocusControl()) activate();
      control.addDisposeListener(
          new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
              deactivate();
            }
          });
    }
 @Override
 public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
   if (!(receiver instanceof SQLEditorBase)) {
     return false;
   }
   SQLEditor editor = (SQLEditor) receiver;
   final Control editorControl = editor.getEditorControl();
   if (editorControl == null) {
     return false;
   }
   boolean isFocused = editorControl.isFocusControl();
   boolean isConnected =
       editor.getDataSourceContainer() != null && editor.getDataSourceContainer().isConnected();
   switch (property) {
     case PROP_CAN_EXECUTE:
       return isConnected
           && isFocused
           && (!"statement".equals(expectedValue) || editor.hasActiveQuery());
     case PROP_CAN_EXPLAIN:
       return isConnected
           && isFocused
           && editor.hasActiveQuery()
           && DBUtils.getAdapter(DBCQueryPlanner.class, editor.getDataSource()) != null;
     case PROP_CAN_NAVIGATE:
       {
         // Check whether some word is under cursor
         ISelectionProvider selectionProvider = editor.getSelectionProvider();
         if (selectionProvider == null) {
           return false;
         }
         ITextSelection selection = (ITextSelection) selectionProvider.getSelection();
         Document document = editor.getDocument();
         return selection != null
             && document != null
             && !new SQLIdentifierDetector(
                     editor.getSyntaxManager().getStructSeparator(),
                     editor.getSyntaxManager().getQuoteSymbol())
                 .detectIdentifier(
                     document, new Region(selection.getOffset(), selection.getLength()))
                 .isEmpty();
       }
     case PROP_CAN_EXPORT:
       return isConnected && editor.hasActiveQuery();
   }
   return false;
 }