1 20 21 package org.apache.directory.ldapstudio.browser.ui.actions; 22 23 24 import org.apache.directory.ldapstudio.browser.common.actions.BrowserAction; 25 import org.apache.directory.ldapstudio.browser.common.actions.CopyAction; 26 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants; 27 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin; 28 import org.eclipse.jface.resource.ImageDescriptor; 29 import org.eclipse.swt.dnd.TextTransfer; 30 import org.eclipse.swt.dnd.Transfer; 31 32 33 39 public class CopyDnAction extends BrowserAction 40 { 41 42 45 public CopyDnAction() 46 { 47 } 48 49 50 53 public void run() 54 { 55 String dn = null; 56 if ( getSelectedEntries().length > 0 ) 57 { 58 dn = getSelectedEntries()[0].getDn().toString(); 59 } 60 else if ( getSelectedAttributes().length > 0 ) 61 { 62 dn = getSelectedAttributes()[0].getEntry().getDn().toString(); 63 } 64 else if ( getSelectedAttributeHierarchies().length > 0 ) 65 { 66 dn = getSelectedAttributeHierarchies()[0].getAttribute().getEntry().getDn().toString(); 67 } 68 else if ( getSelectedValues().length > 0 ) 69 { 70 dn = getSelectedValues()[0].getAttribute().getEntry().getDn().toString(); 71 } 72 else if ( getSelectedSearchResults().length > 0 ) 73 { 74 dn = getSelectedSearchResults()[0].getDn().toString(); 75 } 76 else if ( getSelectedBookmarks().length > 0 ) 77 { 78 dn = getSelectedBookmarks()[0].getDn().toString(); 79 } 80 81 if ( dn != null ) 82 { 83 CopyAction.copyToClipboard( new Object [] 84 { dn }, new Transfer[] 85 { TextTransfer.getInstance() } ); 86 } 87 } 88 89 90 93 public String getText() 94 { 95 return "Copy DN"; 96 } 97 98 99 102 public ImageDescriptor getImageDescriptor() 103 { 104 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_COPY_DN ); 105 } 106 107 108 111 public String getCommandId() 112 { 113 return null; 114 } 115 116 117 120 public boolean isEnabled() 121 { 122 return getSelectedEntries().length + getSelectedSearchResults().length + getSelectedBookmarks().length == 1 123 || getSelectedAttributes().length + getSelectedValues().length > 0; 124 } 125 } 126 | Popular Tags |