0
我有兩類插件,它們負責從彈出菜單和菜單項中執行相同的插件。但由於其中一個run()方法,我不能使用執行事件來創建一個shell。 如何解決這個問題如何在不使用執行事件的情況下創建特定的shell
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可以爲你做到這一點。 – 2010-12-09 17:40:26