Пример #1
0
 public Event createMouseEvent(
     Display display, Widget widget, int x, int y, int button, int stateMask, int count) {
   Event event = new Event();
   event.time = (int) System.currentTimeMillis();
   event.widget = widget;
   event.display = display;
   event.x = x;
   event.y = y;
   event.button = button;
   event.stateMask = stateMask;
   event.count = count;
   return event;
 }
  private void doEventBasedSelection(int item, int stateMask, int button) {

    Table t = table.getViewer().getTable();
    t.setSelection(item);
    while (Display.getCurrent().readAndDispatch()) ;
    Rectangle bounds = t.getItem(item).getBounds();
    Event event = new Event();
    event.button = button;
    event.stateMask = stateMask;
    event.x = bounds.x + 1;
    event.y = bounds.y + 1;
    t.notifyListeners(SWT.MouseUp, event);
    while (Display.getCurrent().readAndDispatch()) ;
  }
  /** Tests the CTRL-D keystroke which initiates a delete from model action. See Bugzilla 115108. */
  public void testDeleteFromModel() throws Exception {

    getTestFixture().openDiagram();

    LEDEditPart editPartToDelete =
        (LEDEditPart)
            getLogicTestFixture()
                .createShapeUsingTool(LogicSemanticType.LED, new Point(0, 0), getDiagramEditPart());

    List primaryEditParts = getDiagramEditPart().getPrimaryEditParts();

    assertTrue(primaryEditParts.contains(editPartToDelete));

    EObject semanticElement = (EObject) editPartToDelete.getAdapter(EObject.class);
    EObject semanticContainer = semanticElement.eContainer();

    // Select the edit part to be deleted.
    EditPartViewer rootViewer = getDiagramEditPart().getRoot().getViewer();
    rootViewer.deselectAll();
    rootViewer.select(editPartToDelete);

    // Set the preference to not confirm the element deletion.
    ((IPreferenceStore) getDiagramEditPart().getDiagramPreferencesHint().getPreferenceStore())
        .setValue(IPreferenceConstants.PREF_PROMPT_ON_DEL_FROM_MODEL, false);

    // Create the CTRL-D event
    Event e = new Event();
    e.character = (char) 0x4;
    e.keyCode = 100;
    e.stateMask = SWT.CTRL;
    e.widget = editPartToDelete.getViewer().getControl();

    // Simulate the CTRL-D keystroke
    SelectionTool tool = new SelectionTool();
    tool.setEditDomain((EditDomain) getDiagramWorkbenchPart().getDiagramEditDomain());
    tool.activate();
    tool.keyDown(new KeyEvent(e), rootViewer);

    // Verify that the edit part and the semantic element have been deleted.
    primaryEditParts = getDiagramEditPart().getPrimaryEditParts();

    assertFalse(
        "Primary edit part not deleted.",
        primaryEditParts.contains(editPartToDelete)); // $NON-NLS-1$

    assertFalse(
        "Semantic element not deleted.",
        semanticContainer.eContents().contains(semanticElement)); // $NON-NLS-1$
  }
Пример #4
0
  // internal callback for when the big button is clicked
  void bigButtonClicked(MouseEvent me) {
    Event e = new Event();
    e.button = me.button;
    e.data = this;
    e.display = me.display;
    e.stateMask = me.stateMask;
    e.widget = me.widget;
    e.x = me.x;
    e.y = me.y;
    SelectionEvent se = new SelectionEvent(e);

    for (int i = 0; i < mBigButtonListeners.size(); i++) {
      mBigButtonListeners.get(i).widgetSelected(se);
    }
  }
Пример #5
0
 public Event sendEvent(final Widget w, final int event, int x, int y, int button, int mask) {
   try {
     Event e = createEvent(w);
     e.x = x;
     e.y = y;
     e.type = event;
     e.button = button;
     e.stateMask = mask;
     sendEventRaw(event, e);
     return e;
   } catch (SecurityException e) {
     TeslaCore.log(e);
   } catch (IllegalArgumentException e) {
     TeslaCore.log(e);
   }
   return null;
 }
