Exemplo n.º 1
0
  @Override
  public void testAddClickListener() {
    final TableRidget ridget = getRidget();
    ridget.updateFromModel();
    final Table control = getWidget();
    control.getColumn(0).setWidth(100);
    control.getColumn(1).setWidth(100);

    try {
      ridget.addClickListener(null);
      fail();
    } catch (final RuntimeException npe) {
      ok();
    }

    final FTClickListener listener1 = new FTClickListener();
    ridget.addClickListener(listener1);

    final FTClickListener listener2 = new FTClickListener();
    ridget.addClickListener(listener2);
    ridget.addClickListener(listener2);

    final Event mdEvent = new Event();
    mdEvent.widget = control;
    mdEvent.type = SWT.MouseDown;
    mdEvent.button = 2;
    final TableItem row2 = control.getItem(2);
    mdEvent.item = row2;
    mdEvent.x = row2.getBounds().x + 1;
    mdEvent.y = row2.getBounds().y + 1;
    control.notifyListeners(SWT.MouseDown, mdEvent);

    assertEquals(0, listener1.getCount());
    assertEquals(0, listener2.getCount());

    mdEvent.type = SWT.MouseUp;
    control.notifyListeners(SWT.MouseUp, mdEvent);

    assertEquals(1, listener1.getCount());
    assertEquals(1, listener2.getCount());

    final ClickEvent event = listener2.getEvent();
    assertEquals(ridget, event.getSource());
    assertEquals(2, event.getButton());
    assertEquals(0, event.getColumnIndex());
    assertEquals(row2.getData(), event.getRow());

    ridget.removeClickListener(listener1);

    mdEvent.type = SWT.MouseDown;
    control.notifyListeners(SWT.MouseDown, mdEvent);
    mdEvent.type = SWT.MouseUp;
    control.notifyListeners(SWT.MouseUp, mdEvent);

    assertEquals(1, listener1.getCount());
  }
Exemplo n.º 2
0
 public void Send_key(IptKey mod, char key_press_char) {
   Event event = new Event();
   int modifier_key_code = Xto_keycode(mod);
   event.keyCode = modifier_key_code;
   event.type = SWT.KeyDown;
   display.post(event);
   event.keyCode = 0;
   event.character = key_press_char;
   display.post(event);
   event.type = SWT.KeyUp;
   display.post(event);
   event.keyCode = modifier_key_code;
   event.character = 0;
   display.post(event);
 }
 private void esc() {
   Event e = new Event();
   e.type = SWT.KeyDown;
   e.character = SWT.ESC;
   Display.getDefault().post(e);
   readAndDispatch();
 }
Exemplo n.º 4
0
  public void testAddDoubleClickListener() {
    final TableRidget ridget = getRidget();
    final Table control = getWidget();

    try {
      ridget.addDoubleClickListener(null);
      fail();
    } catch (final RuntimeException npe) {
      ok();
    }

    final FTActionListener listener1 = new FTActionListener();
    ridget.addDoubleClickListener(listener1);

    final FTActionListener listener2 = new FTActionListener();
    ridget.addDoubleClickListener(listener2);
    ridget.addDoubleClickListener(listener2);

    final Event doubleClick = new Event();
    doubleClick.widget = control;
    doubleClick.type = SWT.MouseDoubleClick;
    control.notifyListeners(SWT.MouseDoubleClick, doubleClick);

    assertEquals(1, listener1.getCount());
    assertEquals(1, listener2.getCount());

    ridget.removeDoubleClickListener(listener1);

    control.notifyListeners(SWT.MouseDoubleClick, doubleClick);

    assertEquals(1, listener1.getCount());
  }
Exemplo n.º 5
0
 /**
  * Handles dispose event
  *
  * @param event
  */
 void handleDispose(Event event) {
   removeListener(SWT.Dispose, listener);
   notifyListeners(SWT.Dispose, event);
   event.type = SWT.None;
   text = null;
   listener = null;
 }
