use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project translationstudio8 by heartsome.
the class DefaultCellSearchStrategy method executeSearch.
/** burke 修改find/replace界面修改 不需要fuzzySearch*/
//private boolean fuzzySearch;
public IRegion executeSearch(String findValue, String dataValue) {
// 如果查找的字符和单元格中的数据长度为 0,,则直接返回没有找到。
if (findValue == null || findValue.length() == 0 || dataValue == null || dataValue.length() == 0) {
return null;
}
Document doc = new Document(dataValue);
FindReplaceDocumentAdapter adapter = new FindReplaceDocumentAdapter(doc);
IRegion region;
try {
if (startOffset == -1) {
if (searchForward) {
startOffset = 0;
} else {
startOffset = adapter.length() - 1;
}
}
region = adapter.find(startOffset, findValue, searchForward, caseSensitive, wholeWord, regExSearch);
while (region != null) {
boolean inTag = false;
for (int i = region.getOffset(); i < region.getOffset() + region.getLength(); i++) {
Position tagRange = InnerTagUtil.getStyledTagRange(dataValue, i);
if (tagRange != null) {
if (searchForward) {
if (tagRange.getOffset() + tagRange.getLength() == dataValue.length()) {
// 如果句首是一个标记,则直接返回 null,会继续查找上一个文本段。
return null;
}
startOffset = tagRange.getOffset() + tagRange.getLength();
} else {
if (tagRange.offset == 0) {
// 如果句首是一个标记,则直接返回 null,会继续查找上一个文本段。
return null;
}
startOffset = tagRange.getOffset() - 1;
}
inTag = true;
break;
}
}
if (inTag) {
region = adapter.find(startOffset, findValue, searchForward, caseSensitive, wholeWord, regExSearch);
} else {
break;
}
}
return region;
} catch (BadLocationException e) {
return null;
}
}
use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project tdi-studio-se by Talend.
the class ReconcilerViewer method hasSnippetsModifications.
/**
* Check if there is any new snippet or if some has been deleted.
*
* @return
*/
private boolean hasSnippetsModifications() {
IDocument document = getDocument();
if (document == null) {
return false;
}
int curNbAnnotations = oldAnnotations.size();
int actualNbAnnotations = 0;
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) {
actualNbAnnotations++;
int endLine = document.getLineOfOffset(endRegion.getOffset());
int endOffset = document.getLineOffset(endLine);
endOffset += document.getLineLength(endLine);
curOffset = endOffset;
boolean contains = false;
String text = document.get(startOffset, endOffset - startOffset);
for (ProjectionAnnotation annotation : oldAnnotations.keySet()) {
Position pos = oldAnnotations.get(annotation);
if (annotation.getText().equals(text) && (startOffset == pos.getOffset())) {
contains = true;
}
}
if (!contains) {
return true;
}
}
if (curOffset < document.getLength()) {
//$NON-NLS-1$
startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false);
}
}
} catch (BadLocationException e) {
ExceptionHandler.process(e);
}
if (curNbAnnotations != actualNbAnnotations) {
return true;
}
return false;
}
use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project tdi-studio-se by Talend.
the class TalendJavaSourceViewer method createViewerForComponent.
public static ISourceViewer createViewerForComponent(Composite composite, int styles, CompilationUnitEditor editor, List<Variable> variableList, String uniqueName, String codePart) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String selectedPart = "[" + uniqueName + " " + codePart + " ] start";
IDocument originalDocument = editor.getDocumentProvider().getDocument(editor.getEditorInput());
int documentOffset = -1;
//$NON-NLS-1$
String globalFields = "";
//$NON-NLS-1$
String localFields = "";
//$NON-NLS-1$
globalFields = "\tprivate static java.util.Properties context = new java.util.Properties();\n";
//$NON-NLS-1$
globalFields += "\tprivate static final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>();\n";
IDocument newDoc = new Document();
boolean checkCode = false;
FindReplaceDocumentAdapter frda = null;
// hywang modified for bug 9180
String documentText = originalDocument.get();
if (documentText != null && !documentText.equals("") && documentText.length() > 0) {
//$NON-NLS-1$
frda = new FindReplaceDocumentAdapter(originalDocument);
}
try {
Region region = null;
if (frda != null) {
region = (Region) frda.find(0, selectedPart, true, false, false, false);
}
if (region != null) {
checkCode = true;
documentOffset = region.getOffset();
documentOffset = originalDocument.getLineOffset(originalDocument.getLineOfOffset(documentOffset) + 2);
JavaCompletionProcessor processor = new JavaCompletionProcessor(editor, new ContentAssistant(), IDocument.DEFAULT_CONTENT_TYPE);
boolean globalFieldsDone = false;
//$NON-NLS-1$
globalFields = "";
String className = editor.getPartName().substring(0, editor.getPartName().indexOf('.') + 1);
ICompletionProposal[] proposals = processor.computeCompletionProposals(editor.getViewer(), documentOffset);
for (ICompletionProposal curProposal : proposals) {
if (curProposal instanceof JavaCompletionProposal) {
JavaCompletionProposal javaProposal = ((JavaCompletionProposal) curProposal);
if (javaProposal.getJavaElement() instanceof SourceField) {
globalFieldsDone = true;
SourceField sourceField = (SourceField) javaProposal.getJavaElement();
//$NON-NLS-1$ //$NON-NLS-2$
globalFields += "\t" + sourceField.getSource() + "\n";
// System.out.println();
}
if (javaProposal.getJavaElement() == null && !globalFieldsDone) {
//$NON-NLS-1$
String[] str = javaProposal.getSortString().split(" ");
//$NON-NLS-1$
String variable = "";
for (int i = str.length - 1; i >= 0; i--) {
//$NON-NLS-1$
variable += str[i].length() == 0 ? " " : str[i];
}
if (variable.contains(className)) {
continue;
}
//$NON-NLS-1$
variable += ";";
//$NON-NLS-1$ //$NON-NLS-2$
localFields += "\t\t" + variable + "\n";
// System.out.println(variable);
}
}
}
}
} catch (BadLocationException e) {
ExceptionHandler.process(e);
} catch (JavaModelException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
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");
buff.append(globalFields);
//$NON-NLS-1$
buff.append("\tpublic void myFunction(){\n");
buff.append(localFields);
documentOffset = buff.toString().length();
//$NON-NLS-1$
buff.append("\n\t\n}\n}");
newDoc.set(buff.toString());
return initializeViewer(composite, styles, checkCode, newDoc, documentOffset);
}
use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project tdi-studio-se by Talend.
the class TalendJavaEditor method placeCursorToSelection.
private void placeCursorToSelection() {
String mainPart;
if (process != null && (ComponentCategory.CATEGORY_4_MAPREDUCE.getName().equals(process.getComponentsType()))) {
//$NON-NLS-1$ //$NON-NLS-2$
mainPart = "[" + currentSelection + " mrconfig ] start";
} else if (process != null && (ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType()))) {
//$NON-NLS-1$ //$NON-NLS-2$
mainPart = "[" + currentSelection + " sparkconfig ] start";
} else if (process != null && (ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType()))) {
//$NON-NLS-1$ //$NON-NLS-2$
mainPart = "[" + currentSelection + " sparkstreamingconfig ] start";
} else {
//$NON-NLS-1$ //$NON-NLS-2$
mainPart = "[" + currentSelection + " main ] start";
}
//$NON-NLS-1$ //$NON-NLS-2$
String assignmentPart = "currentComponent = \"" + currentSelection + "\";";
if (getDocumentProvider() == null) {
return;
}
IDocument doc = getDocumentProvider().getDocument(getEditorInput());
// TDI-21733:since the code page for joblet now will be null,must add the judgement.
if (doc != null) {
FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(doc);
try {
Region region = (Region) frda.find(0, mainPart, true, false, false, false);
if (region != null) {
Region region2 = (Region) frda.find(region.getOffset(), assignmentPart, true, false, false, false);
if (region2 != null) {
selectAndReveal(region2.getOffset(), assignmentPart.length());
} else {
selectAndReveal(region.getOffset(), mainPart.length());
}
} else {
selectAndReveal(0, 0);
}
} catch (BadLocationException e) {
selectAndReveal(0, 0);
}
}
}
use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.
the class FindReplaceDocumentAdapterTest method testFindCaretAtEndStart.
@Test
public void testFindCaretAtEndStart() {
FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
try {
// Find forward when caret is just before a word
// $NON-NLS-1$
IRegion r = findReplaceDocumentAdapter.find(19, "TestPackage", false, false, false, false);
assertEquals(new Region(8, 11), r);
} catch (BadLocationException e) {
Assert.assertTrue(false);
}
}
Aggregations