Search in sources :

Example 1 with ICompletionProposal

use of org.eclipse.jface.text.contentassist.ICompletionProposal in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonContentAssistProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
    if (!(viewer.getDocument() instanceof JsonDocument)) {
        return super.computeCompletionProposals(viewer, documentOffset);
    }
    maybeSwitchScope(documentOffset);
    final JsonDocument document = (JsonDocument) viewer.getDocument();
    final ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
    int line = 0, lineOffset = 0, column = 0;
    try {
        line = document.getLineOfOffset(documentOffset);
        lineOffset = document.getLineOffset(line);
        column = selection.getOffset() - lineOffset;
    } catch (BadLocationException e) {
    }
    final String prefix = extractPrefix(viewer, documentOffset);
    // column to resolve the path
    if (!prefix.isEmpty()) {
        column -= prefix.length();
    }
    Model model = document.getModel(documentOffset - prefix.length());
    currentPath = model.getPath(line, column);
    isRefCompletion = referenceProposalProvider.canProvideProposal(currentPath);
    Collection<Proposal> p;
    if (isRefCompletion) {
        updateStatus();
        p = referenceProposalProvider.getProposals(currentPath, document, currentScope);
    } else {
        clearStatus();
        p = proposalProvider.getProposals(currentPath, model, prefix);
    }
    final Collection<ICompletionProposal> proposals = getCompletionProposals(p, prefix, documentOffset);
    // compute template proposals
    if (!isRefCompletion) {
        final ICompletionProposal[] templateProposals = super.computeCompletionProposals(viewer, documentOffset);
        if (templateProposals != null && templateProposals.length > 0) {
            proposals.addAll(Lists.newArrayList(templateProposals));
        }
    }
    return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Model(com.reprezen.swagedit.core.model.Model) StyledString(org.eclipse.jface.viewers.StyledString) JsonDocument(com.reprezen.swagedit.core.editor.JsonDocument) ITextSelection(org.eclipse.jface.text.ITextSelection) BadLocationException(org.eclipse.jface.text.BadLocationException) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Example 2 with ICompletionProposal

use of org.eclipse.jface.text.contentassist.ICompletionProposal in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonContentAssistProcessor method getCompletionProposals.

