コード例 #1
0
 public void handleEvent(Event event) {
   TableItem item = (TableItem) event.item;
   int index = event.index;
   item.setText(
       0, app.hostManager.get(index).hostname + ":" + app.hostManager.get(index).port);
   item.setText(1, app.hostManager.get(index).credentials.getUsername());
   item.setText(2, app.hostManager.get(index).credentials.getPrivateKeyPath());
   event.detail &= ~SWT.FOCUSED;
 }
コード例 #2
0
ファイル: SWTEvents.java プロジェクト: xored/rcptt
 public Event sendEvent(final Widget w, final Widget item, final int event, int detail) {
   try {
     Event e = createEvent(w);
     e.item = item;
     e.detail = detail;
     sendEventRaw(event, e);
     return e;
   } catch (SecurityException e) {
     TeslaCore.log(e);
   } catch (IllegalArgumentException e) {
     TeslaCore.log(e);
   }
   return null;
 }
コード例 #3
0
ファイル: CCombo2.java プロジェクト: yeins/vietspider
  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;
        }
    }
  }
コード例 #4
0
ファイル: CCombo2.java プロジェクト: yeins/vietspider
  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;
        }
    }
  }
コード例 #5
0
    // Key events from the control
    public void handleEvent(Event e) {
      if (!isValid()) {
        return;
      }

      char key = e.character;

      // Traverse events are handled depending on whether the
      // event has a character.
      if (e.type == SWT.Traverse) {
        // If the traverse event contains a legitimate character,
        // then we must set doit false so that the widget will
        // receive the key event. We return immediately so that
        // the character is handled only in the key event.
        // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=132101
        if (key != 0) {
          e.doit = false;
          return;
        }
        // Traversal does not contain a character. Set doit true
        // to indicate TRAVERSE_NONE will occur and that no key
        // event will be triggered. We will check for navigation
        // keys below.
        e.detail = SWT.TRAVERSE_NONE;
        e.doit = true;
      } else {
        // Default is to only propagate when configured that way.
        // Some keys will always set doit to false anyway.
        e.doit = adapter.getPropagateKeys();
      }

      // No character. Check for navigation keys.

      if (key == 0) {
        int newSelection = proposalTable.getSelectionIndex();
        int visibleRows = (proposalTable.getSize().y / proposalTable.getItemHeight()) - 1;
        switch (e.keyCode) {
          case SWT.ARROW_UP:
            newSelection -= 1;
            if (newSelection < 0) {
              newSelection = proposalTable.getItemCount() - 1;
            }
            // Not typical - usually we get this as a Traverse and
            // therefore it never propagates. Added for consistency.
            if (e.type == SWT.KeyDown) {
              // don't propagate to control
              e.doit = false;
            }
            break;

          case SWT.ARROW_DOWN:
            newSelection += 1;
            if (newSelection > proposalTable.getItemCount() - 1) {
              newSelection = 0;
            }
            // Not typical - usually we get this as a Traverse and
            // therefore it never propagates. Added for consistency.
            if (e.type == SWT.KeyDown) {
              // don't propagate to control
              e.doit = false;
            }
            break;

          case SWT.PAGE_DOWN:
            newSelection += visibleRows;
            if (newSelection >= proposalTable.getItemCount()) {
              newSelection = proposalTable.getItemCount() - 1;
            }
            if (e.type == SWT.KeyDown) {
              // don't propagate to control
              e.doit = false;
            }
            break;

          case SWT.PAGE_UP:
            newSelection -= visibleRows;
            if (newSelection < 0) {
              newSelection = 0;
            }
            if (e.type == SWT.KeyDown) {
              // don't propagate to control
              e.doit = false;
            }
            break;

          case SWT.HOME:
            newSelection = 0;
            if (e.type == SWT.KeyDown) {
              // don't propagate to control
              e.doit = false;
            }
            break;

          case SWT.END:
            newSelection = proposalTable.getItemCount() - 1;
            if (e.type == SWT.KeyDown) {
              // don't propagate to control
              e.doit = false;
            }
            break;

            // If received as a Traverse, these should propagate
            // to the control as keydown. If received as a keydown,
            // proposals should be recomputed since the cursor
            // position has changed.
          case SWT.ARROW_LEFT:
          case SWT.ARROW_RIGHT:
            if (e.type == SWT.Traverse) {
              e.doit = false;
            } else {
              e.doit = true;
              String contents = adapter.getControlContentAdapter().getControlContents(control);
              // If there are no contents, changes in cursor
              // position have no effect. Note also that we do
              // not affect the filter text on ARROW_LEFT as
              // we would with BS.
              if (contents.length() > 0) {
                asyncRecomputeProposals();
              }
            }
            break;

            // Any unknown keycodes will cause the popup to close.
            // Modifier keys are explicitly checked and ignored because
            // they are not complete yet (no character).
          default:
            if (e.keyCode != SWT.CAPS_LOCK
                && e.keyCode != SWT.NUM_LOCK
                && e.keyCode != SWT.MOD1
                && e.keyCode != SWT.MOD2
                && e.keyCode != SWT.MOD3
                && e.keyCode != SWT.MOD4) {
              close();
            }
            return;
        }

        // If any of these navigation events caused a new selection,
        // then handle that now and return.
        if (newSelection >= 0) {
          selectProposal(newSelection);
        }
        return;
      }

      // key != 0
      // Check for special keys involved in cancelling, accepting, or
      // filtering the proposals.
      switch (key) {
        case SWT.ESC:
          e.doit = false;
          close();
          break;

        case SWT.LF:
        case SWT.CR:
          e.doit = false;
          Object p = getSelectedProposal();
          if (p != null) {
            acceptCurrentProposal();
          } else {
            close();
          }
          break;

        case SWT.TAB:
          e.doit = false;
          getShell().setFocus();
          return;

        case SWT.BS:
          // There is no filtering provided by us, but some
          // clients provide their own filtering based on content.
          // Recompute the proposals if the cursor position
          // will change (is not at 0).
          int pos = adapter.getControlContentAdapter().getCursorPosition(control);
          // We rely on the fact that the contents and pos do not yet
          // reflect the result of the BS. If the contents were
          // already empty, then BS should not cause
          // a recompute.
          if (pos > 0) {
            asyncRecomputeProposals();
          }
          break;

        default:
          // If the key is a defined unicode character, and not one of
          // the special cases processed above, update the filter text
          // and filter the proposals.
          if (Character.isDefined(key)) {
            // Recompute proposals after processing this event.
            asyncRecomputeProposals();
          }
          break;
      }
    }