use of org.eclipse.jface.text.ITextSelection in project webtools.sourceediting by eclipse.
the class JSPJavaSelectionProvider method getSelection.
static IJavaScriptElement[] getSelection(ITextEditor textEditor) {
IJavaScriptElement[] elements = null;
IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
ISelection selection = textEditor.getSelectionProvider().getSelection();
if (selection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection) selection;
// get the JSP translation object for this editor's document
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
if (model instanceof IDOMModel) {
IDOMModel xmlModel = (IDOMModel) model;
IDOMDocument xmlDoc = xmlModel.getDocument();
JsTranslationAdapter adapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
if (adapter != null) {
IJsTranslation translation = adapter.getJsTranslation(true);
elements = translation.getElementsFromJsRange(translation.getJavaScriptOffset(textSelection.getOffset()), translation.getJavaScriptOffset(textSelection.getOffset() + textSelection.getLength()));
}
}
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
if (elements == null) {
elements = new IJavaScriptElement[0];
}
return elements;
}
use of org.eclipse.jface.text.ITextSelection in project webtools.sourceediting by eclipse.
the class StructuredTextEditor method handleElementContentReplaced.
protected void handleElementContentReplaced() {
super.handleElementContentReplaced();
// queue a full revalidation of content
IDocument document = getDocumentProvider().getDocument(getEditorInput());
SourceViewerConfiguration sourceViewerConfiguration = getSourceViewerConfiguration();
if (document != null && sourceViewerConfiguration != null && sourceViewerConfiguration.getReconciler(getSourceViewer()) instanceof DirtyRegionProcessor) {
((DirtyRegionProcessor) sourceViewerConfiguration.getReconciler(getSourceViewer())).processDirtyRegion(new DirtyRegion(0, document.getLength(), DirtyRegion.INSERT, document.get()));
}
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=129906 - update
* selection to listeners
*/
ISelectionProvider selectionProvider = getSelectionProvider();
ISelection originalSelection = selectionProvider.getSelection();
if (selectionProvider instanceof StructuredSelectionProvider && originalSelection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection) originalSelection;
// make sure the old selection is actually still valid
if (!textSelection.isEmpty() && (document == null || textSelection.getOffset() + textSelection.getLength() <= document.getLength())) {
SelectionChangedEvent syntheticEvent = new SelectionChangedEvent(selectionProvider, new TextSelection(textSelection.getOffset(), textSelection.getLength()));
((StructuredSelectionProvider) selectionProvider).handleSelectionChanged(syntheticEvent);
((StructuredSelectionProvider) selectionProvider).handlePostSelectionChanged(syntheticEvent);
} else {
SelectionChangedEvent syntheticEvent = new SelectionChangedEvent(selectionProvider, new TextSelection(0, 0));
((StructuredSelectionProvider) selectionProvider).handleSelectionChanged(syntheticEvent);
((StructuredSelectionProvider) selectionProvider).handlePostSelectionChanged(syntheticEvent);
}
}
}
use of org.eclipse.jface.text.ITextSelection in project webtools.sourceediting by eclipse.
the class FindOccurrencesActionDelegate method run.
public void run(IAction action) {
boolean okay = false;
if (fEditor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) fEditor;
IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
if (document != null) {
ITextSelection textSelection = getTextSelection(textEditor);
FindOccurrencesProcessor findOccurrenceProcessor = getProcessorForCurrentSelection(document, textSelection);
if (findOccurrenceProcessor != null) {
if (textEditor.getEditorInput() instanceof IFileEditorInput) {
IFile file = ((IFileEditorInput) textEditor.getEditorInput()).getFile();
okay = findOccurrenceProcessor.findOccurrences(document, textSelection, file);
}
}
}
}
if (okay) {
// clear status message
PlatformStatusLineUtil.clearStatusLine();
} else {
// $NON-NLS-1$
String errorMessage = SSEUIMessages.FindOccurrencesActionProvider_0;
if (fEditor instanceof StructuredTextEditor) {
PlatformStatusLineUtil.displayTemporaryErrorMessage(((StructuredTextEditor) fEditor).getTextViewer(), errorMessage);
} else {
PlatformStatusLineUtil.displayErrorMessage(errorMessage);
PlatformStatusLineUtil.addOneTimeClearListener();
}
}
}
use of org.eclipse.jface.text.ITextSelection in project webtools.sourceediting by eclipse.
the class ToggleBreakpointsTarget method canToggleLineBreakpoints.
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart,
* org.eclipse.jface.viewers.ISelection)
*/
public boolean canToggleLineBreakpoints(IWorkbenchPart part, ISelection selection) {
ITextEditor editor = part.getAdapter(ITextEditor.class);
if (selection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection) selection;
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
if (document != null && textSelection.getOffset() > -1) {
int lineNumber = -1;
try {
lineNumber = document.getLineOfOffset(textSelection.getOffset());
} catch (BadLocationException e) {
}
if (lineNumber >= 0) {
ToggleBreakpointAction toggler = new ToggleBreakpointAction(editor, null);
toggler.update();
return toggler.isEnabled();
}
}
}
return false;
}
use of org.eclipse.jface.text.ITextSelection in project webtools.sourceediting by eclipse.
the class FindOccurrencesHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
ITextEditor textEditor = null;
if (editorPart instanceof ITextEditor)
textEditor = (ITextEditor) editorPart;
else {
Object o = editorPart.getAdapter(ITextEditor.class);
if (o != null)
textEditor = (ITextEditor) o;
}
boolean okay = false;
if (textEditor != null) {
IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
if (document != null) {
ITextSelection textSelection = getTextSelection(textEditor);
FindOccurrencesProcessor findOccurrenceProcessor = getProcessorForCurrentSelection(document, textSelection);
if (findOccurrenceProcessor != null) {
if (textEditor.getEditorInput() instanceof IFileEditorInput) {
IFile file = ((IFileEditorInput) textEditor.getEditorInput()).getFile();
okay = findOccurrenceProcessor.findOccurrences(document, textSelection, file);
}
}
}
}
if (okay) {
// clear status message
PlatformStatusLineUtil.clearStatusLine();
} else {
// $NON-NLS-1$
String errorMessage = SSEUIMessages.FindOccurrencesActionProvider_0;
if (textEditor instanceof StructuredTextEditor) {
PlatformStatusLineUtil.displayTemporaryErrorMessage(((StructuredTextEditor) textEditor).getTextViewer(), errorMessage);
} else {
PlatformStatusLineUtil.displayErrorMessage(errorMessage);
PlatformStatusLineUtil.addOneTimeClearListener();
}
}
return null;
}
Aggregations