org.eclipse.jface.text.contentassist.IContextInformation Java Examples

The following examples show how to use org.eclipse.jface.text.contentassist.IContextInformation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContextInformationPopup.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a context frame for the given offset.
 * 
 * @param information
 *            the context information
 * @param offset
 *            the offset
 * @return the created context frame
 * @since 3.0
 */
private ContextFrame createContextFrame(IContextInformation information, int offset)
{
	IContextInformationValidator validator = fContentAssistSubjectControlAdapter.getContextInformationValidator(
			fContentAssistant, offset);

	if (validator != null)
	{
		int beginOffset = (information instanceof IContextInformationExtension) ? ((IContextInformationExtension) information)
				.getContextInformationPosition() : offset;
		if (beginOffset == -1)
		{
			beginOffset = offset;
		}
		int visibleOffset = fContentAssistSubjectControlAdapter.getWidgetSelectionRange().x
				- (offset - beginOffset);
		IContextInformationPresenter presenter = fContentAssistSubjectControlAdapter
				.getContextInformationPresenter(fContentAssistant, offset);
		return new ContextFrame(information, beginOffset, offset, visibleOffset, validator, presenter);
	}

	return null;
}
 
Example #2
Source File: ModulaContextualCompletionProposal.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a new completion proposal. All fields are initialized based on the provided information.
 *
 * @param replacementString the actual string to be inserted into the document
 * @param replacementOffset the offset of the text to be replaced
 * @param replacementLength the length of the text to be replaced
 * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
 * @param image the image to display for this proposal
 * @param displayString the string to be displayed for the proposal
 * @param contextInformation the context information associated with this proposal
 * @param additionalProposalInfo the additional information associated with this proposal
 */
public ModulaContextualCompletionProposal(String replacementString, int replacementOffset, int replacementLength, 
        int cursorPosition, Image image, StyledString displaySString, IContextInformation contextInformation, String additionalProposalInfo) {
    Assert.isNotNull(replacementString);
    Assert.isTrue(replacementOffset >= 0);
    Assert.isTrue(replacementLength >= 0);
    Assert.isTrue(cursorPosition >= 0);

    fReplacementString= replacementString;
    fReplacementOffset= replacementOffset;
    fReplacementLength= replacementLength;
    fCursorPosition= cursorPosition;
    fImage= image;
    fDisplaySString= displaySString;
    fContextInformation= contextInformation;
    fAdditionalProposalInfo= additionalProposalInfo;
}
 
Example #3
Source File: JavaCompletionProposalComputer1.java    From ContentAssist with MIT License 6 votes vote down vote up
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
    List<ICompletionProposal> propList = new ArrayList<ICompletionProposal>();
    List<ICompletionProposal> newpropList = new ArrayList<ICompletionProposal>();
    List<IContextInformation> propList2 = new ArrayList<IContextInformation>();

    ICompletionProposal first;
    DataManager datamanger = new DataManager(context,monitor);
    Activator.applyoperationlist.add(new ApplyOperation(ConsoleOperationListener2.ope.getStart(), ConsoleOperationListener2.ope.getAuthor(), ConsoleOperationListener2.ope.getFilePath(), propList));
    List<String> list = new ArrayList();
    CompletionProposal proposal;
    propList = datamanger.JavaDefaultProposal();
    propList2 = datamanger.ContextInformation();
    ApplyOperation ao = new ApplyOperation(ConsoleOperationListener2.ope.getStart(), ConsoleOperationListener2.ope.getAuthor(), ConsoleOperationListener2.ope.getFilePath(), propList);
    System.out.println(ao.toString());
    return newpropList;
}
 
Example #4
Source File: CSSContentAssistProcessor.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * createProposal
 * 
 * @param displayName
 * @param name
 * @param image
 * @param description
 * @param userAgents
 * @param fileLocation
 * @param offset
 * @return
 */
protected CommonCompletionProposal createProposal(String displayName, String name, Image image, String description,
		String[] userAgentIds, String fileLocation, int offset)
{
	int length = name.length();
	IContextInformation contextInfo = null;
	int replaceLength = 0;

	if (this._replaceRange != null)
	{
		offset = this._replaceRange.getStartingOffset();
		replaceLength = this._replaceRange.getLength();
	}

	// build proposal
	Image[] userAgents = UserAgentManager.getInstance().getUserAgentImages(getProject(), userAgentIds);

	CommonCompletionProposal proposal = new CommonCompletionProposal(name, offset, replaceLength, length, image,
			displayName, contextInfo, description);
	proposal.setFileLocation(fileLocation);
	proposal.setUserAgentImages(userAgents);
	proposal.setTriggerCharacters(getProposalTriggerCharacters());
	return proposal;
}
 
