Eclipse plugin 如何在不使用执行事件的情况下创建特定的shell
我有两个插件类,它们负责在弹出菜单和菜单项中执行相同的插件。但由于其中一个具有run()方法,因此我无法使用执行事件来创建shell。 我如何克服这个问题Eclipse plugin 如何在不使用执行事件的情况下创建特定的shell,eclipse-plugin,Eclipse Plugin,我有两个插件类,它们负责在弹出菜单和菜单项中执行相同的插件。但由于其中一个具有run()方法,因此我无法使用执行事件来创建shell。 我如何克服这个问题 public class ConvertConstantsToEnumHandler extends AbstractHandler { //execution of the plugin public Object execute(ExecutionEvent event) throws ExecutionException {
public class ConvertConstantsToEnumHandler extends AbstractHandler {
//execution of the plugin
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection currentSelection = HandlerUtil.getCurrentSelectionChecked(event);
RefactoringMenuAction menuitem= new RefactoringMenuAction();
menuitem.setEvent(event);
List selectedFields = getSelectedFields(currentSelection);
Shell shell = HandlerUtil.getActiveShellChecked(event);
//get the selected Fields to do the convertion
IField[] fields = (IField[]) selectedFields.toArray(new IField[] {});
try {
ConvertConstantsToEnumWizard.startConvertConstantsToEnumRefactoring(fields, shell);
} catch (JavaModelException e) {
e.printStackTrace();
}
return null;
}
public class RefactoringMenuAction implements IWorkbenchWindowActionDelegate {
public IWorkbenchWindow window;
public RefactoringMenuAction() {
}
public void run(IAction action) {
RefactoringPlugin rp = new RefactoringPlugin();
try {
rp.start(rp.getTheBundle()); // get the current context of the eclipse
} catch (CoreException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
// here I need to find a way to access or create a shell to compile same as the above class
}
如果您试图执行同一段代码,为什么您要在一个位置通过操作执行,而在另一个位置使用命令执行?为什么您不能简单地使用一个命令并在两个位置添加一个命令贡献?能否请您重新格式化您的问题,使代码段显示为格式化代码?我想CTRL+k可以帮你做到这一点。