类org.eclipse.jface.text.contentassist.ICompletionProposalExtension2源码实例Demo

下面列出了怎么用org.eclipse.jface.text.contentassist.ICompletionProposalExtension2的API类实例代码及写法,或者点击链接到github查看源代码。

protected ContentAssistProcessorTestBuilder appendAndApplyProposal(ICompletionProposal proposal, ISourceViewer sourceViewer, String model, int position)
		throws Exception {
	IDocument document = sourceViewer.getDocument();
	int offset = position;
	if (model != null) {
		document.set(getModel() + model);
		offset += model.length();
	}
	if (proposal instanceof ICompletionProposalExtension2) {
		ICompletionProposalExtension2 proposalExtension2 = (ICompletionProposalExtension2) proposal;
		proposalExtension2.apply(sourceViewer, (char) 0, SWT.NONE, offset);	
	} else if (proposal instanceof ICompletionProposalExtension) {
		ICompletionProposalExtension proposalExtension = (ICompletionProposalExtension) proposal;
		proposalExtension.apply(document, (char) 0, offset);	
	} else  {
		proposal.apply(document);
	}
	return reset().append(document.get());
}
 
protected ContentAssistProcessorTestBuilder appendAndApplyProposal(ICompletionProposal proposal, ISourceViewer sourceViewer, String model, int position)
		throws Exception {
	IDocument document = sourceViewer.getDocument();
	int offset = position;
	if (model != null) {
		document.set(getModel() + model);
		offset += model.length();
	}
	if (proposal instanceof ICompletionProposalExtension2) {
		ICompletionProposalExtension2 proposalExtension2 = (ICompletionProposalExtension2) proposal;
		proposalExtension2.apply(sourceViewer, (char) 0, SWT.NONE, offset);	
	} else if (proposal instanceof ICompletionProposalExtension) {
		ICompletionProposalExtension proposalExtension = (ICompletionProposalExtension) proposal;
		proposalExtension.apply(document, (char) 0, offset);	
	} else  {
		proposal.apply(document);
	}
	return reset().append(document.get());
}
 
源代码3 项目: APICloud-Studio   文件: SnippetTemplateProposal.java
@Override
public void apply(final ITextViewer viewer, char trigger, int stateMask, final int offset)
{
	delegateTemplateProposal = null;
	if (contains(triggerChars, trigger))
	{
		if (triggerChar == trigger)
		{
			doApply(viewer, trigger, stateMask, offset);
		}
		else
		{
			delegateTemplateProposal = templateProposals[trigger - '1'];
			((ICompletionProposalExtension2) templateProposals[trigger - '1']).apply(viewer, trigger, stateMask,
					offset);
		}
	}
	else
	{
		doApply(viewer, trigger, stateMask, offset);
	}
}
 
/**
 * When executed it'll create a proposal and apply it.
 */
/*default*/void execute(RefactoringInfo refactoringInfo, String actTok, List<String> parametersAfterCall,
        int locationStrategy) {
    try {
        ICompletionProposalHandle proposal = createProposal(refactoringInfo, actTok, locationStrategy,
                parametersAfterCall);
        if (proposal != null) {
            if (proposal instanceof ICompletionProposalExtension2) {
                ICompletionProposalExtension2 extension2 = (ICompletionProposalExtension2) proposal;
                extension2.apply(((PyEdit) targetEditor).getPySourceViewer(), '\n', 0, 0);
            } else {
                proposal.apply(refactoringInfo.getDocument());
            }
        }

    } catch (Exception e) {
        Log.log(e);
    }
}
 
源代码5 项目: Pydev   文件: TddTestWorkbench.java
private ICompletionProposalExtension2 waitForQuickFixProps(TddCodeGenerationQuickFixParticipant quickFix,
        PySelection ps, int offset, String expectedCompletion) throws MisconfigurationException,
        BadLocationException {

    long initialTime = System.currentTimeMillis();
    List<ICompletionProposalHandle> props;
    while (true) {
        props = waitForQuickFixProps(quickFix, ps, offset);
        ICompletionProposalExtension2 completion = findCompletion(props, expectedCompletion, false);
        if (completion != null) {
            return completion;
        }
        if (System.currentTimeMillis() - initialTime > 10000) {
            break; //Give it 10 seconds to work.
        }
        goToManual(200);
    }
    // throws exception if not used.
    return findCompletion(props, expectedCompletion);

}
 
