本文介绍如何扩展/定制 Eclipse 的搜索插件 org.eclipse.search(后面附实例)
资源查找是 Eclipse 的一个重要功能。可是,当我们做RCP开发时,Eclipse 搜索功能不一定适合个性化的需求,这是我们就需要扩展 Eclipse 的搜索插件 org.eclipse.search。
这里以Spring IDE Bean Search为例,介绍应扩展之处和其中的关键点。搜索页的类名为BeanSearchPage, 搜索结果页的类名为BeanSearchResultPage
1. 菜单加入显示搜索页(这是入口)
方法一:在org.eclipse.search.menu/dialogGroup中加一个action,以在java\file search 的旁边加一 Tab , 显示你的搜索页 MyBeanSearchPage。
方法二:菜单加入高级查找和替换。如图
2. 扩展org.eclipse.search.searchPages,定制自己的搜索页 MyBeanSearchPage
public class MyBeanSearchPage extends DialogPage implements ISearchPage { private Text txtDirectory; private ISearchPageContainer fContainer; private Text txtPath; public MyBeanSearchPage() { } @Override public void createControl(Composite parent) { initializeDialogUnits(parent); Composite composite = new Composite(parent, SWT.NONE); composite.setFont(parent.getFont()); GridLayout gridLayout = new GridLayout(3, false); composite.setLayout(gridLayout); Label lblNewLabel = new Label(composite, SWT.NONE); lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); lblNewLabel.setText("搜索关键字"); txtDirectory = new Text(composite, SWT.BORDER); txtDirectory.setText("directory"); txtDirectory.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); setControl(composite); new Label(composite, SWT.NONE); Label lblNewLabel_1 = new Label(composite, SWT.NONE); lblNewLabel_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); lblNewLabel_1.setText("目录路径"); txtPath = new Text(composite, SWT.BORDER); txtPath.setText("E:\\yucheng\\bsp\\trunk\\runtime-BankITIDE.product\\HelloBSP\\HelloWorld\\HelloCommu\\Hello\\input\\pcs"); txtPath.setEditable(false); txtPath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); Button btnNewButton = new Button(composite, SWT.NONE); btnNewButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { DirectoryDialog directoryDialog = new DirectoryDialog( getShell()); directoryDialog.setText("选择目录路径"); String directoryPath = directoryDialog.open(); txtPath.setText(directoryPath); } }); btnNewButton.setText("选择目录路径"); } @Override public boolean performAction() { NewSearchUI.activateSearchResultView(); MyBeanSearchQuery myBeanSearchQuery = new MyBeanSearchQuery(); myBeanSearchQuery.setKeyword(txtDirectory.getText()); myBeanSearchQuery.setDirectoryPath(txtPath.getText()); NewSearchUI.runQueryInBackground(myBeanSearchQuery); return true; } @Override public void setContainer(ISearchPageContainer container) { fContainer = container; } }
3. 扩展org.eclipse.search.searchResultViewPages,定制自己的搜索结果页BeanSearchResultPage
public class MySearchResultPage extends AbstractTextSearchViewPage { private MyFileTreeContentProvider fContentProvider; @Override protected void elementsChanged(Object[] objects) { if (fContentProvider != null) { fContentProvider.elementsChanged(objects); } } @Override protected void clear() { if (fContentProvider != null) fContentProvider.clear(); } @Override protected void configureTreeViewer(TreeViewer viewer) { viewer.setUseHashlookup(true); MyFileLabelProvider myFileLabelProvider = new MyFileLabelProvider(); viewer.setLabelProvider(myFileLabelProvider); viewer.setContentProvider(new MyFileTreeContentProvider(viewer)); fContentProvider = (MyFileTreeContentProvider) viewer .getContentProvider(); this.setElementLimit(50); } @Override protected void configureTableViewer(TableViewer viewer) { // TODO Auto-generated method stub } }
2和3的扩展点
4. 此外,还用到的相关接口,详见附件的插件工程
ISearchQuery.java,搜索的入口
Match.java,结果集
NewSearchUI.java,UI启动类
5. 运行
搜索输入界面
搜索结果显示界面
6. 附件是一个简单的示例。
相关推荐
Eclipse IDE for RCP and RAP Developers(eclipse-rcp-2022-06-R-linux-gtk-x86_64.tar.gz) 适用于Linux x86_64: A complete set of tools for developers who want to create Eclipse plug-ins, Rich Client ...
Eclipse IDE for RCP and RAP Developers(eclipse-rcp-2022-06-R-win32-x86_64.zip) 适用于Windows x86_64: A complete set of tools for developers who want to create Eclipse plug-ins, Rich Client ...
linux x86(AMD) 下 RCP 开发工具 eclipse-rcp-2020-06-R-linux-x86
eclipse-rcp-indigo-SR2-win32-x86_64,根据所需可供下载
Eclipse IDE for RCP and RAP Developers(eclipse-rcp-2022-06-R-linux-gtk-aarch64.tar.gz) 适用于Linux aarch64: A complete set of tools for developers who want to create Eclipse plug-ins, Rich Client ...
eclipse-rcp-juno-SR2-win32-x86_64,根据所需进行下载。
Eclipse IDE for RCP and RAP Developers(eclipse-rcp-2022-06-R-macosx-cocoa-x86_64.dmg) 适用于macOS x86_64: A complete set of tools for developers who want to create Eclipse plug-ins, Rich Client ...
Eclipse IDE for RCP and RAP Developers(eclipse-rcp-2022-06-R-macosx-cocoa-aarch64.dmg) 适用于macOS aarch64: A complete set of tools for developers who want to create Eclipse plug-ins, Rich Client ...
eclipse-rcp-2023-09-R-macosx-cocoa-x86_64.dmg 适用于macOS Intel芯片系统
eclipse-rcp-2023-09-R-macosx-cocoa-aarch64.dmg 适用于macOS Arm芯片系统
eclipse-rcp-2023-09-R-win32-x86_64.zip 适用于Windows系统
http://downloads.myeclipseide.com/downloads/products/eworkbench/galileo/myeclipse-8.0.0-win32.exe eclipse\eclipse-RCP-SDK-3.0.1-win32.zip
eclipse-rcp-kepler-SR2-win32-x86_64,根据所需进行下载。
eclipse-rcp-2023-09-R-linux-gtk-aarch64.tar.gz 适用于Linux Arm系统
非常好的birt-RCP实例 非常好的birt-RCP实例 非常好的birt-RCP实例 非常好的birt-RCP实例 非常好的birt-RCP实例
eclipse-rcp-2023-09-R-linux-gtk-x86_64.tar.gz 适用于Linux x86_64位系统
eclipse-rcp-2023-12-R-linux-gtk-aarch64.tar.gz 适用于Linux ARM系统
eclipse-rcp-europa-winter-win32,根据所需各种版本可供下载
SWT RCP 界面--如何编写一个漂亮的 SWT RCP 界面
eclipse-rcp-photon-RC3-win32-x86_64(含SVN及兼容低版本插件)