Search in sources :

Example 36 with IDocument

use of org.eclipse.jface.text.IDocument in project che by eclipse.

the class TextFileChange method acquireDocument.

/**
	 * {@inheritDoc}
	 */
protected IDocument acquireDocument(IProgressMonitor pm) throws CoreException {
    fAcquireCount++;
    if (fAcquireCount > 1)
        return fBuffer.getDocument();
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    IPath path = fFile.getFullPath();
    manager.connect(path, LocationKind.IFILE, pm);
    fBuffer = manager.getTextFileBuffer(path, LocationKind.IFILE);
    IDocument result = fBuffer.getDocument();
    fContentStamp = ContentStamps.get(fFile, result);
    return result;
}
Also used : IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) IDocument(org.eclipse.jface.text.IDocument)

Example 37 with IDocument

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

the class TalendJavaSourceViewer method createViewerForIfConnection.

public static ISourceViewer createViewerForIfConnection(Composite composite) {
    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");
    //$NON-NLS-1$
    buff.append("\tprivate static java.util.Properties context = new java.util.Properties();\n");
    //$NON-NLS-1$
    buff.append("\tprivate static final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>();\n");
    //$NON-NLS-1$
    buff.append("\tpublic void myFunction(){\n");
    //$NON-NLS-1$
    buff.append("\t  if( \n");
    int documentOffset = buff.toString().length();
    //$NON-NLS-1$
    buff.append("){\n\t}");
    //$NON-NLS-1$
    buff.append("\n\t\n}\n}");
    IDocument document = new Document();
    document.set(buff.toString());
    boolean checkCode = false;
    int styles = SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.WRAP;
    return initializeViewer(composite, styles, checkCode, document, documentOffset);
}
Also used : Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument)

Example 38 with IDocument

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

the class TalendJavaSourceViewer method createViewerWithVariables.

public static ReconcilerViewer createViewerWithVariables(Composite composite, int styles, IExpressionDataBean dataBean) {
    IDocument document = new Document();
    StringBuffer buff = new StringBuffer();
    //$NON-NLS-1$
    buff.append("\npackage internal;\n\n");
    buff.append(getImports());
    //$NON-NLS-1$ //$NON-NLS-2$
    buff.append("public class " + VIEWER_CLASS_NAME + currentId + " {\n");
    IRunProcessService runProcessService = getRunProcessService();
    if (runProcessService != null && runProcessService.getSelectedContext() != null) {
        List<IContextParameter> params = runProcessService.getSelectedContext().getContextParameterList();
        buff.append(TEXT_1);
        for (IContextParameter ctxParam : params) {
            buff.append(TEXT_2);
            buff.append(ctxParam.getName());
            buff.append(TEXT_3);
            buff.append(ctxParam.getName());
            buff.append(TEXT_4);
        }
        buff.append(TEXT_5);
        for (IContextParameter ctxParam : params) {
            if (//$NON-NLS-1$ //$NON-NLS-2$
            ctxParam.getType().equals("id_List Of Value") || ctxParam.getType().equals("id_File") || ctxParam.getType().equals("id_Directory") || ctxParam.getType().equals("id_Character")) {
                //$NON-NLS-1$ //$NON-NLS-2$
                buff.append(TEXT_6);
                buff.append(ctxParam.getName());
                buff.append(TEXT_7);
            } else {
                buff.append(TEXT_8);
                buff.append(JavaTypesManager.getTypeToGenerate(ctxParam.getType(), true));
                buff.append(TEXT_9);
                buff.append(ctxParam.getName());
                buff.append(TEXT_10);
            }
        }
        buff.append(TEXT_11);
        //$NON-NLS-1$
        buff.append("\tprivate static ContextProperties context = new ContextProperties();\n");
        //$NON-NLS-1$
        buff.append("\tprivate static final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>();\n");
        if (dataBean != null) {
            buff.append(parseVariables(dataBean.getVariables()));
            //$NON-NLS-1$ //$NON-NLS-2$
            buff.append("\tpublic " + dataBean.getExpressionType() + " myFunction(){\n");
        }
        //$NON-NLS-1$
        buff.append("\t\treturn \n");
    }
    int length = buff.toString().length();
    //$NON-NLS-1$
    String defaultValue = "";
    //$NON-NLS-1$
    buff.append(defaultValue + "\n;\t\n}\n}");
    document.set(buff.toString());
    return initializeViewer(composite, styles, true, document, length);
}
Also used : IRunProcessService(org.talend.designer.runprocess.IRunProcessService) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IContextParameter(org.talend.core.model.process.IContextParameter) IDocument(org.eclipse.jface.text.IDocument)