protected Collection<ICompletionProposal> getCompletionProposals(Collection<Proposal> proposals, String prefix, int offset) {
    final List<ICompletionProposal> result = new ArrayList<>();
    prefix = Strings.emptyToNull(prefix);
    for (Proposal proposal : proposals) {
        StyledCompletionProposal styledProposal = proposal.asStyledCompletionProposal(prefix, offset);
        if (styledProposal != null) {
            result.add(styledProposal);
        }
    }
    return result;
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Example 3 with ICompletionProposal

use of org.eclipse.jface.text.contentassist.ICompletionProposal in project tdi-studio-se by Talend.

the class TalendCompletionProposalComputer method computeCompletionProposals.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer#computeCompletionProposals(org.eclipse.jdt.ui.text
     * .java.ContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
     */
public List computeCompletionProposals(ITextViewer textViewer, String prefix, int offset, IProgressMonitor monitor) {
    List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
    IDesignerCoreService service = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
    IProcess process = service.getCurrentProcess();
    if (process == null) {
        return Collections.EMPTY_LIST;
    }
    // Compute the length of replacement for proposal. See bug 0004266: Replace value with context value using
    // CTRL+Space.
    int replacementLength = textViewer.getSelectedRange().y;
    if (replacementLength == 0) {
        replacementLength = prefix.length();
    }
    // Proposals based on process context
    List<IContextParameter> ctxParams = process.getContextManager().getDefaultContext().getContextParameterList();
    for (IContextParameter ctxParam : ctxParams) {
        String display = CONTEXT_PREFIX + ctxParam.getName();
        String code = getContextContent(ctxParam);
        String description = getContextDescription(ctxParam, display);
        String ctxName = ctxParam.getName();
        if (prefix.equals("") || display.startsWith(prefix)) {
            //$NON-NLS-1$
            TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.CONTEXT_ICON), display, null, description);
            proposal.setType(TalendCompletionProposal.CONTEXT);
            proposals.add(proposal);
        } else if (prefix.equals("") || ctxName.startsWith(prefix)) {
            //$NON-NLS-1$
            if (code.startsWith(CONTEXT_PREFIX)) {
                code = code.replaceFirst(CONTEXT_PREFIX, "");
            }
            TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.CONTEXT_ICON), display, null, description);
            proposal.setType(TalendCompletionProposal.CONTEXT);
            proposals.add(proposal);
        }
    }
    // Proposals based on global variables
    List<? extends INode> nodes = process.getGraphicalNodes();
    for (INode node : nodes) {
        List<? extends INodeReturn> nodeReturns = node.getReturns();
        for (INodeReturn nodeReturn : nodeReturns) {
            //$NON-NLS-1$
            String display = node.getLabel() + "." + nodeReturn.getName();
            if (prefix.equals("") || display.startsWith(prefix)) {
                //$NON-NLS-1$
                String code = getNodeReturnContent(nodeReturn, node);
                String description = getNodeReturnDescription(nodeReturn, node, display);
                TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), CoreImageProvider.getComponentIcon(node.getComponent(), ICON_SIZE.ICON_16), display, null, description);
                proposal.setType(TalendCompletionProposal.NODE_RETURN);
                proposals.add(proposal);
            }
        }
    }
    // Proposals based on global variables(only perl ).
    // add proposals on global variables in java (bugtracker 2554)
    // add variables in java
    IContentProposal[] javavars = JavaGlobalUtils.getProposals();
    for (IContentProposal javavar : javavars) {
        String display = javavar.getLabel();
        if (prefix.equals("") || display.startsWith(prefix)) {
            //$NON-NLS-1$
            String code = javavar.getContent();
            String description = getGlobalVarDescription(javavar, display);
            TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.PROCESS_ICON), display, null, description);
            proposal.setType(TalendCompletionProposal.VARIABLE);
            proposals.add(proposal);
        }
    }
    FunctionManager functionManager = new FunctionManager();
    List<TalendType> talendTypes = functionManager.getTalendTypes();
    for (TalendType type : talendTypes) {
        for (Object objectFunction : type.getFunctions()) {
            Function function = (Function) objectFunction;
            //$NON-NLS-1$
            String display = function.getCategory() + "." + function.getName();
            if (prefix.equals("") || display.startsWith(prefix)) {
                //$NON-NLS-1$
                String code = FunctionManager.getFunctionMethod(function);
                String description = getFunctionDescription(function, display, code);
                TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.ROUTINE_ICON), display, null, description);
                proposal.setType(TalendCompletionProposal.ROUTINE);
                proposals.add(proposal);
            }
        }
    }
    for (IExternalProposals externalProposals : ProposalFactory.getInstances()) {
        proposals.addAll(externalProposals.getAdvancedProposals(offset, prefix));
    }
    return proposals;
}
Also used : IExternalProposals(org.talend.core.ui.proposal.IExternalProposals) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IContextParameter(org.talend.core.model.process.IContextParameter) TalendType(org.talend.designer.rowgenerator.data.TalendType) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) Function(org.talend.designer.rowgenerator.data.Function) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) INodeReturn(org.talend.core.model.process.INodeReturn) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) FunctionManager(org.talend.designer.rowgenerator.data.FunctionManager)

Example 4 with ICompletionProposal

use of org.eclipse.jface.text.contentassist.ICompletionProposal in project tdi-studio-se by Talend.

the class SQLCompletionProcessor method getProposalsByNode.

