use of org.eclipse.jface.text.ITextViewer in project dbeaver by serge-rider.
the class ContentFormatHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (activeEditor instanceof ContentEditor) {
IEditorPart editorPart = ((ContentEditor) activeEditor).getActiveEditor();
ITextViewer textViewer = editorPart.getAdapter(ITextViewer.class);
if (textViewer instanceof TextViewer) {
StyledText textWidget = textViewer.getTextWidget();
boolean oldEditable = textWidget.getEditable();
textWidget.setEditable(true);
try {
if (((TextViewer) textViewer).canDoOperation(SourceViewer.FORMAT)) {
((TextViewer) textViewer).doOperation(SourceViewer.FORMAT);
}
} finally {
textWidget.setEditable(oldEditable);
}
}
}
return null;
}
use of org.eclipse.jface.text.ITextViewer in project dbeaver by dbeaver.
the class ContentFormatHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (activeEditor instanceof ContentEditor) {
IEditorPart editorPart = ((ContentEditor) activeEditor).getActiveEditor();
ITextViewer textViewer = editorPart.getAdapter(ITextViewer.class);
if (textViewer instanceof TextViewer) {
StyledText textWidget = textViewer.getTextWidget();
boolean oldEditable = textWidget.getEditable();
textWidget.setEditable(true);
try {
if (((TextViewer) textViewer).canDoOperation(SourceViewer.FORMAT)) {
((TextViewer) textViewer).doOperation(SourceViewer.FORMAT);
}
} finally {
textWidget.setEditable(oldEditable);
}
}
}
return null;
}
use of org.eclipse.jface.text.ITextViewer in project dbeaver by dbeaver.
the class SQLContextInformer method searchInformation.
public void searchInformation(IRegion region) {
ITextViewer textViewer = editor.getTextViewer();
final DBCExecutionContext executionContext = editor.getExecutionContext();
if (region == null || textViewer == null || executionContext == null) {
return;
}
IDocument document = textViewer.getDocument();
if (document == null) {
return;
}
SQLWordPartDetector wordDetector = new SQLWordPartDetector(document, syntaxManager, region.getOffset());
wordRegion = wordDetector.detectIdentifier(document, region);
if (wordRegion.word.length() == 0) {
return;
}
String fullName = wordRegion.identifier;
String tableName = wordRegion.word;
boolean caseSensitive = false;
if (wordDetector.isQuoted(tableName)) {
tableName = DBUtils.getUnQuotedIdentifier(tableName, syntaxManager.getIdentifierQuoteStrings());
caseSensitive = true;
}
String[] containerNames = null;
if (!CommonUtils.equalObjects(fullName, tableName)) {
int divPos = fullName.indexOf(syntaxManager.getStructSeparator());
if (divPos != -1) {
String[] parts = wordDetector.splitIdentifier(fullName);
tableName = parts[parts.length - 1];
containerNames = ArrayUtils.remove(String.class, parts, parts.length - 1);
for (int i = 0; i < containerNames.length; i++) {
if (wordDetector.isQuoted(containerNames[i])) {
containerNames[i] = DBUtils.getUnQuotedIdentifier(containerNames[i], syntaxManager.getIdentifierQuoteStrings());
}
containerNames[i] = DBObjectNameCaseTransformer.transformName(editor.getDataSource(), containerNames[i]);
}
if (wordDetector.isQuoted(tableName)) {
tableName = DBUtils.getUnQuotedIdentifier(tableName, syntaxManager.getIdentifierQuoteStrings());
}
} else {
// Full name could be quoted
if (wordDetector.isQuoted(fullName)) {
String unquotedName = DBUtils.getUnQuotedIdentifier(tableName, syntaxManager.getIdentifierQuoteStrings());
if (unquotedName.equals(tableName)) {
caseSensitive = true;
}
}
}
}
final SQLDialect dialect = syntaxManager.getDialect();
keywordType = dialect.getKeywordType(fullName);
if (keywordType == DBPKeywordType.KEYWORD && region.getLength() > 1) {
// It is a keyword = let's use whole selection
try {
fullName = document.get(region.getOffset(), region.getLength());
} catch (BadLocationException e) {
log.warn(e);
}
}
keywords = new String[] { fullName };
if (keywordType == DBPKeywordType.KEYWORD || keywordType == DBPKeywordType.FUNCTION) {
// Skip keywords
return;
}
final Map<String, ObjectLookupCache> contextCache = getLinksCache();
if (contextCache == null) {
return;
}
ObjectLookupCache tlc = contextCache.get(fullName);
if (tlc == null) {
// Start new word finder job
tlc = new ObjectLookupCache();
contextCache.put(fullName, tlc);
DBSStructureAssistant structureAssistant = DBUtils.getAdapter(DBSStructureAssistant.class, editor.getDataSource());
TablesFinderJob job = new TablesFinderJob(executionContext, structureAssistant, containerNames, tableName, caseSensitive, tlc);
job.schedule();
}
if (tlc.loading) {
// Wait for 1000ms maximum
for (int i = 0; i < 20; i++) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// interrupted - just go further
break;
}
if (!tlc.loading) {
break;
}
Display.getCurrent().readAndDispatch();
}
}
if (!tlc.loading) {
synchronized (this) {
objectReferences = tlc.references;
}
}
}
use of org.eclipse.jface.text.ITextViewer in project mylyn.docs by eclipse.
the class FileRefHyperlinkDetectorTest method testFileDoesNotExist.
@Test
public void testFileDoesNotExist() throws CoreException {
ImmutableList<String> fileRefPatterns = ImmutableList.of("include::(.+)\\[\\]", "image::(.+)\\[\\]");
FileRefHyperlinkDetector fileRefHyperlinkDetector = new FileRefHyperlinkDetector(project, fileRefPatterns);
ITextViewer mockTextViewer = mock(ITextViewer.class);
when(mockTextViewer.getDocument()).thenReturn(new Document("image::file-that-does-not-exist.png[]"));
IHyperlink[] detectHyperlinks = fileRefHyperlinkDetector.detectHyperlinks(mockTextViewer, new Region(7, 15), false);
assertThat(detectHyperlinks, is(nullValue()));
}
use of org.eclipse.jface.text.ITextViewer in project mylyn.docs by eclipse.
the class FileRefHyperlinkDetectorTest method testFindFileRefAndOpenHyperlink.
@Test
public void testFindFileRefAndOpenHyperlink() throws CoreException {
String asciidocFileName = "simon-scholz.adoc";
IFile file = project.getFile(asciidocFileName);
file.create(new ByteArrayInputStream("== Writing tests is kinda documentation".getBytes()), true, new NullProgressMonitor());
ImmutableList<String> fileRefPatterns = ImmutableList.of("include::(.+)\\[\\]", "image::(.+)\\[\\]");
FileRefHyperlinkDetector fileRefHyperlinkDetector = new FileRefHyperlinkDetector(file.getParent(), fileRefPatterns);
ITextViewer mockTextViewer = mock(ITextViewer.class);
when(mockTextViewer.getDocument()).thenReturn(new Document("include::" + asciidocFileName + "[]"));
IHyperlink[] detectHyperlinks = fileRefHyperlinkDetector.detectHyperlinks(mockTextViewer, new Region(9, 17), false);
assertThat(detectHyperlinks.length, is(1));
IHyperlink hyperlink = detectHyperlinks[0];
hyperlink.open();
IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
IEditorInput editorInput = activeEditor.getEditorInput();
if (editorInput instanceof IFileEditorInput) {
IFile editorFile = ((IFileEditorInput) editorInput).getFile();
assertThat(file, equalTo(editorFile));
}
}
Aggregations