use of org.eclipse.jface.text.ITextSelection in project dbeaver by serge-rider.
the class MorphDelimitedListHandler method execute.
@Override
public Object execute(ExecutionEvent executionEvent) throws ExecutionException {
Shell activeShell = HandlerUtil.getActiveShell(executionEvent);
BaseTextEditor textEditor = BaseTextEditor.getTextEditor(HandlerUtil.getActiveEditor(executionEvent));
if (textEditor != null) {
IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
ISelectionProvider provider = textEditor.getSelectionProvider();
if (provider != null) {
ISelection selection = provider.getSelection();
if (selection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection) selection;
if (textSelection.getLength() <= 0) {
UIUtils.showMessageBox(activeShell, "Morph text", "Text selection is empty. You need to select some text to morph", SWT.ICON_INFORMATION);
return null;
}
String formattedText = morphText(activeShell, textSelection.getText());
if (formattedText != null) {
try {
document.replace(textSelection.getOffset(), textSelection.getLength(), formattedText);
} catch (BadLocationException e) {
DBWorkbench.getPlatformUI().showError("Morph text", "Error replacing text", e);
}
}
}
}
}
return null;
}
use of org.eclipse.jface.text.ITextSelection in project dbeaver by serge-rider.
the class DatabaseLaunchContributionItem method extractSelectedObjects.
protected Object[] extractSelectedObjects() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return NO_OBJECTS;
}
ISelection selection = window.getSelectionService().getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structured = (IStructuredSelection) selection;
Object[] array = structured.toArray();
Object o = structured.getFirstElement();
if (o instanceof IEditorPart) {
IEditorPart part = (IEditorPart) o;
array[0] = part.getEditorInput();
}
return array;
}
if (selection instanceof ITextSelection) {
IWorkbenchPage activePage = window.getActivePage();
if (activePage != null) {
IEditorPart activeEditor = activePage.getActiveEditor();
DBSObject databaseObject = DebugUI.extractDatabaseObject(activeEditor);
if (databaseObject != null) {
return new Object[] { databaseObject };
}
}
}
return NO_OBJECTS;
}
use of org.eclipse.jface.text.ITextSelection in project dbeaver by serge-rider.
the class ToggleProcedureBreakpointTarget method toggleLineBreakpoints.
@Override
public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
IEditorPart editorPart = (IEditorPart) part;
IResource resource = extractResource(editorPart, selection);
if (resource == null) {
return;
}
DBSObject databaseObject = DebugUI.extractDatabaseObject(editorPart);
if (databaseObject == null) {
return;
}
DBNDatabaseNode node = DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(new VoidProgressMonitor(), databaseObject, false);
if (node == null) {
return;
}
String nodeItemPath = node.getNodeItemPath();
ITextSelection textSelection = (ITextSelection) selection;
int lineNumber = textSelection.getStartLine();
IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(DBGConstants.MODEL_IDENTIFIER_DATABASE);
for (IBreakpoint breakpoint : breakpoints) {
if (breakpoint instanceof IDatabaseBreakpoint) {
IDatabaseBreakpoint databaseBreakpoint = (IDatabaseBreakpoint) breakpoint;
if (nodeItemPath.equals(databaseBreakpoint.getNodePath())) {
if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) {
DebugUITools.deleteBreakpoints(new IBreakpoint[] { breakpoint }, part.getSite().getShell(), null);
return;
}
}
}
}
int charstart = -1, charend = -1;
DBGBreakpointDescriptor breakpointDescriptor = GeneralUtils.adapt(databaseObject, DBGBreakpointDescriptor.class);
if (breakpointDescriptor == null) {
throw new CoreException(GeneralUtils.makeErrorStatus("Object '" + DBUtils.getObjectFullName(databaseObject, DBPEvaluationContext.UI) + "' doesn't support breakpoints"));
}
// create line breakpoint (doc line numbers start at 0)
new DatabaseLineBreakpoint(databaseObject, node, resource, breakpointDescriptor, lineNumber + 1, charstart, charend, true);
}
use of org.eclipse.jface.text.ITextSelection in project dbeaver by serge-rider.
the class SQLEditorPropertyTester method test.
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (!(receiver instanceof SQLEditorBase)) {
return false;
}
SQLEditor editor = (SQLEditor) receiver;
final Control editorControl = editor.getEditorControl();
if (editorControl == null) {
return false;
}
boolean hasConnection = editor.getDataSourceContainer() != null;
switch(property) {
case PROP_CAN_EXECUTE:
// Do not check hasActiveQuery - sometimes jface don't update action enablement after cursor change/typing
return true;
/* && (!"statement".equals(expectedValue) || editor.hasActiveQuery())*/
case PROP_CAN_EXPLAIN:
return hasConnection && GeneralUtils.adapt(editor.getDataSource(), DBCQueryPlanner.class) != null;
case PROP_CAN_NAVIGATE:
{
// Check whether some word is under cursor
ISelectionProvider selectionProvider = editor.getSelectionProvider();
if (selectionProvider == null) {
return false;
}
ITextSelection selection = (ITextSelection) selectionProvider.getSelection();
IDocument document = editor.getDocument();
return selection != null && document != null && !new SQLIdentifierDetector(editor.getSyntaxManager().getDialect(), editor.getSyntaxManager().getStructSeparator(), editor.getSyntaxManager().getIdentifierQuoteStrings()).detectIdentifier(document, new Region(selection.getOffset(), selection.getLength())).isEmpty();
}
case PROP_CAN_EXPORT:
return hasConnection && editor.hasActiveQuery();
case PROP_HAS_SELECTION:
{
ISelection selection = editor.getSelectionProvider().getSelection();
return selection instanceof ITextSelection && ((ITextSelection) selection).getLength() > 0;
}
case PROP_FOLDING_ENABLED:
return editor.isFoldingEnabled();
case PROP_FOLDING_SUPPORTED:
return editor.getAnnotationModel() != null;
}
return false;
}
use of org.eclipse.jface.text.ITextSelection in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonContentAssistProcessor method computeCompletionProposals.
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
if (!(viewer.getDocument() instanceof JsonDocument)) {
return super.computeCompletionProposals(viewer, documentOffset);
}
maybeSwitchScope(documentOffset);
final JsonDocument document = (JsonDocument) viewer.getDocument();
final ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
int line = 0, lineOffset = 0, column = 0;
try {
line = document.getLineOfOffset(documentOffset);
lineOffset = document.getLineOffset(line);
column = selection.getOffset() - lineOffset;
} catch (BadLocationException e) {
}
final String prefix = extractPrefix(viewer, documentOffset);
// column to resolve the path
if (!prefix.isEmpty()) {
column -= prefix.length();
}
Model model = document.getModel(documentOffset - prefix.length());
currentPath = model.getPath(line, column);
isRefCompletion = referenceProposalProvider.canProvideProposal(model, currentPath);
Collection<Proposal> p;
if (isRefCompletion) {
updateStatus(model);
p = referenceProposalProvider.getProposals(currentPath, document, currentScope);
} else {
clearStatus();
p = proposalProvider.getProposals(currentPath, model, prefix);
}
final Collection<ICompletionProposal> proposals = getCompletionProposals(p, prefix, documentOffset);
// compute template proposals
if (!isRefCompletion) {
final ICompletionProposal[] templateProposals = super.computeCompletionProposals(viewer, documentOffset);
if (templateProposals != null && templateProposals.length > 0) {
proposals.addAll(Lists.newArrayList(templateProposals));
}
}
return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
Aggregations