处理 Eclipse Package Explorer 中的文件拖放

发布于 2024-10-16 02:40:07 字数 410 浏览 7 评论 0原文

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

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

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

有人有什么想法吗?我的 DropActionDelegate 是否走在正确的轨道上?

I'm trying to create an Eclipse plugin to support a proprietary project file format. My goal is to be able to drag and drop a file in the Project Explorer (any type of file) onto a file of the type I support, and have the name of the file being dragged appended to the end of the proprietary file.

Right now, I have a custom editor that can parse out some data from an existing file in a manageable way. This means that I have an editor associated with the file type, such that my special icon shows up next to it. I don't know if that's relevant.

I'm attempting to use the extension point "org.eclipse.ui.dropActions" but I'm not sure how to register my DropActionDelegate (implements org.eclipse.ui.part.IDropActionDelegate) such that it will be called when a file is dropped onto one of my type within the Project Explorer.

Anybody have any ideas? Am I even on the right track with the DropActionDelegate?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魂ガ小子 2024-10-23 02:40:07

您正在正确实施 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 的目的是为您不需要的视图提供放置行为没有定义自己(如项目资源管理器)。

您注册 删除操作扩展,如下所示:

<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) {
}

}

You are on the right track implementing an 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
    }
}

The purpose of the extension point org.eclipse.ui.dropActions is to provide drop behaviour to views which you don't have defined yourself (like the Project Explorer).

You register the drop action extension like this:

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

Don't forget to attach an adequate listener to your editor in your plugin code:

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) {
}

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文