Exemplo n.º 6
0
 public void notifyListeners(String eventName, JsonObject properties) {
   JsonValue value = properties.get("value");
   Event event = new Event();
   event.type = stringToTypeEvent(eventName);
   event.text = (value != null && value.isString() ? value.asString() : "");
   event.data = properties;
   listener.handleEvent(event);
 }
  public void testBasicContribution() throws Exception {

    IAction a =
        new Action() {
          @Override
          public void run() {
            System.out.println("Hello action");
          }
        };
    final MenuManager manager = new MenuManager();
    final ActionContributionItem item = new ActionContributionItem(a);
    final Expression activeContextExpr =
        new ActiveContextExpression(
            MenuContributionHarness.CONTEXT_TEST1_ID, new String[] {ISources.ACTIVE_CONTEXT_NAME});
    AbstractContributionFactory factory =
        new AbstractContributionFactory(LOCATION, TestPlugin.PLUGIN_ID) {
          @Override
          public void createContributionItems(
              IServiceLocator menuService, IContributionRoot additions) {
            additions.addContributionItem(item, activeContextExpr);
          }
        };

    menuService.addContributionFactory(factory);
    menuService.populateContributionManager(manager, LOCATION);

    Shell shell = window.getShell();

    // Test the initial menu creation
    final Menu menuBar = manager.createContextMenu(shell);
    Event e = new Event();
    e.type = SWT.Show;
    e.widget = menuBar;
    menuBar.notifyListeners(SWT.Show, e);

    assertFalse("starting state", item.isVisible());

    activeContext = contextService.activateContext(MenuContributionHarness.CONTEXT_TEST1_ID);
    menuBar.notifyListeners(SWT.Show, e);

    assertTrue("active context", item.isVisible());

    contextService.deactivateContext(activeContext);
    activeContext = null;
    menuBar.notifyListeners(SWT.Show, e);

    assertFalse("after deactivation", item.isVisible());

    menuService.releaseContributions(manager);
    menuService.removeContributionFactory(factory);
    manager.dispose();
  }
Exemplo n.º 8
0
 public Object execute(ExecutionEvent event) throws ExecutionException {
   XtextEditor editor = EditorUtils.getActiveXtextEditor(event);
   if (editor != null) {
     // Hack, would be nicer with document edits, but this way we don't loose auto edit
     StyledText textWidget = editor.getInternalSourceViewer().getTextWidget();
     Event e = new Event();
     e.character = replaceChar;
     e.type = SWT.KeyDown;
     e.doit = true;
     textWidget.notifyListeners(SWT.KeyDown, e);
   }
   return null;
 }
  private static void click(final MenuItem menuItem) {
    final Event event = new Event();
    event.time = (int) System.currentTimeMillis();
    event.widget = menuItem;
    event.display = menuItem.getDisplay();
    event.type = SWT.Selection;

    UIThreadRunnable.asyncExec(
        menuItem.getDisplay(),
        new VoidResult() {
          public void run() {
            menuItem.notifyListeners(SWT.Selection, event);
          }
        });
  }
Exemplo n.º 10
0
 public Event sendEvent(final Widget w, final int event, int x, int y, int button) {
   try {
     Event e = createEvent(w);
     e.x = x;
     e.y = y;
     e.button = button;
     e.type = event;
     sendEventRaw(event, e);
     return e;
   } catch (SecurityException e) {
     TeslaCore.log(e);
   } catch (IllegalArgumentException e) {
     TeslaCore.log(e);
   }
   return null;
 }
Exemplo n.º 11
0
  void onDispose(Event event) {
    /* make this handler run after other dispose listeners */
    if (ignoreDispose) {
      ignoreDispose = false;
      return;
    }
    ignoreDispose = true;
    notifyListeners(event.type, event);
    event.type = SWT.NONE;

    gradientColors = null;
    gradientPercents = null;
    backgroundImage = null;
    text = null;
    image = null;
    appToolTipText = null;
  }
