首页 > 其他分享 >Eclipse插件开发资源查找

Eclipse插件开发资源查找

时间:2022-10-17 21:35:46浏览次数:51  
标签:插件 shell return String title Eclipse 开发资源 org message


  • 介绍

我们在开发Eclipse插件的时候,需要查找类、接口等资源的时候,怎么办呢?本文介绍如何使用Eclipse自带的查找对话框来获取类路径。

  • 例子

[codesyntax lang="java"]


/**
* http://surenpi.com
*/
package org.surenpi.dev.plugin.utill;

import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.SelectionDialog;

/**
* @author surenpi.com
* @since jdk1.6
* 2015年9月24日
*/
public class SearchDialog {
/**
* 查找类
* @param shell
* @param multipleSelection
* @param title 对话框标题
* @param message
* @return
*/
public static Object[] searchType(Shell shell, int type, boolean multipleSelection,
String title, String message){
try {
SelectionDialog dialog = JavaUI.createTypeDialog(shell,
new ProgressMonitorDialog(shell),
SearchEngine.createWorkspaceScope(), type,
multipleSelection);

dialog.setTitle(title);
dialog.setMessage(message);

if(dialog.open() == IDialogConstants.CANCEL_ID){
return null;
}

return dialog.getResult();
} catch (JavaModelException e) {
e.printStackTrace();
}

return null;
}

public static Object[] searchClass(Shell shell, boolean multipleSelection,
String title, String message){
return searchType(shell, IJavaElementSearchConstants.CONSIDER_CLASSES,
multipleSelection, title, message);
}

public static IType searchClass(Shell shell, String title, String message){
Object[] result = searchClass(shell, false, title, message);

if(result != null && result.length > 0){
return (IType) result[0];
}

return null;
}

/**
* 查找Action中的Module类
* @param shell
* @return
*/
public static IType searchModuleClass(Shell shell){
String title = "查找Module类";
String message = "请选择PO或者VO作为Action的Module(ListModule)";

return searchClass(shell, title, message);
}

public static Object[] searchInterface(Shell shell, boolean multipleSelection,
String title, String message){
return searchType(shell, IJavaElementSearchConstants.CONSIDER_INTERFACES,
multipleSelection, title, message);
}

public static IType searchInterface(Shell shell, String title, String message){
Object[] result = searchType(shell, IJavaElementSearchConstants.CONSIDER_INTERFACES,
false, title, message);

if(result != null && result.length > 0){
return (IType) result[0];
}

return null;
}

/**
* 查找Action中的Module类
* @param shell
* @return
*/
public static IType searchInjectClass(Shell shell){
String title = "查找依赖类";
String message = "请选择服务";

return searchInterface(shell, title, message);
}
}


[/codesyntax]

标签:插件,shell,return,String,title,Eclipse,开发资源,org,message
From: https://blog.51cto.com/suren/5764414

相关文章

  • Eclipse插件开发CleanUp
    扩展点[codesyntaxlang="python"]<extensionpoint="org.eclipse.jdt.ui.cleanUps"><cleanUpConfigurationUIclass="org.suren.cleanup.SuRenCleanUp"name="SuRenS......
  • Eclipse插件开发Java快速修复
    介绍在Eclipse中在有报错的地方,使用快捷键Ctrl+1就会弹出几种解决问题的方案,这时候只要选择一种就可能快速地修复该问题。这些常见的问题,有些可能是通用的,例如:没有导入包。......
  • Eclipse插件开发自定义Classpath
    介绍我们在使用Eclipse做Java开发的时候,如果要用到JDK以外的库文件的话,一般的做法都是自定义一个Library或者逐个添加jar文件,或者是利用Maven。那么,Maven又是怎么做到的呢?......
  • WordPress在插件管理页面添加超链接
    •介绍如果你创建了一个插件,WordPress的插件管理页面中就可以看到,而且会有启用、停用、编辑等默认的超级链接按钮。那么,怎么才能添加一个自定义的呢?•玉照[captionid="a......
  • wangEditor导入word文档 wangEditor word导入插件
    ​ ueditor粘贴不能粘贴word中的图片是一个很头疼的问题,在我们的业务场景中客户要求必须使用ueditor并且支持word的图片粘贴,因为这个需求头疼了半个月,因为前端方面因为安......
  • VSCode 插件开发打包提示Cannot find name 'Blob'
    问题描述执行打包vscepackage提示错误原因分析未知解决方法打开错误源,将Blob改成any实现效果......
  • Eclipse设置Java 代码自动提示和自动补全
    一、打开Eclipse进入配置页面依次点击Window–>Preferences–>Java二、进入Java的设置依次点击Java–>Editor–>ContentAssist–>Autoactivationtri......
  • 将eclipse生成的javadoc制作为CHM文档
    介绍使用EasyCHM将eclipse生成的javadoc制作为CHM文档,这样就可以像看电子书一样来预览项目内容准备工作1、下载EasyCHM软件使用eclipse生成javadoc文件 制作流程1、利用ec......
  • 【学员分享】程序员效率神器,最常用VIM插件安装大全
    相信大家多次被推荐用vim作为编辑程序,知道vim编辑有很多优点,但是vim初始界面太原始了,安装了之后只能用来编辑,如果要运行就需要退出去运行,麻烦死了。回想用现成的IDE是多么的......
  • maven 无法下载插件
    起因本次文章记录一下前段时间来公司按照Jenkins遇到的一个坑。maven安装完成后无法下载插件。解决这次的问题百度之后,都说是插件下载的链接是不对的,都是重复的解决方式,实在......