Search in sources :

Example 1 with ContentAssistant

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

the class JsonSourceViewerConfiguration method getContentAssistant.

@Override
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
    ContentAssistant ca = new ContentAssistant();
    JsonContentAssistProcessor processor = createContentAssistProcessor(ca);
    ca.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
    ca.setInformationControlCreator(getInformationControlCreator(sourceViewer));
    ca.enableAutoInsert(false);
    ca.enablePrefixCompletion(false);
    ca.enableAutoActivation(true);
    ca.setAutoActivationDelay(100);
    ca.enableColoredLabels(true);
    ca.setShowEmptyList(true);
    ca.setRepeatedInvocationMode(true);
    ca.addCompletionListener(processor);
    ca.setStatusLineVisible(true);
    return ca;
}
Also used : JsonContentAssistProcessor(com.reprezen.swagedit.core.assist.JsonContentAssistProcessor) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant)

Example 2 with ContentAssistant

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

the class TalendJavaViewerConfiguration method getContentAssistant.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration#getContentAssistant(org.eclipse.jface.text.source.ISourceViewer
     * )
     */
@Override
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
    ContentAssistant assistant = new ContentAssistant();
    assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
    //$NON-NLS-1$
    assistant.setRestoreCompletionProposalSize(getSettings("completion_proposal_size"));
    IContentAssistProcessor javaProcessor = new TalendJavaCompletionProcessor(assistant, IDocument.DEFAULT_CONTENT_TYPE);
    assistant.setContentAssistProcessor(javaProcessor, IDocument.DEFAULT_CONTENT_TYPE);
    ContentAssistProcessor singleLineProcessor = new TalendJavaCompletionProcessor(assistant, IJavaPartitions.JAVA_SINGLE_LINE_COMMENT);
    assistant.setContentAssistProcessor(singleLineProcessor, IJavaPartitions.JAVA_SINGLE_LINE_COMMENT);
    ContentAssistProcessor stringProcessor = new TalendJavaCompletionProcessor(assistant, IJavaPartitions.JAVA_STRING);
    assistant.setContentAssistProcessor(stringProcessor, IJavaPartitions.JAVA_STRING);
    ContentAssistProcessor multiLineProcessor = new TalendJavaCompletionProcessor(assistant, IJavaPartitions.JAVA_MULTI_LINE_COMMENT);
    assistant.setContentAssistProcessor(multiLineProcessor, IJavaPartitions.JAVA_MULTI_LINE_COMMENT);
    // ContentAssistProcessor javadocProcessor = new TalendJavaCompletionProcessor(assistant,
    // IJavaPartitions.JAVA_DOC);
    // assistant.setContentAssistProcessor(javadocProcessor, IJavaPartitions.JAVA_DOC);
    // ContentAssistProcessor javadocProcessor = new JavadocCompletionProcessor(getInternalEditor(), assistant);
    // assistant.setContentAssistProcessor(javadocProcessor, IJavaPartitions.JAVA_DOC);
    //
    ContentAssistPreference.configure(assistant, fPreferenceStore);
    assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
    assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
    return assistant;
}
Also used : IContentAssistProcessor(org.eclipse.jface.text.contentassist.IContentAssistProcessor) ContentAssistProcessor(org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor) IContentAssistProcessor(org.eclipse.jface.text.contentassist.IContentAssistProcessor) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant)

Example 3 with ContentAssistant

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

the class TalendJavaSourceViewer method createViewerForComponent.

