how to open the find type dialog programmatically in eclipse

夙愿已清 提交于 2019-12-21 23:16:56

问题


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:


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 OpenTypeSelectionDialog2 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.



来源:https://stackoverflow.com/questions/1218801/how-to-open-the-find-type-dialog-programmatically-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!