views:

530

answers:

1

Hi, I want to open the "Ctrl-Shift-T" dialog (find a type) programmatically in eclipse plug-in. I tried the FilteredItemsSelectionDialog and ResourceListSelectionDialog, but how do I get all the types in the workspace?

Thank you, Ido.

+1  A: 

Look at org.eclipse.jdt.internal.ui.actions.OpenTypeAction for how its handled by Eclipse. The key part is this:

SelectionDialog dialog= new OpenTypeSelectionDialog(parent, true,
    PlatformUI.getWorkbench().getProgressService(), null, 
    IJavaSearchConstants.TYPE);
dialog.setTitle(JavaUIMessages.OpenTypeAction_dialogTitle);
dialog.setMessage(JavaUIMessages.OpenTypeAction_dialogMessage);

int result= dialog.open();

Where parent is the composite you want to open the dialog for. Typically the active workbench shell, obtained by:

Shell parent= JavaPlugin.getActiveWorkbenchShell();

OpenTypeSelectionDialog is in an internal package, so you will get a "Discouraged access" warning. As long as you are aware of the risks I'd recommend using this type. "Discouraged" is a warning not an error, and in practice Eclipse would introduce an OpenTypeSelectionDialog**2** rather than change the current one's signatures. The Eclipse platform and major products try to maintain compatibility as much as possible to encourage innovation (see the policy in the wiki). In general with discouraged access it makes sense for you to shield the rest of your code from API changes by using a helper. This means you have a single point you'd have to change if the referenced type changes.

The alternative is for you to implement the dialog and its parent yourself, but the parent, FilteredTypesSelectionDialog, has over 20 internal references, so would make the problem worse.

Rich Seller
It seems that the OpenTypeSelectionDialog is "Discouraged access".What does this means?
Ido
You get a discouraged access warning whenever you reference a type in a package that is not part of the API, typically these are *.internal packages. "Discouraged access" is an indicator that you should look for an API alternative if possible. Be aware that you might be vulnerable to change in later versions of Eclipse. See http://help.eclipse.org/galileo/index.jsp for more details
Rich Seller
Hi,When I used it, I added a dependency to the jdt plugin. I'm using Galileo for the development.When I installed it to clients that are using Ganymede it did not work.How should I configure it to support it?
Ido
Thank you very much for the comment, home4film. However, the link you probably meant to paste is: http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.pde.doc.user/guide/tools/editors/manifest_editor/access_rules.htm(Framesets on pages always make link-copying difficult, I know ;)
Adrian Petrescu