Exemplo n.º 1
0
 /* (non-Javadoc)
  * Method declared on DropTargetAdapter.
  * The user has dropped something on the desktop viewer.
  */
 public void drop(DropTargetEvent event) {
   try {
     if (PluginTransfer.getInstance().isSupportedType(event.currentDataType)) {
       PluginTransferData pluginData = (PluginTransferData) event.data;
       IDropActionDelegate delegate = getPluginAdapter(pluginData);
       if (!delegate.run(pluginData.getData(), getCurrentTarget())) {
         event.detail = DND.DROP_NONE;
       }
     } else {
       super.drop(event);
     }
   } catch (CoreException e) {
     WorkbenchPlugin.log("Drop Failed", e.getStatus()); // $NON-NLS-1$
   }
 }
Exemplo n.º 2
0
  /**
   * Loads the class that will perform the action associated with the given drop data.
   *
   * @param data the drop data
   * @return the viewer drop adapter
   */
  protected static IDropActionDelegate getPluginAdapter(PluginTransferData data)
      throws CoreException {

    IExtensionRegistry registry = Platform.getExtensionRegistry();
    String adapterName = data.getExtensionId();
    IExtensionPoint xpt =
        registry.getExtensionPoint(
            PlatformUI.PLUGIN_ID, IWorkbenchRegistryConstants.PL_DROP_ACTIONS);
    IExtension[] extensions = xpt.getExtensions();
    for (int i = 0; i < extensions.length; i++) {
      IConfigurationElement[] configs = extensions[i].getConfigurationElements();
      if (configs != null && configs.length > 0) {
        for (int j = 0; j < configs.length; j++) {
          String id = configs[j].getAttribute("id"); // $NON-NLS-1$
          if (id != null && id.equals(adapterName)) {
            return (IDropActionDelegate) WorkbenchPlugin.createExtension(configs[j], ATT_CLASS);
          }
        }
      }
    }
    return null;
  }