use of org.eclipse.jface.text.TextSelection in project xtext-eclipse by eclipse.
the class WorkflowPropertyTester method test.
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (receiver == null)
return false;
IResource resource = (IResource) Platform.getAdapterManager().getAdapter(receiver, org.eclipse.core.resources.IResource.class);
if (resource != null) {
return WorkflowLaunchUtils.workflowFileAvailableForGrammarFile(resource);
} else if (receiver instanceof IOutlineNode) {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
XtextEditor activeEditor = (XtextEditor) activePage.getActiveEditor();
return WorkflowLaunchUtils.workflowFileAvailableFor(activeEditor);
}
TextSelection textSelection = (TextSelection) Platform.getAdapterManager().getAdapter(receiver, org.eclipse.jface.text.TextSelection.class);
if (textSelection != null) {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart activeEditor = activePage.getActiveEditor();
return WorkflowLaunchUtils.workflowFileAvailableFor(activeEditor);
}
return false;
}
use of org.eclipse.jface.text.TextSelection in project erlide_eclipse by erlang.
the class ErlangEditor method setSelection.
public void setSelection(final ISourceReference reference, final boolean moveCursor) {
if (getSelectionProvider() == null) {
return;
}
final ISelection selection = getSelectionProvider().getSelection();
if (selection instanceof TextSelection) {
final TextSelection textSelection = (TextSelection) selection;
if (moveCursor && (textSelection.getOffset() != 0 || textSelection.getLength() != 0)) {
markInNavigationHistory();
}
}
if (reference != null) {
StyledText textWidget = null;
final ISourceViewer sourceViewer = getSourceViewer();
if (sourceViewer == null) {
return;
}
textWidget = sourceViewer.getTextWidget();
if (textWidget == null) {
return;
}
try {
ISourceRange range = null;
range = reference.getSourceRange();
if (range == null) {
return;
}
int offset = range.getOffset();
int length = range.getLength();
if (offset < 0 || length < 0) {
return;
}
setHighlightRange(offset, length, moveCursor);
if (!moveCursor) {
return;
}
offset = -1;
length = -1;
if (reference instanceof IErlMember) {
range = ((IErlMember) reference).getNameRange();
if (range != null) {
offset = range.getOffset();
length = range.getLength();
}
} else if (reference instanceof IErlAttribute) {
range = ((IErlAttribute) reference).getNameRange();
if (range != null) {
offset = range.getOffset();
length = range.getLength();
}
} else if (reference instanceof IErlFunctionClause) {
range = ((IErlFunctionClause) reference).getNameRange();
if (range != null) {
offset = range.getOffset();
length = range.getLength();
}
}
if (offset > -1 && length > 0) {
try {
textWidget.setRedraw(false);
sourceViewer.revealRange(offset, length);
sourceViewer.setSelectedRange(offset, length);
} finally {
textWidget.setRedraw(true);
}
markInNavigationHistory();
}
} catch (final IllegalArgumentException x) {
}
} else if (moveCursor) {
resetHighlightRange();
markInNavigationHistory();
}
}
use of org.eclipse.jface.text.TextSelection in project erlide_eclipse by erlang.
the class SendToConsoleAction method getLineSelection.
protected ITextSelection getLineSelection(final ITextSelection selection0, final boolean beginningOfNextLine) {
ITextSelection selection = selection0;
final IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
if (selection.getLength() == 0) {
// don't use isEmpty()!
selection = ErlangAbstractHandler.extendSelectionToWholeLines(document, selection);
}
if (beginningOfNextLine) {
final int endLine = selection.getEndLine();
int offset;
try {
offset = document.getLineOffset(endLine) + document.getLineLength(endLine);
selection = new TextSelection(offset, 0);
} catch (final BadLocationException e) {
offset = document.getLength();
}
}
return selection;
}
use of org.eclipse.jface.text.TextSelection in project erlide_eclipse by erlang.
the class ErlideSelection method selectCompleteLine.
/**
* In event of partial selection, used to select the full lines involved.
*/
public void selectCompleteLine() {
final IRegion endLine = getEndLine();
final IRegion startLine = getStartLine();
textSelection = new TextSelection(doc, startLine.getOffset(), endLine.getOffset() + endLine.getLength() - startLine.getOffset());
}
use of org.eclipse.jface.text.TextSelection in project abstools by abstools.
the class WizardUtil method saveEditorAndGotoOffset.
/**
* Saves the editor and sets the selection to the offset insertOffset
* @param editor
* @param insertOffset
*/
protected static void saveEditorAndGotoOffset(ABSEditor editor, int insertOffset) {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().saveEditor(editor, false);
editor.getSelectionProvider().setSelection(new TextSelection(insertOffset, 0));
}
Aggregations