Exemplo n.º 12
0
  void onDispose(Event event) {
    removeListener(SWT.Dispose, listener);
    notifyListeners(SWT.Dispose, event);
    event.type = SWT.None;

    table.removeListener(SWT.FocusIn, tableListener);
    table.removeListener(SWT.MouseDown, tableListener);
    unhookRowColumnListeners();
    ScrollBar hBar = table.getHorizontalBar();
    if (hBar != null) {
      hBar.removeListener(SWT.Selection, resizeListener);
    }
    ScrollBar vBar = table.getVerticalBar();
    if (vBar != null) {
      vBar.removeListener(SWT.Selection, resizeListener);
    }
  }
Exemplo n.º 13
0
 public Event sendEvent(final SWTUIElement w, final int event, int x, int y) {
   if (PlayerWrapUtils.unwrapWidget(w).isDisposed()) {
     return null;
   }
   try {
     Event e = createEvent(w);
     e.x = x;
     e.y = y;
     e.type = event;
     sendEventRaw(event, e);
     return e;
   } catch (SecurityException e) {
     TeslaCore.log(e);
   } catch (IllegalArgumentException e) {
     TeslaCore.log(e);
   }
   return null;
 }
Exemplo n.º 14
0
  protected void handleAllSelectionChange(boolean state) {
    ArrayList arrayList = (ArrayList) tableViewer.getInput();
    if (!state) {
      selector.getSelectedModels().removeAll(arrayList);
    } else {
      selector.getSelectedModels().addAll(arrayList);
    }
    tableViewer.setAllChecked(state);

    // fire an event so the parent can update its controls
    if (listener != null) {
      Event changeEvent = new Event();
      changeEvent.type = SWT.Selection;
      changeEvent.widget = tableViewer.getTable();
      listener.handleEvent(changeEvent);
    }
    updateCountLabel();
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands
   * .ExecutionEvent)
   */
  public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPart part = HandlerUtil.getActivePart(event);
    if (part != null) {
      IWorkbenchPartSite site = part.getSite();
      if (site instanceof PartSite) {
        final MPart model = ((PartSite) site).getModel();
        Composite partContainer = (Composite) model.getWidget();
        if (partContainer != null) {
          Composite parent = partContainer.getParent();
          while (parent != null && parent instanceof Composite) {
            if (parent instanceof CTabFolder) {
              CTabFolder ctf = (CTabFolder) parent;
              final Control topRight = ctf.getTopRight();
              if (topRight instanceof Composite) {
                for (Control child : ((Composite) topRight).getChildren()) {
                  if (child instanceof ToolBar
                      && "ViewMenu".equals(child.getData())) { // $NON-NLS-1$
                    ToolBar tb = (ToolBar) child;
                    ToolItem ti = tb.getItem(0);
                    Event sevent = new Event();
                    sevent.type = SWT.Selection;
                    sevent.widget = ti;
                    ti.notifyListeners(SWT.Selection, sevent);
                  }
                }
              }
              return null;
            }
            parent = parent.getParent();
          }

          MMenu menuModel = StackRenderer.getViewMenu(model);
          if (menuModel != null) {
            showStandaloneViewMenu(event, model, menuModel, partContainer);
          }
        }
      }
    }
    return null;
  }
Exemplo n.º 16
0
  public void testColumnHeaderChangesSortability() {
    final TableRidget ridget = getRidget();
    final Table table = getWidget();

    ridget.setColumnSortable(0, true);
    ridget.setComparator(0, new TypedComparator<String>());
    ridget.setColumnSortable(1, true);
    ridget.setComparator(1, new TypedComparator<String>());

    ridget.setSortedColumn(-1);

    assertEquals(-1, ridget.getSortedColumn());
    assertFalse(ridget.isSortedAscending());

    final Event e = new Event();
    e.type = SWT.Selection;
    e.widget = table.getColumn(0);
    e.widget.notifyListeners(SWT.Selection, e);

    assertEquals(0, ridget.getSortedColumn());
    assertTrue(ridget.isSortedAscending());

    e.widget.notifyListeners(SWT.Selection, e);

    assertEquals(0, ridget.getSortedColumn());
    assertFalse(ridget.isSortedAscending());

    e.widget.notifyListeners(SWT.Selection, e);

    assertEquals(-1, ridget.getSortedColumn());
    assertFalse(ridget.isSortedAscending());

    e.widget.notifyListeners(SWT.Selection, e);

    assertEquals(0, ridget.getSortedColumn());
    assertTrue(ridget.isSortedAscending());
  }