源代码6 项目: Pydev   文件: TddTestWorkbench.java
private ICompletionProposalExtension2 findCompletion(List<ICompletionProposalHandle> props,
        String expectedCompletion,
        boolean throwException) {
    List<String> buf = new ArrayList<String>(1 + (2 * props.size()));
    buf.add("Available:");
    for (ICompletionProposalHandle iCompletionProposal : props) {
        if (iCompletionProposal.getDisplayString().equals(expectedCompletion)) {
            ICompletionProposalExtension2 p = (ICompletionProposalExtension2) iCompletionProposal;
            return p;
        }
        buf.add("\n");
        buf.add(iCompletionProposal.getDisplayString());
    }
    if (throwException) {
        throw new AssertionError("Could not find completion: " + expectedCompletion +
                "\n"
                + StringUtils.join("\n", buf));
    }
    return null;
}
 
源代码7 项目: APICloud-Studio   文件: CompletionProposalPopup.java
/**
 * Unregister this completion proposal popup.
 * 
 * @since 3.0
 */
private void unregister()
{
	if (fDocumentListener != null)
	{
		IDocument document = fContentAssistSubjectControlAdapter.getDocument();
		if (document != null)
		{
			document.removeDocumentListener(fDocumentListener);
		}
		fDocumentListener = null;
	}
	fDocumentEvents.clear();

	if (fKeyListener != null && Helper.okToUse(fContentAssistSubjectControlAdapter.getControl()))
	{
		fContentAssistSubjectControlAdapter.removeKeyListener(fKeyListener);
		fKeyListener = null;
	}

	if (fLastProposal != null)
	{
		if (fLastProposal instanceof ICompletionProposalExtension2 && fViewer != null)
		{
			ICompletionProposalExtension2 extension = (ICompletionProposalExtension2) fLastProposal;
			extension.unselected(fViewer);
		}
		fLastProposal = null;
	}

	fFilteredProposals = null;
	fComputedProposals = null;

	fContentAssistant.possibleCompletionsClosed();
}
 
源代码8 项目: APICloud-Studio   文件: CompletionProposalPopup.java
/**
 * Selects the entry with the given index in the proposal selector and feeds the selection to the additional info
 * controller.
 * 
 * @param index
 *            the index in the list
 * @param smartToggle
 *            <code>true</code> if the smart toggle key has been pressed
 * @param autoScroll
 *            Do we scroll the item into view at the middle of the list
 * @since 2.1
 */
