1 20 21 package org.apache.directory.ldapstudio.browser.ui.editors.searchresult; 22 23 24 import org.apache.directory.ldapstudio.browser.common.actions.PasteAction; 25 import org.apache.directory.ldapstudio.browser.common.dnd.ValuesTransfer; 26 import org.apache.directory.ldapstudio.browser.core.jobs.CreateValuesJob; 27 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 28 import org.apache.directory.ldapstudio.browser.core.model.IValue; 29 30 31 35 public class SearchResultEditorPasteAction extends PasteAction 36 { 37 38 public SearchResultEditorPasteAction() 39 { 40 super(); 41 } 42 43 44 public String getText() 45 { 46 IValue[] values = getValuesToPaste(); 47 if ( values != null ) 48 { 49 return values.length > 1 ? "Paste Values" : "Paste Value"; 50 } 51 52 return "Paste"; 53 } 54 55 56 public boolean isEnabled() 57 { 58 if ( this.getValuesToPaste() != null ) 59 { 60 return true; 61 } 62 63 return false; 64 } 65 66 67 public void run() 68 { 69 IValue[] values = getValuesToPaste(); 70 if ( values != null ) 71 { 72 73 String attributeDescription = getSelectedAttributeHierarchies()[0].getAttribute().getDescription(); 74 75 String [] attributeDescriptions = new String [values.length]; 76 Object [] rawValues = new Object [values.length]; 77 for ( int v = 0; v < values.length; v++ ) 78 { 79 attributeDescriptions[v] = attributeDescription; 80 rawValues[v] = values[v].getRawValue(); 81 } 82 IEntry entry = getSelectedAttributeHierarchies()[0].getAttribute().getEntry(); 83 84 new CreateValuesJob( entry, attributeDescriptions, rawValues ).execute(); 85 } 86 } 87 88 89 95 private IValue[] getValuesToPaste() 96 { 97 if ( getSelectedEntries().length + getSelectedBookmarks().length + getSelectedValues().length 98 + getSelectedAttributes().length + getSelectedSearches().length + getSelectedConnections().length == 0 99 && getSelectedSearchResults().length == 1 100 && getSelectedAttributeHierarchies().length == 1 101 && getSelectedAttributeHierarchies()[0].size() == 1 ) 102 { 103 104 Object content = this.getFromClipboard( ValuesTransfer.getInstance() ); 105 if ( content != null && content instanceof IValue[] ) 106 { 107 IValue[] values = ( IValue[] ) content; 108 return values; 109 } 110 111 } 119 120 return null; 121 } 122 123 } 124 | Popular Tags |