简体   繁体   中英

How to open a new editor using dnd in Eclipse RCP 3

I need to create drag and drop for my app.

I have a tree in the left part of the window and empty editor area in the right part of the window. I want to drag an element from the tree and drop to the right part. Editor tab should opens after that.

截图

What I have already done: I created the button to open editor of selected tree item and it works. When I drag item and drop it to the existed editor a new editor opens. But I can't to do the same when I don't have any editor (only empty editor area)

Please tell me what should I do or what should I specify like target for drop action. Thanks in advance!

In your RCP's worbench window advisor class you need to set up the editor area drag/drop transfer types and the drop adapter in the preWindowOpen method.

For example Eclipse itself uses:

public void preWindowOpen() {
    IWorkbenchWindowConfigurer configurer = getWindowConfigurer();

    configurer.addEditorAreaTransfer(EditorInputTransfer.getInstance());
    configurer.addEditorAreaTransfer(ResourceTransfer.getInstance());
    configurer.addEditorAreaTransfer(FileTransfer.getInstance());
    configurer.addEditorAreaTransfer(MarkerTransfer.getInstance());

    configurer.configureEditorAreaDropListener(new EditorAreaDropAdapter(
            configurer.getWindow()));

Note that EditorAreaDropAdapter is an internal class so you can't use it, you will have to write your own drop adapter. This is likely to end up calling IWorbenchPage.openEditor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM