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.core.model.URL; 27 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants; 28 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin; 29 30 import org.eclipse.jface.resource.ImageDescriptor; 31 import org.eclipse.swt.dnd.TextTransfer; 32 import org.eclipse.swt.dnd.Transfer; 33 34 35 41 public class CopyUrlAction extends BrowserAction 42 { 43 44 47 public CopyUrlAction() 48 { 49 } 50 51 52 55 public void run() 56 { 57 URL url = null; 58 if ( getSelectedSearches().length > 0 ) 59 { 60 url = getSelectedSearches()[0].getUrl(); 61 } 62 else if ( getSelectedEntries().length > 0 ) 63 { 64 url = getSelectedEntries()[0].getUrl(); 65 } 66 else if ( getSelectedAttributes().length > 0 ) 67 { 68 url = getSelectedAttributes()[0].getEntry().getUrl(); 69 } 70 else if ( getSelectedAttributeHierarchies().length > 0 ) 71 { 72 url = getSelectedAttributeHierarchies()[0].getAttribute().getEntry().getUrl(); 73 } 74 else if ( getSelectedValues().length > 0 ) 75 { 76 url = getSelectedValues()[0].getAttribute().getEntry().getUrl(); 77 } 78 else if ( getSelectedSearchResults().length > 0 ) 79 { 80 url = getSelectedSearchResults()[0].getEntry().getUrl(); 81 } 82 else if ( getSelectedBookmarks().length > 0 ) 83 { 84 url = getSelectedBookmarks()[0].getEntry().getUrl(); 85 } 86 87 if ( url != null ) 88 { 89 CopyAction.copyToClipboard( new Object [] 90 { url.toString() }, new Transfer[] 91 { TextTransfer.getInstance() } ); 92 } 93 } 94 95 96 99 public String getText() 100 { 101 return "Copy URL"; 102 } 103 104 105 108 public ImageDescriptor getImageDescriptor() 109 { 110 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_COPY_URL ); 111 } 112 113 114 117 public String getCommandId() 118 { 119 return null; 120 } 121 122 123 126 public boolean isEnabled() 127 { 128 return getSelectedSearches().length + getSelectedEntries().length + getSelectedSearchResults().length 129 + getSelectedBookmarks().length == 1 130 || getSelectedAttributes().length + getSelectedValues().length > 0; 131 } 132 } 133 | Popular Tags |