调用eclipse自身OpenType
import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.JavaUIMessages; import org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog; import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory; import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.PlatformUI; public class OpenTypeDialog extends OpenTypeSelectionDialog { public OpenTypeDialog(IWorkingSet ws) { super(JavaPlugin.getActiveWorkbenchShell(), true, PlatformUI.getWorkbench().getProgressService(), JavaSearchScopeFactory.getInstance().createJavaSearchScope(ws, true), 0); setTitle(JavaUIMessages.OpenTypeAction_dialogTitle); setMessage(JavaUIMessages.OpenTypeAction_dialogMessage); applyFilter(); } public OpenTypeDialog(IWorkingSet ws, String searchText) { this(ws); setInitialPattern(searchText); } }
然后调用OpenTypeDialog:
IProject[] projects = new IProject[] { project }; IAdaptable[] elements = new IAdaptable[projects.length]; for (int i = 0; i < elements.length; i++) { elements[i] = projects[i]; } IWorkingSet ws = new WorkingSet("source", "source", elements); SelectionDialog dialog = new OpenTypeDialog(ws); int result = dialog.open(); if (result != IDialogConstants.OK_ID) return; Object[] obj = dialog.getResult(); if (obj == null || obj.length == 0) return; String className = null; String packageName = null; for (Object objs : obj) { className = ((SourceType) objs).getElementName(); PackageFragment packet = (PackageFragment) ((SourceType) objs).getParent().getParent(); packageName = packet.getElementName(); }
相关推荐
xnuzfm 2020-02-12
zhangmin0 2019-12-14
heshizui 2015-03-19
lzqlawrence 2015-08-19
小易Smalle 2016-07-22
Yvonne的小 2014-06-05
wangzhe00 2014-06-27
tgxblue 2016-03-25
heshizui 2015-03-19
Christina潇潇 2015-01-27