Search in sources :

Example 1 with FindReplaceDocumentAdapter

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

the class ReconcilerViewer method getAllSnippetsAnnotations.

private Map<ProjectionAnnotation, Position> getAllSnippetsAnnotations() {
    Map<ProjectionAnnotation, Position> annotations = new HashMap<ProjectionAnnotation, Position>();
    IDocument document = getDocument();
    int curOffset = 0;
    FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(document);
    try {
        //$NON-NLS-1$
        IRegion startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false);
        while (startRegion != null && startRegion.getOffset() >= curOffset) {
            int startLine = document.getLineOfOffset(startRegion.getOffset());
            int startOffset = document.getLineOffset(startLine);
            curOffset = startOffset + document.getLineLength(startLine);
            //$NON-NLS-1$
            IRegion endRegion = frda.find(startRegion.getOffset(), "SNIPPET_END", true, false, false, false);
            if (endRegion != null) {
                int endLine = document.getLineOfOffset(endRegion.getOffset());
                int endOffset = document.getLineOffset(endLine);
                endOffset += document.getLineLength(endLine);
                curOffset = endOffset;
                String text = document.get(startOffset, endOffset - startOffset);
                ProjectionAnnotation annotation = new ProjectionAnnotation(true);
                annotation.setText(text);
                annotation.setRangeIndication(true);
                annotations.put(annotation, new Position(startOffset, endOffset - startOffset));
            }
            if (curOffset < document.getLength()) {
                //$NON-NLS-1$
                startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false);
            }
        }
    } catch (BadLocationException e) {
        ExceptionHandler.process(e);
    }
    return annotations;
}
Also used : ProjectionAnnotation(org.eclipse.jface.text.source.projection.ProjectionAnnotation) HashMap(java.util.HashMap) Position(org.eclipse.jface.text.Position) IDocument(org.eclipse.jface.text.IDocument) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with FindReplaceDocumentAdapter

use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project cubrid-manager by CUBRID.

the class SQLEditorComposite method createSQLEditor.

/**
	 * Create the SQL editor
	 */
private void createSQLEditor() {
    final Composite composite = new Composite(this, SWT.NONE);
    composite.setLayout(new FillLayout());
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    CompositeRuler ruler = new CompositeRuler();
    LineNumberRulerColumn lineCol = new LineNumberRulerColumn();
    lineCol.setBackground(ResourceManager.getColor(new RGB(236, 233, 216)));
    ruler.addDecorator(0, lineCol);
    sqlTextViewer = new SQLTextViewer(composite, ruler, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, queryEditor);
    viewerConfig = new SQLViewerConfiguration(queryEditor);
    sqlTextViewer.configure(viewerConfig);
    document = new SQLDocument();
    IDocumentPartitioner partitioner = new FastPartitioner(new SQLPartitionScanner(), SQLPartitionScanner.getAllTypes());
    document.setDocumentPartitioner(ISQLPartitions.SQL_PARTITIONING, partitioner);
    partitioner.connect(document);
    sqlTextViewer.setDocument(document);
    findReplaceDocAdapter = new FindReplaceDocumentAdapter(document);
    undoManager = new TextViewerUndoManager(50);
    undoManager.connect(sqlTextViewer);
    contentAssistant = viewerConfig.getContentAssistant(sqlTextViewer);
    contentAssistant.install(sqlTextViewer);
    recentlyUsedSQLcontentAssistant = viewerConfig.getRecentlyUsedContentAssistant(sqlTextViewer);
    recentlyUsedSQLcontentAssistant.install(sqlTextViewer);
    formatHandler = new TextViewerOperationHandler(sqlTextViewer, ISourceViewer.FORMAT);
    contentAssistHandler = new TextViewerOperationHandler(sqlTextViewer, ISourceViewer.CONTENTASSIST_PROPOSALS);
    text = (StyledText) sqlTextViewer.getTextWidget();
    text.setIndent(1);
    text.setData(SQL_EDITOR_FLAG, sqlTextViewer);
    createContextMenu();
    addListener();
}
Also used : LineNumberRulerColumn(org.eclipse.jface.text.source.LineNumberRulerColumn) SQLDocument(com.cubrid.common.ui.query.editor.SQLDocument) Composite(org.eclipse.swt.widgets.Composite) CompositeRuler(org.eclipse.jface.text.source.CompositeRuler) FillLayout(org.eclipse.swt.layout.FillLayout) SQLTextViewer(com.cubrid.common.ui.query.editor.SQLTextViewer) RGB(org.eclipse.swt.graphics.RGB) SQLViewerConfiguration(com.cubrid.common.ui.query.editor.SQLViewerConfiguration) TextViewerUndoManager(org.eclipse.jface.text.TextViewerUndoManager) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) GridData(org.eclipse.swt.layout.GridData) SQLPartitionScanner(com.cubrid.common.ui.query.editor.SQLPartitionScanner) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter)

