1 11 12 package org.eclipse.ui.texteditor; 13 14 15 import java.util.ResourceBundle ; 16 17 import org.eclipse.swt.custom.BusyIndicator; 18 import org.eclipse.swt.widgets.Display; 19 import org.eclipse.swt.widgets.Shell; 20 21 import org.eclipse.jface.text.ITextOperationTarget; 22 import org.eclipse.jface.text.ITextOperationTargetExtension; 23 import org.eclipse.jface.text.source.ISourceViewer; 24 25 import org.eclipse.ui.IWorkbenchPartSite; 26 27 28 40 public final class ContentAssistAction extends TextEditorAction { 41 42 43 private ITextOperationTarget fOperationTarget; 44 45 60 public ContentAssistAction(ResourceBundle bundle, String prefix, ITextEditor editor) { 61 super(bundle, prefix, editor); 62 } 63 64 67 public void run() { 68 if (fOperationTarget != null) { 69 70 ITextEditor editor= getTextEditor(); 71 if (editor != null && validateEditorInputState()) { 72 73 Display display= null; 74 75 IWorkbenchPartSite site= editor.getSite(); 76 Shell shell= site.getShell(); 77 if (shell != null && !shell.isDisposed()) 78 display= shell.getDisplay(); 79 80 BusyIndicator.showWhile(display, new Runnable () { 81 public void run() { 82 fOperationTarget.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); 83 } 84 }); 85 } 86 } 87 } 88 89 95 public void update() { 96 97 ITextEditor editor= getTextEditor(); 98 99 if (fOperationTarget == null && editor!= null) 100 fOperationTarget= (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class); 101 102 if (fOperationTarget == null) { 103 setEnabled(false); 104 return; 105 } 106 107 if (fOperationTarget instanceof ITextOperationTargetExtension) { 108 ITextOperationTargetExtension targetExtension= (ITextOperationTargetExtension) fOperationTarget; 109 targetExtension.enableOperation(ISourceViewer.CONTENTASSIST_PROPOSALS, canModifyEditor()); 110 } 111 112 setEnabled(fOperationTarget.canDoOperation(ISourceViewer.CONTENTASSIST_PROPOSALS)); 113 } 114 115 118 public void setEditor(ITextEditor editor) { 119 super.setEditor(editor); 120 fOperationTarget= null; 121 } 122 } 123 | Popular Tags |