title: Enable Copy/paste across different applications
body: <p>The default context menu of SWT <code>Text</code> in windows has several options that we did not want. As the default context menu is provided by the operating system and cannot be modified, I created a custom context menu with only basic Text operations such as delete, cut, copy and paste for the Text boxes.</p>
  
  <p><img src="https://i.stack.imgur.com/oKhRB.png" alt="Custom Text context Menu"></p>
  
  <p>The problem now is that when I copy text from another application and try pasting into the TextBox, the paste doesn't seem to work. But it works when we copy/cut text within the application itself.</p>
  
  <p>Here is the code for copy and paste.
  Paste Action:</p>
  
  <pre><code>private class PasteActionHandler extends Action {
  
      /** Creates a new instance. */
      private PasteActionHandler() {
          ...
          setEnabled(false);
      }
  
      @Override
      public void runWithEvent(Event event) {
          if (activeTextControl != null &amp;&amp; !activeTextControl.isDisposed()) {
              activeTextControl.paste();
              updateActionsEnableState();
              return;
          }
      }
  
      /**
       * Updates the state of the Paste Action.
       */
      public void updateEnabledState() {
          if (activeTextControl != null &amp;&amp; !activeTextControl.isDisposed()) {
              boolean canPaste = false;
              if (activeTextControl.getEditable()) {
                  Clipboard clipboard = new Clipboard(activeTextControl.getDisplay());
                  TransferData[] td = clipboard.getAvailableTypes();
                  for (int i = 0; i &lt; td.length; ++i) {
                      if (TextTransfer.getInstance().isSupportedType(td[i])) {
                          canPaste = true;
                          break;
                      }
                  }
                  clipboard.dispose();
              }
              setEnabled(canPaste);
              return;
          }
          setEnabled(false);
      }
  }
  </code></pre>
  
  <p>Copy Action:</p>
  
  <pre><code>private class CopyActionHandler extends Action {
  
      private CopyActionHandler() {
          ...
          setEnabled(false);
      }
  
      @Override
      public void runWithEvent(Event event) {
          if (activeTextControl != null &amp;&amp; !activeTextControl.isDisposed()) {
              activeTextControl.copy();
              updateActionsEnableState();
              return;
          }
      }
  
      /**
       * Updates the state of the {@link Action}.
       */
      public void updateEnabledState() {
          if (activeTextControl != null &amp;&amp; !activeTextControl.isDisposed()) {
              setEnabled(activeTextControl.getSelectionCount() &gt; 0);
              return;
          }
          setEnabled(false);
      }
  }
  </code></pre>
  
  <p>As you could see, I call the Text control's copy and paste functions to do the operations.
  Also is there a way in SWT to get the system clipboard?</p>