void activeKeyScrolling() {
   if (keyScrollingFilter == null) {
     Composite pageParent = getPageContainer().getParent();
     if (!(pageParent instanceof ScrolledComposite)) {
       return;
     }
     final ScrolledComposite sc = (ScrolledComposite) pageParent;
     keyScrollingFilter =
         event -> {
           if (!keyScrollingEnabled || sc.isDisposed()) {
             return;
           }
           switch (event.keyCode) {
             case SWT.ARROW_DOWN:
               sc.setOrigin(sc.getOrigin().x, sc.getOrigin().y + INCREMENT);
               break;
             case SWT.ARROW_UP:
               sc.setOrigin(sc.getOrigin().x, sc.getOrigin().y - INCREMENT);
               break;
             case SWT.ARROW_LEFT:
               sc.setOrigin(sc.getOrigin().x - INCREMENT, sc.getOrigin().y);
               break;
             case SWT.ARROW_RIGHT:
               sc.setOrigin(sc.getOrigin().x + INCREMENT, sc.getOrigin().y);
               break;
             case SWT.PAGE_DOWN:
               sc.setOrigin(sc.getOrigin().x, sc.getOrigin().y + PAGE_MULTIPLIER * INCREMENT);
               break;
             case SWT.PAGE_UP:
               sc.setOrigin(sc.getOrigin().x, sc.getOrigin().y - PAGE_MULTIPLIER * INCREMENT);
               break;
             case SWT.HOME:
               sc.setOrigin(0, 0);
               break;
             case SWT.END:
               sc.setOrigin(0, sc.getSize().y);
               break;
             default:
               keyScrollingEnabled = false;
           }
           event.type = SWT.None;
           event.doit = false;
         };
     Display display = PlatformUI.getWorkbench().getDisplay();
     display.addFilter(SWT.KeyDown, keyScrollingFilter);
     display.addFilter(SWT.Traverse, keyScrollingFilter);
     sc.addDisposeListener(e -> removeKeyScrolling());
   }
   keyScrollingEnabled = true;
 }
  @PostConstruct
  public void init() {
    eventBroker.subscribe(UIEvents.UILabel.TOPIC_ALL, itemUpdater);
    eventBroker.subscribe(UIEvents.Item.TOPIC_SELECTED, selectionUpdater);
    eventBroker.subscribe(UIEvents.Item.TOPIC_ENABLED, enabledUpdater);
    eventBroker.subscribe(UIEvents.UIElement.TOPIC_ALL, toBeRenderedUpdater);

    context.set(MenuManagerRenderer.class, this);
    Display display = context.get(Display.class);
    rendererFilter = ContextInjectionFactory.make(MenuManagerRendererFilter.class, context);
    display.addFilter(SWT.Show, rendererFilter);
    display.addFilter(SWT.Hide, rendererFilter);
    display.addFilter(SWT.Dispose, rendererFilter);
    context.set(MenuManagerRendererFilter.class, rendererFilter);
  }
Ejemplo n.º 3
0
  /** create tabs */
  private void createTabs() {
    // create tab
    tabFolder = Widgets.newTabFolder(shell);
    Widgets.layout(tabFolder, 0, 0, TableLayoutData.NSWE);
    tabStatus = new TabStatus(tabFolder, SWT.F1);
    tabJobs = new TabJobs(tabFolder, SWT.F2);
    tabRestore = new TabRestore(tabFolder, SWT.F3);
    tabStatus.setTabJobs(tabJobs);
    tabJobs.setTabStatus(tabStatus);

    // add tab listener
    display.addFilter(
        SWT.KeyDown,
        new Listener() {
          public void handleEvent(Event event) {
            switch (event.keyCode) {
              case SWT.F1:
                System.out.println(event);
                Widgets.showTab(tabFolder, tabStatus.widgetTab);
                event.doit = false;
                break;
              case SWT.F2:
                Widgets.showTab(tabFolder, tabJobs.widgetTab);
                event.doit = false;
                break;
              case SWT.F3:
                Widgets.showTab(tabFolder, tabRestore.widgetTab);
                event.doit = false;
                break;
              default:
                break;
            }
          }
        });
  }