private void selectProposal(int index, boolean smartToggle, boolean autoScroll)
{
	if (fFilteredProposals == null)
	{
		return;
	}

	ICompletionProposal oldProposal = getSelectedProposal();
	if (oldProposal instanceof ICompletionProposalExtension2 && fViewer != null)
	{
		((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
	}

	ICompletionProposal proposal = fFilteredProposals[index];
	if (proposal instanceof ICompletionProposalExtension2 && fViewer != null)
	{
		((ICompletionProposalExtension2) proposal).selected(fViewer, smartToggle);
	}

	fLastProposal = proposal;
	fProposalTable.setSelection(index);

	if (autoScroll)
	{
		setScroll(index);
	}
	fProposalTable.showSelection();

	if (fAdditionalInfoController != null)
	{
	    fAdditionalInfoController.handleTableSelectionChanged();
    }
}
 
private static IAction[] getActionsFromProposals(IJavaCompletionProposal[] proposals, final int offset, final ITextViewer viewer) {
	List<Action> result= new ArrayList<Action>();

	for (int i= 0, j= 1; i < proposals.length; i++) {
		if (proposals[i] instanceof ICompletionProposalExtension2) {
			final IJavaCompletionProposal proposal= proposals[i];

			StringBuffer actionName= new StringBuffer();
			if (j<10) {
				actionName.append('&').append(j).append(' ');
			}
			actionName.append(proposals[i].getDisplayString());

			Action action= new Action(actionName.toString()) {
				/**
				 * {@inheritDoc}
				 */
				@Override
				public void run() {
					applyProposal(proposal, viewer, (char)0, 0, offset);
				}
			};
			action.setImageDescriptor(JavaPluginImages.DESC_OBJS_TEMPLATE);

			result.add(action);
			j++;
		}
	}
	if (result.size() == 0)
		return null;

	return result.toArray(new IAction[result.size()]);
}
 
源代码10 项目: APICloud-Studio   文件: CompletionProposalPopup.java
/**
 * Initializes the proposal selector with these given proposals.
 * 
 * @param proposals
 *            the proposals
 * @param isFilteredSubset
 *            if <code>true</code>, the proposal table is not cleared, but the proposals that are not in the passed
 *            array are removed from the displayed set
 */
private void setProposals(ICompletionProposal[] proposals, boolean isFilteredSubset)
{
	ICompletionProposal[] oldProposals = fFilteredProposals;
	ICompletionProposal oldProposal = getSelectedProposal(); // may trigger filtering and a reentrant call to
               // setProposals()
	if (oldProposals != fFilteredProposals) 
		return;
	if (!(Helper.okToUse(fProposalTable)))
		return;
	if ((oldProposal instanceof ICompletionProposalExtension2) && (fViewer != null))
	{
		((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
	}
	if (proposals == null)
	{
		proposals = new ICompletionProposal[0];
	}

	fFilteredProposals = proposals;
	int length = proposals.length;
	TableItem[] items;
	if (USE_VIRTUAL)
	{
		fProposalTable.clearAll();
		fProposalTable.setItemCount(length);
		items = fProposalTable.getItems();
		for (int i = 0; i < items.length; ++i)
		{
			setItem(items, i);
		}
	}
	else
	{
		fProposalTable.setRedraw(false);
		fProposalTable.setItemCount(length);
		items = fProposalTable.getItems();
		for (int i = 0; i < items.length; i++)
		{
			TableItem item = items[i];
			ICompletionProposal proposal = proposals[i];
			item.setData("isAlt", "false");
				
			item.setImage(0, proposal.getImage());
			item.setText(1, proposal.getDisplayString());
			setDefaultStyle(item);

			item.setData(proposal);
		}
		fProposalTable.setRedraw(true);
	}

	// Custom code for modifying selection/size
	int defaultIndex = -1;
	int suggestedIndex = -1;

	// select the first proposal
	if (proposals.length > 0)
	{
		defaultIndex = 0;
		suggestedIndex = 0;
	}
	modifySelection(defaultIndex, suggestedIndex);

	if (!(isFilteredSubset))
	{
		resizeTable(0, 0);
	}

}
 
源代码11 项目: APICloud-Studio   文件: CompletionProposalPopup.java
/**
 * Computes the subset of already computed proposals that are still valid for the given offset.
 * 
 * @param offset
 *            the offset
 * @param event
 *            the merged document event
 * @return the set of filtered proposals
 * @since 3.0
 */
private ICompletionProposal[] computeFilteredProposals(int offset, DocumentEvent event)
{

	if (offset == fInvocationOffset && event == null)
	{
		fIsFilteredSubset = false;
		return fComputedProposals;
	}
	IDocument document = fContentAssistSubjectControlAdapter.getDocument();
	// this does go through the array twice (once to figure out if it's okay to use the else case, and the second
	// time to actual filter the proposals, but it is what the original logic suggests
	if ((offset < fInvocationOffset) || ((event != null) && (event.fText.startsWith("("))))
	{
		fIsFilteredSubset = false;
		fInvocationOffset = offset;
		fComputedProposals = computeProposals(fInvocationOffset, false);
		fComputedProposals = filterProposals(fComputedProposals, document, fInvocationOffset, event);
		return fComputedProposals;
	}

	ICompletionProposal[] proposals;
	if (offset < fFilterOffset)
	{
		proposals = fComputedProposals;
		fIsFilteredSubset = false;
	}
	else
	{
		proposals = fFilteredProposals;
		fIsFilteredSubset = true;
	}

	if (proposals == null)
	{
		fIsFilteredSubset = false;
		return null;
	}

	for (int i = 0; i < proposals.length; i++)
	{
		ICompletionProposal proposal = proposals[i];
		if ((proposal instanceof ICompletionProposalExtension2)
				|| (proposal instanceof ICompletionProposalExtension))
		{
			continue;
		}
		fIsFilteredSubset = false;
		fInvocationOffset = offset;
		fComputedProposals = computeProposals(fInvocationOffset, false);

		return fComputedProposals;
	}

	ICompletionProposal[] filtered = filterProposals(proposals, document, offset, event);
	return filtered;
}
 
源代码12 项目: Pydev   文件: TddTestWorkbench.java
private ICompletionProposalExtension2 findCompletion(List<ICompletionProposalHandle> props,
        String expectedCompletion) {
    return findCompletion(props, expectedCompletion, true);
}
 
 类所在包
 类方法
 同包方法