1 11 package org.eclipse.jdt.internal.ui.text.java; 12 13 import org.eclipse.core.commands.AbstractHandler; 14 import org.eclipse.core.commands.ExecutionEvent; 15 import org.eclipse.core.commands.ExecutionException; 16 17 import org.eclipse.ui.IEditorPart; 18 import org.eclipse.ui.IWorkbenchPage; 19 import org.eclipse.ui.IWorkbenchWindow; 20 import org.eclipse.ui.PlatformUI; 21 import org.eclipse.ui.texteditor.ITextEditor; 22 23 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; 24 import org.eclipse.jdt.internal.ui.javaeditor.SpecificContentAssistExecutor; 25 26 30 public final class JavaContentAssistHandler extends AbstractHandler { 31 private final SpecificContentAssistExecutor fExecutor= new SpecificContentAssistExecutor(CompletionProposalComputerRegistry.getDefault()); 32 33 public JavaContentAssistHandler() { 34 } 35 36 39 public Object execute(ExecutionEvent event) throws ExecutionException { 40 ITextEditor editor= getActiveEditor(); 41 if (editor == null) 42 return null; 43 44 String categoryId= event.getParameter("org.eclipse.jdt.ui.specific_content_assist.category_id"); if (categoryId == null) 46 return null; 47 48 fExecutor.invokeContentAssist(editor, categoryId); 49 50 return null; 51 } 52 53 private ITextEditor getActiveEditor() { 54 IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); 55 if (window != null) { 56 IWorkbenchPage page= window.getActivePage(); 57 if (page != null) { 58 IEditorPart editor= page.getActiveEditor(); 59 if (editor instanceof ITextEditor) 60 return (JavaEditor) editor; 61 } 62 } 63 return null; 64 } 65 66 } 67 | Popular Tags |