Ejemplo n.º 4
0
  /**
   * Constructs a new instance of <code>BindingService</code> using a JFace binding manager.
   *
   * @param bindingManager The bind ing manager to use; must not be <code>null</code>.
   * @param commandService The command service providing support for this service; must not be
   *     <code>null</code>;
   * @param workbench The workbench on which this context service will act; must not be <code>null
   *     </code>.
   */
  public BindingService(
      final BindingManager bindingManager,
      final ICommandService commandService,
      final IWorkbench workbench) {
    if (bindingManager == null) {
      throw new NullPointerException(
          "Cannot create a binding service with a null manager"); //$NON-NLS-1$
    }
    if (commandService == null) {
      throw new NullPointerException(
          "Cannot create a binding service with a null command service"); //$NON-NLS-1$
    }
    this.bindingManager = bindingManager;

    this.workbench = workbench;
    // Hook up the key binding support.
    this.bindingPersistence = new BindingPersistence(bindingManager, commandService);
    keyboard = new WorkbenchKeyboard(workbench);
    final Display display = workbench.getDisplay();
    final Listener listener = keyboard.getKeyDownFilter();
    display.addFilter(SWT.KeyDown, listener);
    // RAP [if] Listening for both SWT.KeyDown and SWT.Traverse events execute the command twice
    // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=381092
    //		display.addFilter(SWT.Traverse, listener);
    // ENDRAP

    // Initialize the key formatter.
    KeyFormatterFactory.setDefault(SWTKeySupport.getKeyFormatterForPlatform());
  }
Ejemplo n.º 5
0
  private void addDisplayFilterListener() {

    if (_isDisplayListenerSet) {
      return;
    }

    _display.addFilter(SWT.MouseMove, _ttDisplayListener);

    _isDisplayListenerSet = true;
  }
Ejemplo n.º 6
0
  public static void main(String[] args) {

    final Display display = new Display();

    Shell shell = new Shell(display);

    shell.pack();

    shell.open();

    final int TIME_OUT = 3000;

    final Runnable runnable =
        new Runnable() {

          public void run() {

            System.out.println("Idle for " + (TIME_OUT / 1000) + " seconds");

            display.timerExec(TIME_OUT, this);
          }
        };

    display.addFilter(
        SWT.KeyDown,
        new Listener() {

          public void handleEvent(Event event) {

            display.timerExec(TIME_OUT, runnable);
          }
        });

    display.timerExec(TIME_OUT, runnable);

    while (!shell.isDisposed()) {

      if (!display.readAndDispatch()) display.sleep();
    }

    display.dispose();
  }
Ejemplo n.º 7
0
 void handleFocus(int type) {
   if (isDisposed()) return;
   switch (type) {
     case SWT.FocusIn:
       {
         if (hasFocus) return;
         if (getEditable()) text.selectAll();
         hasFocus = true;
         Shell shell = getShell();
         shell.removeListener(SWT.Deactivate, listener);
         shell.addListener(SWT.Deactivate, listener);
         Display display = getDisplay();
         display.removeFilter(SWT.FocusIn, filter);
         display.addFilter(SWT.FocusIn, filter);
         Event e = new Event();
         notifyListeners(SWT.FocusIn, e);
         break;
       }
     case SWT.FocusOut:
       {
         if (!hasFocus) return;
         Control focusControl = getDisplay().getFocusControl();
         if (focusControl == arrow
             || focusControl == list
             || focusControl == icon
             || focusControl == text) return;
         hasFocus = false;
         Shell shell = getShell();
         shell.removeListener(SWT.Deactivate, listener);
         Display display = getDisplay();
         display.removeFilter(SWT.FocusIn, filter);
         Event e = new Event();
         notifyListeners(SWT.FocusOut, e);
         dropDown(false);
         break;
       }
   }
 }