1 20 21 package org.apache.directory.ldapstudio.browser.ui.actions; 22 23 24 import java.util.Iterator ; 25 import java.util.LinkedHashSet ; 26 import java.util.Set ; 27 28 import org.apache.directory.ldapstudio.browser.common.actions.BrowserAction; 29 import org.apache.directory.ldapstudio.browser.common.actions.CopyAction; 30 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants; 31 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 32 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants; 33 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin; 34 35 import org.eclipse.jface.resource.ImageDescriptor; 36 import org.eclipse.swt.dnd.TextTransfer; 37 import org.eclipse.swt.dnd.Transfer; 38 39 40 46 public class CopyAttributeDescriptionAction extends BrowserAction 47 { 48 49 52 public CopyAttributeDescriptionAction() 53 { 54 } 55 56 57 60 public void run() 61 { 62 StringBuffer text = new StringBuffer (); 63 for ( Iterator iterator = getAttributeNameSet().iterator(); iterator.hasNext(); ) 64 { 65 text.append( iterator.next() ); 66 if ( iterator.hasNext() ) 67 text.append( BrowserCoreConstants.LINE_SEPARATOR ); 68 } 69 70 if ( text.length() > 0 ) 71 { 72 CopyAction.copyToClipboard( new Object [] 73 { text.toString() }, new Transfer[] 74 { TextTransfer.getInstance() } ); 75 } 76 } 77 78 79 85 private Set getAttributeNameSet() 86 { 87 Set <String > attributeNameSet = new LinkedHashSet <String >(); 88 for ( int i = 0; i < getSelectedAttributeHierarchies().length; i++ ) 89 { 90 for ( Iterator it = getSelectedAttributeHierarchies()[i].iterator(); it.hasNext(); ) 91 { 92 IAttribute att = ( IAttribute ) it.next(); 93 attributeNameSet.add( att.getDescription() ); 94 } 95 } 96 for ( int i = 0; i < getSelectedAttributes().length; i++ ) 97 { 98 attributeNameSet.add( getSelectedAttributes()[i].getDescription() ); 99 } 100 for ( int i = 0; i < getSelectedValues().length; i++ ) 101 { 102 attributeNameSet.add( getSelectedValues()[i].getAttribute().getDescription() ); 103 } 104 return attributeNameSet; 105 } 106 107 108 111 public String getText() 112 { 113 if ( getAttributeNameSet().size() > 1 ) 114 { 115 return "Copy Attribute Descriptions"; 116 } 117 else 118 { 119 return "Copy Attribute Description"; 120 } 121 } 122 123 124 127 public ImageDescriptor getImageDescriptor() 128 { 129 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_COPY_ATT ); 130 } 131 132 133 136 public String getCommandId() 137 { 138 return null; 139 } 140 141 142 145 public boolean isEnabled() 146 { 147 return getAttributeNameSet().size() > 0; 148 } 149 } 150 | Popular Tags |