KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > java > JavaContentAssistHandler


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
27  *
28  * @since 3.2
29  */

30 public final class JavaContentAssistHandler extends AbstractHandler {
31     private final SpecificContentAssistExecutor fExecutor= new SpecificContentAssistExecutor(CompletionProposalComputerRegistry.getDefault());
32     
33     public JavaContentAssistHandler() {
34     }
35
36     /*
37      * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
38      */

39     public Object JavaDoc execute(ExecutionEvent event) throws ExecutionException {
40         ITextEditor editor= getActiveEditor();
41         if (editor == null)
42             return null;
43         
44         String JavaDoc categoryId= event.getParameter("org.eclipse.jdt.ui.specific_content_assist.category_id"); //$NON-NLS-1$
45
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