0
votes

I'm developing an IDE plugin with Eclipse at work and need to create a custom import function that adds an existing project into the Project Explorer tree WITHOUT copying the files into the workspace. Ideally the user will be able to import an existing project into the Project Explorer Tree by providing the program with a project directory via a custom import wizard. I'm able to access the Project Explorer tree with the jface AbstractTreeViewer but I'm having difficulties adding to it with the 'add()' function. Specifically I'm not sure what information I need to provide into the 'parentElementOrTreePath' and 'childElement' fields.

The code I'm currently working with is thus:

final IWorkbenchPart activePart = getActivePart();
    if (activePart != null && activePart instanceof IPackagesViewPart) {
        AbstractTreeViewer tree = ((IPackagesViewPart) activePart).getTreeViewer();
        tree.add(parentElementOrTreePath, childElement);
    }
1
Code like that is just not going to work. The tree viewer will be using a content provider and many actions are going to refresh the view from the provider losing any changes you have made. Also IPackagesViewPart is the Packages Explorer view not the Project Explorer view.greg-449
Oh my mistake I got them mixed up but the idea is the same. Is something like this not possible in Eclipse?Grant Sherman

1 Answers

0
votes

Code like that is just not going to work. The tree viewer will be using a content provider and many actions are going to refresh the view from the provider losing any changes you have made. Also IPackagesViewPart is the Packages Explorer view not the Project Explorer view.

You can only add to views like this using proper interfaces and extension points that Eclipse provides. You can't just try and hack things. You aren't going to get things that are not in the workspace to show in the Packages/Project view - everything these views do expect proper workspace objects.

It is possible to use the IFolder.createLink and IFile.createLink methods to create links to objects outside of the workspace.