Example #5
Source File: XMLContentAssistProcessor.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * createProsal
 * 
 * @param displayName
 * @param name
 * @param image
 * @param description
 * @param userAgents
 * @param fileLocation
 * @param offset
 * @param length
 * @return
 */
protected CommonCompletionProposal createProposal(String displayName, String name, Image image, String description,
		Image[] userAgents, String fileLocation, int offset, int length)
{
	IContextInformation contextInfo = null;

	// TEMP:
	int replaceLength = 0;

	if (this._replaceRange != null)
	{
		offset = this._replaceRange.getStartingOffset();
		replaceLength = this._replaceRange.getLength();
	}

	// build proposal
	CommonCompletionProposal proposal = new CommonCompletionProposal(name, offset, replaceLength, length, image,
			displayName, contextInfo, description);
	proposal.setFileLocation(fileLocation);
	proposal.setUserAgentImages(userAgents);
	proposal.setTriggerCharacters(getProposalTriggerCharacters());
	return proposal;
}
 
Example #6
Source File: ContentAssistant.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns an array of context information objects computed based on the specified document position. The position
 * is used to determine the appropriate code assist processor to invoke.
 * 
 * @param viewer
 *            the viewer for which to compute the context information
 * @param offset
 *            a document offset
 * @return an array of context information objects
 * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int)
 */
IContextInformation[] computeContextInformation(ITextViewer viewer, int offset)
{
	fLastErrorMessage = null;

	IContextInformation[] result = null;

	IContentAssistProcessor p = getProcessor(viewer, offset);
	if (p != null)
	{
		result = p.computeContextInformation(viewer, offset);
		fLastErrorMessage = p.getErrorMessage();
	}

	return result;
}
 
Example #7
Source File: HTMLContentAssistProcessor.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * createProposal
 * 
 * @param displayName
 * @param name
 * @param image
 * @param description
 * @param userAgents
 * @param fileLocation
 * @param offset
 * @param length
 * @return
 */
protected CommonCompletionProposal createProposal(String displayName, String name, Image image, String description,
		String[] userAgentIds, String fileLocation, int offset, int length)
{
	IContextInformation contextInfo = null;

	// TEMP:
	int replaceLength = 0;

	if (this._replaceRange != null)
	{
		offset = this._replaceRange.getStartingOffset();
		replaceLength = this._replaceRange.getLength();
	}

	Image[] userAgents = UserAgentManager.getInstance().getUserAgentImages(getProject(), userAgentIds);

	// build proposal
	CommonCompletionProposal proposal = new CommonCompletionProposal(name, offset, replaceLength, length, image,
			displayName, contextInfo, description);
	proposal.setFileLocation(fileLocation);
	proposal.setUserAgentImages(userAgents);
	return proposal;
}
 
Example #8
Source File: ContextInformationComputer.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IContextInformation[] exec(XtextResource resource) throws Exception {
	IContextInformationAcceptor acceptor = state.decorateAcceptor(this);
	ContentAssistContext[] contexts = state.getContextFactory().create(viewer, offset, resource);
	for (ContentAssistContext context: contexts) {
		if (acceptor.canAcceptMoreInformation())
			state.getContextInformationProvider().getContextInformation(context, acceptor);
	}
	if (information.isEmpty())
		return null;
	return information.toArray(new IContextInformation[information.size()]);
}
 
Example #9
Source File: ContextInformationPopup.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Displays the given context information for the given offset.
 * 
 * @param info
 *            the context information
 * @param offset
 *            the offset
 * @since 2.0
 */
public void showContextInformation(final IContextInformation info, final int offset)
{
	Control control = fContentAssistSubjectControlAdapter.getControl();
	BusyIndicator.showWhile(control.getDisplay(), new Runnable()
	{
		public void run()
		{
			if (info == null)
			{
				validateContextInformation();
			}
			else
			{
				ContextFrame frame = createContextFrame(info, offset);
				if (isDuplicate(frame))
				{
					validateContextInformation();
				}
				else
				{
					internalShowContextInfo(frame);
				}
				hideContextSelector();
			}
		}
	});
}
 
Example #10
Source File: SmartInformationAwareContextInformationValidator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isContextInformationValid(int offset) {
	if (fContextInformation instanceof ISmartContextInformation) {
		return ((ISmartContextInformation) fContextInformation).isContextInformationValid(fViewer, offset);
	} else {
		IContextInformation[] infos= fProcessor.computeContextInformation(fViewer, offset);
		if (infos != null && infos.length > 0) {
			for (int i= 0; i < infos.length; i++)
				if (fContextInformation.equals(infos[i]))
					return true;
		}
		return false;
	}
}
 