Example 39 with IDocument

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

the class TalendJavaSourceViewer method initializeModel.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.ui.viewer.ReconcilerViewer#initializeModel(IDocument document)
     */
@Override
protected void initializeModel() {
    getSourceViewerDecorationSupport().install(JavaPlugin.getDefault().getCombinedPreferenceStore());
    this.setRangeIndicator(new DefaultRangeIndicator());
    IAnnotationModel model;
    IDocument document;
    if (checkCode) {
        IDocumentProvider provider = JavaPlugin.getDefault().getCompilationUnitDocumentProvider();
        IEditorInput ei = new FileEditorInput(file);
        try {
            provider.connect(ei);
        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
        document = provider.getDocument(ei);
        model = provider.getAnnotationModel(ei);
    } else {
        model = new AnnotationModel();
        document = getDocument();
        model.connect(document);
    }
    if (document != null) {
        setDocument(document, model);
        showAnnotations(model != null && checkCode);
    }
    super.initializeModel();
}
Also used : DefaultRangeIndicator(org.eclipse.ui.texteditor.DefaultRangeIndicator) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) IEditorInput(org.eclipse.ui.IEditorInput)

Example 40 with IDocument

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

the class TalendCompletionProposalComputer method computeCompletionProposals.

@Override
public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
    //$NON-NLS-1$
    String prefix = "";
    try {
        if (context != null) {
            prefix = context.computeIdentifierPrefix().toString();
            //$NON-NLS-1$
            String tmpPrefix = "";
            IDocument doc = context.getDocument();
            if ((!prefix.equals("")) || (doc.get().length() == 0)) {
                //$NON-NLS-1$
                tmpPrefix = prefix;
            } else {
                int offset = context.getInvocationOffset();
                if (doc.getChar(offset - 1) == '.') {
                    // set by default to avoid other completions
                    //$NON-NLS-1$
                    tmpPrefix = ".";
                    if (offset >= CONTEXT_PREFIX.length() && doc.get(offset - CONTEXT_PREFIX.length(), CONTEXT_PREFIX.length()).equals(CONTEXT_PREFIX)) {
                        tmpPrefix = CONTEXT_PREFIX;
                    } else if (offset >= PERL_GLOBAL_PREFIX.length() & doc.get(offset - PERL_GLOBAL_PREFIX.length(), PERL_GLOBAL_PREFIX.length()).equals(PERL_GLOBAL_PREFIX)) {
                        switch(LanguageManager.getCurrentLanguage()) {
                            case JAVA:
                                // do nothing
                                break;
                            case PERL:
                            default:
                                tmpPrefix = PERL_GLOBAL_PREFIX;
                        }
                    } else {
                        // test each component label.
                        IDesignerCoreService service = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
                        IProcess process = service.getCurrentProcess();
                        if (process == null) {
                            return Collections.EMPTY_LIST;
                        }
                        List<? extends INode> nodes = process.getGraphicalNodes();
                        for (INode node : nodes) {
                            //$NON-NLS-1$
                            String toTest = node.getLabel() + ".";
                            if (offset >= toTest.length() && doc.get(offset - toTest.length(), toTest.length()).equals(toTest)) {
                                tmpPrefix = toTest;
                                break;
                            }
                        }
                    }
                }
            }
            prefix = tmpPrefix;
            if (".".equals(prefix) && LanguageManager.getCurrentLanguage().equals(ECodeLanguage.PERL)) {
                //$NON-NLS-1$
                //$NON-NLS-1$
                prefix = "";
            }
        }
    } catch (BadLocationException e) {
        throw new RuntimeException(e);
    }
    return computeCompletionProposals(context.getViewer(), prefix, context.getInvocationOffset(), monitor);
}
Also used : INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) List(java.util.List) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

IDocument (org.eclipse.jface.text.IDocument)1055 BadLocationException (org.eclipse.jface.text.BadLocationException)379 Document (org.eclipse.jface.text.Document)189 IRegion (org.eclipse.jface.text.IRegion)150 Test (org.junit.Test)107 CoreException (org.eclipse.core.runtime.CoreException)102 Point (org.eclipse.swt.graphics.Point)94 IFile (org.eclipse.core.resources.IFile)90 ArrayList (java.util.ArrayList)85 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)84 Position (org.eclipse.jface.text.Position)74 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)74 IEditorPart (org.eclipse.ui.IEditorPart)62 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)54 IPath (org.eclipse.core.runtime.IPath)54 ITextSelection (org.eclipse.jface.text.ITextSelection)53 TextEdit (org.eclipse.text.edits.TextEdit)49 Region (org.eclipse.jface.text.Region)47 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)44 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)41