1 11 package org.eclipse.ui.internal.navigator.dnd; 12 13 import org.eclipse.core.runtime.IStatus; 14 import org.eclipse.jface.util.LocalSelectionTransfer; 15 import org.eclipse.jface.viewers.IStructuredSelection; 16 import org.eclipse.ui.navigator.CommonDropAdapterAssistant; 17 import org.eclipse.ui.navigator.INavigatorContentService; 18 import org.eclipse.ui.part.IDropActionDelegate; 19 import org.eclipse.ui.part.PluginTransferData; 20 21 27 public class NavigatorPluginDropAction implements IDropActionDelegate { 28 29 private static final boolean DEBUG = false; 30 31 private static final String CN_PLUGIN_ACTION_ID = "org.eclipse.ui.navigator.PluginDropAction"; 33 37 public NavigatorPluginDropAction() { 38 super(); 39 } 40 41 47 public boolean run(Object sourceData, Object target) { 48 49 if (DEBUG) { 50 System.out.println("NavigatorPluginDropAction.run (begin)"); } 52 53 String sourceViewerId = new String ((byte[]) sourceData); 54 55 IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer 56 .getTransfer().getSelection(); 57 58 INavigatorContentService contentService = NavigatorContentServiceTransfer 59 .getInstance().findService(sourceViewerId); 60 61 if (contentService == null) { 62 return false; 63 } 64 try { 65 CommonDropAdapterAssistant[] assistants = contentService 66 .getDnDService().findCommonDropAdapterAssistants(target, 67 selection); 68 69 IStatus valid = null; 70 for (int i = 0; i < assistants.length; i++) { 71 valid = assistants[i].validatePluginTransferDrop(selection, target); 72 if (valid != null && valid.isOK()) { 73 valid = assistants[i].handlePluginTransferDrop(selection, target); 74 return valid != null && valid.isOK(); 75 } 76 } 77 } finally { 78 NavigatorContentServiceTransfer.getInstance() 79 .unregisterContentService(contentService); 80 } 81 82 if (DEBUG) { 83 System.out.println("NavigatorPluginDropAction.run (exit)"); } 85 86 return false; 87 } 88 89 96 public static PluginTransferData createTransferData( 97 INavigatorContentService aContentService) { 98 NavigatorContentServiceTransfer.getInstance().registerContentService( 99 aContentService); 100 return new PluginTransferData(CN_PLUGIN_ACTION_ID, aContentService 101 .getViewerId().getBytes()); 102 } 103 104 } 105 | Popular Tags |