use of org.eclipse.jface.text.ITextViewer in project webtools.sourceediting by eclipse.
the class OpenFileHyperlinkTracker method mouseMove.
/*
* @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
*/
public void mouseMove(MouseEvent event) {
if (event.widget instanceof Control && !((Control) event.widget).isFocusControl()) {
deactivate();
return;
}
if (!fActive) {
if (event.stateMask != fKeyModifierMask)
return;
// modifier was already pressed
fActive = true;
}
ITextViewer viewer = getTextViewer();
if (viewer == null) {
deactivate();
return;
}
StyledText text = viewer.getTextWidget();
if (text == null || text.isDisposed()) {
deactivate();
return;
}
if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() != 0) {
deactivate();
return;
}
IRegion region = null;
int offset = getCurrentTextOffset();
IOpenOn openOn = OpenOnProvider.getInstance().getOpenOn(getTextViewer().getDocument(), offset);
if (openOn != null) {
region = openOn.getOpenOnRegion(getTextViewer().getDocument(), offset);
}
if (region == null || region.getLength() == 0) {
repairRepresentation();
return;
}
highlightRegion(viewer, region);
activateCursor(viewer);
}
use of org.eclipse.jface.text.ITextViewer in project dbeaver by serge-rider.
the class SQLCompletionProposal method validate.
@Override
public boolean validate(IDocument document, int offset, DocumentEvent event) {
if (event == null) {
return false;
}
SQLSyntaxManager syntaxManager = getContext().getSyntaxManager();
DBPDataSource dataSource = getContext().getDataSource();
final SQLWordPartDetector wordDetector = new SQLWordPartDetector(document, syntaxManager, offset);
String wordPart = wordDetector.getWordPart();
int divPos = wordPart.lastIndexOf(syntaxManager.getStructSeparator());
if (divPos != -1) {
if (divPos == wordPart.length() - 1) {
// It is valid only if full word matches (it should be the only proposal)
if (replacementString.equals(wordPart.substring(0, divPos))) {
{
// Call completion popup again
UIUtils.asyncExec(() -> {
IEditorPart activeEditor = UIUtils.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (activeEditor != null) {
ITextViewer textViewer = activeEditor.getAdapter(ITextViewer.class);
if (textViewer != null) {
textViewer.getTextOperationTarget().doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
}
}
});
}
}
return false;
}
wordPart = wordPart.substring(divPos + 1);
}
String wordLower = wordPart.toLowerCase(Locale.ENGLISH);
if (!CommonUtils.isEmpty(wordPart)) {
boolean matchContains = dataSource != null && dataSource.getContainer().getPreferenceStore().getBoolean(SQLPreferenceConstants.PROPOSALS_MATCH_CONTAINS);
boolean matched;
if (getObject() == null || !matchContains) {
// For keywords use strict matching
matched = (matchContains ? replacementFull.contains(wordLower) : replacementFull.startsWith(wordLower)) && (CommonUtils.isEmpty(event.getText()) || replacementFull.contains(event.getText().toLowerCase(Locale.ENGLISH))) || (this.replacementLast != null && this.replacementLast.startsWith(wordLower));
} else {
// For objects use fuzzy matching
int score = TextUtils.fuzzyScore(replacementFull, wordLower);
matched = (score > 0 && (CommonUtils.isEmpty(event.getText()) || TextUtils.fuzzyScore(replacementFull, event.getText()) > 0)) || (this.replacementLast != null && TextUtils.fuzzyScore(this.replacementLast, wordLower) > 0);
if (matched) {
setProposalScore(score);
}
}
if (matched) {
setPosition(wordDetector);
return true;
}
} else if (divPos != -1) {
// Most likely it is a column name after an alias - all columns are valid
if (getObject() != null) {
return true;
}
}
return false;
}
use of org.eclipse.jface.text.ITextViewer in project dbeaver by serge-rider.
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 dbeaver by serge-rider.
the class GenerateUUIDHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
if (activePart == null) {
return null;
}
IResultSetController rsc = activePart.getAdapter(IResultSetController.class);
if (rsc != null && UIUtils.hasFocus(rsc.getControl())) {
IResultSetSelection selection = rsc.getSelection();
if (selection != null && !selection.isEmpty()) {
for (Object cell : selection.toArray()) {
DBDAttributeBinding attr = selection.getElementAttribute(cell);
ResultSetRow row = selection.getElementRow(cell);
if (row != null && attr != null) {
ResultSetValueController valueController = new ResultSetValueController(rsc, attr, row, IValueController.EditType.NONE, null);
DBDValueHandler valueHandler = valueController.getValueHandler();
String uuid = generateUUID();
valueController.updateValue(uuid, false);
}
}
rsc.redrawData(false, false);
rsc.updateEditControls();
}
} else {
ITextViewer textViewer = activePart.getAdapter(ITextViewer.class);
if (textViewer != null) {
ISelection selection = textViewer.getSelectionProvider().getSelection();
if (selection instanceof TextSelection) {
try {
int offset = ((TextSelection) selection).getOffset();
int length = ((TextSelection) selection).getLength();
String uuid = generateUUID();
textViewer.getDocument().replace(offset, length, uuid);
textViewer.getSelectionProvider().setSelection(new TextSelection(offset + uuid.length(), 0));
} catch (BadLocationException e) {
DBWorkbench.getPlatformUI().showError("Insert UUID", "Error inserting UUID in text editor", e);
}
}
}
}
return null;
}
use of org.eclipse.jface.text.ITextViewer in project dbeaver by dbeaver.
the class ToggleBreakpointHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (activeEditor != null) {
SQLEditorBase sqlEditor = activeEditor.getAdapter(SQLEditorBase.class);
if (sqlEditor != null) {
ITextViewer textViewer = sqlEditor.getAdapter(ITextViewer.class);
if (textViewer != null) {
IVerticalRulerInfo rulerInfo = sqlEditor.getAdapter(IVerticalRulerInfo.class);
ToggleBreakpointAction action = new ToggleBreakpointAction(sqlEditor, textViewer.getDocument(), rulerInfo);
action.runWithEvent(new Event());
}
}
}
return null;
}
Aggregations