public static ISourceViewer createViewerForComponent(Composite composite, int styles, CompilationUnitEditor editor, List<Variable> variableList, String uniqueName, String codePart) {
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    String selectedPart = "[" + uniqueName + " " + codePart + " ] start";
    IDocument originalDocument = editor.getDocumentProvider().getDocument(editor.getEditorInput());
    int documentOffset = -1;
    //$NON-NLS-1$
    String globalFields = "";
    //$NON-NLS-1$
    String localFields = "";
    //$NON-NLS-1$
    globalFields = "\tprivate static java.util.Properties context = new java.util.Properties();\n";
    //$NON-NLS-1$
    globalFields += "\tprivate static final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>();\n";
    IDocument newDoc = new Document();
    boolean checkCode = false;
    FindReplaceDocumentAdapter frda = null;
    // hywang modified for bug 9180
    String documentText = originalDocument.get();
    if (documentText != null && !documentText.equals("") && documentText.length() > 0) {
        //$NON-NLS-1$
        frda = new FindReplaceDocumentAdapter(originalDocument);
    }
    try {
        Region region = null;
        if (frda != null) {
            region = (Region) frda.find(0, selectedPart, true, false, false, false);
        }
        if (region != null) {
            checkCode = true;
            documentOffset = region.getOffset();
            documentOffset = originalDocument.getLineOffset(originalDocument.getLineOfOffset(documentOffset) + 2);
            JavaCompletionProcessor processor = new JavaCompletionProcessor(editor, new ContentAssistant(), IDocument.DEFAULT_CONTENT_TYPE);
            boolean globalFieldsDone = false;
            //$NON-NLS-1$
            globalFields = "";
            String className = editor.getPartName().substring(0, editor.getPartName().indexOf('.') + 1);
            ICompletionProposal[] proposals = processor.computeCompletionProposals(editor.getViewer(), documentOffset);
            for (ICompletionProposal curProposal : proposals) {
                if (curProposal instanceof JavaCompletionProposal) {
                    JavaCompletionProposal javaProposal = ((JavaCompletionProposal) curProposal);
                    if (javaProposal.getJavaElement() instanceof SourceField) {
                        globalFieldsDone = true;
                        SourceField sourceField = (SourceField) javaProposal.getJavaElement();
                        //$NON-NLS-1$ //$NON-NLS-2$
                        globalFields += "\t" + sourceField.getSource() + "\n";
                    // System.out.println();
                    }
                    if (javaProposal.getJavaElement() == null && !globalFieldsDone) {
                        //$NON-NLS-1$
                        String[] str = javaProposal.getSortString().split(" ");
                        //$NON-NLS-1$
                        String variable = "";
                        for (int i = str.length - 1; i >= 0; i--) {
                            //$NON-NLS-1$
                            variable += str[i].length() == 0 ? " " : str[i];
                        }
                        if (variable.contains(className)) {
                            continue;
                        }
                        //$NON-NLS-1$
                        variable += ";";
                        //$NON-NLS-1$ //$NON-NLS-2$
                        localFields += "\t\t" + variable + "\n";
                    // System.out.println(variable);
                    }
                }
            }
        }
    } catch (BadLocationException e) {
        ExceptionHandler.process(e);
    } catch (JavaModelException e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
    StringBuffer buff = new StringBuffer();
    //$NON-NLS-1$
    buff.append("package internal;\n\n");
    buff.append(getImports());
    //$NON-NLS-1$ //$NON-NLS-2$
    buff.append("public class " + VIEWER_CLASS_NAME + currentId + " {\n");
    buff.append(globalFields);
    //$NON-NLS-1$
    buff.append("\tpublic void myFunction(){\n");
    buff.append(localFields);
    documentOffset = buff.toString().length();
    //$NON-NLS-1$
    buff.append("\n\t\n}\n}");
    newDoc.set(buff.toString());
    return initializeViewer(composite, styles, checkCode, newDoc, documentOffset);
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) SourceField(org.eclipse.jdt.internal.core.SourceField) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Region(org.eclipse.jface.text.Region) JavaCompletionProcessor(org.eclipse.jdt.internal.ui.text.java.JavaCompletionProcessor) IDocument(org.eclipse.jface.text.IDocument) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) BadLocationException(org.eclipse.jface.text.BadLocationException) JavaCompletionProposal(org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal)

Example 4 with ContentAssistant

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

the class SQLSourceViewerConfiguration method getContentAssistant.

public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
    ContentAssistant assistant = new ContentAssistant() {

        public void uninstall() {
            SQLCompletionProcessor p1 = (SQLCompletionProcessor) getContentAssistProcessor(IConstants.SQL_STRING);
            SQLCompletionProcessor p2 = (SQLCompletionProcessor) getContentAssistProcessor(IConstants.SQL_SINGLE_LINE_COMMENT);
            p1.dispose();
            p2.dispose();
            super.uninstall();
        }
    };
    SQLCompletionProcessor processor = new SQLCompletionProcessor(fSQLTextTools.getDictionary());
    assistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
    // Register the same processor for strings and single line comments to
    // get code completion at the start of those partitions.
    assistant.setContentAssistProcessor(processor, IConstants.SQL_STRING);
    assistant.setContentAssistProcessor(processor, IConstants.SQL_SINGLE_LINE_COMMENT);
    assistant.enableAutoActivation(true);
    assistant.setAutoActivationDelay(500);
    assistant.enableAutoInsert(true);
    assistant.enableAutoActivation(true);
    processor.setCompletionProposalAutoActivationCharacters(//$NON-NLS-1$
    ".".toCharArray());
    /*
		 * assistant.setProposalSelectorForeground(c); c= getColor(store,
		 * PROPOSALS_BACKGROUND, manager);
		 * assistant.setProposalSelectorBackground(c);
		 * 
		 * c= getColor(store, PARAMETERS_FOREGROUND, manager);
		 * assistant.setContextInformationPopupForeground(c);
		 * assistant.setContextSelectorForeground(c);
		 * 
		 * c= getColor(store, PARAMETERS_BACKGROUND, manager);
		 * assistant.setContextInformationPopupBackground(c);
		 * assistant.setContextSelectorBackground(c);
		 */
    // ContentAssistPreference.configure(assistant, getPreferenceStore());
    assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
    assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
    return assistant;
}
Also used : IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant)

Aggregations

ContentAssistant (org.eclipse.jface.text.contentassist.ContentAssistant)4 IContentAssistant (org.eclipse.jface.text.contentassist.IContentAssistant)3 JsonContentAssistProcessor (com.reprezen.swagedit.core.assist.JsonContentAssistProcessor)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 SourceField (org.eclipse.jdt.internal.core.SourceField)1 ContentAssistProcessor (org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor)1 JavaCompletionProcessor (org.eclipse.jdt.internal.ui.text.java.JavaCompletionProcessor)1 JavaCompletionProposal (org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 Document (org.eclipse.jface.text.Document)1 FindReplaceDocumentAdapter (org.eclipse.jface.text.FindReplaceDocumentAdapter)1 IDocument (org.eclipse.jface.text.IDocument)1 Region (org.eclipse.jface.text.Region)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 IContentAssistProcessor (org.eclipse.jface.text.contentassist.IContentAssistProcessor)1