/**
     * DOC dev Comment method "getProposalsByNode".
     * 
     * @param documentOffset
     * @param node
     * @return
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private ICompletionProposal[] getProposalsByNode(int documentOffset, INode node) {
    Object[] children = (Object[]) node.getChildNodes();
    ArrayList propList = new ArrayList();
    if (children != null) {
        for (int i = 0; i < children.length; i++) {
            String childName = children[i].toString().toLowerCase();
            if (//$NON-NLS-1$
            childName.equals("table") || childName.equals("view")) {
                //$NON-NLS-1$
                Object[] tables = (Object[]) ((INode) children[i]).getChildNodes();
                if (tables != null) {
                    for (int j = 0; j < tables.length; j++) {
                        Image tmpImage = null;
                        String tableName = tables[j].toString();
                        if (tables[j] instanceof TableNode) {
                            if (((TableNode) tables[j]).isTable()) {
                                tmpImage = tableImage;
                            } else if (((TableNode) tables[j]).isView()) {
                                tmpImage = viewImage;
                            }
                            propList.add(new ExtendedCompletionProposal(tableName, documentOffset, 0, tableName.length(), tmpImage, tableName, (TableNode) tables[j]));
                        }
                    }
                }
            }
        }
    }
    ICompletionProposal[] res = new ICompletionProposal[propList.size()];
    System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
    Arrays.sort(res, new ICompletionProposalComparator());
    return res;
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point)

Example 5 with ICompletionProposal

use of org.eclipse.jface.text.contentassist.ICompletionProposal in project tdi-studio-se by Talend.

the class SQLCompletionProcessor method inputNotContainDot.

/**
     * DOC dev Comment method "inputNotContainDot".
     * 
     * @param documentOffset
     * @param string
     * @param length
     * @return
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private ICompletionProposal[] inputNotContainDot(int documentOffset, String string, int length) {
    // The string does not contain "."
    String[] keywordProposal = Dictionary.matchKeywordsPrefix(string);
    ICompletionProposal[] resKey = new ICompletionProposal[keywordProposal.length];
    for (int i = 0; i < keywordProposal.length; i++) {
        resKey[i] = new CompletionProposal(keywordProposal[i], documentOffset - length, length, keywordProposal[i].length(), keywordImage, keywordProposal[i], null, null);
    }
    String[] proposalsString = dictionary.matchTablePrefix(string.toLowerCase());
    ArrayList propList = new ArrayList();
    for (int i = 0; i < proposalsString.length; i++) {
        ArrayList ls = dictionary.getTableObjectList(proposalsString[i]);
        for (int j = 0; j < ls.size(); j++) {
            TableNode tbNode = (TableNode) ls.get(j);
            Image tmpImage = null;
            if (tbNode.isView()) {
                tmpImage = viewImage;
            } else if (tbNode.isTable()) {
                tmpImage = tableImage;
            }
            ICompletionProposal cmp = new ExtendedCompletionProposal(proposalsString[i], documentOffset - length, length, proposalsString[i].length(), tmpImage, proposalsString[i], tbNode);
            propList.add(cmp);
        }
    }
    String[] proposalsString2 = dictionary.matchCatalogSchemaPrefix(string.toLowerCase());
    ICompletionProposal[] resKey2 = new ICompletionProposal[proposalsString2.length];
    for (int i = 0; i < proposalsString2.length; i++) {
        resKey2[i] = new CompletionProposal(proposalsString2[i], documentOffset - length, length, proposalsString2[i].length(), catalogImage, proposalsString2[i], null, null);
    }
    ICompletionProposal[] res = new ICompletionProposal[propList.size() + keywordProposal.length + resKey2.length];
    System.arraycopy(resKey, 0, res, 0, resKey.length);
    System.arraycopy(propList.toArray(), 0, res, resKey.length, propList.size());
    System.arraycopy(resKey2, 0, res, resKey.length + propList.size(), resKey2.length);
    Arrays.sort(res, new ICompletionProposalComparator());
    return res;
}
Also used : CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point)

Aggregations

ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)17 ArrayList (java.util.ArrayList)7 LinkedList (java.util.LinkedList)5 CompletionProposal (org.eclipse.jface.text.contentassist.CompletionProposal)5 BadLocationException (org.eclipse.jface.text.BadLocationException)4 Point (org.eclipse.swt.graphics.Point)4 TableNode (org.talend.sqlbuilder.dbstructure.nodes.TableNode)4 Image (org.eclipse.swt.graphics.Image)3 Iterator (java.util.Iterator)2 BuildErrorDetailsHandler (org.bndtools.build.api.BuildErrorDetailsHandler)2 IMarker (org.eclipse.core.resources.IMarker)2 SourceField (org.eclipse.jdt.internal.core.SourceField)2 JavaCompletionProposal (org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal)2 IDocument (org.eclipse.jface.text.IDocument)2 IMarkerResolution (org.eclipse.ui.IMarkerResolution)2 INode (org.talend.sqlbuilder.dbstructure.nodes.INode)2 JsonDocument (com.reprezen.swagedit.core.editor.JsonDocument)1 Model (com.reprezen.swagedit.core.model.Model)1 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1