@SuppressWarnings("unchecked")
  private void doSuggest(final String cmd, final String id, final JSONArray paramArray) {
    final SpellChecker checker = new SpellChecker(dict);
    String word = paramArray.optString(1);
    List<String> suggestions = checker.getSuggestions(word, 2);

    respond(suggestions.iterator(), cmd, id);
  }
  private void doSpell(final String cmd, final String id, final JSONArray paramArray) {
    final SpellChecker checker = new SpellChecker(dict);

    final Set<String> errors = new HashSet<String>();

    checker.addSpellCheckListener(
        new SpellCheckListener() {
          public void spellingError(SpellCheckEvent event) {
            errors.add(event.getInvalidWord());
          }
        });

    JSONArray words = paramArray.optJSONArray(1);
    checker.checkSpelling(new StringWordTokenizer(words.toString()));
    respond(errors.iterator(), cmd, id);
  }
Exemple #3
0
    protected IStatus doRun(final IProgressMonitor monitor) {
      start = System.currentTimeMillis();
      if (monitor.isCanceled() || display.isDisposed() || !isActive()) return Status.CANCEL_STATUS;

      final String[] context = new String[1];
      display.syncExec(
          new Runnable() {
            public void run() {
              if (monitor.isCanceled() || display.isDisposed() || !isActive()) return;
              context[0] = contentAdapter.getControlContents(control);
            }
          });
      if (monitor.isCanceled() || display.isDisposed() || !isActive()) return Status.CANCEL_STATUS;

      if (context[0] == null || "".equals(context[0])) { // $NON-NLS-1$
        if (!ranges.isEmpty()) {
          ranges.clear();
          redraw(display);
        }
        return Status.OK_STATUS;
      }

      while (System.currentTimeMillis() < start + CHECK_DELAY) {
        if (monitor.isCanceled() || display.isDisposed() || !isActive())
          return Status.CANCEL_STATUS;
        try {
          Thread.sleep(1);
        } catch (InterruptedException e) {
          return Status.CANCEL_STATUS;
        }
      }
      start = -2;
      if (monitor.isCanceled() || display.isDisposed() || !isActive()) return Status.CANCEL_STATUS;

      display.syncExec(
          new Runnable() {
            public void run() {
              if (monitor.isCanceled() || display.isDisposed() || !isActive()) return;
              context[0] = contentAdapter.getControlContents(control);
            }
          });

      if (monitor.isCanceled() || display.isDisposed() || !isActive()) return Status.CANCEL_STATUS;

      if (context[0] != null) {
        ranges.clear();

        if (!"".equals(context[0])) { // $NON-NLS-1$
          SpellChecker theSpellChecker = spellChecker;
          theSpellChecker.addSpellCheckListener(this);
          theSpellChecker.checkSpelling(new StringWordTokenizer(context[0]));
          theSpellChecker.removeSpellCheckListener(this);
        }
        if (monitor.isCanceled() || display.isDisposed() || !isActive())
          return Status.CANCEL_STATUS;

        redraw(display);
      }

      return Status.OK_STATUS;
    }