Exemplo n.º 1
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);
 }
  /** 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$
  }
Exemplo n.º 3
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;
        }
    }
  }
Exemplo n.º 4
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;
        }
    }
  }