Search in sources :

Example 11 with IDocumentListener

use of org.eclipse.jface.text.IDocumentListener in project titan.EclipsePlug-ins by eclipse.

the class DocumentSetupParticipant method setup.

/*
	 * (non-Javadoc)
	 *
	 * @see
	 * org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.
	 * eclipse.jface.text.IDocument)
	 */
@Override
public void setup(final IDocument document) {
    DocumentTracker.put((IFile) editor.getEditorInput().getAdapter(IFile.class), document);
    IDocumentPartitioner partitioner = new FastPartitioner(new PartitionScanner(), PartitionScanner.PARTITION_TYPES);
    if (document instanceof IDocumentExtension3) {
        IDocumentExtension3 extension3 = (IDocumentExtension3) document;
        extension3.setDocumentPartitioner(PartitionScanner.TTCN3_PARTITIONING, partitioner);
    } else {
        document.setDocumentPartitioner(partitioner);
    }
    partitioner.connect(document);
    document.addDocumentListener(new IDocumentListener() {

        @Override
        public void documentAboutToBeChanged(final DocumentEvent event) {
            GlobalIntervalHandler.putInterval(event.getDocument(), null);
        }

        @Override
        public void documentChanged(final DocumentEvent event) {
        // Do nothing
        }
    });
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) IDocumentListener(org.eclipse.jface.text.IDocumentListener) DocumentEvent(org.eclipse.jface.text.DocumentEvent)

Example 12 with IDocumentListener

use of org.eclipse.jface.text.IDocumentListener in project titan.EclipsePlug-ins by eclipse.

the class DocumentSetupParticipant method setup.

@Override
public void setup(final IDocument document) {
    DocumentTracker.put((IFile) editor.getEditorInput().getAdapter(IFile.class), document);
    IDocumentPartitioner partitioner = new FastPartitioner(new PartitionScanner(), PartitionScanner.PARTITION_TYPES);
    if (document instanceof IDocumentExtension3) {
        IDocumentExtension3 extension3 = (IDocumentExtension3) document;
        extension3.setDocumentPartitioner(PartitionScanner.TTCNPP_PARTITIONING, partitioner);
    } else {
        document.setDocumentPartitioner(partitioner);
    }
    partitioner.connect(document);
    document.addDocumentListener(new IDocumentListener() {

        @Override
        public void documentAboutToBeChanged(final DocumentEvent event) {
            GlobalIntervalHandler.putInterval(event.getDocument(), null);
        }

        @Override
        public void documentChanged(final DocumentEvent event) {
        // Do nothing
        }
    });
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) IDocumentListener(org.eclipse.jface.text.IDocumentListener) DocumentEvent(org.eclipse.jface.text.DocumentEvent)

Example 13 with IDocumentListener

use of org.eclipse.jface.text.IDocumentListener in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class Editor method createSourceViewer.

@Override
protected ISourceViewer createSourceViewer(final Composite parent, final IVerticalRuler ruler, final int styles) {
    final ISourceViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles);
    getSourceViewerDecorationSupport(viewer);
    final IEditorInput input = getEditorInput();
    final IDocument document = getDocumentProvider().getDocument(input);
    file = new TestFile((FileEditorInput) input, getDocumentProvider());
    file.parse();
    document.addDocumentListener(new IDocumentListener() {

        @Override
        public void documentChanged(final DocumentEvent event) {
            file.parse();
        }

        @Override
        public void documentAboutToBeChanged(final DocumentEvent event) {
        }
    });
    return viewer;
}
Also used : TestFile(name.graf.emanuel.testfileeditor.model.TestFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IDocumentListener(org.eclipse.jface.text.IDocumentListener) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ProjectionViewer(org.eclipse.jface.text.source.projection.ProjectionViewer) DocumentEvent(org.eclipse.jface.text.DocumentEvent) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 14 with IDocumentListener

use of org.eclipse.jface.text.IDocumentListener in project watchdog by TestRoots.

the class EditorListener method listenToDocumentChanges.

/**
 * Adds a document change listener to the supplied editor. Fires a
 * {@link StartEditingEditorEvent} when a change to a document is made.
 *
 * @param partEditor
 * @throws IllegalArgumentException
 */
private void listenToDocumentChanges() throws IllegalArgumentException {
    IDocumentProvider documentProvider = editor.getDocumentProvider();
    document = documentProvider.getDocument(editor.getEditorInput());
    documentListener = new IDocumentListener() {

        @Override
        public void documentChanged(DocumentEvent event) {
            /*
				 * Three events exist that can influence the Levenshtein
				 * distance: 
				 * 1. Addition. In this case length=0 and text>0,  therefore max(length,text)=text=Levenshtein distance. 
				 * 2. Removal. In this case length>0 and text=0, therefore max(length,text)=length=Levenshtein distance. 
				 * 3. Modification. In this case length>0 and text>0, therefore max(length,text)>=Levenshtein distance.
				 * 
				 * So, in general it holds that modCount >= Levenshtein
				 * distance.
				 */
            int textLength = 0;
            if (event.getText() != null) {
                textLength = event.getText().length();
            }
            int modCount = Math.max(event.getLength(), textLength);
            WatchDogEventType.SUBSEQUENT_EDIT.process(new WatchDogEventType.EditorWithModCount(editor, modCount));
        }

        @Override
        public void documentAboutToBeChanged(DocumentEvent event) {
            WatchDogEventType.START_EDIT.process(editor);
        }
    };
    document.addDocumentListener(documentListener);
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IDocumentListener(org.eclipse.jface.text.IDocumentListener) DocumentEvent(org.eclipse.jface.text.DocumentEvent)

Example 15 with IDocumentListener

use of org.eclipse.jface.text.IDocumentListener in project xtext-eclipse by eclipse.

the class DocumentTokenSourceTest method setUp.

@Before
public void setUp() throws Exception {
    tokenSource = new DocumentTokenSource();
    tokenSource.setLexer(new Provider<Lexer>() {

        @Override
        public Lexer get() {
            return new org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer();
        }
    });
    document = new Document("");
    document.addDocumentListener(new IDocumentListener() {

        @Override
        public void documentChanged(DocumentEvent event) {
            tokenSource.updateStructure(event);
        }

        @Override
        public void documentAboutToBeChanged(DocumentEvent event) {
        }
    });
}
Also used : Lexer(org.eclipse.xtext.parser.antlr.Lexer) DocumentTokenSource(org.eclipse.xtext.ui.editor.model.DocumentTokenSource) IDocumentListener(org.eclipse.jface.text.IDocumentListener) Document(org.eclipse.jface.text.Document) DocumentEvent(org.eclipse.jface.text.DocumentEvent) Before(org.junit.Before)

Aggregations

IDocumentListener (org.eclipse.jface.text.IDocumentListener)28 DocumentEvent (org.eclipse.jface.text.DocumentEvent)27 IDocument (org.eclipse.jface.text.IDocument)11 ArrayList (java.util.ArrayList)6 Document (org.eclipse.jface.text.Document)5 IDocumentExtension3 (org.eclipse.jface.text.IDocumentExtension3)4 IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)4 FastPartitioner (org.eclipse.jface.text.rules.FastPartitioner)4 Composite (org.eclipse.swt.widgets.Composite)4 List (java.util.List)3 SourceViewer (org.eclipse.jface.text.source.SourceViewer)3 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)3 StyledText (org.eclipse.swt.custom.StyledText)3 RGB (org.eclipse.swt.graphics.RGB)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IFile (org.eclipse.core.resources.IFile)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2