public int getCaretPosition() {
   if (BUG_106024_TEXT_SELECTION) {
     selectionChanged();
     return fCaretPosition;
   } else {
     return fText.getCaretPosition();
   }
 }
  public void widgetSelected(SelectionEvent e) {
    //        String fileName = Util.substituteVar(fPomDirName.getText());
    //        if(!isDirectoryExist(fileName)) {
    //          MessageDialog.openError(getShell(), Messages.getString("launch.errorPomMissing"),
    //              Messages.getString("launch.errorSelectPom")); //$NON-NLS-1$ //$NON-NLS-2$
    //          return;
    //        }
    MavenGoalSelectionDialog dialog = new MavenGoalSelectionDialog(shell);
    int rc = dialog.open();
    if (rc == IDialogConstants.OK_ID) {
      text.insert(""); // clear selected text

      String txt = text.getText();
      int len = txt.length();
      int pos = text.getCaretPosition();

      StringBuffer sb = new StringBuffer();
      if ((pos > 0 && txt.charAt(pos - 1) != ' ')) {
        sb.append(' ');
      }

      String sep = "";
      Object[] o = dialog.getResult();
      for (int i = 0; i < o.length; i++) {
        if (o[i] instanceof MavenGoalSelectionDialog.Entry) {
          if (dialog.isQualifiedName()) {
            sb.append(sep).append(((MavenGoalSelectionDialog.Entry) o[i]).getQualifiedName());
          } else {
            sb.append(sep).append(((MavenGoalSelectionDialog.Entry) o[i]).getName());
          }
        }
        sep = " ";
      }

      if (pos < len && txt.charAt(pos) != ' ') {
        sb.append(' ');
      }

      text.insert(sb.toString());
      text.setFocus();
    }
  }
示例#3
0
    public void keyPressed(KeyEvent e) {
      Text portsText = (Text) e.getSource();

      if (e.keyCode == SWT.TAB) {
        portsText.getShell().traverse(SWT.TRAVERSE_TAB_NEXT);
        e.doit = false;
        return;
      } else if (e.keyCode == SWT.CR) {
        if ((e.stateMask & SWT.MOD1) > 0) {
          // allow ctrl+enter to insert newlines
          e.stateMask = 0;
        } else {
          // single-enter will traverse
          portsText.getShell().traverse(SWT.TRAVERSE_RETURN);
          e.doit = false;
          return;
        }
      } else if (Character.isISOControl(e.character)) {
        return;
      }

      e.doit = validateChar(e.character, portsText.getText(), portsText.getCaretPosition());
    }
示例#4
0
文件: Text_Test.java 项目: ciancu/rap
 @Test
 public void testGetCaretPosition() {
   Text text = new Text(shell, SWT.SINGLE);
   text.setText("Sample text");
   assertEquals(0, text.getCaretPosition());
   text.setSelection(5);
   assertEquals(5, text.getCaretPosition());
   text.setSelection(3, 8);
   assertEquals(3, text.getCaretPosition());
   text.setSelection(8, 5);
   assertEquals(5, text.getCaretPosition());
   text.setText("New text");
   assertEquals(0, text.getCaretPosition());
   text.setSelection(3, 8);
   text.clearSelection();
   assertEquals(new Point(8, 8), text.getSelection());
   assertEquals(8, text.getCaretPosition());
 }