Search in sources :

Example 1 with ContextType

use of com.reprezen.swagedit.core.assist.contexts.ContextType in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonContentAssistProcessor method initTextMessages.

protected String[] initTextMessages() {
    IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
    String bindingKey = bindingService.getBestActiveBindingFormattedFor(EDIT_CONTENT_ASSIST);
    ContextType contextType = referenceProposalProvider.getContextTypes().get(getCurrentPath() != null ? getCurrentPath().toString() : "");
    String context = contextType != null ? contextType.label() : "";
    return new String[] { //
    String.format(Messages.content_assist_proposal_project, bindingKey, context), String.format(Messages.content_assist_proposal_workspace, bindingKey, context), String.format(Messages.content_assist_proposal_local, bindingKey, context) };
}
Also used : TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) ContextType(com.reprezen.swagedit.core.assist.contexts.ContextType) StyledString(org.eclipse.jface.viewers.StyledString) IBindingService(org.eclipse.ui.keys.IBindingService)

Example 2 with ContextType

use of com.reprezen.swagedit.core.assist.contexts.ContextType in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonReferenceProposalProvider method getProposals.

/**
     * Returns collection of JSON reference proposals.
     * 
     * If the scope is local, it will only return JSON references from within the current document.
     * 
     * If the scope is project, it will return all JSON references from within the current document and from all
     * documents inside the same project.
     * 
     * If the scope is workspace, it will return all JSON references from within the current document and from all
     * documents inside the same workspace.
     * 
     * @param pointer
     * @param document
     * @param scope
     * @return proposals
     */
public Collection<Proposal> getProposals(JsonPointer pointer, JsonDocument document, Scope scope) {
    final ContextType type = contextTypes.get(pointer.toString());
    final IFile currentFile = getActiveFile();
    final IPath basePath = currentFile.getParent().getFullPath();
    final List<Proposal> proposals = Lists.newArrayList();
    if (scope == Scope.LOCAL) {
        proposals.addAll(type.collectProposals(document, null));
    } else if (!type.isLocalOnly()) {
        final SwaggerFileFinder fileFinder = new SwaggerFileFinder(fileContentType);
        for (IFile file : fileFinder.collectFiles(scope, currentFile)) {
            IPath relative = file.equals(currentFile) ? null : file.getFullPath().makeRelativeTo(basePath);
            if (file.equals(currentFile)) {
                proposals.addAll(type.collectProposals(document, relative));
            } else {
                proposals.addAll(type.collectProposals(manager.getDocument(file.getLocationURI()), relative));
            }
        }
    }
    return proposals;
}
Also used : ContextType(com.reprezen.swagedit.core.assist.contexts.ContextType) IFile(org.eclipse.core.resources.IFile) SwaggerFileFinder(com.reprezen.swagedit.core.utils.SwaggerFileFinder) IPath(org.eclipse.core.runtime.IPath)

Aggregations

ContextType (com.reprezen.swagedit.core.assist.contexts.ContextType)2 SwaggerFileFinder (com.reprezen.swagedit.core.utils.SwaggerFileFinder)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)1 StyledString (org.eclipse.jface.viewers.StyledString)1 IBindingService (org.eclipse.ui.keys.IBindingService)1