eclipse - 在 Eclipse Package Explorer 中处理文件的拖放

标签 eclipse eclipse-plugin drag-and-drop eclipse-pde

我正在尝试创建一个 Eclipse 插件来支持专有项目文件格式。我的目标是能够将项目资源管理器中的文件(任何类型的文件)拖放到我支持的类型的文件上,并将被拖动文件的名称附加到专有文件的末尾。

现在,我有一个自定义编辑器,可以以可管理的方式从现有文件中解析出一些数据。这意味着我有一个与文件类型相关联的编辑器,这样我的特殊图标就会显示在它旁边。我不知道这是否相关。

我正在尝试使用扩展点“org.eclipse.ui.dropActions”,但我不确定如何注册我的 DropActionDelegate(实现 org.eclipse.ui.part.IDropActionDelegate),以便在文件被放到项目资源管理器中我的一种类型上。

有人有任何想法吗?我使用 DropActionDelegate 是否走在正确的轨道上?

最佳答案

您正走在实现 IDropActionDelegate 的正确轨道上:

class DropActionDelegate implements IDropActionDelegate {

    @Override
    public boolean run(Object source, Object target) {
        String transferredData (String) target; // whatever type is needed  
        return true; // if drop successful
    }
}

扩展点的用途 org.eclipse.ui.dropActions是为您没有定义自己的 View (如项目资源管理器)提供放置行为。

您注册 drop action extension像这样:

<extension point="org.eclipse.ui.dropActions"> 
        <action 
            id="my_drop_action" 
            class="com.xyz.DropActionDelegate"> 
        </action> 
</extension>

不要忘记在你的插件代码中为你的编辑器附加一个足够的监听器:

class DragListener implements DragSourceListener {

@Override
public void dragStart(DragSourceEvent event) {
}

@Override
public void dragSetData(DragSourceEvent event) {
    PluginTransferData p;
    p = new PluginTransferData(
        "my_drop_action", // must be id of registered drop action
         "some_data" // may be of arbitrary type
        );
    event.data = p;
}

@Override
public void dragFinished(DragSourceEvent event) {
}

}

关于eclipse - 在 Eclipse Package Explorer 中处理文件的拖放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4893194/

相关文章:

java - Eclipse 的代码感知风格自动完成

c# - 在没有 Storyboard 的情况下以编程方式创建 float 的可拖动按钮(Xamarin)

html - 使用 Google Doc AddOn 的 Apps 脚本处理 'drop' 事件

java - 如何导出小程序以及引用的库

eclipse - 如何更改 Eclipse 更新管理器的 'Read timeout' 值?

java - 开发 Eclipse Content Assist 插件

eclipse - 如何在 GoClipse 中启用自动完成?

reactjs - React-beautiful-dnd 在 next.js 上不可拖动

java - arraylist 给出 "cannot be resolved"和 "cannot be resolved to a type"错误(eclipse)

android - 为什么从 windows 和 mac 构建时 android apk 大小不同