Example #11
Source File: ContextInformationPopup.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public ContextFrame(IContextInformation information, int beginOffset, int offset, int visibleOffset,
		IContextInformationValidator validator, IContextInformationPresenter presenter)
{
	fInformation = information;
	fBeginOffset = beginOffset;
	fOffset = offset;
	fVisibleOffset = visibleOffset;
	fValidator = validator;
	fPresenter = presenter;
}
 
Example #12
Source File: JsonQuickAssistProcessor.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IContextInformation getContextInformation() {
    if (markerResolution instanceof IMarkerResolution2) {
        IMarkerResolution2 mr2 = (IMarkerResolution2) markerResolution;
        String displayString = mr2.getDescription() == null ? mr2.getLabel() : mr2.getDescription();

        return new ContextInformation(mr2.getImage(), mr2.getLabel(), displayString);
    }
    return null;
}
 
Example #13
Source File: N4JSCompletionProposal.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new proposal.
 */
public N4JSCompletionProposal(String replacementString, int replacementOffset, int replacementLength,
		int cursorPosition, Image image, StyledString displayString, IContextInformation contextInformation,
		String additionalProposalInfo) {
	super(replacementString, replacementOffset, replacementLength, cursorPosition, image, displayString,
			contextInformation, additionalProposalInfo);
}
 
Example #14
Source File: HContentAssistProcessor.java    From http4e with Apache License 2.0 5 votes vote down vote up
public IContextInformation[] computeContextInformation( ITextViewer viewer, int documentOffset){
   // viewer.getSelectedRange();
   // if (selectedRange.y > 0) Text is selected. Create a context information array.
   // ContextInformation[] contextInfos = new
   // ContextInformation[STYLELABELS.length];
   // // Create one context information item for each style
   // for (int i = 0; i < STYLELABELS.length; i++)
   // contextInfos[i] = new ContextInformation("<" + STYLETAGS[i] + ">",
   // STYLELABELS[i] + " Style");
   // return contextInfos;
   // }
   return new ContextInformation[0];
}
 
Example #15
Source File: XtextContentAssistProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IContextInformation[] computeContextInformation(final ITextViewer viewer, final int offset) {
	if (contextInformationProvider == null)
		return null;
	
	IXtextDocument document = xtextDocumentUtil.getXtextDocument(viewer);
	return document.priorityReadOnly(createContextInformationComputer(viewer, offset));
}
 
Example #16
Source File: ContextInformationComputer.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public ContextInformationComputer(State state, ITextViewer viewer, int offset) {
	super();
	this.information = new LinkedHashSet<IContextInformation>();
	this.state = state;
	this.offset = offset;
	this.viewer = viewer;
}
 
Example #17
Source File: JSContextInformationValidator.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void install(IContextInformation info, ITextViewer viewer, int offset)
{
	this._contextInformation = info;
	this._viewer = viewer;

	if (info instanceof IContextInformationExtension)
	{
		this._startingOffset = ((IContextInformationExtension) info).getContextInformationPosition();
	}
	else
	{
		this._startingOffset = offset;
	}
}
 
Example #18
Source File: CommonCompletionProposal.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * CommonCompletionProposal
 * 
 * @param replacementString
 * @param replacementOffset
 * @param replacementLength
 * @param cursorPosition
 * @param image
 * @param displayString
 * @param contextInformation
 * @param additionalProposalInfo
 */
public CommonCompletionProposal(String replacementString, int replacementOffset, int replacementLength,
		int cursorPosition, Image image, String displayString, IContextInformation contextInformation,
		String additionalProposalInfo)
{
	this._replacementString = (replacementString == null) ? StringUtil.EMPTY : replacementString;
	this._replacementOffset = replacementOffset;
	this._replacementLength = replacementLength;
	this._cursorPosition = cursorPosition;
	this._image = image;
	this._displayString = (displayString == null) ? StringUtil.EMPTY : displayString;
	this._contextInformation = contextInformation;
	this._additionalProposalInformation = additionalProposalInfo;
}
 
Example #19
Source File: TypeScriptCompletionProposal.java    From typescript.java with MIT License 5 votes vote down vote up
private IContextInformation createContextInformation() {
	try {
		String information = null;
		List<CompletionEntryDetails> entryDetails = super.getEntryDetails();
		if (entryDetails == null || entryDetails.size() < 1) {
			return null;
		}
		if (isFunction()) {
			information = TypeScriptHelper.extractFunctionParameters(entryDetails.get(0).getDisplayParts());
		}
		return information != null ? new ContextInformation("", information) : null;
	} catch (TypeScriptException e) {
	}
	return null;
}
 
Example #20
Source File: TexStyleCompletionManager.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the style context.
 * 
 * @return Array of style contexts
 */
public IContextInformation[] getStyleContext() {
    ContextInformation[] contextInfos = new ContextInformation[STYLELABELS.length];
    
    // Create one context information item for each style
    for (int i = 0; i < STYLELABELS.length; i++) {
        contextInfos[i] = new ContextInformation(null, STYLELABELS[i]+" Style");
    }
    return contextInfos;
}
 