Example 3 with FindReplaceDocumentAdapter

use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.

the class FindReplaceDocumentAdapterTest method testFind.

@org.junit.Test
public void testFind() {
    FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
    try {
        IRegion result = new Region(8, 11);
        // Find case-sensitive
        // $NON-NLS-1$
        IRegion r = findReplaceDocumentAdapter.find(0, "TestPackage", true, true, false, false);
        assertEquals(result, r);
        // $NON-NLS-1$
        r = findReplaceDocumentAdapter.find(0, "testpackage", true, true, false, false);
        assertNull(r);
        // Find non-case-sensitive
        // $NON-NLS-1$
        r = findReplaceDocumentAdapter.find(0, "TestPackage", true, false, false, false);
        assertEquals(r, result);
        // $NON-NLS-1$
        r = findReplaceDocumentAdapter.find(0, "testpackage", true, false, false, false);
        assertEquals(r, result);
    } catch (BadLocationException e) {
        Assert.assertTrue(false);
    }
}
Also used : Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 4 with FindReplaceDocumentAdapter

use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.

the class FindReplaceDocumentAdapterTest method testRegexFindLinebreak3.

@Test
public void testRegexFindLinebreak3() throws Exception {
    FindReplaceDocumentAdapter adapter = new FindReplaceDocumentAdapter(fDocument);
    String contents = "One\r\nTwo\r\n\r\nEnd";
    fDocument.set(contents);
    int two = contents.indexOf("Two");
    int end = contents.indexOf("End");
    IRegion region = adapter.find(0, "[a-zA-Z]+\\R", true, false, false, true);
    assertEquals(new Region(0, two), region);
    region = adapter.find(two, "[a-zA-Z]+\\R", true, false, false, true);
    assertEquals(new Region(two, 3 + 2), region);
    region = adapter.find(0, "[a-zA-Z]+\\R{2}", true, false, false, true);
    assertEquals(new Region(two, end - two), region);
}
Also used : Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) Test(org.junit.Test)

Example 5 with FindReplaceDocumentAdapter

use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.

the class FindReplaceDocumentAdapterTest method testBug386751.

/**
 * Test case for: https://bugs.eclipse.org/386751
 */
@Test
public void testBug386751() {
    FindReplaceDocumentAdapter adapter = new FindReplaceDocumentAdapter(fDocument);
    try {
        IRegion result = adapter.find(0, ".", true, false, true, false);
        assertNull(result);
    } catch (BadLocationException e) {
        Assert.assertTrue(false);
    }
}
Also used : FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Aggregations

FindReplaceDocumentAdapter (org.eclipse.jface.text.FindReplaceDocumentAdapter)35 IRegion (org.eclipse.jface.text.IRegion)24 Test (org.junit.Test)20 BadLocationException (org.eclipse.jface.text.BadLocationException)18 Region (org.eclipse.jface.text.Region)12 IDocument (org.eclipse.jface.text.IDocument)7 Document (org.eclipse.jface.text.Document)4 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 Position (org.eclipse.jface.text.Position)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 ProjectionAnnotation (org.eclipse.jface.text.source.projection.ProjectionAnnotation)2 MultiPageEditorPart (org.eclipse.ui.part.MultiPageEditorPart)2 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)2 Ignore (org.junit.Ignore)2 SQLDocument (com.cubrid.common.ui.query.editor.SQLDocument)1 SQLPartitionScanner (com.cubrid.common.ui.query.editor.SQLPartitionScanner)1 SQLTextViewer (com.cubrid.common.ui.query.editor.SQLTextViewer)1 SQLViewerConfiguration (com.cubrid.common.ui.query.editor.SQLViewerConfiguration)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1