Пример #6
0
  void listEvent(Event event) {
    switch (event.type) {
      case SWT.Dispose:
        if (getShell() != popup.getParent()) {
          String[] items = list.getItems();
          int selectionIndex = list.getSelectionIndex();
          popup = null;
          list = null;
          createPopup(items, selectionIndex);
        }
        break;
      case SWT.FocusIn:
        {
          handleFocus(SWT.FocusIn);
          break;
        }
      case SWT.MouseUp:
        {
          if (event.button != 1) return;
          dropDown(false);
          break;
        }
      case SWT.Selection:
        {
          int index = list.getSelectionIndex();
          if (index == -1) return;
          text.setText(list.getItem(index));
          //    text.selectAll ();
          list.setSelection(index);
          //    list.forceFocus();

          Event e = new Event();
          e.time = event.time;
          e.stateMask = event.stateMask;
          e.doit = event.doit;
          notifyListeners(SWT.Selection, e);
          event.doit = e.doit;
          break;
        }
      case SWT.Traverse:
        {
          switch (event.detail) {
            case SWT.TRAVERSE_RETURN:
            case SWT.TRAVERSE_ESCAPE:
            case SWT.TRAVERSE_ARROW_PREVIOUS:
            case SWT.TRAVERSE_ARROW_NEXT:
              event.doit = false;
              break;
          }
          Event e = new Event();
          e.time = event.time;
          e.detail = event.detail;
          e.doit = event.doit;
          e.character = event.character;
          e.keyCode = event.keyCode;
          notifyListeners(SWT.Traverse, e);
          event.doit = e.doit;
          event.detail = e.detail;
          break;
        }
      case SWT.KeyUp:
        {
          Event e = new Event();
          e.time = event.time;
          e.character = event.character;
          e.keyCode = event.keyCode;
          e.stateMask = event.stateMask;
          notifyListeners(SWT.KeyUp, e);
          break;
        }

      case SWT.KeyDown:
        {
          if (event.character == SWT.ESC) {
            // Escape key cancels popup list
            dropDown(false);
          }
          if ((event.stateMask & SWT.ALT) != 0
              && (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN)) {
            dropDown(false);
          }
          if (event.character == SWT.CR) {
            // Enter causes default selection
            dropDown(false);
            Event e = new Event();
            e.time = event.time;
            e.stateMask = event.stateMask;
            notifyListeners(SWT.DefaultSelection, e);
          }
          // At this point the widget may have been disposed.
          // If so, do not continue.
          if (isDisposed()) break;
          Event e = new Event();
          e.time = event.time;
          e.character = event.character;
          e.keyCode = event.keyCode;
          e.stateMask = event.stateMask;
          notifyListeners(SWT.KeyDown, e);
          break;
        }
    }
  }
Пример #7
0
  void textEvent(Event event) {
    switch (event.type) {
      case SWT.FocusIn:
        {
          handleFocus(SWT.FocusIn);
          break;
        }
      case SWT.KeyDown:
        {
          if (event.character == SWT.CR) {
            dropDown(false);
            Event e = new Event();
            e.time = event.time;
            e.stateMask = event.stateMask;
            notifyListeners(SWT.DefaultSelection, e);
          }
          // At this point the widget may have been disposed.
          // If so, do not continue.
          if (isDisposed()) break;

          if (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN) {
            event.doit = false;
            if ((event.stateMask & SWT.ALT) != 0) {
              boolean dropped = isDropped();
              text.selectAll();
              if (!dropped) setFocus();
              dropDown(!dropped);
              break;
            }

            int oldIndex = getSelectionIndex();
            if (event.keyCode == SWT.ARROW_UP && popup.isVisible()) {
              select(Math.max(oldIndex - 1, 0));
            } else if (popup.isVisible()) {
              select(Math.min(oldIndex + 1, getItemCount() - 1));
            }
            if (oldIndex != getSelectionIndex()) {
              Event e = new Event();
              e.time = event.time;
              e.stateMask = event.stateMask;
              notifyListeners(SWT.Selection, e);
            }
            // At this point the widget may have been disposed.
            // If so, do not continue.
            if (isDisposed()) break;
          }

          // Further work : Need to add support for incremental search in
          // pop up list as characters typed in text widget

          Event e = new Event();
          e.time = event.time;
          e.character = event.character;
          e.keyCode = event.keyCode;
          e.stateMask = event.stateMask;
          notifyListeners(SWT.KeyDown, e);
          break;
        }
      case SWT.KeyUp:
        {
          Event e = new Event();
          e.time = event.time;
          e.character = event.character;
          e.keyCode = event.keyCode;
          e.stateMask = event.stateMask;
          notifyListeners(SWT.KeyUp, e);
          break;
        }
      case SWT.Modify:
        {
          list.deselectAll();
          Event e = new Event();
          e.time = event.time;
          notifyListeners(SWT.Modify, e);
          break;
        }

      case SWT.MouseDown:
        {
          if (event.button != 1) return;
          if (text.getEditable()) return;
          boolean dropped = isDropped();
          text.selectAll();
          if (!dropped) setFocus();
          dropDown(!dropped);
          break;
        }

      case SWT.MouseUp:
        {
          if (event.button != 1) return;
          if (text.getEditable()) return;
          text.selectAll();
          break;
        }

      case SWT.Traverse:
        {
          switch (event.detail) {
            case SWT.TRAVERSE_RETURN:
            case SWT.TRAVERSE_ARROW_PREVIOUS:
            case SWT.TRAVERSE_ARROW_NEXT:
              // The enter causes default selection and
              // the arrow keys are used to manipulate the list contents so
              // do not use them for traversal.
              event.doit = false;
              break;
          }

          Event e = new Event();
          e.time = event.time;
          e.detail = event.detail;
          e.doit = event.doit;
          e.character = event.character;
          e.keyCode = event.keyCode;
          notifyListeners(SWT.Traverse, e);
          event.doit = e.doit;
          event.detail = e.detail;
          break;
        }
    }
  }