Example #21
Source File: TypeScriptCompletionProposal.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
public IContextInformation getContextInformation() {
	if (contextInformationComputed) {
		return contextInformation;
	}
	this.contextInformation = createContextInformation();
	contextInformationComputed = true;
	return contextInformation;
}
 
Example #22
Source File: TLACompletionProcessor.java    From tlaplus with MIT License 5 votes vote down vote up
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
	// Retrieve selected range
	final Point selectedRange = viewer.getSelectedRange();
	if (selectedRange.y > 0) {
		// Text is selected. Create a context information array.
		final IContextInformation[] contextInfos = new ContextInformation[ITLAReserveredWords.ALL_WORDS_ARRAY.length];

		// Create one context information item for each style
		for (int i = 0; i < ITLAReserveredWords.ALL_WORDS_ARRAY.length; i++) {
			contextInfos[i] = new ContextInformation(null, ITLAReserveredWords.ALL_WORDS_ARRAY[i] + " Style");
		}
		return contextInfos;
	}
	return new ContextInformation[0];
}
 
Example #23
Source File: ToolboxCompletionProcessor.java    From tlaplus with MIT License 5 votes vote down vote up
public CompletionProposalTemplate(String replacementString, Image image, String dipslayString,
		IContextInformation contextInformation, String additionalProposalInfo) {
	this.fReplacementString = replacementString;
	this.fImage = image;
	this.fDisplayString = dipslayString;
	this.fContextInformation = contextInformation;
	this.fAdditionalProposalInfo = additionalProposalInfo;
}
 
Example #24
Source File: ToolboxCompletionProcessor.java    From tlaplus with MIT License 5 votes vote down vote up
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
	// Retrieve selected range
	final Point selectedRange = viewer.getSelectedRange();
	if (selectedRange.y > 0) {
		// Text is selected. Create a context information array.
		final IContextInformation[] contextInfos = new ContextInformation[ITLAReserveredWords.ALL_WORDS_ARRAY.length];

		// Create one context information item for each style
		for (int i = 0; i < ITLAReserveredWords.ALL_WORDS_ARRAY.length; i++) {
			contextInfos[i] = new ContextInformation(null, ITLAReserveredWords.ALL_WORDS_ARRAY[i] + " Style");
		}
		return contextInfos;
	}
	return new ContextInformation[0];
}
 
Example #25
Source File: PositionBasedCompletionProposal.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public IContextInformation getContextInformation()
{
	return fContextInformation;
}
 
Example #26
Source File: DisableSpellCheckingProposal.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public final IContextInformation getContextInformation() {
	return null;
}
 
Example #27
Source File: ToolboxCompletionProcessor.java    From tlaplus with MIT License 4 votes vote down vote up
public IContextInformation getContextInformation() {
	return fContextInformation;
}
 
Example #28
Source File: ToolboxCompletionProcessor.java    From tlaplus with MIT License 4 votes vote down vote up
/**
 * Creates a new completion proposal. All fields are initialized based on the
 * provided information.
 *
 * @param replacementString
 *            the actual string to be inserted into the document
 * @param replacementOffset
 *            the offset of the text to be replaced
 * @param replacementLength
 *            the length of the text to be replaced
 * @param cursorPosition
 *            the position of the cursor following the insert relative to
 *            replacementOffset
 * @param image
 *            the image to display for this proposal
 * @param displayString
 *            the string to be displayed for the proposal
 * @param contextInformation
 *            the context information associated with this proposal
 * @param additionalProposalInfo
 *            the additional information associated with this proposal
 */
public ToolboxCompletionProposal(String replacementString, int replacementOffset, int replacementLength,
		int cursorPosition, Image image, String displayString, IContextInformation contextInformation,
		String additionalProposalInfo) {
	Assert.isNotNull(replacementString);
	Assert.isTrue(replacementOffset >= 0);
	Assert.isTrue(replacementLength >= 0);
	Assert.isTrue(cursorPosition >= 0);

	fReplacementString = replacementString;
	fReplacementOffset = replacementOffset;
	fReplacementLength = replacementLength;
	fCursorPosition = cursorPosition;
	fImage = image;
	fDisplayString = displayString;
	fContextInformation = contextInformation;
	fAdditionalProposalInfo = additionalProposalInfo;
}
 
Example #29
Source File: ImpexTypeAttributeContentAssistProcessor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public IContextInformation[] computeContextInformation(ITextViewer itv, int cursorPosition) {

	exMsg = "No Context Information available";
	return null;
}
 
Example #30
Source File: ModulaContextualCompletionProposal.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public IContextInformation getContextInformation() {
    return fContextInformation;
}