Package org.rstudio.studio.client.common.spelling.model

Examples of org.rstudio.studio.client.common.spelling.model.SpellCheckerResult


   public void checkSpelling(
                     List<String> words,
                     final ServerRequestCallback<SpellCheckerResult> callback)
   {
      // results to return
      final SpellCheckerResult spellCheckerResult = new SpellCheckerResult();
     
      // only send words to the server that aren't in the cache
      final ArrayList<String> wordsToCheck = new ArrayList<String>();
      for (int i = 0; i<words.size(); i++)
      {
         String word = words.get(i);
         Boolean isCorrect = previousResults_.get(word);
         if (isCorrect != null)
         {
            if (isCorrect)
               spellCheckerResult.getCorrect().add(word);
            else
               spellCheckerResult.getIncorrect().add(word);
         }
         else
         {
            wordsToCheck.add(word);
         }
      }
     
      // if there are no words to check then return
      if (wordsToCheck.size() == 0)
      {
         callback.onResponseReceived(spellCheckerResult);
         return;
      }
     
      // hit the server
      server_.checkSpelling(JsUtil.toJsArrayString(wordsToCheck),
                            new ServerRequestCallback<JsArrayInteger>() {

         @Override
         public void onResponseReceived(JsArrayInteger result)
         {
            // get misspelled indexes
            ArrayList<Integer> misspelledIndexes = new ArrayList<Integer>();
            for (int i=0; i<result.length(); i++)
               misspelledIndexes.add(result.get(i));
           
            // determine correct/incorrect status and populate result & cache
            for (int i=0; i<wordsToCheck.size(); i++)
            {
               String word = wordsToCheck.get(i);
               if (misspelledIndexes.contains(i))
               {
                  spellCheckerResult.getIncorrect().add(word);
                  previousResults_.put(word, false);
               }
               else
               {
                  spellCheckerResult.getCorrect().add(word);
                  previousResults_.put(word,  true);
               }
            }
           
            // return result
View Full Code Here


   public void checkSpelling(
                  List<String> words,
                  final ServerRequestCallback<SpellCheckerResult> callback)
   {
      // allocate results
      final SpellCheckerResult spellCheckerResult = new SpellCheckerResult();

      if (words.isEmpty())
      {
         callback.onResponseReceived(spellCheckerResult);
         return;
      }
     
      // only send words to the server that aren't ignored
      final ArrayList<String> wordsToCheck = new ArrayList<String>();
      for (int i = 0; i<words.size(); i++)
      {
         String word = words.get(i);
         if (isWordIgnored(word))
            spellCheckerResult.getCorrect().add(word);
         else
            wordsToCheck.add(word);
      }
     
      // call the service to check the non-ignored words
      spellingService_.checkSpelling(
         wordsToCheck,
         new ServerRequestCallback<SpellCheckerResult>() {

            @Override
            public void onResponseReceived(SpellCheckerResult result)
            {
               spellCheckerResult.getCorrect().addAll(result.getCorrect());
               spellCheckerResult.getIncorrect().addAll(result.getIncorrect());
               callback.onResponseReceived(spellCheckerResult);
            }
           
            @Override
            public void onError(ServerError error)
View Full Code Here

TOP

Related Classes of org.rstudio.studio.client.common.spelling.model.SpellCheckerResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.