title: SWT: get number of characters that are about to be deleted from Text widget
body: <p>I am validating inputs from some SWT Text widgets.<br>
  Assume a user selects some portion of the text he himself inserted into the widget by using the mouse or <code>Ctrl. + A</code> etc. and then presses delete; how do I get the number of characters that are about to be deleted? I am using a SWT verify event for the input validation. The documentation says that event.text will give "the new text that will be inserted.[...]" and has the ability to modify the text that will be deleted, but I am unable to find a way to just get the amount of text that will be deleted. </p>
  
  <p>Google didn't give me the answer either. Has anybody a idea how to achieve this?</p>
  
  <p>As the actual code is rather lengthy, I had to cut the unnecessary parts for posting it here:</p>
  
  <p>The purpose of the code is to take 32 Hexadecimal digits and allowing Copy/Paste.</p>
  
  <pre><code>int len = 0;
  // input is a SWT Text widget with initial text set to ""
  input.addVerifyListener(new VerifyListener() {
      public void verifyText(VerifyEvent e){
          e.doit = false;
          int addit = 0;
          // do nothing when there are already 32 characters in the widget
          if (len == 32){
              return;
          }
          // allow Ctrl + v to paste
          if(((e.stateMask &amp; SWT.CTRL) == SWT.CTRL) &amp;&amp; (e.keyCode == 'v') &amp;&amp; (len + e.text.length()) &lt;= 32){
              e.doit = true;
              // here it works like a charm
              addit = e.text.length();
          }
          // allow deleting characters: Problem: deleting multiple characters at a time
          if (e.keyCode == SWT.BS || e.keyCode == SWT.DEL){
              e.doit = true;
              addit = ???;    // this is the problem: how many characters are deleted, when the key is pressed
          }
          // isHex is a function that checks, weather e.character is a hexadecimal digit
          if (isHex(e.character) || Character.isDigit(e.character) &amp;&amp; len+1 &lt;= 32){
              e.doit = true;
              addit = 1;
          } else if (e.keyCode != SWT.BS &amp;&amp; e.keyCode != SWT.BS &amp;&amp; ((e.stateMask &amp; SWT.CTRL) != SWT.CTRL) &amp;&amp; e.keyCode != 'v') {
              System.out.println(e.character + " is not valid");
              return;
          }
          len += addit;
          if (len == 32){
              somemethod();
          }
          // print how many characters are there the moment the user types or deletes them
          System.out.println((32 - len) + "chars");
      }});
  }
  </code></pre>