Search in sources :

Example 51 with IDocument

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

the class ResourceChange method getModificationStamp.

private long getModificationStamp(IResource resource) {
    if (!(resource instanceof IFile))
        return resource.getModificationStamp();
    IFile file = (IFile) resource;
    ITextFileBuffer buffer = getBuffer(file);
    if (buffer == null) {
        return file.getModificationStamp();
    } else {
        IDocument document = buffer.getDocument();
        if (document instanceof IDocumentExtension4) {
            return ((IDocumentExtension4) document).getModificationStamp();
        } else {
            return file.getModificationStamp();
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument)

Example 52 with IDocument

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

the class MultiStateUndoChange method perform.

/**
	 * {@inheritDoc}
	 */
public Change perform(IProgressMonitor pm) throws CoreException {
    if (fValidationState == null || fValidationState.isValid(needsSaving(), false).hasFatalError())
        return new NullChange();
    if (pm == null)
        pm = new NullProgressMonitor();
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    //$NON-NLS-1$
    pm.beginTask("", 2);
    ITextFileBuffer buffer = null;
    try {
        manager.connect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
        buffer = manager.getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
        IDocument document = buffer.getDocument();
        ContentStamp currentStamp = ContentStamps.get(fFile, document);
        // perform the changes
        LinkedList list = new LinkedList();
        for (int index = 0; index < fUndos.length; index++) {
            UndoEdit edit = fUndos[index];
            UndoEdit redo = edit.apply(document, TextEdit.CREATE_UNDO);
            list.addFirst(redo);
        }
        // try to restore the document content stamp
        boolean success = ContentStamps.set(document, fContentStampToRestore);
        if (needsSaving()) {
            buffer.commit(pm, false);
            if (!success) {
                // We weren't able to restore document stamp.
                // Since we save restore the file stamp instead
                ContentStamps.set(fFile, fContentStampToRestore);
            }
        }
        return createUndoChange((UndoEdit[]) list.toArray(new UndoEdit[list.size()]), currentStamp);
    } catch (BadLocationException e) {
        throw Changes.asCoreException(e);
    } finally {
        if (buffer != null)
            manager.disconnect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) NullChange(org.eclipse.ltk.core.refactoring.NullChange) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) ContentStamp(org.eclipse.ltk.core.refactoring.ContentStamp) UndoEdit(org.eclipse.text.edits.UndoEdit) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IDocument(org.eclipse.jface.text.IDocument) LinkedList(java.util.LinkedList) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 53 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 54 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 55 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)

Aggregations

IDocument (org.eclipse.jface.text.IDocument)488 BadLocationException (org.eclipse.jface.text.BadLocationException)195 Document (org.eclipse.jface.text.Document)118 Test (org.junit.Test)93 IRegion (org.eclipse.jface.text.IRegion)72 Point (org.eclipse.swt.graphics.Point)63 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)54 Position (org.eclipse.jface.text.Position)51 ArrayList (java.util.ArrayList)44 CoreException (org.eclipse.core.runtime.CoreException)39 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)30 IPath (org.eclipse.core.runtime.IPath)26 IFile (org.eclipse.core.resources.IFile)25 IStatus (org.eclipse.core.runtime.IStatus)25 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)24 TextEdit (org.eclipse.text.edits.TextEdit)23 Region (org.eclipse.jface.text.Region)22 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)22 LinkedPositionGroup (org.eclipse.jface.text.link.LinkedPositionGroup)21 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)20