1 11 package org.eclipse.jdt.internal.ui.javaeditor; 12 13 import java.util.Collection ; 14 import java.util.Iterator ; 15 16 import org.eclipse.core.runtime.Assert; 17 18 import org.eclipse.jface.text.ITextOperationTarget; 19 import org.eclipse.jface.text.source.ISourceViewer; 20 21 import org.eclipse.ui.texteditor.ITextEditor; 22 23 24 import org.eclipse.jdt.internal.ui.text.java.CompletionProposalCategory; 25 import org.eclipse.jdt.internal.ui.text.java.CompletionProposalComputerRegistry; 26 27 32 public final class SpecificContentAssistExecutor { 33 34 private final CompletionProposalComputerRegistry fRegistry; 35 36 41 public SpecificContentAssistExecutor(CompletionProposalComputerRegistry registry) { 42 Assert.isNotNull(registry); 43 fRegistry= registry; 44 } 45 46 53 public void invokeContentAssist(final ITextEditor editor, String categoryId) { 54 Collection categories= fRegistry.getProposalCategories(); 55 boolean[] inclusionState= new boolean[categories.size()]; 56 boolean[] separateState= new boolean[categories.size()]; 57 int i= 0; 58 for (Iterator it= categories.iterator(); it.hasNext(); i++) { 59 CompletionProposalCategory cat= (CompletionProposalCategory) it.next(); 60 inclusionState[i]= cat.isIncluded(); 61 cat.setIncluded(cat.getId().equals(categoryId)); 62 separateState[i]= cat.isSeparateCommand(); 63 cat.setSeparateCommand(false); 64 } 65 66 try { 67 ITextOperationTarget target= (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class); 68 if (target != null && target.canDoOperation(ISourceViewer.CONTENTASSIST_PROPOSALS)) 69 target.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); 70 } finally { 71 i= 0; 72 for (Iterator it= categories.iterator(); it.hasNext(); i++) { 73 CompletionProposalCategory cat= (CompletionProposalCategory) it.next(); 74 cat.setIncluded(inclusionState[i]); 75 cat.setSeparateCommand(separateState[i]); 76 } 77 } 78 } 79 } 80 | Popular Tags |