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;
}
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();
}
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);
}
}
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);
}
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);
}
}
Aggregations