Exemplo n.º 17
0
  public void open() {
    if (screenPos == null) screenPos = Display.getDefault().getCursorLocation();
    leftScreenPos = screenPos;
    popupRight = true;
    if (control == null || control.isDisposed()) return;
    control.addDisposeListener(
        new DisposeListener() {

          public void widgetDisposed(DisposeEvent e) {
            dispose();
          }
        });
    final ShellListener shellListener =
        new ShellAdapter() {

          public void shellClosed(ShellEvent e) {
            hideMenu();
          }

          public void shellDeactivated(ShellEvent e) {
            hideMenu();
          }

          public void shellIconified(ShellEvent e) {
            hideMenu();
          }
        };
    control.getShell().addShellListener(shellListener);
    ignoreTaskbar = true;

    Event event = new Event();
    event.data = this;
    event.type = SWT.OPEN;
    menu.fireMenuEvent(event);

    createAndShowWindow();
    installMouseHook();
    shell.addDisposeListener(
        new DisposeListener() {

          public void widgetDisposed(DisposeEvent e) {
            if (!control.isDisposed()) control.getShell().removeShellListener(shellListener);
          }
        });

    final Listener mouseDownListener =
        new Listener() {

          public void handleEvent(Event e) {
            if (shell == null || shell.isDisposed()) {
              Display.getDefault().removeFilter(SWT.MouseDown, this);
              return;
            }
            if (e.widget == null
                || e.widget.isDisposed()
                || checkMouseDownEvent(((Control) e.widget).toDisplay(e.x, e.y))) {
              hideMenu();
            }
          }
        };

    Display.getDefault().addFilter(SWT.MouseDown, mouseDownListener);

    final Listener keyDownListener =
        new Listener() {

          public void handleEvent(Event e) {
            if (shell == null || shell.isDisposed()) {
              Display.getDefault().removeFilter(SWT.KeyDown, this);
              e.doit = false;
              return;
            }
            KeyEvent ke = new KeyEvent(e);
            if ((ke.keyCode == SWT.ALT) || ke.keyCode == SWT.F10) {
              hideMenu();
              return;
            }
            getCurrentMenu().dealAltKeyEvent(ke);

            if (ke.keyCode == KEY_RIGHT && trackItemIndex > -1) {
              getCurrentMenu().subMenuSelected();
            }
            if (ke.keyCode == KEY_LEFT && trackItemIndex > -1) {
              getCurrentMenu().parentMenuSelected();
            }
            if (ke.keyCode == KEY_DOWN || ke.keyCode == KEY_UP) {
              if (ke.keyCode == KEY_DOWN) getCurrentMenu().downSelected();
              else getCurrentMenu().upSelected();
            }
            if (ke.keyCode == SWT.ESC) {
              if (getCurrentMenu().parentMenu == null) getCurrentMenu().hideMenu();
              else getCurrentMenu().parentMenuSelected();
            }
            if (ke.keyCode == SWT.CR) {
              getCurrentMenu().handleSelectedEvent();
            }
          }
        };
    Display.getDefault().addFilter(SWT.KeyDown, keyDownListener);

    shell.addDisposeListener(
        new DisposeListener() {

          public void widgetDisposed(DisposeEvent e) {
            Display.getDefault().removeFilter(SWT.MouseDown, mouseDownListener);
            Display.getDefault().removeFilter(SWT.KeyDown, keyDownListener);
            getShell().removeShellListener(shellListener);
          }
        });
  }