在RCP Password Gate中,用户可以复制节点的密码,此功能将密码复制到操作系统的剪贴板中,方便用户粘贴到别的需要添入密码的控件中。
实现这个功能是用了一个Action,在Action中复制信息到系统剪切板中。
<!--CTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt--><style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- ======================================================== --><!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = --><!-- = Further information: http://www.java2html.de = -->
ClipboardCopyAction.java
01 publicabstractclass ClipboardCopyAction extends SelectionProviderAction { 02 03 public ClipboardCopyAction ( ISelectionProviderprovider ){ 04 super ( provider, null ) ; 05 setImageDescriptor ( ImageShop.getDescriptor ( "copy" )) ; 06 } 07 08 public void selectionChanged ( IStructuredSelectionselection ){ 09 boolean enable= false ; 10 if ( selection.size () == 1 ){ 11 Objecto=selection.getFirstElement () ; 12 if ( o instanceof Record ){ 13 enable= true ; 14 } 15 } 16 setEnabled ( enable ) ; 17 } 18 19 public void run (){ 20 Clipboardcb= new Clipboard ( Display.getCurrent ()) ; 21 try { 22 StringtextData=getTextData () ; 23 TextTransfertextTransfer=TextTransfer.getInstance () ; 24 cb.setContents ( new Object []{ textData } , 25 new Transfer []{ textTransfer }) ; 26 } catch ( IOExceptionex ){ 27 PwdgatePlugin.log ( "copytoclipboard" ,ex ) ; 28 } 29 } 30 31 publicabstract StringgetTextData () throws IOException; 32 33 }
<!-- = END of automatically generated HTML code = --><!-- ======================================================== -->
Row 22,åå°è¦å¤å¶çæåä¿¡æ¯ï¼R23-25,å°æåå¤å¶å°ç³»ç»åªåæ¿ä¸ãå¤å¶çåå®¹ææ¤ç±»çåç±»æä¾ã